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