]> Dogcows Code - chaz/tint2/blob - src/tint.c
Scrolling through tasks by schattenprinz
[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 }
439 }
440 //printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
441
442 // Window title changed
443 if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
444 Task *tsk2;
445 GSList *l0;
446 get_title(tsk);
447 // changed other tsk->title
448 for (i=0 ; i < nb_panel ; i++) {
449 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
450 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
451 tsk2 = l0->data;
452 if (tsk->win == tsk2->win && tsk != tsk2) {
453 tsk2->title = tsk->title;
454 tsk2->area.redraw = 1;
455 }
456 }
457 }
458 }
459 panel_refresh = 1;
460 }
461 // Demand attention
462 else if (at == server.atom._NET_WM_STATE) {
463 if (window_is_urgent (win)) {
464 add_urgent(tsk);
465 }
466 if (window_is_skip_taskbar(win)) {
467 remove_task( tsk );
468 panel_refresh = 1;
469 }
470 }
471 // We do not check for the iconified state, since it only unsets our active window
472 // but in openbox a shaded window is considered iconified. So we would loose the active window
473 // property on unshading it again (commented 01.10.2009)
474 // else if (at == server.atom.WM_STATE) {
475 // // Iconic state
476 // // TODO : try to delete following code
477 // if (window_is_iconified (win)) {
478 // if (task_active) {
479 // if (task_active->win == tsk->win) {
480 // Task *tsk2;
481 // GSList *l0;
482 // for (i=0 ; i < nb_panel ; i++) {
483 // for (j=0 ; j < panel1[i].nb_desktop ; j++) {
484 // for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
485 // tsk2 = l0->data;
486 // tsk2->area.is_active = 0;
487 // }
488 // }
489 // }
490 // task_active = 0;
491 // }
492 // }
493 // }
494 // }
495 // Window icon changed
496 else if (at == server.atom._NET_WM_ICON) {
497 get_icon(tsk);
498 Task *tsk2;
499 GSList *l0;
500 for (i=0 ; i < nb_panel ; i++) {
501 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
502 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
503 tsk2 = l0->data;
504 if (tsk->win == tsk2->win && tsk != tsk2) {
505 tsk2->icon_width = tsk->icon_width;
506 tsk2->icon_height = tsk->icon_height;
507 tsk2->icon = tsk->icon;
508 tsk2->icon_active = tsk->icon_active;
509 tsk2->area.redraw = 1;
510 }
511 }
512 }
513 }
514 panel_refresh = 1;
515 }
516 // Window desktop changed
517 else if (at == server.atom._NET_WM_DESKTOP) {
518 int desktop = window_get_desktop (win);
519 int active = tsk->area.is_active;
520 //printf(" Window desktop changed %d, %d\n", tsk->desktop, desktop);
521 // bug in windowmaker : send unecessary 'desktop changed' when focus changed
522 if (desktop != tsk->desktop) {
523 remove_task (tsk);
524 tsk = add_task (win);
525 if (tsk && active) {
526 tsk->area.is_active = 1;
527 task_active = tsk;
528 }
529 panel_refresh = 1;
530 }
531 }
532 else if (at == server.atom.WM_HINTS) {
533 XWMHints* wmhints = XGetWMHints(server.dsp, win);
534 if (wmhints && wmhints->flags & XUrgencyHint) {
535 add_urgent(tsk);
536 }
537 XFree(wmhints);
538 }
539
540 if (!server.got_root_win) server.root_win = RootWindow (server.dsp, server.screen);
541 }
542 }
543
544
545 void event_expose (XEvent *e)
546 {
547 Panel *panel;
548 panel = get_panel(e->xany.window);
549 if (!panel) return;
550 // TODO : one panel_refresh per panel ?
551 panel_refresh = 1;
552 }
553
554
555 void event_configure_notify (Window win)
556 {
557 // change in root window (xrandr)
558 if (win == server.root_win) {
559 get_monitors();
560 init_config();
561 config_read_file (config_path);
562 init_panel();
563 cleanup_config();
564 return;
565 }
566
567 // 'win' is a trayer icon
568 TrayWindow *traywin;
569 GSList *l;
570 for (l = systray.list_icons; l ; l = l->next) {
571 traywin = (TrayWindow*)l->data;
572 if (traywin->id == win) {
573 //printf("move tray %d\n", traywin->x);
574 XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
575 panel_refresh = 1;
576 return;
577 }
578 }
579
580 // 'win' move in another monitor
581 if (nb_panel == 1) return;
582 Task *tsk = task_get_task (win);
583 if (!tsk) return;
584
585 Panel *p = tsk->area.panel;
586 if (p->monitor != window_get_monitor (win)) {
587 remove_task (tsk);
588 add_task (win);
589 if (win == window_get_active ()) {
590 Task *tsk = task_get_task (win);
591 tsk->area.is_active = 1;
592 task_active = tsk;
593 }
594 panel_refresh = 1;
595 }
596 }
597
598
599 void dnd_message(XClientMessageEvent *e)
600 {
601 Panel *panel = get_panel(e->window);
602 int x, y, mapX, mapY;
603 Window child;
604 x = (e->data.l[2] >> 16) & 0xFFFF;
605 y = e->data.l[2] & 0xFFFF;
606 XTranslateCoordinates(server.dsp, server.root_win, e->window, x, y, &mapX, &mapY, &child);
607 Task* task = click_task(panel, mapX, mapY);
608 if (task) {
609 if (task->desktop != server.desktop )
610 set_desktop (task->desktop);
611 window_action(task, TOGGLE);
612 }
613
614 // send XdndStatus event to get more XdndPosition events
615 XClientMessageEvent se;
616 se.type = ClientMessage;
617 se.window = e->data.l[0];
618 se.message_type = server.atom.XdndStatus;
619 se.format = 32;
620 se.data.l[0] = e->window; // XID of the target window
621 se.data.l[1] = 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
622 se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
623 se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
624 se.data.l[4] = None; // None = drop will not be accepted
625 XSendEvent(server.dsp, e->data.l[0], False, NoEventMask, (XEvent*)&se);
626 }
627
628
629 int main (int argc, char *argv[])
630 {
631 XEvent e;
632 fd_set fdset;
633 int x11_fd, i;
634 Panel *panel;
635 GSList *it;
636 GSList* timer_iter;
637 struct timer* timer;
638
639 init (argc, argv);
640
641 i = 0;
642 init_config();
643 if (config_path)
644 i = config_read_file (config_path);
645 else
646 i = config_read ();
647 if (!i) {
648 fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
649 cleanup();
650 exit(1);
651 }
652 init_panel();
653 cleanup_config();
654 if (snapshot_path) {
655 get_snapshot(snapshot_path);
656 cleanup();
657 exit(0);
658 }
659
660 x11_fd = ConnectionNumber(server.dsp);
661 XSync(server.dsp, False);
662
663 sigset_t empty_mask;
664 sigemptyset(&empty_mask);
665
666 while (1) {
667 if (panel_refresh) {
668 panel_refresh = 0;
669
670 if (refresh_systray) {
671 panel = (Panel*)systray.area.panel;
672 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
673 }
674 for (i=0 ; i < nb_panel ; i++) {
675 panel = &panel1[i];
676
677 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
678 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
679
680 refresh(&panel->area);
681 XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
682 }
683 XFlush (server.dsp);
684
685 if (refresh_systray) {
686 refresh_systray = 0;
687 panel = (Panel*)systray.area.panel;
688 // tint2 doen't draw systray icons. it just redraw background.
689 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
690 // force icon's refresh
691 refresh_systray_icon();
692 }
693 }
694
695 // thanks to AngryLlama for the timer
696 // Create a File Description Set containing x11_fd, and every timer_fd
697 FD_ZERO (&fdset);
698 FD_SET (x11_fd, &fdset);
699 int max_fd = x11_fd;
700 timer_iter = timer_list;
701 while (timer_iter) {
702 timer = timer_iter->data;
703 max_fd = timer->id > max_fd ? timer->id : max_fd;
704 FD_SET(timer->id, &fdset);
705 timer_iter = timer_iter->next;
706 }
707
708 // Wait for X Event or a Timer
709 if (pselect(max_fd+1, &fdset, 0, 0, 0, &empty_mask) > 0) {
710 while (XPending (server.dsp)) {
711 XNextEvent(server.dsp, &e);
712
713 switch (e.type) {
714 case ButtonPress:
715 tooltip_hide();
716 event_button_press (&e);
717 break;
718
719 case ButtonRelease:
720 event_button_release(&e);
721 break;
722
723 case MotionNotify: {
724 if (!g_tooltip.enabled) break;
725 Panel* panel = get_panel(e.xmotion.window);
726 Area* area = click_area(panel, e.xmotion.x, e.xmotion.y);
727 if (area->_get_tooltip_text) {
728 tooltip_trigger_show(area, panel, e.xmotion.x_root, e.xmotion.y_root);
729 }
730 else
731 tooltip_trigger_hide();
732 break;
733 }
734
735 case LeaveNotify:
736 tooltip_trigger_hide();
737 break;
738
739 case Expose:
740 event_expose(&e);
741 break;
742
743 case MapNotify:
744 if (e.xany.window == g_tooltip.window)
745 tooltip_update();
746 break;
747
748 case PropertyNotify:
749 event_property_notify(&e);
750 break;
751
752 case ConfigureNotify:
753 event_configure_notify (e.xconfigure.window);
754 break;
755
756 case ReparentNotify:
757 if (!systray_enabled)
758 break;
759 panel = (Panel*)systray.area.panel;
760 if (e.xany.window == panel->main_win) // reparented to us
761 break;
762 // FIXME: 'reparent to us' badly detected => disabled
763 break;
764 case UnmapNotify:
765 case DestroyNotify:
766 if (e.xany.window == g_tooltip.window || !systray.area.on_screen)
767 break;
768 for (it = systray.list_icons; it; it = g_slist_next(it)) {
769 if (((TrayWindow*)it->data)->id == e.xany.window) {
770 remove_icon((TrayWindow*)it->data);
771 break;
772 }
773 }
774 break;
775
776 case ClientMessage:
777 if (!systray.area.on_screen) break;
778 if (e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
779 net_message(&e.xclient);
780 }
781 else if (e.xclient.message_type == server.atom.XdndPosition) {
782 dnd_message(&e.xclient);
783 }
784 break;
785 }
786 }
787
788 // we need to iterate over the whole timer list, since fd_set can only be checked with the
789 // brute force method FD_ISSET for every possible timer
790 timer_iter = timer_list;
791 while (timer_iter) {
792 timer = timer_iter->data;
793 if (FD_ISSET(timer->id, &fdset)) {
794 uint64_t dummy;
795 read(timer->id, &dummy, sizeof(uint64_t));
796 timer->_callback();
797 }
798 timer_iter = timer_iter->next;
799 }
800 }
801
802 switch (signal_pending) {
803 case SIGUSR1: // reload config file
804 signal_pending = 0;
805 init_config();
806 config_read_file (config_path);
807 init_panel();
808 cleanup_config();
809 break;
810 case SIGINT:
811 case SIGTERM:
812 case SIGHUP:
813 cleanup ();
814 return 0;
815 }
816 }
817 }
818
819
This page took 0.072774 seconds and 5 git commands to generate.