]>
Dogcows Code - chaz/tint2/blob - src/tint.c
1 /**************************************************************************
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
29 #include <X11/Xlocale.h>
44 void signal_handler(int sig
)
46 // signal handler is light as it should be
47 panel
.signal_pending
= sig
;
54 signal(SIGUSR1
, signal_handler
);
55 signal(SIGINT
, signal_handler
);
56 signal(SIGTERM
, signal_handler
);
59 memset(&panel
, 0, sizeof(Panel
));
60 memset(&server
, 0, sizeof(Server_global
));
61 memset(&g_task
, 0, sizeof(Global_task
));
62 memset(&g_taskbar
, 0, sizeof(Area
));
63 panel
.clock
.area
.draw_foreground
= draw_foreground_clock
;
64 g_task
.area
.draw_foreground
= draw_foreground_task
;
67 // append full transparency background
68 //Area *back = calloc(1, sizeof(Area));
69 list_back
= g_slist_append(0, calloc(1, sizeof(Area
)));
71 server
.dsp
= XOpenDisplay (NULL
);
73 fprintf(stderr
, "Could not open display.\n");
77 server
.screen
= DefaultScreen (server
.dsp
);
78 server
.root_win
= RootWindow(server
.dsp
, server
.screen
);
79 server
.depth
= DefaultDepth (server
.dsp
, server
.screen
);
80 server
.visual
= DefaultVisual (server
.dsp
, server
.screen
);
81 server
.desktop
= server_get_current_desktop ();
83 XSetErrorHandler ((XErrorHandler
) server_catch_error
);
87 root
= RootWindow(display
, DefaultScreen(display
));
88 //create_main_window();
93 imlib_context_set_display (server
.dsp
);
94 imlib_context_set_visual (server
.visual
);
95 imlib_context_set_colormap (DefaultColormap (server
.dsp
, server
.screen
));
98 XSelectInput (server
.dsp
, server
.root_win
, PropertyChangeMask
|StructureNotifyMask
);
100 setlocale(LC_ALL
, "");
104 void window_action (Task
*tsk
, int action
)
108 set_close (tsk
->win
);
111 set_active(tsk
->win
);
114 XIconifyWindow (server
.dsp
, tsk
->win
, server
.screen
);
117 if (tsk
== panel
.task_active
) XIconifyWindow (server
.dsp
, tsk
->win
, server
.screen
);
118 else set_active (tsk
->win
);
121 window_toggle_shade (tsk
->win
);
127 void event_button_press (int x
, int y
)
129 if (panel
.mode
== SINGLE_DESKTOP
) {
130 // drag and drop disabled
131 XLowerWindow (server
.dsp
, window
.main_win
);
137 for (l0
= panel
.area
.list
; l0
; l0
= l0
->next
) {
139 if (x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
145 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
147 if (x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
148 panel
.task_drag
= tsk
;
154 XLowerWindow (server
.dsp
, window
.main_win
);
158 void event_button_release (int button
, int x
, int y
)
160 int action
= TOGGLE_ICONIFY
;
164 action
= panel
.mouse_middle
;
167 action
= panel
.mouse_right
;
170 action
= panel
.mouse_scroll_up
;
173 action
= panel
.mouse_scroll_down
;
177 // TODO: ne pas afficher les taskbar invisibles
178 //if (panel.mode != MULTI_DESKTOP && desktop != server.desktop) continue;
183 for (l0
= panel
.area
.list
; l0
; l0
= l0
->next
) {
185 if (x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
189 // TODO: check better solution to keep window below
190 XLowerWindow (server
.dsp
, window
.main_win
);
195 // drag and drop task
196 if (panel
.task_drag
) {
197 if (tskbar
!= panel
.task_drag
->area
.parent
&& action
== TOGGLE_ICONIFY
) {
198 windows_set_desktop(panel
.task_drag
->win
, tskbar
->desktop
);
199 if (tskbar
->desktop
== server
.desktop
)
200 set_active(panel
.task_drag
->win
);
204 else panel
.task_drag
= 0;
208 if (panel
.mode
== MULTI_DESKTOP
)
209 if (tskbar
->desktop
!= server
.desktop
&& action
!= CLOSE
)
210 set_desktop (tskbar
->desktop
);
215 for (l
= tskbar
->area
.list
; l
; l
= l
->next
) {
217 if (x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
218 window_action (tsk
, action
);
223 // to keep window below
224 XLowerWindow (server
.dsp
, window
.main_win
);
228 void event_property_notify (Window win
, Atom at
)
231 if (win
== server
.root_win
) {
232 if (!server
.got_root_win
) {
233 XSelectInput (server
.dsp
, server
.root_win
, PropertyChangeMask
|StructureNotifyMask
);
234 server
.got_root_win
= 1;
237 /* Change number of desktops */
238 else if (at
== server
.atom
._NET_NUMBER_OF_DESKTOPS
) {
244 else if (at
== server
.atom
._NET_CURRENT_DESKTOP
) {
245 server
.desktop
= server_get_current_desktop ();
246 if (panel
.mode
!= MULTI_DESKTOP
) panel
.refresh
= 1;
249 else if (at
== server
.atom
._NET_CLIENT_LIST
) {
250 task_refresh_tasklist ();
254 else if (at
== server
.atom
._NET_ACTIVE_WINDOW
) {
255 Window w1
= window_get_active ();
256 Task
*t
= task_get_task(w1
);
257 if (t
) panel
.task_active
= t
;
260 if (XGetTransientForHint(server
.dsp
, w1
, &w2
) != 0)
261 if (w2
) panel
.task_active
= task_get_task(w2
);
265 /* Wallpaper changed */
266 else if (at
== server
.atom
._XROOTPMAP_ID
) {
267 XFreePixmap (server
.dsp
, server
.root_pmap
);
268 server
.root_pmap
= 0;
270 panel
.clock
.area
.redraw
= 1;
276 tsk
= task_get_task (win
);
278 //printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
280 /* Window title changed */
281 if (at
== server
.atom
._NET_WM_VISIBLE_NAME
|| at
== server
.atom
._NET_WM_NAME
|| at
== server
.atom
.WM_NAME
) {
283 tsk
->area
.redraw
= 1;
287 else if (at
== server
.atom
.WM_STATE
) {
288 if (window_is_iconified (win
))
289 if (panel
.task_active
== tsk
) panel
.task_active
= 0;
291 /* Window icon changed */
292 else if (at
== server
.atom
._NET_WM_ICON
) {
293 if (tsk
->icon_data
!= 0) XFree (tsk
->icon_data
);
294 tsk
->area
.redraw
= 1;
298 /* Window desktop changed */
299 else if (at
== server
.atom
._NET_WM_DESKTOP
) {
305 if (!server
.got_root_win
) server
.root_win
= RootWindow (server
.dsp
, server
.screen
);
310 void event_configure_notify (Window win
)
314 tsk
= task_get_task (win
);
317 /* TODO ??? voir ancien code !!
319 tskbar = tsk->area.parent;
320 int new_monitor = window_get_monitor (win);
321 int desktop = tskbar->desktop;
323 // task on the same monitor
324 if (tsk->id_taskbar == index(desktop, new_monitor)) return;
337 if (!panel
.clock
.time1_format
) return;
339 if (gettimeofday(&stv
, 0)) return;
341 if (abs(stv
.tv_sec
- panel
.clock
.clock
.tv_sec
) < panel
.clock
.time_precision
) return;
344 panel
.clock
.clock
.tv_sec
= stv
.tv_sec
;
345 panel
.clock
.clock
.tv_sec
-= panel
.clock
.clock
.tv_sec
% panel
.clock
.time_precision
;
346 panel
.clock
.area
.redraw
= 1;
351 int main (int argc
, char *argv
[])
358 c
= getopt (argc
, argv
, "c:");
362 if (server
.root_pmap
) XFreePixmap (server
.dsp
, server
.root_pmap
);
363 server
.root_pmap
= 0;
364 // read tint2rc config
367 i
= config_read_file (optarg
);
371 fprintf(stderr
, "usage: tint2 [-c] <config_file>\n");
377 window_draw_panel ();
379 x11_fd
= ConnectionNumber (server
.dsp
);
380 XSync (server
.dsp
, False
);
383 // thanks to AngryLlama for the timer
384 // Create a File Description Set containing x11_fd
386 FD_SET (x11_fd
, &fd
);
391 // Wait for X Event or a Timer
392 if (select(x11_fd
+1, &fd
, 0, 0, &tv
)) {
393 while (XPending (server
.dsp
)) {
394 XNextEvent(server
.dsp
, &e
);
398 if (e
.xbutton
.button
== 1) event_button_press (e
.xbutton
.x
, e
.xbutton
.y
);
402 event_button_release (e
.xbutton
.button
, e
.xbutton
.x
, e
.xbutton
.y
);
406 XCopyArea (server
.dsp
, server
.pmap
, window
.main_win
, server
.gc
, 0, 0, panel
.area
.width
, panel
.area
.height
, 0, 0);
410 //printf("PropertyNotify\n");
411 event_property_notify (e
.xproperty
.window
, e
.xproperty
.atom
);
414 case ConfigureNotify
:
415 if (e
.xconfigure
.window
== server
.root_win
)
418 if (panel
.mode
== MULTI_MONITOR
)
419 event_configure_notify (e
.xconfigure
.window
);
426 switch (panel
.signal_pending
) {
435 if (panel
.refresh
&& !panel
.sleep_mode
) {
437 //printf(" *** visual_refresh\n");
This page took 0.049838 seconds and 4 git commands to generate.