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