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