]> Dogcows Code - chaz/tint2/blob - src/tint.c
fixed WM menu management
[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 int action = TOGGLE_ICONIFY;
295 switch (e->xbutton.button) {
296 case 2:
297 action = mouse_middle;
298 break;
299 case 3:
300 action = mouse_right;
301 break;
302 case 4:
303 action = mouse_scroll_up;
304 break;
305 case 5:
306 action = mouse_scroll_down;
307 break;
308 case 6:
309 action = mouse_tilt_left;
310 break;
311 case 7:
312 action = mouse_tilt_right;
313 break;
314 }
315
316 if ( click_clock(panel, e->xbutton.x, e->xbutton.y)) {
317 clock_action(e->xbutton.button);
318 XLowerWindow (server.dsp, panel->main_win);
319 task_drag = 0;
320 return;
321 }
322
323 Taskbar *tskbar;
324 if ( !(tskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y)) ) {
325 // TODO: check better solution to keep window below
326 XLowerWindow (server.dsp, panel->main_win);
327 task_drag = 0;
328 return;
329 }
330
331 // drag and drop task
332 if (task_drag) {
333 if (tskbar != task_drag->area.parent && action == TOGGLE_ICONIFY) {
334 if (task_drag->desktop != ALLDESKTOP && panel_mode == MULTI_DESKTOP) {
335 windows_set_desktop(task_drag->win, tskbar->desktop);
336 if (tskbar->desktop == server.desktop)
337 set_active(task_drag->win);
338 task_drag = 0;
339 }
340 return;
341 }
342 else task_drag = 0;
343 }
344
345 // switch desktop
346 if (panel_mode == MULTI_DESKTOP) {
347 if (tskbar->desktop != server.desktop && action != CLOSE && action != DESKTOP_LEFT && action != DESKTOP_RIGHT)
348 set_desktop (tskbar->desktop);
349 }
350
351 // action on task
352 window_action( click_task(panel, e->xbutton.x, e->xbutton.y), action);
353
354 // to keep window below
355 XLowerWindow (server.dsp, panel->main_win);
356 }
357
358
359 void event_property_notify (XEvent *e)
360 {
361 int i, j;
362 Task *tsk;
363 Window win = e->xproperty.window;
364 Atom at = e->xproperty.atom;
365
366 if (win == server.root_win) {
367 if (!server.got_root_win) {
368 XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
369 server.got_root_win = 1;
370 }
371
372 // Change number of desktops
373 else if (at == server.atom._NET_NUMBER_OF_DESKTOPS) {
374 server.nb_desktop = server_get_number_of_desktop ();
375 cleanup_taskbar();
376 init_taskbar();
377 visible_object();
378 for (i=0 ; i < nb_panel ; i++) {
379 panel1[i].area.resize = 1;
380 }
381 task_refresh_tasklist();
382 panel_refresh = 1;
383 }
384 // Change desktop
385 else if (at == server.atom._NET_CURRENT_DESKTOP) {
386 int old_desktop = server.desktop;
387 server.desktop = server_get_current_desktop ();
388 for (i=0 ; i < nb_panel ; i++) {
389 Panel *panel = &panel1[i];
390 if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) {
391 // redraw both taskbar
392 panel->taskbar[old_desktop].area.is_active = 0;
393 panel->taskbar[old_desktop].area.redraw = 1;
394 panel->taskbar[server.desktop].area.is_active = 1;
395 panel->taskbar[server.desktop].area.redraw = 1;
396 panel_refresh = 1;
397 }
398 // check ALLDESKTOP task => resize taskbar
399 Taskbar *tskbar;
400 Task *tsk;
401 GSList *l;
402 tskbar = &panel->taskbar[old_desktop];
403 for (l = tskbar->area.list; l ; l = l->next) {
404 tsk = l->data;
405 if (tsk->desktop == ALLDESKTOP) {
406 tsk->area.on_screen = 0;
407 tskbar->area.resize = 1;
408 panel_refresh = 1;
409 }
410 }
411 tskbar = &panel->taskbar[server.desktop];
412 for (l = tskbar->area.list; l ; l = l->next) {
413 tsk = l->data;
414 if (tsk->desktop == ALLDESKTOP) {
415 tsk->area.on_screen = 1;
416 tskbar->area.resize = 1;
417 }
418 }
419 }
420 if (panel_mode != MULTI_DESKTOP) {
421 visible_object();
422 }
423 }
424 // Window list
425 else if (at == server.atom._NET_CLIENT_LIST) {
426 task_refresh_tasklist();
427 panel_refresh = 1;
428 }
429 // Change active
430 else if (at == server.atom._NET_ACTIVE_WINDOW) {
431 GSList *l0;
432 if (task_active) {
433 for (i=0 ; i < nb_panel ; i++) {
434 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
435 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
436 tsk = l0->data;
437 tsk->area.is_active = 0;
438 }
439 }
440 }
441 task_active = 0;
442 }
443 Window w1 = window_get_active ();
444 Task *t = task_get_task(w1);
445 if (!t) {
446 Window w2;
447 if (XGetTransientForHint(server.dsp, w1, &w2) != 0)
448 if (w2) t = task_get_task(w2);
449 }
450 if (task_urgent == t) {
451 init_precision();
452 task_urgent = 0;
453 }
454 // put active state on all task (multi_desktop)
455 if (t) {
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 if (tsk->win == t->win) {
461 tsk->area.is_active = 1;
462 //printf("active monitor %d, task %s\n", panel1[i].monitor, tsk->title);
463 }
464 }
465 }
466 }
467 task_active = t;
468 }
469 panel_refresh = 1;
470 }
471 else if (at == server.atom._XROOTPMAP_ID) {
472 // change Wallpaper
473 for (i=0 ; i < nb_panel ; i++) {
474 set_panel_background(&panel1[i]);
475 }
476 panel_refresh = 1;
477 }
478 }
479 else {
480 tsk = task_get_task (win);
481 if (!tsk) {
482 if ( at != server.atom._NET_WM_STATE)
483 return;
484 else if ( !(tsk = add_task(win)) )
485 return;
486 }
487 //printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
488
489 // Window title changed
490 if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
491 Task *tsk2;
492 GSList *l0;
493 get_title(tsk);
494 // changed other tsk->title
495 for (i=0 ; i < nb_panel ; i++) {
496 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
497 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
498 tsk2 = l0->data;
499 if (tsk->win == tsk2->win && tsk != tsk2) {
500 tsk2->title = tsk->title;
501 tsk2->area.redraw = 1;
502 }
503 }
504 }
505 }
506 panel_refresh = 1;
507 }
508 // Demand attention
509 else if (at == server.atom._NET_WM_STATE) {
510 if (window_is_urgent (win)) {
511 task_urgent = tsk;
512 tick_urgent = 0;
513 time_precision = 1;
514 }
515 if (window_is_skip_taskbar(win)) {
516 remove_task( tsk );
517 panel_refresh = 1;
518 }
519 }
520 // else if (at == server.atom.WM_STATE) {
521 // // Iconic state
522 // // TODO : try to delete following code
523 // if (window_is_iconified (win)) {
524 // if (task_active) {
525 // if (task_active->win == tsk->win) {
526 // Task *tsk2;
527 // GSList *l0;
528 // for (i=0 ; i < nb_panel ; i++) {
529 // for (j=0 ; j < panel1[i].nb_desktop ; j++) {
530 // for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
531 // tsk2 = l0->data;
532 // tsk2->area.is_active = 0;
533 // }
534 // }
535 // }
536 // task_active = 0;
537 // }
538 // }
539 // }
540 // }
541 // Window icon changed
542 else if (at == server.atom._NET_WM_ICON) {
543 get_icon(tsk);
544 Task *tsk2;
545 GSList *l0;
546 for (i=0 ; i < nb_panel ; i++) {
547 for (j=0 ; j < panel1[i].nb_desktop ; j++) {
548 for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
549 tsk2 = l0->data;
550 if (tsk->win == tsk2->win && tsk != tsk2) {
551 tsk2->icon_width = tsk->icon_width;
552 tsk2->icon_height = tsk->icon_height;
553 tsk2->icon = tsk->icon;
554 tsk2->icon_active = tsk->icon_active;
555 tsk2->area.redraw = 1;
556 }
557 }
558 }
559 }
560 panel_refresh = 1;
561 }
562 // Window desktop changed
563 else if (at == server.atom._NET_WM_DESKTOP) {
564 int desktop = window_get_desktop (win);
565 int active = tsk->area.is_active;
566 //printf(" Window desktop changed %d, %d\n", tsk->desktop, desktop);
567 // bug in windowmaker : send unecessary 'desktop changed' when focus changed
568 if (desktop != tsk->desktop) {
569 remove_task (tsk);
570 tsk = add_task (win);
571 if (tsk && active) {
572 tsk->area.is_active = 1;
573 task_active = tsk;
574 }
575 panel_refresh = 1;
576 }
577 }
578 else if (at == server.atom.WM_HINTS) {
579 XWMHints* wmhints = XGetWMHints(server.dsp, win);
580 if (wmhints && wmhints->flags & XUrgencyHint) {
581 task_urgent = tsk;
582 tick_urgent = 0;
583 time_precision = 1;
584 }
585 XFree(wmhints);
586 }
587
588 if (!server.got_root_win) server.root_win = RootWindow (server.dsp, server.screen);
589 }
590 }
591
592
593 void event_expose (XEvent *e)
594 {
595 if (e->xany.window == g_tooltip.window)
596 tooltip_update();
597 else {
598 Panel *panel;
599 panel = get_panel(e->xany.window);
600 if (!panel) return;
601 // TODO : one panel_refresh per panel ?
602 panel_refresh = 1;
603 }
604 }
605
606
607 void event_configure_notify (Window win)
608 {
609 // change in root window (xrandr)
610 if (win == server.root_win) {
611 int i, old_monitor = server.nb_monitor;
612
613 get_monitors();
614 if (old_monitor != server.nb_monitor) {
615 }
616 for (i=0 ; i < nb_panel ; i++) {
617 Panel *panel = &panel1[i];
618
619 init_panel_size_and_position(panel);
620 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy, panel->area.width, panel->area.height);
621 set_panel_background(panel);
622
623 // force the resize of childs
624 GSList *l0;
625 panel->area.resize = 1;
626 for (l0 = panel->area.list; l0 ; l0 = l0->next)
627 ((Area*)l0->data)->resize = 1;
628 }
629 panel_refresh = 1;
630 return;
631 }
632
633 // 'win' is a trayer icon
634 TrayWindow *traywin;
635 GSList *l;
636 for (l = systray.list_icons; l ; l = l->next) {
637 traywin = (TrayWindow*)l->data;
638 if (traywin->id == win) {
639 //printf("move tray %d\n", traywin->x);
640 XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
641 panel_refresh = 1;
642 return;
643 }
644 }
645
646 // 'win' move in another monitor
647 if (nb_panel == 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 event_configure_notify (e.xconfigure.window);
814 break;
815
816 case ReparentNotify:
817 if (!systray.area.on_screen)
818 break;
819 panel = (Panel*)systray.area.panel;
820 if (e.xany.window == panel->main_win) // reparented to us
821 break;
822 // FIXME: 'reparent to us' badly detected => disabled
823 break;
824 case UnmapNotify:
825 case DestroyNotify:
826 if (!systray.area.on_screen)
827 break;
828 for (it = systray.list_icons; it; it = g_slist_next(it)) {
829 if (((TrayWindow*)it->data)->id == e.xany.window) {
830 remove_icon((TrayWindow*)it->data);
831 break;
832 }
833 }
834 break;
835
836 case ClientMessage:
837 if (!systray.area.on_screen) break;
838 if (e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
839 net_message(&e.xclient);
840 }
841 else if (e.xclient.message_type == server.atom.XdndPosition) {
842 dnd_message(&e.xclient);
843 }
844 break;
845 }
846 }
847 }
848 event_timer();
849
850 switch (signal_pending) {
851 case SIGUSR1:
852 signal_pending = 0;
853 goto load_config;
854 case SIGINT:
855 case SIGTERM:
856 case SIGHUP:
857 cleanup ();
858 return 0;
859 }
860
861 if (panel_refresh) {
862 panel_refresh = 0;
863
864 if (refresh_systray) {
865 panel = (Panel*)systray.area.panel;
866 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
867 }
868 for (i=0 ; i < nb_panel ; i++) {
869 panel = &panel1[i];
870
871 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
872 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
873
874 refresh(&panel->area);
875 XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
876 }
877 XFlush (server.dsp);
878
879 if (refresh_systray) {
880 refresh_systray = 0;
881 panel = (Panel*)systray.area.panel;
882 // tint2 doen't draw systray icons. it just redraw background.
883 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
884 // force icon's refresh
885 refresh_systray_icon();
886 }
887 }
888 }
889 }
890
891
This page took 0.08228 seconds and 5 git commands to generate.