]>
Dogcows Code - chaz/tint2/blob - src/taskbar/taskbar.c
1 /**************************************************************************
5 * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
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.
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 **************************************************************************/
21 #include <X11/Xutil.h>
22 #include <X11/Xatom.h>
42 for (i
=0 ; i
< nb_panel
; i
++) {
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
);
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
);
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
);
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
;
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
;
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);
87 if (!panel
->g_task
.maximum_width
&& panel_horizontal
)
88 panel
->g_task
.maximum_width
= server
.monitor
[panel
->monitor
].width
;
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;
97 //printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
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
));
106 if (j
== server
.desktop
&& tskbar
->area
.use_active
)
107 tskbar
->area
.is_active
= 1;
109 // add taskbar to the panel
110 panel
->area
.list
= g_slist_append(panel
->area
.list
, tskbar
);
116 void cleanup_taskbar()
124 for (i
=0 ; i
< nb_panel
; i
++) {
127 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
128 tskbar
= &panel
->taskbar
[j
];
129 l0
= tskbar
->area
.list
;
133 // careful : remove_task change l0->next
136 free_area (&tskbar
->area
);
138 // remove taskbar from the panel
139 panel
->area
.list
= g_slist_remove(panel
->area
.list
, tskbar
);
143 for (i
=0 ; i
< nb_panel
; i
++) {
145 if (panel
->taskbar
) {
146 free(panel
->taskbar
);
153 Task
*task_get_task (Window win
)
159 for (i
=0 ; i
< nb_panel
; i
++) {
160 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
161 for (l0
= panel1
[i
].taskbar
[j
].area
.list
; l0
; l0
= l0
->next
) {
172 GSList
* task_get_tasks(Window win
)
178 for (i
=0; i
<nb_panel
; ++i
) {
179 for (j
=0; j
<panel1
[i
].nb_desktop
; ++j
) {
180 for (it
=panel1
[i
].taskbar
[j
].area
.list
; it
; it
=it
->next
) {
183 l
= g_slist_prepend(l
, tsk
);
191 void task_refresh_tasklist ()
193 Window
*win
, active_win
;
194 int num_results
, i
, j
, k
;
198 win
= server_get_property (server
.root_win
, server
.atom
._NET_CLIENT_LIST
, XA_WINDOW
, &num_results
);
201 // Remove any old and set active win
204 for (i
=0 ; i
< nb_panel
; i
++) {
205 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
206 l0
= panel1
[i
].taskbar
[j
].area
.list
;
211 for (k
= 0; k
< num_results
; k
++) {
212 if (tsk
->win
== win
[k
]) break;
214 // careful : remove_task change l0->next
215 if (k
== num_results
) remove_task (tsk
);
221 for (i
= 0; i
< num_results
; i
++)
222 if (!task_get_task (win
[i
]))
229 void resize_taskbar(void *obj
)
231 Taskbar
*taskbar
= (Taskbar
*)obj
;
232 Panel
*panel
= (Panel
*)taskbar
->area
.panel
;
235 int task_count
, border_width
;
237 //printf("resize_taskbar : posx et width des taches\n");
238 taskbar
->area
.redraw
= 1;
240 if (taskbar
->area
.is_active
&& taskbar
->area
.use_active
)
241 border_width
= taskbar
->area
.pix_active
.border
.width
;
243 border_width
= taskbar
->area
.pix
.border
.width
;
245 if (panel_horizontal
) {
246 int pixel_width
, modulo_width
=0;
247 int x
, taskbar_width
;
249 // new task width for 'desktop'
250 task_count
= g_slist_length(taskbar
->area
.list
);
251 if (!task_count
) pixel_width
= panel
->g_task
.maximum_width
;
253 taskbar_width
= taskbar
->area
.width
- (2 * border_width
) - (2 * panel
->g_taskbar
.paddingxlr
);
254 if (task_count
>1) taskbar_width
-= ((task_count
-1) * panel
->g_taskbar
.paddingx
);
256 pixel_width
= taskbar_width
/ task_count
;
257 if (pixel_width
> panel
->g_task
.maximum_width
)
258 pixel_width
= panel
->g_task
.maximum_width
;
260 modulo_width
= taskbar_width
% task_count
;
263 taskbar
->task_width
= pixel_width
;
264 taskbar
->task_modulo
= modulo_width
;
265 taskbar
->text_width
= pixel_width
- panel
->g_task
.text_posx
- panel
->g_task
.area
.pix
.border
.width
- panel
->g_task
.area
.paddingx
;
267 // change pos_x and width for all tasks
268 x
= taskbar
->area
.posx
+ border_width
+ taskbar
->area
.paddingxlr
;
269 for (l
= taskbar
->area
.list
; l
; l
= l
->next
) {
271 if (!tsk
->area
.on_screen
) continue;
273 tsk
->area
.width
= pixel_width
;
279 x
+= tsk
->area
.width
+ panel
->g_taskbar
.paddingx
;
283 int pixel_height
, modulo_height
=0;
284 int y
, taskbar_height
;
286 // new task width for 'desktop'
287 task_count
= g_slist_length(taskbar
->area
.list
);
288 if (!task_count
) pixel_height
= panel
->g_task
.maximum_height
;
290 taskbar_height
= taskbar
->area
.height
- (2 * border_width
) - (2 * panel
->g_taskbar
.paddingxlr
);
291 if (task_count
>1) taskbar_height
-= ((task_count
-1) * panel
->g_taskbar
.paddingx
);
293 pixel_height
= taskbar_height
/ task_count
;
294 if (pixel_height
> panel
->g_task
.maximum_height
)
295 pixel_height
= panel
->g_task
.maximum_height
;
297 modulo_height
= taskbar_height
% task_count
;
300 taskbar
->task_width
= pixel_height
;
301 taskbar
->task_modulo
= modulo_height
;
302 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
;
304 // change pos_y and height for all tasks
305 y
= taskbar
->area
.posy
+ border_width
+ taskbar
->area
.paddingxlr
;
306 for (l
= taskbar
->area
.list
; l
; l
= l
->next
) {
308 if (!tsk
->area
.on_screen
) continue;
310 tsk
->area
.height
= pixel_height
;
316 y
+= tsk
->area
.height
+ panel
->g_taskbar
.paddingx
;
This page took 0.05108 seconds and 4 git commands to generate.