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