]>
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
++) {
46 panel
->g_taskbar
._resize
= resize_taskbar
;
47 panel
->g_taskbar
.posy
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingy
;
48 panel
->g_taskbar
.height
= panel
->area
.height
- (2 * panel
->g_taskbar
.posy
);
49 panel
->g_taskbar
.redraw
= 1;
52 panel
->g_task
.area
._draw_foreground
= draw_foreground_task
;
53 panel
->g_task
.area
.posy
= panel
->g_taskbar
.posy
+ panel
->g_taskbar
.pix
.border
.width
+ panel
->g_taskbar
.paddingy
;
54 panel
->g_task
.area
.height
= panel
->area
.height
- (2 * panel
->g_task
.area
.posy
);
55 panel
->g_task
.area
.use_active
= 1;
56 panel
->g_task
.area
.redraw
= 1;
58 if (panel
->g_task
.area
.pix
.border
.rounded
> panel
->g_task
.area
.height
/2) {
59 panel
->g_task
.area
.pix
.border
.rounded
= panel
->g_task
.area
.height
/2;
60 panel
->g_task
.area
.pix_active
.border
.rounded
= panel
->g_task
.area
.pix
.border
.rounded
;
63 // compute vertical position : text and icon
64 int height_ink
, height
;
65 get_text_size(panel
->g_task
.font_desc
, &height_ink
, &height
, panel
->area
.height
, "TAjpg", 5);
67 if (!panel
->g_task
.maximum_width
)
68 panel
->g_task
.maximum_width
= server
.monitor
[panel
->monitor
].width
;
71 panel
->g_task
.text_posx
= panel
->g_task
.area
.paddingxlr
+ panel
->g_task
.area
.pix
.border
.width
;
72 panel
->g_task
.text_posy
= (panel
->g_task
.area
.height
- height
) / 2.0;
73 if (panel
->g_task
.icon
) {
74 panel
->g_task
.icon_size1
= panel
->g_task
.area
.height
- (2 * panel
->g_task
.area
.paddingy
);
75 panel
->g_task
.text_posx
+= panel
->g_task
.icon_size1
;
76 panel
->g_task
.icon_posy
= (panel
->g_task
.area
.height
- panel
->g_task
.icon_size1
) / 2;
78 //printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
81 panel
->nb_desktop
= server
.nb_desktop
;
82 panel
->taskbar
= calloc(panel
->nb_desktop
, sizeof(Taskbar
));
83 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
84 tskbar
= &panel
->taskbar
[j
];
85 memcpy(&tskbar
->area
, &panel
->g_taskbar
, sizeof(Area
));
92 void cleanup_taskbar()
99 for (i
=0 ; i
< nb_panel
; i
++) {
102 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
103 l0
= panel
->taskbar
[j
].area
.list
;
107 // careful : remove_task change l0->next
110 free_area (&panel
->taskbar
[j
].area
);
114 for (i
=0 ; i
< nb_panel
; i
++) {
116 if (panel
->taskbar
) {
117 free(panel
->taskbar
);
124 Task
*task_get_task (Window win
)
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
) {
143 void task_refresh_tasklist ()
145 Window
*win
, active_win
;
146 int num_results
, i
, j
, k
;
150 win
= server_get_property (server
.root_win
, server
.atom
._NET_CLIENT_LIST
, XA_WINDOW
, &num_results
);
154 // Remove any old and set active win
155 active_win
= window_get_active ();
157 task_active
->area
.is_active
= 0;
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
;
168 if (tsk
->win
== active_win
) {
169 tsk
->area
.is_active
= 1;
173 for (k
= 0; k
< num_results
; k
++) {
174 if (tsk
->win
== win
[k
]) break;
176 // careful : remove_task change l0->next
177 if (k
== num_results
) remove_task (tsk
);
183 for (i
= 0; i
< num_results
; i
++)
184 if (!task_get_task (win
[i
]))
191 int resize_tasks (Taskbar
*taskbar
)
193 int ret
, task_count
, pixel_width
, modulo_width
=0;
194 int x
, taskbar_width
;
196 Panel
*panel
= (Panel
*)taskbar
->area
.panel
;
199 // new task width for 'desktop'
200 task_count
= g_slist_length(taskbar
->area
.list
);
202 if (!task_count
) pixel_width
= panel
->g_task
.maximum_width
;
204 taskbar_width
= taskbar
->area
.width
- (2 * panel
->g_taskbar
.pix
.border
.width
) - (2 * panel
->g_taskbar
.paddingxlr
);
205 if (task_count
>1) taskbar_width
-= ((task_count
-1) * panel
->g_taskbar
.paddingx
);
207 pixel_width
= taskbar_width
/ task_count
;
208 if (pixel_width
> panel
->g_task
.maximum_width
)
209 pixel_width
= panel
->g_task
.maximum_width
;
211 modulo_width
= taskbar_width
% task_count
;
213 //printf("monitor %d, resize_tasks %d %d\n", panel->monitor, task_count, pixel_width);
215 if ((taskbar
->task_width
== pixel_width
) && (taskbar
->task_modulo
== modulo_width
)) {
220 taskbar
->task_width
= pixel_width
;
221 taskbar
->task_modulo
= modulo_width
;
222 taskbar
->text_width
= pixel_width
- panel
->g_task
.text_posx
- panel
->g_task
.area
.pix
.border
.width
- panel
->g_task
.area
.paddingx
;
225 // change pos_x and width for all tasks
226 x
= taskbar
->area
.posx
+ taskbar
->area
.pix
.border
.width
+ taskbar
->area
.paddingxlr
;
227 for (l
= taskbar
->area
.list
; l
; l
= l
->next
) {
230 tsk
->area
.width
= pixel_width
;
236 x
+= tsk
->area
.width
+ panel
->g_taskbar
.paddingx
;
242 // initialise taskbar posx and width
243 void resize_taskbar(void *obj
)
245 Panel
*panel
= ((Area
*)obj
)->panel
;
246 int taskbar_width
, modulo_width
, taskbar_on_screen
;
248 if (panel_mode
== MULTI_DESKTOP
) taskbar_on_screen
= panel
->nb_desktop
;
249 else taskbar_on_screen
= 1;
251 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
253 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
254 //taskbar_width -= (panel->trayer.area.width + panel->area.paddingx);
256 taskbar_width
= (taskbar_width
- ((taskbar_on_screen
-1) * panel
->area
.paddingx
)) / taskbar_on_screen
;
258 if (taskbar_on_screen
> 1)
259 modulo_width
= (taskbar_width
- ((taskbar_on_screen
-1) * panel
->area
.paddingx
)) % taskbar_on_screen
;
263 int i
, modulo
=0, posx
=0;
264 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
265 if ((i
% taskbar_on_screen
) == 0) {
266 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
267 modulo
= modulo_width
;
269 else posx
+= taskbar_width
+ panel
->area
.paddingx
;
271 panel
->taskbar
[i
].area
.posx
= posx
;
272 panel
->taskbar
[i
].area
.width
= taskbar_width
;
274 panel
->taskbar
[i
].area
.width
++;
278 set_redraw (&panel
->taskbar
[i
].area
);
279 resize_tasks(&panel
->taskbar
[i
]);
This page took 0.045607 seconds and 4 git commands to generate.