]> Dogcows Code - chaz/tint2/blob - src/taskbar/taskbar.c
fixed bugs with new design (first step)
[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 "taskbar.h"
30 #include "server.h"
31 #include "window.h"
32 #include "panel.h"
33
34
35
36 Task *task_get_task (Window win)
37 {
38 Task *tsk;
39 GSList *l0;
40 int i, nb;
41
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) {
45 tsk = l0->data;
46 if (win == tsk->win) return tsk;
47 }
48 }
49 return 0;
50 }
51
52
53 void task_refresh_tasklist ()
54 {
55 Window *win, active_win;
56 int num_results, i, j, nb;
57 GSList *l0;
58 Task *tsk;
59
60 win = server_get_property (server.root_win, server.atom._NET_CLIENT_LIST, XA_WINDOW, &num_results);
61
62 if (!win) return;
63
64 // Remove any old and set active win
65 active_win = window_get_active ();
66
67 nb = panel.nb_desktop * panel.nb_monitor;
68 for (i=0 ; i < nb ; i++) {
69 for (l0 = panel.taskbar[i].area.list; l0 ; l0 = l0->next) {
70 tsk = l0->data;
71
72 if (tsk->win == active_win) panel.task_active = tsk;
73
74 for (j = 0; j < num_results; j++) {
75 if (tsk->win == win[j]) break;
76 }
77 if (tsk->win != win[j]) remove_task (tsk);
78 }
79 }
80
81 // Add any new
82 for (i = 0; i < num_results; i++)
83 if (!task_get_task (win[i]))
84 add_task (win[i]);
85
86 XFree (win);
87 }
88
89
90 int resize_tasks (Taskbar *taskbar)
91 {
92 int ret, task_count, pixel_width, modulo_width=0;
93 int x, taskbar_width;
94 Task *tsk;
95 GSList *l;
96
97 // new task width for 'desktop'
98 task_count = g_slist_length(taskbar->area.list);
99 if (!task_count) pixel_width = g_task.maximum_width;
100 else {
101 taskbar_width = taskbar->area.width - (2 * g_taskbar.border.width) - ((task_count+1) * g_taskbar.paddingx);
102
103 pixel_width = taskbar_width / task_count;
104 if (pixel_width > g_task.maximum_width) pixel_width = g_task.maximum_width;
105 else modulo_width = taskbar_width % task_count;
106 }
107
108 if ((taskbar->task_width == pixel_width) && (taskbar->task_modulo == modulo_width)) {
109 ret = 0;
110 }
111 else {
112 ret = 1;
113 taskbar->task_width = pixel_width;
114 taskbar->task_modulo = modulo_width;
115 taskbar->text_width = pixel_width - g_task.text_posx - g_task.area.border.width - g_task.area.paddingx;
116 }
117
118 // change pos_x and width for all tasks
119 x = taskbar->area.posx + taskbar->area.border.width + taskbar->area.paddingx;
120 for (l = taskbar->area.list; l ; l = l->next) {
121 tsk = l->data;
122 tsk->area.posx = x;
123 tsk->area_active.posx = x;
124 tsk->area.width = pixel_width;
125 tsk->area_active.width = pixel_width;
126 if (modulo_width) {
127 tsk->area.width++;
128 tsk->area_active.width++;
129 modulo_width--;
130 }
131
132 x += tsk->area.width + g_taskbar.paddingx;
133 }
134 return ret;
135 }
136
137
138 // initialise taskbar posx and width
139 void resize_taskbar()
140 {
141 int taskbar_width, modulo_width, taskbar_on_screen;
142
143 if (panel.mode == MULTI_DESKTOP) taskbar_on_screen = panel.nb_desktop;
144 else taskbar_on_screen = panel.nb_monitor;
145
146 taskbar_width = panel.area.width - (2 * panel.area.paddingx) - (2 * panel.area.border.width);
147 if (panel.clock.time1_format)
148 taskbar_width -= (panel.clock.area.width + panel.area.paddingx);
149 taskbar_width = (taskbar_width - ((taskbar_on_screen-1) * panel.area.paddingx)) / taskbar_on_screen;
150
151 if (taskbar_on_screen > 1)
152 modulo_width = (taskbar_width - ((taskbar_on_screen-1) * panel.area.paddingx)) % taskbar_on_screen;
153 else
154 modulo_width = 0;
155
156 int posx, modulo, i, nb;
157 nb = panel.nb_desktop * panel.nb_monitor;
158 for (i=0 ; i < nb ; i++) {
159 if ((i % taskbar_on_screen) == 0) {
160 posx = panel.area.border.width + panel.area.paddingx;
161 modulo = modulo_width;
162 }
163 else posx += taskbar_width + panel.area.paddingx;
164
165 panel.taskbar[i].area.posx = posx;
166 panel.taskbar[i].area.width = taskbar_width;
167 if (modulo) {
168 panel.taskbar[i].area.width++;
169 modulo--;
170 }
171
172 resize_tasks(&panel.taskbar[i]);
173 }
174 }
175
176
This page took 0.042185 seconds and 5 git commands to generate.