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