]> Dogcows Code - chaz/tint2/blob - src/tint.c
*add* clock supports timezones
[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.8\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.desktop = server_get_current_desktop ();
105 XGCValues gcv;
106 server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)0, &gcv);
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 for (i = 0; data_dirs[i] != NULL; i++) {
124 path = g_build_filename(data_dirs[i], "tint2", "default_icon.png", NULL);
125 if (g_file_test (path, G_FILE_TEST_EXISTS))
126 default_icon = imlib_load_image(path);
127 g_free(path);
128 }
129
130 // get monitor and desktop config
131 get_monitors();
132 get_desktops();
133 }
134
135
136 void cleanup()
137 {
138 cleanup_systray();
139 stop_net();
140 cleanup_panel();
141 cleanup_tooltip();
142 cleanup_clock();
143 #ifdef ENABLE_BATTERY
144 cleanup_battery();
145 #endif
146
147 if (default_icon) {
148 imlib_context_set_image(default_icon);
149 imlib_free_image();
150 }
151 if (config_path) g_free(config_path);
152 if (snapshot_path) g_free(snapshot_path);
153
154 if (server.monitor) free(server.monitor);
155 XFreeGC(server.dsp, server.gc);
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->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 panel_refresh = 1;
619 return;
620 }
621 }
622
623 // 'win' move in another monitor
624 if (nb_panel == 1) return;
625 Task *tsk = task_get_task (win);
626 if (!tsk) return;
627
628 Panel *p = tsk->area.panel;
629 if (p->monitor != window_get_monitor (win)) {
630 remove_task (tsk);
631 add_task (win);
632 if (win == window_get_active ()) {
633 GSList* task_list = task_get_tasks(win);
634 while (task_list) {
635 Task *tsk = task_list->data;
636 tsk->area.is_active = 1;
637 task_active = tsk;
638 task_list = task_list->next;
639 }
640 }
641 panel_refresh = 1;
642 }
643 }
644
645
646 void dnd_message(XClientMessageEvent *e)
647 {
648 Panel *panel = get_panel(e->window);
649 int x, y, mapX, mapY;
650 Window child;
651 x = (e->data.l[2] >> 16) & 0xFFFF;
652 y = e->data.l[2] & 0xFFFF;
653 XTranslateCoordinates(server.dsp, server.root_win, e->window, x, y, &mapX, &mapY, &child);
654 Task* task = click_task(panel, mapX, mapY);
655 if (task) {
656 if (task->desktop != server.desktop )
657 set_desktop (task->desktop);
658 window_action(task, TOGGLE);
659 }
660
661 // send XdndStatus event to get more XdndPosition events
662 XClientMessageEvent se;
663 se.type = ClientMessage;
664 se.window = e->data.l[0];
665 se.message_type = server.atom.XdndStatus;
666 se.format = 32;
667 se.data.l[0] = e->window; // XID of the target window
668 se.data.l[1] = 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
669 se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
670 se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
671 se.data.l[4] = None; // None = drop will not be accepted
672 XSendEvent(server.dsp, e->data.l[0], False, NoEventMask, (XEvent*)&se);
673 }
674
675
676 int main (int argc, char *argv[])
677 {
678 XEvent e;
679 fd_set fdset;
680 int x11_fd, i;
681 Panel *panel;
682 GSList *it;
683 const struct timespec* timeout;
684
685 init (argc, argv);
686
687 i = 0;
688 init_config();
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 init_panel();
699 cleanup_config();
700 if (snapshot_path) {
701 get_snapshot(snapshot_path);
702 cleanup();
703 exit(0);
704 }
705
706 x11_fd = ConnectionNumber(server.dsp);
707 XSync(server.dsp, False);
708
709 sigset_t empty_mask;
710 sigemptyset(&empty_mask);
711
712 while (1) {
713 if (panel_refresh) {
714 panel_refresh = 0;
715
716 // QUESTION: do we need this first refresh_systray, because we check refresh_systray once again later...
717 if (refresh_systray) {
718 panel = (Panel*)systray.area.panel;
719 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
720 }
721 for (i=0 ; i < nb_panel ; i++) {
722 panel = &panel1[i];
723
724 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
725 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
726
727 refresh(&panel->area);
728 XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
729 }
730 XFlush (server.dsp);
731
732 if (refresh_systray) {
733 refresh_systray = 0;
734 panel = (Panel*)systray.area.panel;
735 // tint2 doen't draw systray icons. it just redraw background.
736 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
737 // force icon's refresh
738 refresh_systray_icon();
739 }
740 }
741
742 // thanks to AngryLlama for the timer
743 // Create a File Description Set containing x11_fd
744 FD_ZERO (&fdset);
745 FD_SET (x11_fd, &fdset);
746 update_next_timeout();
747 if (next_timeout.tv_sec >= 0 && next_timeout.tv_nsec >= 0)
748 timeout = &next_timeout;
749 else
750 timeout = 0;
751
752 // Wait for X Event or a Timer
753 if (pselect(x11_fd+1, &fdset, 0, 0, timeout, &empty_mask) > 0) {
754 while (XPending (server.dsp)) {
755 XNextEvent(server.dsp, &e);
756
757 switch (e.type) {
758 case ButtonPress:
759 tooltip_hide();
760 event_button_press (&e);
761 break;
762
763 case ButtonRelease:
764 event_button_release(&e);
765 break;
766
767 case MotionNotify: {
768 if (!g_tooltip.enabled) break;
769 Panel* panel = get_panel(e.xmotion.window);
770 Area* area = click_area(panel, e.xmotion.x, e.xmotion.y);
771 if (area->_get_tooltip_text)
772 tooltip_trigger_show(area, panel, e.xmotion.x_root, e.xmotion.y_root);
773 else
774 tooltip_trigger_hide();
775 break;
776 }
777
778 case LeaveNotify:
779 tooltip_trigger_hide();
780 break;
781
782 case Expose:
783 event_expose(&e);
784 break;
785
786 case MapNotify:
787 if (e.xany.window == g_tooltip.window)
788 tooltip_update();
789 break;
790
791 case PropertyNotify:
792 event_property_notify(&e);
793 break;
794
795 case ConfigureNotify:
796 event_configure_notify (e.xconfigure.window);
797 break;
798
799 case ReparentNotify:
800 if (!systray_enabled)
801 break;
802 panel = (Panel*)systray.area.panel;
803 if (e.xany.window == panel->main_win) // reparented to us
804 break;
805 // FIXME: 'reparent to us' badly detected => disabled
806 break;
807 case UnmapNotify:
808 case DestroyNotify:
809 if (e.xany.window == g_tooltip.window || !systray.area.on_screen)
810 break;
811 for (it = systray.list_icons; it; it = g_slist_next(it)) {
812 if (((TrayWindow*)it->data)->id == e.xany.window) {
813 remove_icon((TrayWindow*)it->data);
814 break;
815 }
816 }
817 break;
818
819 case ClientMessage:
820 if (!systray.area.on_screen) break;
821 if (e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
822 net_message(&e.xclient);
823 }
824 else if (e.xclient.message_type == server.atom.XdndPosition) {
825 dnd_message(&e.xclient);
826 }
827 break;
828 }
829 }
830 }
831
832 callback_timeout_expired();
833
834 switch (signal_pending) {
835 case SIGUSR1: // reload config file
836 signal_pending = 0;
837 init_config();
838 config_read_file (config_path);
839 init_panel();
840 cleanup_config();
841 break;
842 case SIGINT:
843 case SIGTERM:
844 case SIGHUP:
845 cleanup ();
846 return 0;
847 }
848 }
849 }
850
851
This page took 0.076773 seconds and 5 git commands to generate.