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