]> Dogcows Code - chaz/tint2/blobdiff - src/tint.c
*fix* panel_monitor = n works again, after I've broken it with revision 308
[chaz/tint2] / src / tint.c
index 01db88cc73ce580f179c522151e7a6ccff0ef741..5b042a87e4aef59df8a6d1bd3d30378271ea961a 100644 (file)
@@ -80,13 +80,16 @@ void init (int argc, char *argv[])
        sigaction(SIGTERM, &sa, 0);
        sigaction(SIGHUP, &sa, 0);
        signal(SIGCHLD, SIG_IGN);               // don't have to wait() after fork()
+
+       // BSD is too stupid to support pselect(), therefore we have to use select and hope that we do not
+       // end up in a race condition there
        // block all signals, such that no race conditions occur before pselect in our main loop
-       sigset_t block_mask;
-       sigaddset(&block_mask, SIGINT);
-       sigaddset(&block_mask, SIGTERM);
-       sigaddset(&block_mask, SIGHUP);
-       sigaddset(&block_mask, SIGUSR1);
-       sigprocmask(SIG_BLOCK, &block_mask, 0);
+//     sigset_t block_mask;
+//     sigaddset(&block_mask, SIGINT);
+//     sigaddset(&block_mask, SIGTERM);
+//     sigaddset(&block_mask, SIGHUP);
+//     sigaddset(&block_mask, SIGUSR1);
+//     sigprocmask(SIG_BLOCK, &block_mask, 0);
 
        // set global data
        memset(&server, 0, sizeof(Server_global));
@@ -136,6 +139,7 @@ void init_X11()
 
 void cleanup()
 {
+       stop_all_timeouts();
        cleanup_systray();
        stop_net();
        cleanup_panel();
@@ -377,7 +381,7 @@ void event_button_release (XEvent *e)
 
 void event_property_notify (XEvent *e)
 {
-       int i, j;
+       int i;
        Task *tsk;
        Window win = e->xproperty.window;
        Atom at = e->xproperty.atom;
@@ -411,10 +415,10 @@ void event_property_notify (XEvent *e)
                                        // redraw both taskbar
                                        if (server.nb_desktop > old_desktop) {
                                                // can happen if last desktop is deleted and we've been on the last desktop
-                                               panel->taskbar[old_desktop].area.is_active = 0;
+                                               panel->taskbar[old_desktop].area.bg = panel->g_taskbar.bg;
                                                panel->taskbar[old_desktop].area.resize = 1;
                                        }
-                                       panel->taskbar[server.desktop].area.is_active = 1;
+                                       panel->taskbar[server.desktop].area.bg = panel->g_taskbar.bg_active;
                                        panel->taskbar[server.desktop].area.resize = 1;
                                        panel_refresh = 1;
                                }
@@ -488,21 +492,7 @@ void event_property_notify (XEvent *e)
 
                // Window title changed
                if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
-                       Task *tsk2;
-                       GSList *l0;
                        get_title(tsk);
-                       // changed other tsk->title
-                       for (i=0 ; i < nb_panel ; i++) {
-                               for (j=0 ; j < panel1[i].nb_desktop ; j++) {
-                                       for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
-                                               tsk2 = l0->data;
-                                               if (tsk->win == tsk2->win && tsk != tsk2) {
-                                                       tsk2->title = tsk->title;
-                                                       tsk2->area.redraw = 1;
-                                               }
-                                       }
-                               }
-                       }
                        panel_refresh = 1;
                }
                // Demand attention
@@ -515,49 +505,17 @@ void event_property_notify (XEvent *e)
                                panel_refresh = 1;
                        }
                }
-// We do not check for the iconified state, since it only unsets our active window
-// but in openbox a shaded window is considered iconified. So we would loose the active window
-// property on unshading it again (commented 01.10.2009)
-//             else if (at == server.atom.WM_STATE) {
-//                     // Iconic state
-//                     // TODO : try to delete following code
-//                     if (window_is_iconified (win)) {
-//                             if (task_active) {
-//                                     if (task_active->win == tsk->win) {
-//                                             Task *tsk2;
-//                                             GSList *l0;
-//                                             for (i=0 ; i < nb_panel ; i++) {
-//                                                     for (j=0 ; j < panel1[i].nb_desktop ; j++) {
-//                                                             for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
-//                                                                     tsk2 = l0->data;
-//                                                                     tsk2->area.is_active = 0;
-//                                                             }
-//                                                     }
-//                                             }
-//                                             task_active = 0;
-//                                     }
-//                             }
-//                     }
-//             }
+               else if (at == server.atom.WM_STATE) {
+                       // Iconic state
+                       int state = (task_active && tsk->win == task_active->win ? TASK_ACTIVE : TASK_NORMAL);
+                       if (window_is_iconified(win))
+                               state = TASK_ICONIFIED;
+                       set_task_state(tsk, state);
+                       panel_refresh = 1;
+               }
                // Window icon changed
                else if (at == server.atom._NET_WM_ICON) {
                        get_icon(tsk);
-                       Task *tsk2;
-                       GSList *l0;
-                       for (i=0 ; i < nb_panel ; i++) {
-                               for (j=0 ; j < panel1[i].nb_desktop ; j++) {
-                                       for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
-                                               tsk2 = l0->data;
-                                               if (tsk->win == tsk2->win && tsk != tsk2) {
-                                                       tsk2->icon_width = tsk->icon_width;
-                                                       tsk2->icon_height = tsk->icon_height;
-                                                       tsk2->icon = tsk->icon;
-                                                       tsk2->icon_active = tsk->icon_active;
-                                                       tsk2->area.redraw = 1;
-                                               }
-                                       }
-                               }
-                       }
                        panel_refresh = 1;
                }
                // Window desktop changed
@@ -631,13 +589,8 @@ void event_configure_notify (Window win)
                remove_task (tsk);
                add_task (win);
                if (win == window_get_active ()) {
-                       GSList* task_list = task_get_tasks(win);
-                       while (task_list) {
-                               Task *tsk = task_list->data;
-                               tsk->area.is_active = 1;
-                               task_active = tsk;
-                               task_list = task_list->next;
-                       }
+                       set_task_state(tsk, TASK_ACTIVE);
+                       task_active = tsk;
                }
                panel_refresh = 1;
        }
@@ -681,7 +634,7 @@ int main (int argc, char *argv[])
        int x11_fd, i;
        Panel *panel;
        GSList *it;
-       const struct timespec* timeout;
+       struct timeval* timeout;
 
        init (argc, argv);
        init_config();
@@ -710,8 +663,8 @@ int main (int argc, char *argv[])
        x11_fd = ConnectionNumber(server.dsp);
        XSync(server.dsp, False);
 
-       sigset_t empty_mask;
-       sigemptyset(&empty_mask);
+//     sigset_t empty_mask;
+//     sigemptyset(&empty_mask);
 
        while (1) {
                if (panel_refresh) {
@@ -725,15 +678,19 @@ int main (int argc, char *argv[])
                        for (i=0 ; i < nb_panel ; i++) {
                                panel = &panel1[i];
 
-                               if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
-                               panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
-
-                               refresh(&panel->area);
-                               XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
+                               if (panel->is_hidden)
+                                       XCopyArea(server.dsp, panel->hidden_pixmap, panel->main_win, server.gc, 0, 0, panel->hidden_width, panel->hidden_height, 0, 0);
+                               else {
+                                       if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
+                                       panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
+                                       refresh(&panel->area);
+                                       XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
+                               }
                        }
                        XFlush (server.dsp);
 
-                       if (refresh_systray) {
+                       panel = (Panel*)systray.area.panel;
+                       if (refresh_systray && !panel->is_hidden) {
                                refresh_systray = 0;
                                panel = (Panel*)systray.area.panel;
                                // tint2 doen't draw systray icons. it just redraw background.
@@ -748,19 +705,29 @@ int main (int argc, char *argv[])
                FD_ZERO (&fdset);
                FD_SET (x11_fd, &fdset);
                update_next_timeout();
-               if (next_timeout.tv_sec >= 0 && next_timeout.tv_nsec >= 0)
+               if (next_timeout.tv_sec >= 0 && next_timeout.tv_usec >= 0)
                        timeout = &next_timeout;
                else
                        timeout = 0;
 
                // Wait for X Event or a Timer
-               if (pselect(x11_fd+1, &fdset, 0, 0, timeout, &empty_mask) > 0) {
+               if (select(x11_fd+1, &fdset, 0, 0, timeout) > 0) {
                        while (XPending (server.dsp)) {
                                XNextEvent(server.dsp, &e);
 
+                               panel = get_panel(e.xany.window);
+                               if (panel && panel_autohide) {
+                                       if (e.type == EnterNotify)
+                                               autohide_trigger_show(panel);
+                                       else if (e.type == LeaveNotify)
+                                               autohide_trigger_hide(panel);
+                                       if (panel->is_hidden)
+                                               continue;   // discard further processing of this event because the panel is not visible yet
+                               }
+
                                switch (e.type) {
                                        case ButtonPress:
-                                               tooltip_hide();
+                                               tooltip_hide(0);
                                                event_button_press (&e);
                                                break;
 
@@ -780,7 +747,8 @@ int main (int argc, char *argv[])
                                        }
 
                                        case LeaveNotify:
-                                               tooltip_trigger_hide();
+                                               if (g_tooltip.enabled)
+                                                       tooltip_trigger_hide();
                                                break;
 
                                        case Expose:
@@ -831,9 +799,18 @@ int main (int argc, char *argv[])
                                                break;
 
                                        default:
-                                               if (e.type == XDamageNotify+damage_event)
-                                                       // TODO: update only the damaged icon, not all of them
-                                                       systray.area.redraw = 1;
+                                               if (e.type == XDamageNotify+damage_event) {
+                                                       TrayWindow *traywin;
+                                                       GSList *l;
+                                                       XDamageNotifyEvent* de = (XDamageNotifyEvent*)&e;
+                                                       for (l = systray.list_icons; l ; l = l->next) {
+                                                               traywin = (TrayWindow*)l->data;
+                                                               if ( traywin->id == de->drawable && !de->more ) {
+                                                                       systray_render_icon(traywin);
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
                                }
                        }
                }
This page took 0.031352 seconds and 4 git commands to generate.