]> Dogcows Code - chaz/tint2/blob - src/tint.c
cleanup : global setting outside panel.c
[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 int i, old_nb_panel = nb_panel;
640
641 get_monitors();
642 if (panel_config.monitor >= 0)
643 nb_panel = 1;
644 else
645 nb_panel = server.nb_monitor;
646
647 if (old_nb_panel != nb_panel) {
648 // changed number of panel
649 printf("changed number of panel\n");
650 //realloc(panel1, nb_panel * sizeof(Panel));
651 }
652 for (i=0 ; i < nb_panel && i < old_nb_panel ; i++) {
653 Panel *panel = &panel1[i];
654
655 init_panel_size_and_position(panel);
656 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy, panel->area.width, panel->area.height);
657 set_panel_background(panel);
658
659 // force the resize of childs
660 GSList *l0;
661 panel->area.resize = 1;
662 for (l0 = panel->area.list; l0 ; l0 = l0->next)
663 ((Area*)l0->data)->resize = 1;
664 }
665 panel_refresh = 1;
666 return;
667 }
668
669 // 'win' is a trayer icon
670 TrayWindow *traywin;
671 GSList *l;
672 for (l = systray.list_icons; l ; l = l->next) {
673 traywin = (TrayWindow*)l->data;
674 if (traywin->id == win) {
675 //printf("move tray %d\n", traywin->x);
676 XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
677 panel_refresh = 1;
678 return;
679 }
680 }
681
682 // 'win' move in another monitor
683 if (nb_panel == 1) return;
684 Task *tsk = task_get_task (win);
685 if (!tsk) return;
686
687 Panel *p = tsk->area.panel;
688 if (p->monitor != window_get_monitor (win)) {
689 remove_task (tsk);
690 add_task (win);
691 if (win == window_get_active ()) {
692 Task *tsk = task_get_task (win);
693 tsk->area.is_active = 1;
694 task_active = tsk;
695 }
696 panel_refresh = 1;
697 }
698 }
699
700
701 void event_timer()
702 {
703 struct timeval stv;
704 int i;
705
706 if (gettimeofday(&stv, 0)) return;
707
708 if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
709 time_clock.tv_sec = stv.tv_sec;
710 time_clock.tv_sec -= time_clock.tv_sec % time_precision;
711
712 // urgent task
713 if (task_urgent) {
714 if (tick_urgent < max_tick_urgent) {
715 task_urgent->area.is_active = !task_urgent->area.is_active;
716 task_urgent->area.redraw = 1;
717 tick_urgent++;
718 }
719 }
720
721 // update battery
722 #ifdef ENABLE_BATTERY
723 if (panel1[0].battery.area.on_screen) {
724 update_battery();
725 for (i=0 ; i < nb_panel ; i++)
726 panel1[i].battery.area.resize = 1;
727 }
728 #endif
729
730 // update clock
731 if (time1_format) {
732 for (i=0 ; i < nb_panel ; i++)
733 panel1[i].clock.area.resize = 1;
734 }
735 panel_refresh = 1;
736 }
737
738
739 void dnd_message(XClientMessageEvent *e)
740 {
741 Panel *panel = get_panel(e->window);
742 int x, y, mapX, mapY;
743 Window child;
744 x = (e->data.l[2] >> 16) & 0xFFFF;
745 y = e->data.l[2] & 0xFFFF;
746 XTranslateCoordinates(server.dsp, server.root_win, e->window, x, y, &mapX, &mapY, &child);
747 Task* task = click_task(panel, mapX, mapY);
748 if (task) {
749 if (task->desktop != server.desktop )
750 set_desktop (task->desktop);
751 window_action(task, TOGGLE);
752 }
753
754 // send XdndStatus event to get more XdndPosition events
755 XClientMessageEvent se;
756 se.type = ClientMessage;
757 se.window = e->data.l[0];
758 se.message_type = server.atom.XdndStatus;
759 se.format = 32;
760 se.data.l[0] = e->window; // XID of the target window
761 se.data.l[1] = 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
762 se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
763 se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
764 se.data.l[4] = None; // None = drop will not be accepted
765 XSendEvent(server.dsp, e->data.l[0], False, NoEventMask, (XEvent*)&se);
766 }
767
768
769 int main (int argc, char *argv[])
770 {
771 XEvent e;
772 fd_set fd;
773 int x11_fd, i;
774 struct timeval tv;
775 Panel *panel;
776 GSList *it;
777
778 init (argc, argv);
779
780 i = 0;
781 init_config();
782 if (config_path)
783 i = config_read_file (config_path);
784 else
785 i = config_read ();
786 if (!i) {
787 fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
788 cleanup();
789 exit(1);
790 }
791 config_finish();
792 if (thumbnail_path) {
793 // usage: tint2 -j <file> for internal use
794 printf("file %s\n", thumbnail_path);
795 cleanup();
796 exit(0);
797 }
798
799 x11_fd = ConnectionNumber(server.dsp);
800 XSync(server.dsp, False);
801
802 while (1) {
803 // thanks to AngryLlama for the timer
804 // Create a File Description Set containing x11_fd
805 FD_ZERO (&fd);
806 FD_SET (x11_fd, &fd);
807
808 tv.tv_usec = 500000;
809 tv.tv_sec = 0;
810
811 // Wait for X Event or a Timer
812 if (select(x11_fd+1, &fd, 0, 0, &tv)) {
813 while (XPending (server.dsp)) {
814 XNextEvent(server.dsp, &e);
815
816 switch (e.type) {
817 case ButtonPress:
818 tooltip_hide();
819 event_button_press (&e);
820 break;
821
822 case ButtonRelease:
823 event_button_release(&e);
824 break;
825
826 case MotionNotify: {
827 Panel* panel = get_panel(e.xmotion.window);
828 Task* task = click_task(panel, e.xmotion.x, e.xmotion.y);
829 if (task)
830 tooltip_trigger_show(task, e.xmotion.x_root, e.xmotion.y_root);
831 else
832 tooltip_trigger_hide();
833 break;
834 }
835
836 case LeaveNotify:
837 tooltip_trigger_hide();
838 break;
839
840 case Expose:
841 event_expose(&e);
842 break;
843
844 case PropertyNotify:
845 event_property_notify(&e);
846 break;
847
848 case ConfigureNotify:
849 event_configure_notify (e.xconfigure.window);
850 break;
851
852 case ReparentNotify:
853 if (!systray.area.on_screen)
854 break;
855 panel = (Panel*)systray.area.panel;
856 if (e.xany.window == panel->main_win) // reparented to us
857 break;
858 // FIXME: 'reparent to us' badly detected => disabled
859 break;
860 case UnmapNotify:
861 case DestroyNotify:
862 if (!systray.area.on_screen)
863 break;
864 for (it = systray.list_icons; it; it = g_slist_next(it)) {
865 if (((TrayWindow*)it->data)->id == e.xany.window) {
866 remove_icon((TrayWindow*)it->data);
867 break;
868 }
869 }
870 break;
871
872 case ClientMessage:
873 if (!systray.area.on_screen) break;
874 if (e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
875 net_message(&e.xclient);
876 }
877 else if (e.xclient.message_type == server.atom.XdndPosition) {
878 dnd_message(&e.xclient);
879 }
880 break;
881 }
882 }
883 }
884 event_timer();
885
886 switch (signal_pending) {
887 case SIGUSR1:
888 signal_pending = 0;
889 return 0;
890 case SIGINT:
891 case SIGTERM:
892 case SIGHUP:
893 cleanup ();
894 return 0;
895 }
896
897 if (panel_refresh) {
898 panel_refresh = 0;
899
900 if (refresh_systray) {
901 panel = (Panel*)systray.area.panel;
902 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
903 }
904 for (i=0 ; i < nb_panel ; i++) {
905 panel = &panel1[i];
906
907 if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
908 panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
909
910 refresh(&panel->area);
911 XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
912 }
913 XFlush (server.dsp);
914
915 if (refresh_systray) {
916 refresh_systray = 0;
917 panel = (Panel*)systray.area.panel;
918 // tint2 doen't draw systray icons. it just redraw background.
919 XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
920 // force icon's refresh
921 refresh_systray_icon();
922 }
923 }
924 }
925 }
926
927
This page took 0.082206 seconds and 5 git commands to generate.