]> Dogcows Code - chaz/tint2/blobdiff - src/tint.c
*add* real transparency is now supported... most systray applications work out of...
[chaz/tint2] / src / tint.c
index a91f8cc38267d1110376dfd61f3ed30b596fb20b..27458b8d87a4569c4487179012f391d81cf141e7 100644 (file)
@@ -61,7 +61,7 @@ void init (int argc, char *argv[])
                        printf("tint2 version 0.8\n");
                        exit(0);
                }
-               if (!strcmp(argv[i], "-c"))     {
+               if (!strcmp(argv[i], "-c")) {
                        i++;
                        if (i < argc)
                                config_path = strdup(argv[i]);
@@ -91,7 +91,7 @@ void init (int argc, char *argv[])
 
        // set global data
        memset(&server, 0, sizeof(Server_global));
-       memset(&systray, 0, sizeof(Systraybar));
+//     memset(&systray, 0, sizeof(Systraybar));
 
        server.dsp = XOpenDisplay (NULL);
        if (!server.dsp) {
@@ -101,17 +101,13 @@ void init (int argc, char *argv[])
        server_init_atoms ();
        server.screen = DefaultScreen (server.dsp);
        server.root_win = RootWindow(server.dsp, server.screen);
-       server.depth = DefaultDepth (server.dsp, server.screen);
-       server.visual = DefaultVisual (server.dsp, server.screen);
        server.desktop = server_get_current_desktop ();
-       XGCValues  gcv;
-       server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)0, &gcv);
-
+       server_init_visual();
        XSetErrorHandler ((XErrorHandler) server_catch_error);
 
        imlib_context_set_display (server.dsp);
        imlib_context_set_visual (server.visual);
-       imlib_context_set_colormap (DefaultColormap (server.dsp, server.screen));
+       imlib_context_set_colormap (server.colormap);
 
        /* Catch events */
        XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
@@ -153,8 +149,7 @@ void cleanup()
        if (config_path) g_free(config_path);
        if (snapshot_path) g_free(snapshot_path);
 
-       if (server.monitor) free(server.monitor);
-       XFreeGC(server.dsp, server.gc);
+       cleanup_server();
        XCloseDisplay(server.dsp);
 }
 
@@ -241,26 +236,61 @@ void window_action (Task *tsk, int action)
 }
 
 
+int tint2_handles_click(Panel* panel, XButtonEvent* e)
+{
+       Task* task = click_task(panel, e->x, e->y);
+       if (task) {
+               if(   (e->button == 1)
+                        || (e->button == 2 && mouse_middle != 0)
+                        || (e->button == 3 && mouse_right != 0)
+                        || (e->button == 4 && mouse_scroll_up != 0)
+                        || (e->button == 5 && mouse_scroll_down !=0) )
+               {
+                       return 1;
+               }
+               else
+                       return 0;
+       }
+       // no task clicked --> check if taskbar clicked
+       Taskbar *tskbar = click_taskbar(panel, e->x, e->y);
+       if (tskbar && e->button == 1 && panel_mode == MULTI_DESKTOP)
+               return 1;
+       if (click_clock(panel, e->x, e->y)) {
+               if ( (e->button == 1 && clock_lclick_command) || (e->button == 2 && clock_rclick_command) )
+                       return 1;
+               else
+                       return 0;
+       }
+       return 0;
+}
+
+
+void forward_click(XEvent* e)
+{
+       // forward the click to the desktop window (thanks conky)
+       XUngrabPointer(server.dsp, e->xbutton.time);
+       e->xbutton.window = server.root_win;
+       // icewm doesn't open under the mouse.
+       // and xfce doesn't open at all.
+       e->xbutton.x = e->xbutton.x_root;
+       e->xbutton.y = e->xbutton.y_root;
+       //printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y);
+       //XSetInputFocus(server.dsp, e->xbutton.window, RevertToParent, e->xbutton.time);
+       XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e);
+}
+
+
 void event_button_press (XEvent *e)
 {
        Panel *panel = get_panel(e->xany.window);
        if (!panel) return;
 
-       task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
 
-       if (wm_menu && !task_drag && !click_clock(panel, e->xbutton.x, e->xbutton.y) && (e->xbutton.button != 1) ) {
-               // forward the click to the desktop window (thanks conky)
-               XUngrabPointer(server.dsp, e->xbutton.time);
-               e->xbutton.window = server.root_win;
-               // icewm doesn't open under the mouse.
-               // and xfce doesn't open at all.
-               e->xbutton.x = e->xbutton.x_root;
-               e->xbutton.y = e->xbutton.y_root;
-               //printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y);
-               //XSetInputFocus(server.dsp, e->xbutton.window, RevertToParent, e->xbutton.time);
-               XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e);
+       if (wm_menu && !tint2_handles_click(panel, &e->xbutton) ) {
+               forward_click(e);
                return;
        }
+       task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
 
        XLowerWindow (server.dsp, panel->main_win);
 }
@@ -271,6 +301,12 @@ void event_button_release (XEvent *e)
        Panel *panel = get_panel(e->xany.window);
        if (!panel) return;
 
+       if (wm_menu && !tint2_handles_click(panel, &e->xbutton)) {
+               forward_click(e);
+               task_drag = 0;
+               return;
+       }
+
        int action = TOGGLE_ICONIFY;
        switch (e->xbutton.button) {
                case 2:
@@ -359,6 +395,7 @@ void event_property_notify (XEvent *e)
                                panel1[i].area.resize = 1;
                        }
                        task_refresh_tasklist();
+                       active_task();
                        panel_refresh = 1;
                }
                // Change desktop
@@ -369,8 +406,11 @@ void event_property_notify (XEvent *e)
                                Panel *panel = &panel1[i];
                                if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) {
                                        // redraw both taskbar
-                                       panel->taskbar[old_desktop].area.is_active = 0;
-                                       panel->taskbar[old_desktop].area.resize = 1;
+                                       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.resize = 1;
+                                       }
                                        panel->taskbar[server.desktop].area.is_active = 1;
                                        panel->taskbar[server.desktop].area.resize = 1;
                                        panel_refresh = 1;
@@ -379,13 +419,15 @@ void event_property_notify (XEvent *e)
                                Taskbar *tskbar;
                                Task *tsk;
                                GSList *l;
-                               tskbar = &panel->taskbar[old_desktop];
-                               for (l = tskbar->area.list; l ; l = l->next) {
-                                       tsk = l->data;
-                                       if (tsk->desktop == ALLDESKTOP) {
-                                               tsk->area.on_screen = 0;
-                                               tskbar->area.resize = 1;
-                                               panel_refresh = 1;
+                               if (server.nb_desktop > old_desktop) {
+                                       tskbar = &panel->taskbar[old_desktop];
+                                       for (l = tskbar->area.list; l ; l = l->next) {
+                                               tsk = l->data;
+                                               if (tsk->desktop == ALLDESKTOP) {
+                                                       tsk->area.on_screen = 0;
+                                                       tskbar->area.resize = 1;
+                                                       panel_refresh = 1;
+                                               }
                                        }
                                }
                                tskbar = &panel->taskbar[server.desktop];
@@ -518,16 +560,12 @@ void event_property_notify (XEvent *e)
                // Window desktop changed
                else if (at == server.atom._NET_WM_DESKTOP) {
                        int desktop = window_get_desktop (win);
-                       int active = tsk->area.is_active;
                        //printf("  Window desktop changed %d, %d\n", tsk->desktop, desktop);
                        // bug in windowmaker : send unecessary 'desktop changed' when focus changed
                        if (desktop != tsk->desktop) {
                                remove_task (tsk);
                                tsk = add_task (win);
-                               if (tsk && active) {
-                                       tsk->area.is_active = 1;
-                                       task_active = tsk;
-                               }
+                               active_task();
                                panel_refresh = 1;
                        }
                }
@@ -589,9 +627,13 @@ void event_configure_notify (Window win)
                remove_task (tsk);
                add_task (win);
                if (win == window_get_active ()) {
-                       Task *tsk = task_get_task (win);
-                       tsk->area.is_active = 1;
-                       task_active = tsk;
+                       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;
+                       }
                }
                panel_refresh = 1;
        }
@@ -637,10 +679,8 @@ int main (int argc, char *argv[])
        GSList *it;
        const struct timespec* timeout;
 
-       init (argc, argv);
-
-       i = 0;
        init_config();
+       i = 0;
        if (config_path)
                i = config_read_file (config_path);
        else
@@ -650,6 +690,9 @@ int main (int argc, char *argv[])
                cleanup();
                exit(1);
        }
+
+       init (argc, argv);
+
        init_panel();
        cleanup_config();
        if (snapshot_path) {
@@ -668,6 +711,7 @@ int main (int argc, char *argv[])
                if (panel_refresh) {
                        panel_refresh = 0;
 
+                       // QUESTION: do we need this first refresh_systray, because we check refresh_systray once again later...
                        if (refresh_systray) {
                                panel = (Panel*)systray.area.panel;
                                XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None);
This page took 0.029125 seconds and 4 git commands to generate.