]>
Dogcows Code - chaz/tint2/blob - 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>
36 Task
*task_get_task (Window win
)
42 nb
= panel
.nb_desktop
* panel
.nb_monitor
;
43 for (i
=0 ; i
< nb
; i
++) {
44 for (l0
= panel
.taskbar
[i
].area
.list
; l0
; l0
= l0
->next
) {
46 if (win
== tsk
->win
) return tsk
;
53 void task_refresh_tasklist ()
55 Window
*win
, active_win
;
56 int num_results
, i
, j
, nb
;
60 win
= server_get_property (server
.root_win
, server
.atom
._NET_CLIENT_LIST
, XA_WINDOW
, &num_results
);
64 // Remove any old and set active win
65 active_win
= window_get_active ();
67 nb
= panel
.nb_desktop
* panel
.nb_monitor
;
68 for (i
=0 ; i
< nb
; i
++) {
69 l0
= panel
.taskbar
[i
].area
.list
;
74 if (tsk
->win
== active_win
) panel
.task_active
= tsk
;
76 for (j
= 0; j
< num_results
; j
++) {
77 if (tsk
->win
== win
[j
]) break;
79 // careful : remove_task change l0->next
80 if (tsk
->win
!= win
[j
]) remove_task (tsk
);
85 for (i
= 0; i
< num_results
; i
++)
86 if (!task_get_task (win
[i
]))
93 int resize_tasks (Taskbar
*taskbar
)
95 int ret
, task_count
, pixel_width
, modulo_width
=0;
100 // new task width for 'desktop'
101 task_count
= g_slist_length(taskbar
->area
.list
);
102 if (!task_count
) pixel_width
= g_task
.maximum_width
;
104 taskbar_width
= taskbar
->area
.width
- (2 * g_taskbar
.border
.width
) - ((task_count
+1) * g_taskbar
.paddingx
);
106 pixel_width
= taskbar_width
/ task_count
;
107 if (pixel_width
> g_task
.maximum_width
) pixel_width
= g_task
.maximum_width
;
108 else modulo_width
= taskbar_width
% task_count
;
111 if ((taskbar
->task_width
== pixel_width
) && (taskbar
->task_modulo
== modulo_width
)) {
116 taskbar
->task_width
= pixel_width
;
117 taskbar
->task_modulo
= modulo_width
;
118 taskbar
->text_width
= pixel_width
- g_task
.text_posx
- g_task
.area
.border
.width
- g_task
.area
.paddingx
;
121 // change pos_x and width for all tasks
122 x
= taskbar
->area
.posx
+ taskbar
->area
.border
.width
+ taskbar
->area
.paddingx
;
123 for (l
= taskbar
->area
.list
; l
; l
= l
->next
) {
126 tsk
->area_active
.posx
= x
;
127 tsk
->area
.width
= pixel_width
;
128 tsk
->area_active
.width
= pixel_width
;
131 tsk
->area_active
.width
++;
135 x
+= tsk
->area
.width
+ g_taskbar
.paddingx
;
141 // initialise taskbar posx and width
142 void resize_taskbar()
144 int taskbar_width
, modulo_width
, taskbar_on_screen
;
146 if (panel
.mode
== MULTI_DESKTOP
) taskbar_on_screen
= panel
.nb_desktop
;
147 else taskbar_on_screen
= panel
.nb_monitor
;
149 taskbar_width
= panel
.area
.width
- (2 * panel
.area
.paddingx
) - (2 * panel
.area
.border
.width
);
150 if (panel
.clock
.time1_format
)
151 taskbar_width
-= (panel
.clock
.area
.width
+ panel
.area
.paddingx
);
152 taskbar_width
= (taskbar_width
- ((taskbar_on_screen
-1) * panel
.area
.paddingx
)) / taskbar_on_screen
;
154 if (taskbar_on_screen
> 1)
155 modulo_width
= (taskbar_width
- ((taskbar_on_screen
-1) * panel
.area
.paddingx
)) % taskbar_on_screen
;
159 int posx
, modulo
, i
, nb
;
160 nb
= panel
.nb_desktop
* panel
.nb_monitor
;
161 for (i
=0 ; i
< nb
; i
++) {
162 if ((i
% taskbar_on_screen
) == 0) {
163 posx
= panel
.area
.border
.width
+ panel
.area
.paddingx
;
164 modulo
= modulo_width
;
166 else posx
+= taskbar_width
+ panel
.area
.paddingx
;
168 panel
.taskbar
[i
].area
.posx
= posx
;
169 panel
.taskbar
[i
].area
.width
= taskbar_width
;
171 panel
.taskbar
[i
].area
.width
++;
175 resize_tasks(&panel
.taskbar
[i
]);
This page took 0.043357 seconds and 4 git commands to generate.