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