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