]> Dogcows Code - chaz/tint2/blob - src/taskbar/taskbar.c
backward compatibility with tint-0.6 config, feature freeze
[chaz/tint2] / src / taskbar / taskbar.c
1 /**************************************************************************
2 *
3 * Tint2 : taskbar
4 *
5 * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **************************************************************************/
19
20 #include <X11/Xlib.h>
21 #include <X11/Xutil.h>
22 #include <X11/Xatom.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <glib.h>
27 #include <Imlib2.h>
28
29 #include "task.h"
30 #include "taskbar.h"
31 #include "server.h"
32 #include "window.h"
33 #include "panel.h"
34
35
36
37 void init_taskbar()
38 {
39 Panel *panel;
40 int i, j;
41
42 for (i=0 ; i < nb_panel ; i++) {
43 panel = &panel1[i];
44
45 // taskbar
46 panel->g_taskbar.posy = panel->area.pix.border.width + panel->area.paddingy;
47 panel->g_taskbar.height = panel->area.height - (2 * panel->g_taskbar.posy);
48 panel->g_taskbar.redraw = 1;
49
50 // task
51 panel->g_task.area.draw_foreground = draw_foreground_task;
52 panel->g_task.area.posy = panel->g_taskbar.posy + panel->g_taskbar.pix.border.width + panel->g_taskbar.paddingy;
53 panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy);
54 panel->g_task.area.use_active = 1;
55 panel->g_task.area.redraw = 1;
56
57 if (panel->g_task.area.pix.border.rounded > panel->g_task.area.height/2) {
58 panel->g_task.area.pix.border.rounded = panel->g_task.area.height/2;
59 panel->g_task.area.pix_active.border.rounded = panel->g_task.area.pix.border.rounded;
60 }
61
62 // compute vertical position : text and icon
63 int height_ink, height;
64 get_text_size(panel->g_task.font_desc, &height_ink, &height, panel->area.height, "TAjpg", 5);
65
66 if (!panel->g_task.maximum_width)
67 panel->g_task.maximum_width = server.monitor[panel->monitor].width;
68
69 // add task_icon_size
70 panel->g_task.text_posx = panel->g_task.area.paddingxlr + panel->g_task.area.pix.border.width;
71 panel->g_task.text_posy = (panel->g_task.area.height - height) / 2.0;
72 if (panel->g_task.icon) {
73 panel->g_task.icon_size1 = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
74 panel->g_task.text_posx += panel->g_task.icon_size1;
75 panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2;
76 }
77 //printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
78
79 Taskbar *tskbar;
80 panel->nb_desktop = server.nb_desktop;
81 panel->taskbar = calloc(panel->nb_desktop, sizeof(Taskbar));
82 for (j=0 ; j < panel->nb_desktop ; j++) {
83 tskbar = &panel->taskbar[j];
84 memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area));
85 tskbar->desktop = j;
86 }
87
88 resize_taskbar(panel);
89 }
90
91 }
92
93
94 void cleanup_taskbar()
95 {
96 Panel *panel;
97 int i, j;
98 GSList *l0;
99 Task *tsk;
100
101 for (i=0 ; i < nb_panel ; i++) {
102 panel = &panel1[i];
103
104 for (j=0 ; j < panel->nb_desktop ; j++) {
105 l0 = panel->taskbar[j].area.list;
106 while (l0) {
107 tsk = l0->data;
108 l0 = l0->next;
109 // careful : remove_task change l0->next
110 remove_task (tsk);
111 }
112 free_area (&panel->taskbar[j].area);
113 }
114 }
115
116 for (i=0 ; i < nb_panel ; i++) {
117 panel = &panel1[i];
118 free(panel->taskbar);
119 panel->taskbar = 0;
120 }
121 }
122
123
124 Task *task_get_task (Window win)
125 {
126 Task *tsk;
127 GSList *l0;
128 int i, j;
129
130 for (i=0 ; i < nb_panel ; i++) {
131 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
132 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
133 tsk = l0->data;
134 if (win == tsk->win)
135 return tsk;
136 }
137 }
138 }
139 return 0;
140 }
141
142
143 void task_refresh_tasklist ()
144 {
145 Window *win, active_win;
146 int num_results, i, j, k;
147 GSList *l0;
148 Task *tsk;
149
150 win = server_get_property (server.root_win, server.atom._NET_CLIENT_LIST, XA_WINDOW, &num_results);
151
152 if (!win) return;
153
154 // Remove any old and set active win
155 active_win = window_get_active ();
156 if (task_active) {
157 task_active->area.is_active = 0;
158 task_active = 0;
159 }
160
161 for (i=0 ; i < nb_panel ; i++) {
162 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
163 l0 = panel1[i].taskbar[j].area.list;
164 while (l0) {
165 tsk = l0->data;
166 l0 = l0->next;
167
168 if (tsk->win == active_win) {
169 tsk->area.is_active = 1;
170 task_active = tsk;
171 }
172
173 for (k = 0; k < num_results; k++) {
174 if (tsk->win == win[k]) break;
175 }
176 // careful : remove_task change l0->next
177 if (tsk->win != win[k]) remove_task (tsk);
178 }
179 }
180 }
181
182 // Add any new
183 for (i = 0; i < num_results; i++)
184 if (!task_get_task (win[i]))
185 add_task (win[i]);
186
187 XFree (win);
188 }
189
190
191 int resize_tasks (Taskbar *taskbar)
192 {
193 int ret, task_count, pixel_width, modulo_width=0;
194 int x, taskbar_width;
195 Task *tsk;
196 Panel *panel = (Panel*)taskbar->area.panel;
197 GSList *l;
198
199 // new task width for 'desktop'
200 task_count = g_slist_length(taskbar->area.list);
201 if (!task_count) pixel_width = panel->g_task.maximum_width;
202 else {
203 taskbar_width = taskbar->area.width - (2 * panel->g_taskbar.pix.border.width) - (2 * panel->g_taskbar.paddingxlr);
204 if (task_count>1) taskbar_width -= ((task_count-1) * panel->g_taskbar.paddingx);
205
206 pixel_width = taskbar_width / task_count;
207 if (pixel_width > panel->g_task.maximum_width)
208 pixel_width = panel->g_task.maximum_width;
209 else
210 modulo_width = taskbar_width % task_count;
211 }
212 //printf("monitor %d, resize_tasks %d %d\n", panel->monitor, task_count, pixel_width);
213
214 if ((taskbar->task_width == pixel_width) && (taskbar->task_modulo == modulo_width)) {
215 ret = 0;
216 }
217 else {
218 ret = 1;
219 taskbar->task_width = pixel_width;
220 taskbar->task_modulo = modulo_width;
221 taskbar->text_width = pixel_width - panel->g_task.text_posx - panel->g_task.area.pix.border.width - panel->g_task.area.paddingx;
222 }
223
224 // change pos_x and width for all tasks
225 x = taskbar->area.posx + taskbar->area.pix.border.width + taskbar->area.paddingxlr;
226 for (l = taskbar->area.list; l ; l = l->next) {
227 tsk = l->data;
228 tsk->area.posx = x;
229 tsk->area.width = pixel_width;
230 if (modulo_width) {
231 tsk->area.width++;
232 modulo_width--;
233 }
234
235 x += tsk->area.width + panel->g_taskbar.paddingx;
236 }
237 return ret;
238 }
239
240
241 // initialise taskbar posx and width
242 void resize_taskbar(void *p)
243 {
244 Panel *panel = p;
245 int taskbar_width, modulo_width, taskbar_on_screen;
246
247 if (panel_mode == MULTI_DESKTOP) taskbar_on_screen = panel->nb_desktop;
248 else taskbar_on_screen = 1;
249
250 taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width);
251 if (time1_format)
252 taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
253 taskbar_width = (taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx)) / taskbar_on_screen;
254
255 if (taskbar_on_screen > 1)
256 modulo_width = (taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx)) % taskbar_on_screen;
257 else
258 modulo_width = 0;
259
260 int i, modulo=0, posx=0;
261 for (i=0 ; i < panel->nb_desktop ; i++) {
262 if ((i % taskbar_on_screen) == 0) {
263 posx = panel->area.pix.border.width + panel->area.paddingxlr;
264 modulo = modulo_width;
265 }
266 else posx += taskbar_width + panel->area.paddingx;
267
268 panel->taskbar[i].area.posx = posx;
269 panel->taskbar[i].area.width = taskbar_width;
270 if (modulo) {
271 panel->taskbar[i].area.width++;
272 modulo--;
273 }
274
275 resize_tasks(&panel->taskbar[i]);
276 }
277 }
278
279
This page took 0.043554 seconds and 5 git commands to generate.