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