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