]> Dogcows Code - chaz/tint2/blob - src/tint.c
tint2conf : right clic on 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 if (wm_menu && (e->xbutton.button != 1) ) {
299 task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
300 if (!task_drag && !click_clock(panel, e->xbutton.x, e->xbutton.y) ) {
301 */
302 task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
303
304 if (wm_menu && !task_drag && !click_clock(panel, e->xbutton.x, e->xbutton.y) && (e->xbutton.button != 1) ) {
305 // forward the click to the desktop window (thanks conky)
306 XUngrabPointer(server.dsp, e->xbutton.time);
307 e->xbutton.window = server.root_win;
308 // icewm doesn't open under the mouse.
309 // and xfce doesn't open at all.
310 e->xbutton.x = e->xbutton.x_root;
311 e->xbutton.y = e->xbutton.y_root;
312 //printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y);
313 //XSetInputFocus(server.dsp, e->xbutton.window, RevertToParent, e->xbutton.time);
314 XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e);
315 return;
316 }
317
318 XLowerWindow (server.dsp, panel->main_win);
319 }
320
321
322 void event_button_release (XEvent *e)
323 {
324 Panel *panel = get_panel(e->xany.window);
325 if (!panel) return;
326
327 int action = TOGGLE_ICONIFY;
328 switch (e->xbutton.button) {
329 case 2:
330 action = mouse_middle;
331 break;
332 case 3:
333 action = mouse_right;
334 break;
335 case 4:
336 action = mouse_scroll_up;
337 break;
338 case 5:
339 action = mouse_scroll_down;
340 break;
341 case 6:
342 action = mouse_tilt_left;
343 break;
344 case 7:
345 action = mouse_tilt_right;
346 break;
347 }
348
349 if ( click_clock(panel, e->xbutton.x, e->xbutton.y)) {
350 clock_action(e->xbutton.button);
351 XLowerWindow (server.dsp, panel->main_win);
352 task_drag = 0;
353 return;
354 }
355
356 Taskbar *tskbar;
357 if ( !(tskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y)) ) {
358 // TODO: check better solution to keep window below
359 XLowerWindow (server.dsp, panel->main_win);
360 task_drag = 0;
361 return;
362 }
363
364 // drag and drop task
365 if (task_drag) {
366 if (tskbar != task_drag->area.parent && action == TOGGLE_ICONIFY) {
367 if (task_drag->desktop != ALLDESKTOP && panel_mode == MULTI_DESKTOP) {
368 windows_set_desktop(task_drag->win, tskbar->desktop);
369 if (tskbar->desktop == server.desktop)
370 set_active(task_drag->win);
371 task_drag = 0;
372 }
373 return;
374 }
375 else task_drag = 0;
376 }
377
378 // switch desktop
379 if (panel_mode == MULTI_DESKTOP) {
380 if (tskbar->desktop != server.desktop && action != CLOSE && action != DESKTOP_LEFT && action != DESKTOP_RIGHT)
381 set_desktop (tskbar->desktop);
382 }
383
384 // action on task
385 window_action( click_task(panel, e->xbutton.x, e->xbutton.y), action);
386
387 // to keep window below
388 XLowerWindow (server.dsp, panel->main_win);
389 }
390
391
392 void event_property_notify (XEvent *e)
393 {
394 int i, j;
395 Task *tsk;
396 Window win = e->xproperty.window;
397 Atom at = e->xproperty.atom;
398
399 if (win == server.root_win) {
400 if (!server.got_root_win) {
401 XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
402 server.got_root_win = 1;
403 }
404
405 // Change number of desktops
406 else if (at == server.atom._NET_NUMBER_OF_DESKTOPS) {
407 server.nb_desktop = server_get_number_of_desktop ();
408 cleanup_taskbar();
409 init_taskbar();
410 visible_object();
411 for (i=0 ; i < nb_panel ; i++) {
412 panel1[i].area.resize = 1;
413 }
414 task_refresh_tasklist();
415 panel_refresh = 1;
416 }
417 // Change desktop
418 else if (at == server.atom._NET_CURRENT_DESKTOP) {
419 int old_desktop = server.desktop;
420 server.desktop = server_get_current_desktop ();
421 for (i=0 ; i < nb_panel ; i++) {
422 Panel *panel = &panel1[i];
423 if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) {
424 // redraw both taskbar
425 panel->taskbar[old_desktop].area.is_active = 0;
426 panel->taskbar[old_desktop].area.redraw = 1;
427 panel->taskbar[server.desktop].area.is_active = 1;
428 panel->taskbar[server.desktop].area.redraw = 1;
429 panel_refresh = 1;
430 }
431 // check ALLDESKTOP task => resize taskbar
432 Taskbar *tskbar;
433 Task *tsk;
434 GSList *l;
435 tskbar = &panel->taskbar[old_desktop];
436 for (l = tskbar->area.list; l ; l = l->next) {
437 tsk = l->data;
438 if (tsk->desktop == ALLDESKTOP) {
439 tsk->area.on_screen = 0;
440 tskbar->area.resize = 1;
441 panel_refresh = 1;
442 }
443 }
444 tskbar = &panel->taskbar[server.desktop];
445 for (l = tskbar->area.list; l ; l = l->next) {
446 tsk = l->data;
447 if (tsk->desktop == ALLDESKTOP) {
448 tsk->area.on_screen = 1;
449 tskbar->area.resize = 1;
450 }
451 }
452 }
453 if (panel_mode != MULTI_DESKTOP) {
454 visible_object();
455 }
456 }
457 // Window list
458 else if (at == server.atom._NET_CLIENT_LIST) {
459 task_refresh_tasklist();
460 panel_refresh = 1;
461 }
462 // Change active
463 else if (at == server.atom._NET_ACTIVE_WINDOW) {
464 active_task();
465 panel_refresh = 1;
466 }
467 else if (at == server.atom._XROOTPMAP_ID) {
468 // change Wallpaper
469 for (i=0 ; i < nb_panel ; i++) {
470 set_panel_background(&panel1[i]);
471 }
472 panel_refresh = 1;
473 }
474 }
475 else {
476 tsk = task_get_task (win);
477 if (!tsk) {
478 if ( at != server.atom._NET_WM_STATE)
479 return;
480 else if ( !(tsk = add_task(win)) )
481 return;
482 }
483 //printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
484
485 // Window title changed
486 if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
487 Task *tsk2;
488 GSList *l0;
489 get_title(tsk);
490 // changed other tsk->title
491 for (i=0 ; i < nb_panel ; i++) {
492 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
493 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
494 tsk2 = l0->data;
495 if (tsk->win == tsk2->win && tsk != tsk2) {
496 tsk2->title = tsk->title;
497 tsk2->area.redraw = 1;
498 }
499 }
500 }
501 }
502 panel_refresh = 1;
503 }
504 // Demand attention
505 else if (at == server.atom._NET_WM_STATE) {
506 if (window_is_urgent (win)) {
507 task_urgent = tsk;
508 tick_urgent = 0;
509 time_precision = 1;
510 }
511 if (window_is_skip_taskbar(win)) {
512 remove_task( tsk );
513 panel_refresh = 1;
514 }
515 }
516 // We do not check for the iconified state, since it only unsets our active window
517 // but in openbox a shaded window is considered iconified. So we would loose the active window
518 // property on unshading it again (commented 01.10.2009)
519 // else if (at == server.atom.WM_STATE) {
520 // // Iconic state
521 // // TODO : try to delete following code
522 // if (window_is_iconified (win)) {
523 // if (task_active) {
524 // if (task_active->win == tsk->win) {
525 // Task *tsk2;
526 // GSList *l0;
527 // for (i=0 ; i < nb_panel ; i++) {
528 // for (j=0 ; j < panel1[i].nb_desktop ; j++) {
529 // for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
530 // tsk2 = l0->data;
531 // tsk2->area.is_active = 0;
532 // }
533 // }
534 // }
535 // task_active = 0;
536 // }
537 // }
538 // }
539 // }
540 // Window icon changed
541 else if (at == server.atom._NET_WM_ICON) {
542 get_icon(tsk);
543 Task *tsk2;
544 GSList *l0;
545 for (i=0 ; i < nb_panel ; i++) {
546 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
547 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
548 tsk2 = l0->data;
549 if (tsk->win == tsk2->win && tsk != tsk2) {
550 tsk2->icon_width = tsk->icon_width;
551 tsk2->icon_height = tsk->icon_height;
552 tsk2->icon = tsk->icon;
553 tsk2->icon_active = tsk->icon_active;
554 tsk2->area.redraw = 1;
555 }
556 }
557 }
558 }
559 panel_refresh = 1;
560 }
561 // Window desktop changed
562 else if (at == server.atom._NET_WM_DESKTOP) {
563 int desktop = window_get_desktop (win);
564 int active = tsk->area.is_active;
565 //printf(" Window desktop changed %d, %d\n", tsk->desktop, desktop);
566 // bug in windowmaker : send unecessary 'desktop changed' when focus changed
567 if (desktop != tsk->desktop) {
568 remove_task (tsk);
569 tsk = add_task (win);
570 if (tsk && active) {
571 tsk->area.is_active = 1;
572 task_active = tsk;
573 }
574 panel_refresh = 1;
575 }
576 }
577 else if (at == server.atom.WM_HINTS) {
578 XWMHints* wmhints = XGetWMHints(server.dsp, win);
579 if (wmhints && wmhints->flags & XUrgencyHint) {
580 task_urgent = tsk;
581 tick_urgent = 0;
582 time_precision = 1;
583 }
584 XFree(wmhints);
585 }
586
587 if (!server.got_root_win) server.root_win = RootWindow (server.dsp, server.screen);
588 }
589 }
590
591
592 void event_expose (XEvent *e)
593 {
594 if (e->xany.window == g_tooltip.window)
595 tooltip_update();
596 else {
597 Panel *panel;
598 panel = get_panel(e->xany.window);
599 if (!panel) return;
600 // TODO : one panel_refresh per panel ?
601 panel_refresh = 1;
602 }
603 }
604
605
606 void event_configure_notify (Window win)
607 {
608 // change in root window (xrandr)
609 if (win == server.root_win) {
610 get_monitors();
611 init_panel();
612 return;
613 }
614
615 // 'win' is a trayer icon
616 TrayWindow *traywin;
617 GSList *l;
618 for (l = systray.list_icons; l ; l = l->next) {
619 traywin = (TrayWindow*)l->data;
620 if (traywin->id == win) {
621 //printf("move tray %d\n", traywin->x);
622 XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
623 panel_refresh = 1;
624 return;
625 }
626 }
627
628 // 'win' move in another monitor
629 if (nb_panel == 1) return;
630 Task *tsk = task_get_task (win);
631 if (!tsk) return;
632
633 Panel *p = tsk->area.panel;
634 if (p->monitor != window_get_monitor (win)) {
635 remove_task (tsk);
636 add_task (win);
637 if (win == window_get_active ()) {
638 Task *tsk = task_get_task (win);
639 tsk->area.is_active = 1;
640 task_active = tsk;
641 }
642 panel_refresh = 1;
643 }
644 }
645
646
647 void event_timer()
648 {
649 struct timeval stv;
650 int i;
651
652 if (gettimeofday(&stv, 0)) return;
653
654 if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
655 time_clock.tv_sec = stv.tv_sec;
656 time_clock.tv_sec -= time_clock.tv_sec % time_precision;
657
658 // urgent task
659 if (task_urgent) {
660 if (tick_urgent < max_tick_urgent) {
661 task_urgent->area.is_active = !task_urgent->area.is_active;
662 task_urgent->area.redraw = 1;
663 tick_urgent++;
664 }
665 }
666
667 // update battery
668 #ifdef ENABLE_BATTERY
669 if (panel1[0].battery.area.on_screen) {
670 update_battery();
671 for (i=0 ; i < nb_panel ; i++)
672 panel1[i].battery.area.resize = 1;
673 }
674 #endif
675
676 // update clock
677 if (time1_format) {
678 for (i=0 ; i < nb_panel ; i++)
679 panel1[i].clock.area.resize = 1;
680 }
681 panel_refresh = 1;
682 }
683
684
685 void dnd_message(XClientMessageEvent *e)
686 {
687 Panel *panel = get_panel(e->window);
688 int x, y, mapX, mapY;
689 Window child;
690 x = (e->data.l[2] >> 16) & 0xFFFF;
691 y = e->data.l[2] & 0xFFFF;
692 XTranslateCoordinates(server.dsp, server.root_win, e->window, x, y, &mapX, &mapY, &child);
693 Task* task = click_task(panel, mapX, mapY);
694 if (task) {
695 if (task->desktop != server.desktop )
696 set_desktop (task->desktop);
697 window_action(task, TOGGLE);
698 }
699
700 // send XdndStatus event to get more XdndPosition events
701 XClientMessageEvent se;
702 se.type = ClientMessage;
703 se.window = e->data.l[0];
704 se.message_type = server.atom.XdndStatus;
705 se.format = 32;
706 se.data.l[0] = e->window; // XID of the target window
707 se.data.l[1] = 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
708 se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
709 se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
710 se.data.l[4] = None; // None = drop will not be accepted
711 XSendEvent(server.dsp, e->data.l[0], False, NoEventMask, (XEvent*)&se);
712 }
713
714
715 int main (int argc, char *argv[])
716 {
717 XEvent e;
718 fd_set fd;
719 int x11_fd, i;
720 struct timeval tv;
721 Panel *panel;
722 GSList *it;
723
724 init (argc, argv);
725
726 i = 0;
727 init_config();
728 if (config_path)
729 i = config_read_file (config_path);
730 else
731 i = config_read ();
732 if (!i) {
733 fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
734 cleanup();
735 exit(1);
736 }
737 config_finish();
738 if (thumbnail_path) {
739 // usage: tint2 -j <file> for internal use
740 printf("file %s\n", thumbnail_path);
741 cleanup();
742 exit(0);
743 }
744
745 x11_fd = ConnectionNumber(server.dsp);
746 XSync(server.dsp, False);
747
748 while (1) {
749 // thanks to AngryLlama for the timer
750 // Create a File Description Set containing x11_fd
751 FD_ZERO (&fd);
752 FD_SET (x11_fd, &fd);
753
754 tv.tv_usec = 500000;
755 tv.tv_sec = 0;
756
757 // Wait for X Event or a Timer
758 if (select(x11_fd+1, &fd, 0, 0, &tv)) {
759 while (XPending (server.dsp)) {
760 XNextEvent(server.dsp, &e);
761
762 switch (e.type) {
763 case ButtonPress:
764 tooltip_hide();
765 event_button_press (&e);
766 break;
767
768 case ButtonRelease:
769 event_button_release(&e);
770 break;
771
772 case MotionNotify: {
773 Panel* panel = get_panel(e.xmotion.window);
774 Task* task = click_task(panel, e.xmotion.x, e.xmotion.y);
775 if (task)
776 tooltip_trigger_show(task, e.xmotion.x_root, e.xmotion.y_root);
777 else
778 tooltip_trigger_hide();
779 break;
780 }
781
782 case LeaveNotify:
783 tooltip_trigger_hide();
784 break;
785
786 case Expose:
787 event_expose(&e);
788 break;
789
790 case PropertyNotify:
791 event_property_notify(&e);
792 break;
793
794 case ConfigureNotify:
795 event_configure_notify (e.xconfigure.window);
796 break;
797
798 case ReparentNotify:
799 if (!systray.area.on_screen)
800 break;
801 panel = (Panel*)systray.area.panel;
802 if (e.xany.window == panel->main_win) // reparented to us
803 break;
804 // FIXME: 'reparent to us' badly detected => disabled
805 break;
806 case UnmapNotify:
807 case DestroyNotify:
808 if (!systray.area.on_screen)
809 break;
810 for (it = systray.list_icons; it; it = g_slist_next(it)) {
811 if (((TrayWindow*)it->data)->id == e.xany.window) {
812 remove_icon((TrayWindow*)it->data);
813 break;
814 }
815 }
816 break;
817
818 case ClientMessage:
819 if (!systray.area.on_screen) break;
820 if (e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
821 net_message(&e.xclient);
822 }
823 else if (e.xclient.message_type == server.atom.XdndPosition) {
824 dnd_message(&e.xclient);
825 }
826 break;
827 }
828 }
829 }
830 event_timer();
831
832 switch (signal_pending) {
833 case SIGUSR1: // reload config file
834 signal_pending = 0;
835 init_config();
836 config_read_file (config_path);
837 init_panel();
838 cleanup_config();
839 break;
840 case SIGINT:
841 case SIGTERM:
842 case SIGHUP:
843 cleanup ();
844 return 0;
845 }
846
847 if (panel_refresh) {
848 panel_refresh = 0;
849
850 if (refresh_systray) {
851 panel = (Panel*)systray.area.panel;
852 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
853 }
854 for (i=0 ; i < nb_panel ; i++) {
855 panel = &panel1[i];
856
857 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
858 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
859
860 refresh(&panel->area);
861 XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
862 }
863 XFlush (server.dsp);
864
865 if (refresh_systray) {
866 refresh_systray = 0;
867 panel = (Panel*)systray.area.panel;
868 // tint2 doen't draw systray icons. it just redraw background.
869 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
870 // force icon's refresh
871 refresh_systray_icon();
872 }
873 }
874 }
875 }
876
877
This page took 0.081972 seconds and 5 git commands to generate.