]>
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
.posy
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingy
;
53 panel
->g_taskbar
.height
= panel
->area
.height
- (2 * panel
->g_taskbar
.posy
);
54 panel
->g_taskbar
.redraw
= 1;
55 panel
->g_taskbar
.on_screen
= 1;
58 panel
->g_task
.area
._draw_foreground
= draw_task
;
59 panel
->g_task
.area
.posy
= panel
->g_taskbar
.posy
+ panel
->g_taskbar
.pix
.border
.width
+ panel
->g_taskbar
.paddingy
;
60 panel
->g_task
.area
.height
= panel
->area
.height
- (2 * panel
->g_task
.area
.posy
);
61 panel
->g_task
.area
.use_active
= 1;
62 panel
->g_task
.area
.redraw
= 1;
63 panel
->g_task
.area
.on_screen
= 1;
65 if (panel
->g_task
.area
.pix
.border
.rounded
> panel
->g_task
.area
.height
/2) {
66 panel
->g_task
.area
.pix
.border
.rounded
= panel
->g_task
.area
.height
/2;
67 panel
->g_task
.area
.pix_active
.border
.rounded
= panel
->g_task
.area
.pix
.border
.rounded
;
70 // compute vertical position : text and icon
71 int height_ink
, height
;
72 get_text_size(panel
->g_task
.font_desc
, &height_ink
, &height
, panel
->area
.height
, "TAjpg", 5);
74 if (!panel
->g_task
.maximum_width
)
75 panel
->g_task
.maximum_width
= server
.monitor
[panel
->monitor
].width
;
78 panel
->g_task
.text_posx
= panel
->g_task
.area
.paddingxlr
+ panel
->g_task
.area
.pix
.border
.width
;
79 panel
->g_task
.text_posy
= (panel
->g_task
.area
.height
- height
) / 2.0;
80 if (panel
->g_task
.icon
) {
81 panel
->g_task
.icon_size1
= panel
->g_task
.area
.height
- (2 * panel
->g_task
.area
.paddingy
);
82 panel
->g_task
.text_posx
+= panel
->g_task
.icon_size1
;
83 panel
->g_task
.icon_posy
= (panel
->g_task
.area
.height
- panel
->g_task
.icon_size1
) / 2;
85 //printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
88 panel
->nb_desktop
= server
.nb_desktop
;
89 panel
->taskbar
= calloc(panel
->nb_desktop
, sizeof(Taskbar
));
90 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
91 tskbar
= &panel
->taskbar
[j
];
92 memcpy(&tskbar
->area
, &panel
->g_taskbar
, sizeof(Area
));
95 // add taskbar to the panel
96 panel
->area
.list
= g_slist_append(panel
->area
.list
, tskbar
);
102 void cleanup_taskbar()
110 for (i
=0 ; i
< nb_panel
; i
++) {
113 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
114 tskbar
= &panel
->taskbar
[j
];
115 l0
= tskbar
->area
.list
;
119 // careful : remove_task change l0->next
122 free_area (&tskbar
->area
);
124 // remove taskbar from the panel
125 panel
->area
.list
= g_slist_remove(panel
->area
.list
, tskbar
);
129 for (i
=0 ; i
< nb_panel
; i
++) {
131 if (panel
->taskbar
) {
132 free(panel
->taskbar
);
139 Task
*task_get_task (Window win
)
145 for (i
=0 ; i
< nb_panel
; i
++) {
146 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
147 for (l0
= panel1
[i
].taskbar
[j
].area
.list
; l0
; l0
= l0
->next
) {
158 void task_refresh_tasklist ()
160 Window
*win
, active_win
;
161 int num_results
, i
, j
, k
;
165 win
= server_get_property (server
.root_win
, server
.atom
._NET_CLIENT_LIST
, XA_WINDOW
, &num_results
);
169 // Remove any old and set active win
170 active_win
= window_get_active ();
172 task_active
->area
.is_active
= 0;
176 for (i
=0 ; i
< nb_panel
; i
++) {
177 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
178 l0
= panel1
[i
].taskbar
[j
].area
.list
;
183 if (tsk
->win
== active_win
) {
184 tsk
->area
.is_active
= 1;
188 for (k
= 0; k
< num_results
; k
++) {
189 if (tsk
->win
== win
[k
]) break;
191 // careful : remove_task change l0->next
192 if (k
== num_results
) remove_task (tsk
);
198 for (i
= 0; i
< num_results
; i
++)
199 if (!task_get_task (win
[i
]))
206 void resize_taskbar(void *obj
)
208 Taskbar
*taskbar
= (Taskbar
*)obj
;
209 Panel
*panel
= (Panel
*)taskbar
->area
.panel
;
210 int task_count
, pixel_width
, modulo_width
=0;
211 int x
, taskbar_width
;
215 //printf("resize_taskbar : posx et width des taches\n");
217 taskbar
->area
.redraw
= 1;
219 // new task width for 'desktop'
220 task_count
= g_slist_length(taskbar
->area
.list
);
221 if (!task_count
) pixel_width
= panel
->g_task
.maximum_width
;
223 taskbar_width
= taskbar
->area
.width
- (2 * panel
->g_taskbar
.pix
.border
.width
) - (2 * panel
->g_taskbar
.paddingxlr
);
224 if (task_count
>1) taskbar_width
-= ((task_count
-1) * panel
->g_taskbar
.paddingx
);
226 pixel_width
= taskbar_width
/ task_count
;
227 if (pixel_width
> panel
->g_task
.maximum_width
)
228 pixel_width
= panel
->g_task
.maximum_width
;
230 modulo_width
= taskbar_width
% task_count
;
233 if ((taskbar
->task_width
== pixel_width
) && (taskbar
->task_modulo
== modulo_width
)) {
236 taskbar
->task_width
= pixel_width
;
237 taskbar
->task_modulo
= modulo_width
;
238 taskbar
->text_width
= pixel_width
- panel
->g_task
.text_posx
- panel
->g_task
.area
.pix
.border
.width
- panel
->g_task
.area
.paddingx
;
241 // change pos_x and width for all tasks
242 x
= taskbar
->area
.posx
+ taskbar
->area
.pix
.border
.width
+ taskbar
->area
.paddingxlr
;
243 for (l
= taskbar
->area
.list
; l
; l
= l
->next
) {
246 tsk
->area
.width
= pixel_width
;
247 tsk
->area
.redraw
= 1;
253 x
+= tsk
->area
.width
+ panel
->g_taskbar
.paddingx
;
This page took 0.043771 seconds and 4 git commands to generate.