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