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