]> Dogcows Code - chaz/tint2/blob - src/tint.c
cleanup
[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 <sys/time.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <stdlib.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
41
42 void signal_handler(int sig)
43 {
44 // signal handler is light as it should be
45 signal_pending = sig;
46 }
47
48
49 void init (int argc, char *argv[])
50 {
51 int c;
52
53 // read options
54 while ((c = getopt(argc , argv, "c:j:v")) != -1) {
55 switch (c) {
56 case 'c':
57 config_path = strdup (optarg);
58 break;
59 case 'j':
60 thumbnail_path = strdup (optarg);
61 break;
62 case 'v':
63 printf("tint2 version 0.7-svn\n");
64 exit(0);
65 break;
66 }
67 }
68
69 // Set signal handler
70 signal(SIGUSR1, signal_handler);
71 signal(SIGINT, signal_handler);
72 signal(SIGTERM, signal_handler);
73 signal(SIGHUP, signal_handler);
74 signal(SIGCHLD, SIG_IGN); // don't have to wait() after fork()
75
76 // set global data
77 memset(&server, 0, sizeof(Server_global));
78 memset(&systray, 0, sizeof(Systraybar));
79
80 server.dsp = XOpenDisplay (NULL);
81 if (!server.dsp) {
82 fprintf(stderr, "tint2 exit : could not open display.\n");
83 exit(0);
84 }
85 server_init_atoms ();
86 server.screen = DefaultScreen (server.dsp);
87 server.root_win = RootWindow(server.dsp, server.screen);
88 server.depth = DefaultDepth (server.dsp, server.screen);
89 server.visual = DefaultVisual (server.dsp, server.screen);
90 server.desktop = server_get_current_desktop ();
91 XGCValues gcv;
92 server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)0, &gcv) ;
93
94 XSetErrorHandler ((XErrorHandler) server_catch_error);
95
96 imlib_context_set_display (server.dsp);
97 imlib_context_set_visual (server.visual);
98 imlib_context_set_colormap (DefaultColormap (server.dsp, server.screen));
99
100 /* Catch events */
101 XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
102
103 setlocale (LC_ALL, "");
104 }
105
106
107 void cleanup()
108 {
109 cleanup_panel();
110
111 if (time1_font_desc) pango_font_description_free(time1_font_desc);
112 if (time2_font_desc) pango_font_description_free(time2_font_desc);
113 if (time1_format) g_free(time1_format);
114 if (time2_format) g_free(time2_format);
115 #ifdef ENABLE_BATTERY
116 if (bat1_font_desc) pango_font_description_free(bat1_font_desc);
117 if (bat2_font_desc) pango_font_description_free(bat2_font_desc);
118 if (battery_low_cmd) g_free(battery_low_cmd);
119 if (path_energy_now) g_free(path_energy_now);
120 if (path_energy_full) g_free(path_energy_full);
121 if (path_current_now) g_free(path_current_now);
122 if (path_status) g_free(path_status);
123 #endif
124 if (clock_lclick_command) g_free(clock_lclick_command);
125 if (clock_rclick_command) g_free(clock_rclick_command);
126 if (config_path) g_free(config_path);
127 if (thumbnail_path) g_free(thumbnail_path);
128
129 if (server.monitor) free(server.monitor);
130 XFreeGC(server.dsp, server.gc);
131 XCloseDisplay(server.dsp);
132 }
133
134
135 Taskbar *click_taskbar (Panel *panel, int x, int y)
136 {
137 Taskbar *tskbar;
138 int i;
139
140 if (panel_horizontal) {
141 for (i=0; i < panel->nb_desktop ; i++) {
142 tskbar = &panel->taskbar[i];
143 if (!tskbar->area.on_screen) continue;
144 if (x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
145 return tskbar;
146 }
147 }
148 else {
149 for (i=0; i < panel->nb_desktop ; i++) {
150 tskbar = &panel->taskbar[i];
151 if (!tskbar->area.on_screen) continue;
152 if (y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
153 return tskbar;
154 }
155 }
156 return NULL;
157 }
158
159
160 Task *click_task (Panel *panel, int x, int y)
161 {
162 GSList *l0;
163 Taskbar *tskbar;
164
165 if ( (tskbar = click_taskbar(panel, x, y)) ) {
166 if (panel_horizontal) {
167 Task *tsk;
168 for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
169 tsk = l0->data;
170 if (x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
171 return tsk;
172 }
173 }
174 }
175 else {
176 Task *tsk;
177 for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
178 tsk = l0->data;
179 if (y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
180 return tsk;
181 }
182 }
183 }
184 }
185 return NULL;
186 }
187
188
189 int click_padding(Panel *panel, int x, int y)
190 {
191 if (panel_horizontal) {
192 if (x < panel->area.paddingxlr || x > panel->area.width-panel->area.paddingxlr)
193 return 1;
194 }
195 else {
196 if (y < panel->area.paddingxlr || y > panel->area.height-panel->area.paddingxlr)
197 return 1;
198 }
199 return 0;
200 }
201
202
203 int click_clock(Panel *panel, int x, int y)
204 {
205 Clock clk = panel->clock;
206 if (panel_horizontal) {
207 if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width))
208 return TRUE;
209 } else {
210 if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height))
211 return TRUE;
212 }
213 return FALSE;
214 }
215
216
217 void window_action (Task *tsk, int action)
218 {
219 if (!tsk) return;
220 int desk;
221 switch (action) {
222 case CLOSE:
223 set_close (tsk->win);
224 break;
225 case TOGGLE:
226 set_active(tsk->win);
227 break;
228 case ICONIFY:
229 XIconifyWindow (server.dsp, tsk->win, server.screen);
230 break;
231 case TOGGLE_ICONIFY:
232 if (tsk == task_active) XIconifyWindow (server.dsp, tsk->win, server.screen);
233 else set_active (tsk->win);
234 break;
235 case SHADE:
236 window_toggle_shade (tsk->win);
237 break;
238 case MAXIMIZE_RESTORE:
239 window_maximize_restore (tsk->win);
240 break;
241 case MAXIMIZE:
242 window_maximize_restore (tsk->win);
243 break;
244 case RESTORE:
245 window_maximize_restore (tsk->win);
246 break;
247 case DESKTOP_LEFT:
248 if ( tsk->desktop == 0 ) break;
249 desk = tsk->desktop - 1;
250 windows_set_desktop(tsk->win, desk);
251 if (desk == server.desktop)
252 set_active(tsk->win);
253 break;
254 case DESKTOP_RIGHT:
255 if (tsk->desktop == server.nb_desktop ) break;
256 desk = tsk->desktop + 1;
257 windows_set_desktop(tsk->win, desk);
258 if (desk == server.desktop)
259 set_active(tsk->win);
260 }
261 }
262
263
264 void event_button_press (XEvent *e)
265 {
266 Panel *panel = get_panel(e->xany.window);
267 if (!panel) return;
268
269 if (panel_mode == MULTI_DESKTOP)
270 task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
271
272 if (wm_menu && !task_drag && !click_clock(panel, e->xbutton.x, e->xbutton.y) && (e->xbutton.button != 1) ) {
273 // forward the click to the desktop window (thanks conky)
274 XUngrabPointer(server.dsp, e->xbutton.time);
275 e->xbutton.window = server.root_win;
276 // icewm doesn't open under the mouse.
277 // and xfce doesn't open at all.
278 //e->xbutton.x = e->xbutton.x_root;
279 //e->xbutton.y = e->xbutton.y_root;
280 //printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y);
281 XSetInputFocus(server.dsp, e->xbutton.window, RevertToParent, e->xbutton.time);
282 XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e);
283 return;
284 }
285
286 XLowerWindow (server.dsp, panel->main_win);
287 }
288
289
290 void event_button_release (XEvent *e)
291 {
292 Panel *panel = get_panel(e->xany.window);
293 if (!panel) return;
294
295 if (wm_menu && click_padding(panel, e->xbutton.x, e->xbutton.y)) {
296 // forward the click to the desktop window (thanks conky)
297 e->xbutton.window = server.root_win;
298 XSendEvent(server.dsp, e->xbutton.window, False, ButtonReleaseMask, e);
299 return;
300 }
301
302 int action = TOGGLE_ICONIFY;
303 switch (e->xbutton.button) {
304 case 2:
305 action = mouse_middle;
306 break;
307 case 3:
308 action = mouse_right;
309 break;
310 case 4:
311 action = mouse_scroll_up;
312 break;
313 case 5:
314 action = mouse_scroll_down;
315 break;
316 case 6:
317 action = mouse_tilt_left;
318 break;
319 case 7:
320 action = mouse_tilt_right;
321 break;
322 }
323
324 if ( click_clock(panel, e->xbutton.x, e->xbutton.y)) {
325 clock_action(e->xbutton.button);
326 XLowerWindow (server.dsp, panel->main_win);
327 task_drag = 0;
328 return;
329 }
330
331 Taskbar *tskbar;
332 if ( !(tskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y)) ) {
333 // TODO: check better solution to keep window below
334 XLowerWindow (server.dsp, panel->main_win);
335 task_drag = 0;
336 return;
337 }
338
339 // drag and drop task
340 if (task_drag) {
341 if (tskbar != task_drag->area.parent && action == TOGGLE_ICONIFY) {
342 if (task_drag->desktop != ALLDESKTOP && panel_mode == MULTI_DESKTOP) {
343 windows_set_desktop(task_drag->win, tskbar->desktop);
344 if (tskbar->desktop == server.desktop)
345 set_active(task_drag->win);
346 task_drag = 0;
347 }
348 return;
349 }
350 else task_drag = 0;
351 }
352
353 // switch desktop
354 if (panel_mode == MULTI_DESKTOP) {
355 if (tskbar->desktop != server.desktop && action != CLOSE && action != DESKTOP_LEFT && action != DESKTOP_RIGHT)
356 set_desktop (tskbar->desktop);
357 }
358
359 // action on task
360 window_action( click_task(panel, e->xbutton.x, e->xbutton.y), action);
361
362 // to keep window below
363 XLowerWindow (server.dsp, panel->main_win);
364 }
365
366
367 void event_property_notify (XEvent *e)
368 {
369 int i, j;
370 Task *tsk;
371 Window win = e->xproperty.window;
372 Atom at = e->xproperty.atom;
373
374 if (win == server.root_win) {
375 if (!server.got_root_win) {
376 XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
377 server.got_root_win = 1;
378 }
379
380 // Change number of desktops
381 else if (at == server.atom._NET_NUMBER_OF_DESKTOPS) {
382 server.nb_desktop = server_get_number_of_desktop ();
383 cleanup_taskbar();
384 init_taskbar();
385 visible_object();
386 for (i=0 ; i < nb_panel ; i++) {
387 panel1[i].area.resize = 1;
388 }
389 task_refresh_tasklist();
390 panel_refresh = 1;
391 }
392 // Change desktop
393 else if (at == server.atom._NET_CURRENT_DESKTOP) {
394 server.desktop = server_get_current_desktop ();
395 for (i=0 ; i < nb_panel ; i++) {
396 Panel *panel = &panel1[i];
397 if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) {
398 // redraw taskbar
399 panel_refresh = 1;
400 Taskbar *tskbar;
401 Task *tsk;
402 GSList *l;
403 for (j=0 ; j < panel->nb_desktop ; j++) {
404 tskbar = &panel->taskbar[j];
405 if (tskbar->area.is_active) {
406 tskbar->area.is_active = 0;
407 tskbar->area.redraw = 1;
408 for (l = tskbar->area.list; l ; l = l->next) {
409 tsk = l->data;
410 tsk->area.redraw = 1;
411 }
412 }
413 if (j == server.desktop) {
414 tskbar->area.is_active = 1;
415 tskbar->area.redraw = 1;
416 for (l = tskbar->area.list; l ; l = l->next) {
417 tsk = l->data;
418 tsk->area.redraw = 1;
419 }
420 }
421 }
422 }
423 }
424 if (panel_mode != MULTI_DESKTOP) {
425 visible_object();
426 }
427 }
428 // Window list
429 else if (at == server.atom._NET_CLIENT_LIST) {
430 task_refresh_tasklist();
431 panel_refresh = 1;
432 }
433 // Change active
434 else if (at == server.atom._NET_ACTIVE_WINDOW) {
435 GSList *l0;
436 if (task_active) {
437 for (i=0 ; i < nb_panel ; i++) {
438 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
439 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
440 tsk = l0->data;
441 tsk->area.is_active = 0;
442 }
443 }
444 }
445 task_active = 0;
446 }
447 Window w1 = window_get_active ();
448 Task *t = task_get_task(w1);
449 if (!t) {
450 Window w2;
451 if (XGetTransientForHint(server.dsp, w1, &w2) != 0)
452 if (w2) t = task_get_task(w2);
453 }
454 if (task_urgent == t) {
455 init_precision();
456 task_urgent = 0;
457 }
458 // put active state on all task (multi_desktop)
459 if (t) {
460 for (i=0 ; i < nb_panel ; i++) {
461 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
462 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
463 tsk = l0->data;
464 if (tsk->win == t->win) {
465 tsk->area.is_active = 1;
466 //printf("active monitor %d, task %s\n", panel1[i].monitor, tsk->title);
467 }
468 }
469 }
470 }
471 task_active = t;
472 }
473 panel_refresh = 1;
474 }
475 else if (at == server.atom._XROOTPMAP_ID) {
476 // change Wallpaper
477 for (i=0 ; i < nb_panel ; i++) {
478 set_panel_background(&panel1[i]);
479 }
480 panel_refresh = 1;
481 }
482 }
483 else {
484 tsk = task_get_task (win);
485 if (!tsk) {
486 if ( at != server.atom._NET_WM_STATE)
487 return;
488 else if ( !(tsk = add_task(win)) )
489 return;
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 task_urgent = tsk;
516 tick_urgent = 0;
517 time_precision = 1;
518 }
519 if (window_is_skip_taskbar(win)) {
520 remove_task( tsk );
521 panel_refresh = 1;
522 }
523 }
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_data = tsk->icon_data;
558 tsk2->icon_data_active = tsk->icon_data_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 int active = tsk->area.is_active;
570 //printf(" Window desktop changed %d, %d\n", tsk->desktop, desktop);
571 // bug in windowmaker : send unecessary 'desktop changed' when focus changed
572 if (desktop != tsk->desktop) {
573 remove_task (tsk);
574 tsk = add_task (win);
575 if (tsk && active) {
576 tsk->area.is_active = 1;
577 task_active = tsk;
578 }
579 panel_refresh = 1;
580 }
581 }
582
583 if (!server.got_root_win) server.root_win = RootWindow (server.dsp, server.screen);
584 }
585 }
586
587
588 void event_expose (XEvent *e)
589 {
590 Panel *panel;
591
592 panel = get_panel(e->xany.window);
593 if (!panel) return;
594 // TODO : one panel_refresh per panel ?
595 panel_refresh = 1;
596 }
597
598
599 void event_configure_notify (Window win)
600 {
601 // check 'win' move in systray
602 TrayWindow *traywin;
603 GSList *l;
604 for (l = systray.list_icons; l ; l = l->next) {
605 traywin = (TrayWindow*)l->data;
606 if (traywin->id == win) {
607 //printf("move tray %d\n", traywin->x);
608 XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
609 panel_refresh = 1;
610 return;
611 }
612 }
613
614 // check 'win' move in another monitor
615 if (nb_panel == 1) return;
616 if (server.nb_monitor == 1) return;
617 Task *tsk = task_get_task (win);
618 if (!tsk) return;
619
620 Panel *p = tsk->area.panel;
621 if (p->monitor != window_get_monitor (win)) {
622 remove_task (tsk);
623 add_task (win);
624 if (win == window_get_active ()) {
625 Task *tsk = task_get_task (win);
626 tsk->area.is_active = 1;
627 task_active = tsk;
628 }
629 panel_refresh = 1;
630 }
631 }
632
633
634 void event_timer()
635 {
636 struct timeval stv;
637 int i;
638
639 if (gettimeofday(&stv, 0)) return;
640
641 if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
642 time_clock.tv_sec = stv.tv_sec;
643 time_clock.tv_sec -= time_clock.tv_sec % time_precision;
644
645 // urgent task
646 if (task_urgent) {
647 if (tick_urgent < max_tick_urgent) {
648 task_urgent->area.is_active = !task_urgent->area.is_active;
649 task_urgent->area.redraw = 1;
650 tick_urgent++;
651 }
652 }
653
654 // update battery
655 #ifdef ENABLE_BATTERY
656 if (panel1[0].battery.area.on_screen) {
657 update_battery();
658 for (i=0 ; i < nb_panel ; i++)
659 panel1[i].battery.area.resize = 1;
660 }
661 #endif
662
663 // update clock
664 if (time1_format) {
665 for (i=0 ; i < nb_panel ; i++)
666 panel1[i].clock.area.resize = 1;
667 }
668 panel_refresh = 1;
669 }
670
671
672 void dnd_message(XClientMessageEvent *e)
673 {
674 Panel *panel = get_panel(e->window);
675 int x, y, mapX, mapY;
676 Window child;
677 x = (e->data.l[2] >> 16) & 0xFFFF;
678 y = e->data.l[2] & 0xFFFF;
679 XTranslateCoordinates(server.dsp, server.root_win, e->window, x, y, &mapX, &mapY, &child);
680 Task* task = click_task(panel, mapX, mapY);
681 if (task) {
682 if (task->desktop != server.desktop )
683 set_desktop (task->desktop);
684 window_action(task, TOGGLE);
685 }
686
687 // send XdndStatus event to get more XdndPosition events
688 XClientMessageEvent se;
689 se.type = ClientMessage;
690 se.window = e->data.l[0];
691 se.message_type = server.atom.XdndStatus;
692 se.format = 32;
693 se.data.l[0] = e->window; // XID of the target window
694 se.data.l[1] = 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
695 se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
696 se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
697 se.data.l[4] = None; // None = drop will not be accepted
698 XSendEvent(server.dsp, e->data.l[0], False, NoEventMask, (XEvent*)&se);
699 }
700
701
702 int main (int argc, char *argv[])
703 {
704 XEvent e;
705 fd_set fd;
706 int x11_fd, i;
707 struct timeval tv;
708 Panel *panel;
709 GSList *it;
710
711 init (argc, argv);
712
713 load_config:
714 i = 0;
715 init_config();
716 if (config_path)
717 i = config_read_file (config_path);
718 else
719 i = config_read ();
720 if (!i) {
721 fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
722 cleanup();
723 exit(1);
724 }
725 config_finish();
726 if (thumbnail_path) {
727 // usage: tint2 -j <file> for internal use
728 printf("file %s\n", thumbnail_path);
729 cleanup();
730 exit(0);
731 }
732
733 x11_fd = ConnectionNumber(server.dsp);
734 XSync(server.dsp, False);
735
736 while (1) {
737 // thanks to AngryLlama for the timer
738 // Create a File Description Set containing x11_fd
739 FD_ZERO (&fd);
740 FD_SET (x11_fd, &fd);
741
742 tv.tv_usec = 500000;
743 tv.tv_sec = 0;
744
745 // Wait for X Event or a Timer
746 if (select(x11_fd+1, &fd, 0, 0, &tv)) {
747 while (XPending (server.dsp)) {
748 XNextEvent(server.dsp, &e);
749
750 switch (e.type) {
751 case ButtonPress:
752 event_button_press (&e);
753 break;
754
755 case ButtonRelease:
756 event_button_release(&e);
757 break;
758
759 case Expose:
760 event_expose(&e);
761 break;
762
763 case PropertyNotify:
764 event_property_notify(&e);
765 break;
766
767 case ConfigureNotify:
768 if (e.xconfigure.window == server.root_win)
769 goto load_config;
770 else
771 event_configure_notify (e.xconfigure.window);
772 break;
773
774 case ReparentNotify:
775 if (!systray.area.on_screen)
776 break;
777 panel = (Panel*)systray.area.panel;
778 if (e.xany.window == panel->main_win) // reparented to us
779 break;
780 // FIXME: 'reparent to us' badly detected => disabled
781 break;
782 case UnmapNotify:
783 case DestroyNotify:
784 if (!systray.area.on_screen)
785 break;
786 for (it = systray.list_icons; it; it = g_slist_next(it)) {
787 if (((TrayWindow*)it->data)->id == e.xany.window) {
788 remove_icon((TrayWindow*)it->data);
789 break;
790 }
791 }
792 break;
793
794 case ClientMessage:
795 if (!systray.area.on_screen) break;
796 if (e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
797 net_message(&e.xclient);
798 }
799 else if (e.xclient.message_type == server.atom.XdndPosition) {
800 dnd_message(&e.xclient);
801 }
802 break;
803 }
804 }
805 }
806 event_timer();
807
808 switch (signal_pending) {
809 case SIGUSR1:
810 signal_pending = 0;
811 goto load_config;
812 case SIGINT:
813 case SIGTERM:
814 case SIGHUP:
815 cleanup ();
816 return 0;
817 }
818
819 if (panel_refresh) {
820 panel_refresh = 0;
821
822 if (refresh_systray) {
823 panel = (Panel*)systray.area.panel;
824 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
825 }
826 for (i=0 ; i < nb_panel ; i++) {
827 panel = &panel1[i];
828
829 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
830 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
831
832 refresh(&panel->area);
833 XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
834 }
835 XFlush (server.dsp);
836
837 if (refresh_systray) {
838 refresh_systray = 0;
839 panel = (Panel*)systray.area.panel;
840 // tint2 doen't draw systray icons. it just redraw background.
841 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
842 // force icon's refresh
843 refresh_systray_icon();
844 }
845 }
846 }
847 }
848
849
This page took 0.075941 seconds and 5 git commands to generate.