]> Dogcows Code - chaz/tint2/blob - src/taskbar/taskbar.c
removed old code
[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 if (panel->taskbar) {
46 free(panel->taskbar);
47 panel->taskbar = 0;
48 }
49
50 // taskbar
51 panel->g_taskbar._resize = resize_taskbar;
52 panel->g_taskbar.redraw = 1;
53 panel->g_taskbar.on_screen = 1;
54 if (panel_horizontal) {
55 panel->g_taskbar.posy = panel->area.pix.border.width + panel->area.paddingy;
56 panel->g_taskbar.height = panel->area.height - (2 * panel->g_taskbar.posy);
57 }
58 else {
59 panel->g_taskbar.posx = panel->area.pix.border.width + panel->area.paddingy;
60 panel->g_taskbar.width = panel->area.width - (2 * panel->g_taskbar.posx);
61 }
62
63 // task
64 panel->g_task.area._draw_foreground = draw_task;
65 panel->g_task.area.use_active = 1;
66 panel->g_task.area.redraw = 1;
67 panel->g_task.area.on_screen = 1;
68 if (panel_horizontal) {
69 panel->g_task.area.posy = panel->g_taskbar.posy + panel->g_taskbar.pix.border.width + panel->g_taskbar.paddingy;
70 panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy);
71 }
72 else {
73 panel->g_task.area.posx = panel->g_taskbar.posx + panel->g_taskbar.pix.border.width + panel->g_taskbar.paddingy;
74 panel->g_task.area.width = panel->area.width - (2 * panel->g_task.area.posx);
75 panel->g_task.area.height = panel->g_task.maximum_height;
76 }
77
78 if (panel->g_task.area.pix.border.rounded > panel->g_task.area.height/2) {
79 panel->g_task.area.pix.border.rounded = panel->g_task.area.height/2;
80 panel->g_task.area.pix_active.border.rounded = panel->g_task.area.pix.border.rounded;
81 }
82
83 // compute vertical position : text and icon
84 int height_ink, height;
85 get_text_size(panel->g_task.font_desc, &height_ink, &height, panel->area.height, "TAjpg", 5);
86
87 if (!panel->g_task.maximum_width && panel_horizontal)
88 panel->g_task.maximum_width = server.monitor[panel->monitor].width;
89
90 panel->g_task.text_posx = panel->g_task.area.pix.border.width + panel->g_task.area.paddingxlr;
91 panel->g_task.text_posy = (panel->g_task.area.height - height) / 2.0;
92 if (panel->g_task.icon) {
93 panel->g_task.icon_size1 = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
94 panel->g_task.text_posx += panel->g_task.icon_size1;
95 panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2;
96 }
97 //printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
98
99 Taskbar *tskbar;
100 panel->nb_desktop = server.nb_desktop;
101 panel->taskbar = calloc(panel->nb_desktop, sizeof(Taskbar));
102 for (j=0 ; j < panel->nb_desktop ; j++) {
103 tskbar = &panel->taskbar[j];
104 memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area));
105 tskbar->desktop = j;
106 if (j == server.desktop && tskbar->area.use_active)
107 tskbar->area.is_active = 1;
108
109 // add taskbar to the panel
110 panel->area.list = g_slist_append(panel->area.list, tskbar);
111 }
112 }
113 }
114
115
116 void cleanup_taskbar()
117 {
118 Panel *panel;
119 Taskbar *tskbar;
120 int i, j;
121 GSList *l0;
122 Task *tsk;
123
124 if (panel_config.g_task.font_desc)
125 pango_font_description_free(panel_config.g_task.font_desc);
126 for (i=0 ; i < nb_panel ; i++) {
127 panel = &panel1[i];
128
129 for (j=0 ; j < panel->nb_desktop ; j++) {
130 tskbar = &panel->taskbar[j];
131 l0 = tskbar->area.list;
132 while (l0) {
133 tsk = l0->data;
134 l0 = l0->next;
135 // careful : remove_task change l0->next
136 remove_task (tsk);
137 }
138 free_area (&tskbar->area);
139
140 // remove taskbar from the panel
141 panel->area.list = g_slist_remove(panel->area.list, tskbar);
142 }
143 }
144
145 for (i=0 ; i < nb_panel ; i++) {
146 panel = &panel1[i];
147 if (panel->taskbar) {
148 free(panel->taskbar);
149 panel->taskbar = 0;
150 }
151 }
152 }
153
154
155 Task *task_get_task (Window win)
156 {
157 Task *tsk;
158 GSList *l0;
159 int i, j;
160
161 for (i=0 ; i < nb_panel ; i++) {
162 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
163 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
164 tsk = l0->data;
165 if (win == tsk->win)
166 return tsk;
167 }
168 }
169 }
170 return 0;
171 }
172
173
174 void task_refresh_tasklist ()
175 {
176 Window *win, active_win;
177 int num_results, i, j, k;
178 GSList *l0;
179 Task *tsk;
180
181 win = server_get_property (server.root_win, server.atom._NET_CLIENT_LIST, XA_WINDOW, &num_results);
182 if (!win) return;
183
184 // Remove any old and set active win
185 active_win = window_get_active ();
186 if (task_active) {
187 task_active->area.is_active = 0;
188 task_active = 0;
189 }
190
191 for (i=0 ; i < nb_panel ; i++) {
192 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
193 l0 = panel1[i].taskbar[j].area.list;
194 while (l0) {
195 tsk = l0->data;
196 l0 = l0->next;
197
198 if (tsk->win == active_win) {
199 tsk->area.is_active = 1;
200 task_active = tsk;
201 }
202
203 for (k = 0; k < num_results; k++) {
204 if (tsk->win == win[k]) break;
205 }
206 // careful : remove_task change l0->next
207 if (k == num_results) remove_task (tsk);
208 }
209 }
210 }
211
212 // Add any new
213 for (i = 0; i < num_results; i++)
214 if (!task_get_task (win[i]))
215 add_task (win[i]);
216
217 XFree (win);
218 }
219
220
221 void resize_taskbar(void *obj)
222 {
223 Taskbar *taskbar = (Taskbar*)obj;
224 Panel *panel = (Panel*)taskbar->area.panel;
225 Task *tsk;
226 GSList *l;
227 int task_count;
228
229 //printf("resize_taskbar : posx et width des taches\n");
230
231 taskbar->area.redraw = 1;
232
233 if (panel_horizontal) {
234 int pixel_width, modulo_width=0;
235 int x, taskbar_width;
236
237 // new task width for 'desktop'
238 task_count = g_slist_length(taskbar->area.list);
239 if (!task_count) pixel_width = panel->g_task.maximum_width;
240 else {
241 taskbar_width = taskbar->area.width - (2 * panel->g_taskbar.pix.border.width) - (2 * panel->g_taskbar.paddingxlr);
242 if (task_count>1) taskbar_width -= ((task_count-1) * panel->g_taskbar.paddingx);
243
244 pixel_width = taskbar_width / task_count;
245 if (pixel_width > panel->g_task.maximum_width)
246 pixel_width = panel->g_task.maximum_width;
247 else
248 modulo_width = taskbar_width % task_count;
249 }
250
251 if ((taskbar->task_width == pixel_width) && (taskbar->task_modulo == modulo_width)) {
252 }
253 else {
254 taskbar->task_width = pixel_width;
255 taskbar->task_modulo = modulo_width;
256 taskbar->text_width = pixel_width - panel->g_task.text_posx - panel->g_task.area.pix.border.width - panel->g_task.area.paddingx;
257 }
258
259 // change pos_x and width for all tasks
260 x = taskbar->area.posx + taskbar->area.pix.border.width + taskbar->area.paddingxlr;
261 for (l = taskbar->area.list; l ; l = l->next) {
262 tsk = l->data;
263 if (!tsk->area.on_screen) continue;
264 tsk->area.posx = x;
265 tsk->area.width = pixel_width;
266 if (modulo_width) {
267 tsk->area.width++;
268 modulo_width--;
269 }
270
271 x += tsk->area.width + panel->g_taskbar.paddingx;
272 }
273 }
274 else {
275 int pixel_height, modulo_height=0;
276 int y, taskbar_height;
277
278 // new task width for 'desktop'
279 task_count = g_slist_length(taskbar->area.list);
280 if (!task_count) pixel_height = panel->g_task.maximum_height;
281 else {
282 taskbar_height = taskbar->area.height - (2 * panel->g_taskbar.pix.border.width) - (2 * panel->g_taskbar.paddingxlr);
283 if (task_count>1) taskbar_height -= ((task_count-1) * panel->g_taskbar.paddingx);
284
285 pixel_height = taskbar_height / task_count;
286 if (pixel_height > panel->g_task.maximum_height)
287 pixel_height = panel->g_task.maximum_height;
288 else
289 modulo_height = taskbar_height % task_count;
290 }
291
292 if ((taskbar->task_width == pixel_height) && (taskbar->task_modulo == modulo_height)) {
293 }
294 else {
295 taskbar->task_width = pixel_height;
296 taskbar->task_modulo = modulo_height;
297 taskbar->text_width = taskbar->area.width - (2 * panel->g_taskbar.paddingy) - panel->g_task.text_posx - panel->g_task.area.pix.border.width - panel->g_task.area.paddingx;
298 }
299
300 // change pos_y and height for all tasks
301 y = taskbar->area.posy + taskbar->area.pix.border.width + taskbar->area.paddingxlr;
302 for (l = taskbar->area.list; l ; l = l->next) {
303 tsk = l->data;
304 if (!tsk->area.on_screen) continue;
305 tsk->area.posy = y;
306 tsk->area.height = pixel_height;
307 if (modulo_height) {
308 tsk->area.height++;
309 modulo_height--;
310 }
311
312 y += tsk->area.height + panel->g_taskbar.paddingx;
313 }
314 }
315 }
316
317
318
This page took 0.045143 seconds and 5 git commands to generate.