]> Dogcows Code - chaz/tint2/blob - src/tint.c
fixed issue 176
[chaz/tint2] / src / tint.c
1 /**************************************************************************
2 *
3 * Tint2 panel
4 *
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
7 *
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.
11 *
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 **************************************************************************/
20
21 #include <sys/stat.h>
22 #include <unistd.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdint.h>
26 #include <string.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
29 #include <X11/Xlocale.h>
30 #include <Imlib2.h>
31 #include <signal.h>
32
33 #include "server.h"
34 #include "window.h"
35 #include "config.h"
36 #include "task.h"
37 #include "taskbar.h"
38 #include "systraybar.h"
39 #include "panel.h"
40 #include "tooltip.h"
41 #include "timer.h"
42
43 void signal_handler(int sig)
44 {
45 // signal handler is light as it should be
46 signal_pending = sig;
47 }
48
49
50 void init (int argc, char *argv[])
51 {
52 int i;
53
54 // read options
55 for (i = 1; i < argc; ++i) {
56 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
57 printf("Usage: tint2 [-c] <config_file>\n");
58 exit(0);
59 }
60 if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
61 printf("tint2 version 0.7.svn\n");
62 exit(0);
63 }
64 if (!strcmp(argv[i], "-c")) {
65 i++;
66 if (i < argc)
67 config_path = strdup(argv[i]);
68 }
69 if (!strcmp(argv[i], "-s")) {
70 i++;
71 if (i < argc)
72 snapshot_path = strdup(argv[i]);
73 }
74 }
75
76 // Set signal handler
77 struct sigaction sa = { .sa_handler = signal_handler };
78 sigaction(SIGUSR1, &sa, 0);
79 sigaction(SIGINT, &sa, 0);
80 sigaction(SIGTERM, &sa, 0);
81 sigaction(SIGHUP, &sa, 0);
82 signal(SIGCHLD, SIG_IGN); // don't have to wait() after fork()
83 // block all signals, such that no race conditions occur before pselect in our main loop
84 sigset_t block_mask;
85 sigaddset(&block_mask, SIGINT);
86 sigaddset(&block_mask, SIGTERM);
87 sigaddset(&block_mask, SIGHUP);
88 sigaddset(&block_mask, SIGUSR1);
89 sigprocmask(SIG_BLOCK, &block_mask, 0);
90
91
92 // set global data
93 memset(&server, 0, sizeof(Server_global));
94 memset(&systray, 0, sizeof(Systraybar));
95
96 server.dsp = XOpenDisplay (NULL);
97 if (!server.dsp) {
98 fprintf(stderr, "tint2 exit : could not open display.\n");
99 exit(0);
100 }
101 server_init_atoms ();
102 server.screen = DefaultScreen (server.dsp);
103 server.root_win = RootWindow(server.dsp, server.screen);
104 server.depth = DefaultDepth (server.dsp, server.screen);
105 server.visual = DefaultVisual (server.dsp, server.screen);
106 server.desktop = server_get_current_desktop ();
107 XGCValues gcv;
108 server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)0, &gcv);
109
110 XSetErrorHandler ((XErrorHandler) server_catch_error);
111
112 imlib_context_set_display (server.dsp);
113 imlib_context_set_visual (server.visual);
114 imlib_context_set_colormap (DefaultColormap (server.dsp, server.screen));
115
116 /* Catch events */
117 XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
118
119 setlocale (LC_ALL, "");
120
121 // load default icon
122 gchar *path;
123 const gchar * const *data_dirs;
124 data_dirs = g_get_system_data_dirs ();
125 for (i = 0; data_dirs[i] != NULL; i++) {
126 path = g_build_filename(data_dirs[i], "tint2", "default_icon.png", NULL);
127 if (g_file_test (path, G_FILE_TEST_EXISTS))
128 default_icon = imlib_load_image(path);
129 g_free(path);
130 }
131
132 // get monitor and desktop config
133 get_monitors();
134 get_desktops();
135 }
136
137
138 void cleanup()
139 {
140 cleanup_systray();
141 stop_net();
142 cleanup_panel();
143 cleanup_tooltip();
144 cleanup_clock();
145 #ifdef ENABLE_BATTERY
146 cleanup_battery();
147 #endif
148
149 if (default_icon) {
150 imlib_context_set_image(default_icon);
151 imlib_free_image();
152 }
153 if (config_path) g_free(config_path);
154 if (snapshot_path) g_free(snapshot_path);
155
156 if (server.monitor) free(server.monitor);
157 XFreeGC(server.dsp, server.gc);
158 XCloseDisplay(server.dsp);
159 }
160
161
162 void get_snapshot(const char *path)
163 {
164 Panel *panel = &panel1[0];
165
166 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
167 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
168
169 refresh(&panel->area);
170
171 Imlib_Image img = NULL;
172 imlib_context_set_drawable(panel->temp_pmap);
173 img = imlib_create_image_from_drawable(0, 0, 0, panel->area.width, panel->area.height, 0);
174
175 imlib_context_set_image(img);
176 imlib_save_image(path);
177 imlib_free_image();
178 }
179
180
181 void window_action (Task *tsk, int action)
182 {
183 if (!tsk) return;
184 int desk;
185 switch (action) {
186 case CLOSE:
187 set_close (tsk->win);
188 break;
189 case TOGGLE:
190 set_active(tsk->win);
191 break;
192 case ICONIFY:
193 XIconifyWindow (server.dsp, tsk->win, server.screen);
194 break;
195 case TOGGLE_ICONIFY:
196 if (task_active && tsk->win == task_active->win)
197 XIconifyWindow (server.dsp, tsk->win, server.screen);
198 else
199 set_active (tsk->win);
200 break;
201 case SHADE:
202 window_toggle_shade (tsk->win);
203 break;
204 case MAXIMIZE_RESTORE:
205 window_maximize_restore (tsk->win);
206 break;
207 case MAXIMIZE:
208 window_maximize_restore (tsk->win);
209 break;
210 case RESTORE:
211 window_maximize_restore (tsk->win);
212 break;
213 case DESKTOP_LEFT:
214 if ( tsk->desktop == 0 ) break;
215 desk = tsk->desktop - 1;
216 windows_set_desktop(tsk->win, desk);
217 if (desk == server.desktop)
218 set_active(tsk->win);
219 break;
220 case DESKTOP_RIGHT:
221 if (tsk->desktop == server.nb_desktop ) break;
222 desk = tsk->desktop + 1;
223 windows_set_desktop(tsk->win, desk);
224 if (desk == server.desktop)
225 set_active(tsk->win);
226 break;
227 case NEXT_TASK:
228 if (task_active) {
229 Task *tsk1;
230 tsk1 = next_task(task_active);
231 set_active(tsk1->win);
232 }
233 break;
234 case PREV_TASK:
235 if (task_active) {
236 Task *tsk1;
237 tsk1 = prev_task(task_active);
238 set_active(tsk1->win);
239 }
240 }
241 }
242
243
244 void event_button_press (XEvent *e)
245 {
246 Panel *panel = get_panel(e->xany.window);
247 if (!panel) return;
248
249 task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
250
251 if (wm_menu && !task_drag && !click_clock(panel, e->xbutton.x, e->xbutton.y) && (e->xbutton.button != 1) ) {
252 // forward the click to the desktop window (thanks conky)
253 XUngrabPointer(server.dsp, e->xbutton.time);
254 e->xbutton.window = server.root_win;
255 // icewm doesn't open under the mouse.
256 // and xfce doesn't open at all.
257 e->xbutton.x = e->xbutton.x_root;
258 e->xbutton.y = e->xbutton.y_root;
259 //printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y);
260 //XSetInputFocus(server.dsp, e->xbutton.window, RevertToParent, e->xbutton.time);
261 XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e);
262 return;
263 }
264
265 XLowerWindow (server.dsp, panel->main_win);
266 }
267
268
269 void event_button_release (XEvent *e)
270 {
271 Panel *panel = get_panel(e->xany.window);
272 if (!panel) return;
273
274 int action = TOGGLE_ICONIFY;
275 switch (e->xbutton.button) {
276 case 2:
277 action = mouse_middle;
278 break;
279 case 3:
280 action = mouse_right;
281 break;
282 case 4:
283 action = mouse_scroll_up;
284 break;
285 case 5:
286 action = mouse_scroll_down;
287 break;
288 case 6:
289 action = mouse_tilt_left;
290 break;
291 case 7:
292 action = mouse_tilt_right;
293 break;
294 }
295
296 if ( click_clock(panel, e->xbutton.x, e->xbutton.y)) {
297 clock_action(e->xbutton.button);
298 XLowerWindow (server.dsp, panel->main_win);
299 task_drag = 0;
300 return;
301 }
302
303 Taskbar *tskbar;
304 if ( !(tskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y)) ) {
305 // TODO: check better solution to keep window below
306 XLowerWindow (server.dsp, panel->main_win);
307 task_drag = 0;
308 return;
309 }
310
311 // drag and drop task
312 if (task_drag) {
313 if (tskbar != task_drag->area.parent && action == TOGGLE_ICONIFY) {
314 if (task_drag->desktop != ALLDESKTOP && panel_mode == MULTI_DESKTOP) {
315 windows_set_desktop(task_drag->win, tskbar->desktop);
316 if (tskbar->desktop == server.desktop)
317 set_active(task_drag->win);
318 task_drag = 0;
319 }
320 return;
321 }
322 else task_drag = 0;
323 }
324
325 // switch desktop
326 if (panel_mode == MULTI_DESKTOP) {
327 if (tskbar->desktop != server.desktop && action != CLOSE && action != DESKTOP_LEFT && action != DESKTOP_RIGHT)
328 set_desktop (tskbar->desktop);
329 }
330
331 // action on task
332 window_action( click_task(panel, e->xbutton.x, e->xbutton.y), action);
333
334 // to keep window below
335 XLowerWindow (server.dsp, panel->main_win);
336 }
337
338
339 void event_property_notify (XEvent *e)
340 {
341 int i, j;
342 Task *tsk;
343 Window win = e->xproperty.window;
344 Atom at = e->xproperty.atom;
345
346 if (win == server.root_win) {
347 if (!server.got_root_win) {
348 XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
349 server.got_root_win = 1;
350 }
351
352 // Change number of desktops
353 else if (at == server.atom._NET_NUMBER_OF_DESKTOPS) {
354 server.nb_desktop = server_get_number_of_desktop ();
355 cleanup_taskbar();
356 init_taskbar();
357 visible_object();
358 for (i=0 ; i < nb_panel ; i++) {
359 panel1[i].area.resize = 1;
360 }
361 task_refresh_tasklist();
362 panel_refresh = 1;
363 }
364 // Change desktop
365 else if (at == server.atom._NET_CURRENT_DESKTOP) {
366 int old_desktop = server.desktop;
367 server.desktop = server_get_current_desktop ();
368 for (i=0 ; i < nb_panel ; i++) {
369 Panel *panel = &panel1[i];
370 if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) {
371 // redraw both taskbar
372 panel->taskbar[old_desktop].area.is_active = 0;
373 panel->taskbar[old_desktop].area.resize = 1;
374 panel->taskbar[server.desktop].area.is_active = 1;
375 panel->taskbar[server.desktop].area.resize = 1;
376 panel_refresh = 1;
377 }
378 // check ALLDESKTOP task => resize taskbar
379 Taskbar *tskbar;
380 Task *tsk;
381 GSList *l;
382 tskbar = &panel->taskbar[old_desktop];
383 for (l = tskbar->area.list; l ; l = l->next) {
384 tsk = l->data;
385 if (tsk->desktop == ALLDESKTOP) {
386 tsk->area.on_screen = 0;
387 tskbar->area.resize = 1;
388 panel_refresh = 1;
389 }
390 }
391 tskbar = &panel->taskbar[server.desktop];
392 for (l = tskbar->area.list; l ; l = l->next) {
393 tsk = l->data;
394 if (tsk->desktop == ALLDESKTOP) {
395 tsk->area.on_screen = 1;
396 tskbar->area.resize = 1;
397 }
398 }
399 }
400 if (panel_mode != MULTI_DESKTOP) {
401 visible_object();
402 }
403 }
404 // Window list
405 else if (at == server.atom._NET_CLIENT_LIST) {
406 task_refresh_tasklist();
407 panel_refresh = 1;
408 }
409 // Change active
410 else if (at == server.atom._NET_ACTIVE_WINDOW) {
411 active_task();
412 panel_refresh = 1;
413 }
414 else if (at == server.atom._XROOTPMAP_ID) {
415 // change Wallpaper
416 for (i=0 ; i < nb_panel ; i++) {
417 set_panel_background(&panel1[i]);
418 }
419 panel_refresh = 1;
420 }
421 }
422 else {
423 tsk = task_get_task (win);
424 if (!tsk) {
425 if (at != server.atom._NET_WM_STATE)
426 return;
427 else {
428 // xfce4 sends _NET_WM_STATE after minimized to tray, so we need to check if window is mapped
429 // if it is mapped and not set as skip_taskbar, we must add it to our task list
430 XWindowAttributes wa;
431 XGetWindowAttributes(server.dsp, win, &wa);
432 if (wa.map_state == IsViewable && !window_is_skip_taskbar(win)) {
433 if ( (tsk = add_task(win)) )
434 panel_refresh = 1;
435 else
436 return;
437 }
438 else
439 return;
440 }
441 }
442 //printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
443
444 // Window title changed
445 if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
446 Task *tsk2;
447 GSList *l0;
448 get_title(tsk);
449 // changed other tsk->title
450 for (i=0 ; i < nb_panel ; i++) {
451 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
452 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
453 tsk2 = l0->data;
454 if (tsk->win == tsk2->win && tsk != tsk2) {
455 tsk2->title = tsk->title;
456 tsk2->area.redraw = 1;
457 }
458 }
459 }
460 }
461 panel_refresh = 1;
462 }
463 // Demand attention
464 else if (at == server.atom._NET_WM_STATE) {
465 if (window_is_urgent (win)) {
466 add_urgent(tsk);
467 }
468 if (window_is_skip_taskbar(win)) {
469 remove_task( tsk );
470 panel_refresh = 1;
471 }
472 }
473 // We do not check for the iconified state, since it only unsets our active window
474 // but in openbox a shaded window is considered iconified. So we would loose the active window
475 // property on unshading it again (commented 01.10.2009)
476 // else if (at == server.atom.WM_STATE) {
477 // // Iconic state
478 // // TODO : try to delete following code
479 // if (window_is_iconified (win)) {
480 // if (task_active) {
481 // if (task_active->win == tsk->win) {
482 // Task *tsk2;
483 // GSList *l0;
484 // for (i=0 ; i < nb_panel ; i++) {
485 // for (j=0 ; j < panel1[i].nb_desktop ; j++) {
486 // for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
487 // tsk2 = l0->data;
488 // tsk2->area.is_active = 0;
489 // }
490 // }
491 // }
492 // task_active = 0;
493 // }
494 // }
495 // }
496 // }
497 // Window icon changed
498 else if (at == server.atom._NET_WM_ICON) {
499 get_icon(tsk);
500 Task *tsk2;
501 GSList *l0;
502 for (i=0 ; i < nb_panel ; i++) {
503 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
504 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
505 tsk2 = l0->data;
506 if (tsk->win == tsk2->win && tsk != tsk2) {
507 tsk2->icon_width = tsk->icon_width;
508 tsk2->icon_height = tsk->icon_height;
509 tsk2->icon = tsk->icon;
510 tsk2->icon_active = tsk->icon_active;
511 tsk2->area.redraw = 1;
512 }
513 }
514 }
515 }
516 panel_refresh = 1;
517 }
518 // Window desktop changed
519 else if (at == server.atom._NET_WM_DESKTOP) {
520 int desktop = window_get_desktop (win);
521 int active = tsk->area.is_active;
522 //printf(" Window desktop changed %d, %d\n", tsk->desktop, desktop);
523 // bug in windowmaker : send unecessary 'desktop changed' when focus changed
524 if (desktop != tsk->desktop) {
525 remove_task (tsk);
526 tsk = add_task (win);
527 if (tsk && active) {
528 tsk->area.is_active = 1;
529 task_active = tsk;
530 }
531 panel_refresh = 1;
532 }
533 }
534 else if (at == server.atom.WM_HINTS) {
535 XWMHints* wmhints = XGetWMHints(server.dsp, win);
536 if (wmhints && wmhints->flags & XUrgencyHint) {
537 add_urgent(tsk);
538 }
539 XFree(wmhints);
540 }
541
542 if (!server.got_root_win) server.root_win = RootWindow (server.dsp, server.screen);
543 }
544 }
545
546
547 void event_expose (XEvent *e)
548 {
549 Panel *panel;
550 panel = get_panel(e->xany.window);
551 if (!panel) return;
552 // TODO : one panel_refresh per panel ?
553 panel_refresh = 1;
554 }
555
556
557 void event_configure_notify (Window win)
558 {
559 // change in root window (xrandr)
560 if (win == server.root_win) {
561 get_monitors();
562 init_config();
563 config_read_file (config_path);
564 init_panel();
565 cleanup_config();
566 return;
567 }
568
569 // 'win' is a trayer icon
570 TrayWindow *traywin;
571 GSList *l;
572 for (l = systray.list_icons; l ; l = l->next) {
573 traywin = (TrayWindow*)l->data;
574 if (traywin->id == win) {
575 //printf("move tray %d\n", traywin->x);
576 XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
577 panel_refresh = 1;
578 return;
579 }
580 }
581
582 // 'win' move in another monitor
583 if (nb_panel == 1) return;
584 Task *tsk = task_get_task (win);
585 if (!tsk) return;
586
587 Panel *p = tsk->area.panel;
588 if (p->monitor != window_get_monitor (win)) {
589 remove_task (tsk);
590 add_task (win);
591 if (win == window_get_active ()) {
592 Task *tsk = task_get_task (win);
593 tsk->area.is_active = 1;
594 task_active = tsk;
595 }
596 panel_refresh = 1;
597 }
598 }
599
600
601 void dnd_message(XClientMessageEvent *e)
602 {
603 Panel *panel = get_panel(e->window);
604 int x, y, mapX, mapY;
605 Window child;
606 x = (e->data.l[2] >> 16) & 0xFFFF;
607 y = e->data.l[2] & 0xFFFF;
608 XTranslateCoordinates(server.dsp, server.root_win, e->window, x, y, &mapX, &mapY, &child);
609 Task* task = click_task(panel, mapX, mapY);
610 if (task) {
611 if (task->desktop != server.desktop )
612 set_desktop (task->desktop);
613 window_action(task, TOGGLE);
614 }
615
616 // send XdndStatus event to get more XdndPosition events
617 XClientMessageEvent se;
618 se.type = ClientMessage;
619 se.window = e->data.l[0];
620 se.message_type = server.atom.XdndStatus;
621 se.format = 32;
622 se.data.l[0] = e->window; // XID of the target window
623 se.data.l[1] = 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
624 se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
625 se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
626 se.data.l[4] = None; // None = drop will not be accepted
627 XSendEvent(server.dsp, e->data.l[0], False, NoEventMask, (XEvent*)&se);
628 }
629
630
631 int main (int argc, char *argv[])
632 {
633 XEvent e;
634 fd_set fdset;
635 int x11_fd, i;
636 Panel *panel;
637 GSList *it;
638 GSList* timer_iter;
639 struct timer* timer;
640
641 init (argc, argv);
642
643 i = 0;
644 init_config();
645 if (config_path)
646 i = config_read_file (config_path);
647 else
648 i = config_read ();
649 if (!i) {
650 fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
651 cleanup();
652 exit(1);
653 }
654 init_panel();
655 cleanup_config();
656 if (snapshot_path) {
657 get_snapshot(snapshot_path);
658 cleanup();
659 exit(0);
660 }
661
662 x11_fd = ConnectionNumber(server.dsp);
663 XSync(server.dsp, False);
664
665 sigset_t empty_mask;
666 sigemptyset(&empty_mask);
667
668 while (1) {
669 if (panel_refresh) {
670 panel_refresh = 0;
671
672 if (refresh_systray) {
673 panel = (Panel*)systray.area.panel;
674 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
675 }
676 for (i=0 ; i < nb_panel ; i++) {
677 panel = &panel1[i];
678
679 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
680 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
681
682 refresh(&panel->area);
683 XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
684 }
685 XFlush (server.dsp);
686
687 if (refresh_systray) {
688 refresh_systray = 0;
689 panel = (Panel*)systray.area.panel;
690 // tint2 doen't draw systray icons. it just redraw background.
691 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
692 // force icon's refresh
693 refresh_systray_icon();
694 }
695 }
696
697 // thanks to AngryLlama for the timer
698 // Create a File Description Set containing x11_fd, and every timer_fd
699 FD_ZERO (&fdset);
700 FD_SET (x11_fd, &fdset);
701 int max_fd = x11_fd;
702 timer_iter = timer_list;
703 while (timer_iter) {
704 timer = timer_iter->data;
705 max_fd = timer->id > max_fd ? timer->id : max_fd;
706 FD_SET(timer->id, &fdset);
707 timer_iter = timer_iter->next;
708 }
709
710 // Wait for X Event or a Timer
711 if (pselect(max_fd+1, &fdset, 0, 0, 0, &empty_mask) > 0) {
712 // we need to iterate over the whole timer list, since fd_set can only be checked with the
713 // brute force method FD_ISSET for every possible timer
714 timer_iter = timer_list;
715 while (timer_iter) {
716 timer = timer_iter->data;
717 if (FD_ISSET(timer->id, &fdset)) {
718 uint64_t dummy;
719 if ( -1 != read(timer->id, &dummy, sizeof(uint64_t)) )
720 timer->_callback();
721 }
722 timer_iter = timer_iter->next;
723 }
724
725 while (XPending (server.dsp)) {
726 XNextEvent(server.dsp, &e);
727
728 switch (e.type) {
729 case ButtonPress:
730 tooltip_hide();
731 event_button_press (&e);
732 break;
733
734 case ButtonRelease:
735 event_button_release(&e);
736 break;
737
738 case MotionNotify: {
739 if (!g_tooltip.enabled) break;
740 Panel* panel = get_panel(e.xmotion.window);
741 Area* area = click_area(panel, e.xmotion.x, e.xmotion.y);
742 if (area->_get_tooltip_text)
743 tooltip_trigger_show(area, panel, e.xmotion.x_root, e.xmotion.y_root);
744 else
745 tooltip_trigger_hide();
746 break;
747 }
748
749 case LeaveNotify:
750 tooltip_trigger_hide();
751 break;
752
753 case Expose:
754 event_expose(&e);
755 break;
756
757 case MapNotify:
758 if (e.xany.window == g_tooltip.window)
759 tooltip_update();
760 break;
761
762 case PropertyNotify:
763 event_property_notify(&e);
764 break;
765
766 case ConfigureNotify:
767 event_configure_notify (e.xconfigure.window);
768 break;
769
770 case ReparentNotify:
771 if (!systray_enabled)
772 break;
773 panel = (Panel*)systray.area.panel;
774 if (e.xany.window == panel->main_win) // reparented to us
775 break;
776 // FIXME: 'reparent to us' badly detected => disabled
777 break;
778 case UnmapNotify:
779 case DestroyNotify:
780 if (e.xany.window == g_tooltip.window || !systray.area.on_screen)
781 break;
782 for (it = systray.list_icons; it; it = g_slist_next(it)) {
783 if (((TrayWindow*)it->data)->id == e.xany.window) {
784 remove_icon((TrayWindow*)it->data);
785 break;
786 }
787 }
788 break;
789
790 case ClientMessage:
791 if (!systray.area.on_screen) break;
792 if (e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
793 net_message(&e.xclient);
794 }
795 else if (e.xclient.message_type == server.atom.XdndPosition) {
796 dnd_message(&e.xclient);
797 }
798 break;
799 }
800 }
801 }
802
803 switch (signal_pending) {
804 case SIGUSR1: // reload config file
805 signal_pending = 0;
806 init_config();
807 config_read_file (config_path);
808 init_panel();
809 cleanup_config();
810 break;
811 case SIGINT:
812 case SIGTERM:
813 case SIGHUP:
814 cleanup ();
815 return 0;
816 }
817 }
818 }
819
820
This page took 0.082391 seconds and 5 git commands to generate.