]> Dogcows Code - chaz/tint2/blob - src/taskbar/taskbar.c
New import
[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 Taskbar *tskbar;
39 Task *tsk;
40 GSList *l0;
41
42 for (l0 = panel.area.list; l0 ; l0 = l0->next) {
43 tskbar = l0->data;
44 GSList *l1;
45 for (l1 = tskbar->area.list; l1 ; l1 = l1->next) {
46 tsk = l1->data;
47 if (win == tsk->win) return tsk;
48 }
49 }
50
51 // nb = panel.nb_desktop * panel.nb_monitor;
52 //printf("task_get_task return 0\n");
53 return 0;
54 }
55
56
57 void task_refresh_tasklist ()
58 {
59 Window *win, active_win;
60 int num_results, i, j;
61
62 win = server_get_property (server.root_win, server.atom._NET_CLIENT_LIST, XA_WINDOW, &num_results);
63
64 if (!win) return;
65
66 /* Remove any old and set active win */
67 active_win = window_get_active ();
68
69 Task *tsk;
70 Taskbar *tskbar;
71 GSList *l0;
72 for (l0 = panel.area.list; l0 ; l0 = l0->next) {
73 tskbar = l0->data;
74 GSList *l1;
75 for (l1 = tskbar->area.list; l1 ; l1 = l1->next) {
76 tsk = l1->data;
77
78 if (tsk->win == active_win) panel.task_active = tsk;
79
80 for (j = 0; j < num_results; j++) {
81 if (tsk->win == win[j]) break;
82 }
83 if (tsk->win != win[j]) remove_task (tsk);
84 }
85 }
86
87 /* Add any new */
88 for (i = 0; i < num_results; i++) {
89 if (!task_get_task (win[i])) add_task (win[i]);
90 }
91
92 XFree (win);
93 }
94
95
96 int resize_tasks (Taskbar *taskbar)
97 {
98 int ret, task_count, pixel_width, modulo_width=0;
99 int x, taskbar_width;
100 Task *tsk;
101 GSList *l;
102
103 // new task width for 'desktop'
104 task_count = g_slist_length(taskbar->area.list);
105 if (!task_count) pixel_width = g_task.maximum_width;
106 else {
107 taskbar_width = taskbar->area.width - (2 * g_taskbar.border.width) - ((task_count+1) * g_taskbar.paddingx);
108
109 pixel_width = taskbar_width / task_count;
110 if (pixel_width > g_task.maximum_width) pixel_width = g_task.maximum_width;
111 else modulo_width = taskbar_width % task_count;
112 }
113
114 if ((taskbar->task_width == pixel_width) && (taskbar->task_modulo == modulo_width)) {
115 ret = 0;
116 }
117 else {
118 ret = 1;
119 taskbar->task_width = pixel_width;
120 taskbar->task_modulo = modulo_width;
121 taskbar->text_width = pixel_width - g_task.text_posx - g_task.area.border.width - g_task.area.paddingx;
122 }
123
124 // change pos_x and width for all tasks
125 x = taskbar->area.posx + taskbar->area.border.width + taskbar->area.paddingx;
126 for (l = taskbar->area.list; l ; l = l->next) {
127 tsk = l->data;
128 tsk->area.posx = x;
129 tsk->area_active.posx = x;
130 tsk->area.width = pixel_width;
131 tsk->area_active.width = pixel_width;
132 if (modulo_width) {
133 tsk->area.width++;
134 tsk->area_active.width++;
135 modulo_width--;
136 }
137
138 x += tsk->area.width + g_taskbar.paddingx;
139 }
140 return ret;
141 }
142
143
This page took 0.03722 seconds and 5 git commands to generate.