]> Dogcows Code - chaz/tint2/blobdiff - src/tint.c
added taskbar_active_background_id to change current desktop background
[chaz/tint2] / src / tint.c
index f08692c03a21ec7a617250ad40dec97d67716065..a75b1b4d4117ec860665e17ac3b03e0cbb3e9973 100644 (file)
@@ -46,8 +46,19 @@ void signal_handler(int sig)
 }
 
 
-void init ()
+void init (int argc, char *argv[])
 {
+   int c;
+
+       // read options
+   c = getopt (argc, argv, "c:");
+   if (c != -1) {
+               config_path = strdup (optarg);
+          c = getopt (argc, argv, "j:");
+          if (c != -1)
+                       thumbnail_path = strdup (optarg);
+       }
+
        // Set signal handler
    signal(SIGUSR1, signal_handler);
        signal(SIGINT, signal_handler);
@@ -105,6 +116,8 @@ void cleanup()
 #endif
        if (clock_lclick_command) g_free(clock_lclick_command);
        if (clock_rclick_command) g_free(clock_rclick_command);
+       if (config_path) g_free(config_path);
+       if (thumbnail_path) g_free(thumbnail_path);
 
    if (server.monitor) free(server.monitor);
    XFreeGC(server.dsp, server.gc);
@@ -200,6 +213,7 @@ int click_clock(Panel *panel, XEvent *e)
 void window_action (Task *tsk, int action)
 {
    if (!tsk) return;
+       int desk;
        switch (action) {
                case CLOSE:
                        set_close (tsk->win);
@@ -226,6 +240,19 @@ void window_action (Task *tsk, int action)
                case RESTORE:
                        window_maximize_restore (tsk->win);
                        break;
+               case DESKTOP_LEFT:
+                       if ( tsk->desktop == 0 ) break;
+                       desk = tsk->desktop - 1;
+                       windows_set_desktop(tsk->win, desk);
+                       if (desk == server.desktop)
+                               set_active(tsk->win);
+                       break;
+               case DESKTOP_RIGHT:
+                       if (tsk->desktop == server.nb_desktop ) break;
+                       desk = tsk->desktop + 1;
+                       windows_set_desktop(tsk->win, desk);
+                       if (desk == server.desktop)
+                               set_active(tsk->win);
        }
 }
 
@@ -234,23 +261,7 @@ void event_button_press (XEvent *e)
 {
    Panel *panel = get_panel(e->xany.window);
        if (!panel) return;
-/*
-       if (wm_menu) {
-               if ((panel_horizontal && (e->xbutton.x < panel->area.paddingxlr || e->xbutton.x > panel->area.width-panel->area.paddingxlr || e->xbutton.y < panel->area.paddingy || e->xbutton.y > panel->area.paddingy+panel->g_taskbar.height)) || (!panel_horizontal && (e->xbutton.y < panel->area.paddingxlr || e->xbutton.y > panel->area.height-panel->area.paddingxlr || e->xbutton.x < panel->area.paddingy || e->xbutton.x > panel->area.paddingy+panel->g_taskbar.width))) {
-                       // 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);
-                       return;
-               }
-       }
-*/
+
        if (panel_mode == MULTI_DESKTOP)
                task_drag = click_task(panel, e);
 
@@ -267,49 +278,7 @@ void event_button_press (XEvent *e)
                XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e);
                return;
    }
-/*
-       if (e->xbutton.button != 1) return;
-   GSList *l0;
-   Taskbar *tskbar;
-       if (panel_horizontal) {
-               int x = e->xbutton.x;
-               for (l0 = panel->area.list; l0 ; l0 = l0->next) {
-                       tskbar = l0->data;
-                       if (!tskbar->area.on_screen) continue;
-                       if (x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
-                               break;
-               }
-               if (l0) {
-                       Task *tsk;
-                       for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
-                               tsk = l0->data;
-                               if (x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
-                                       task_drag = tsk;
-                                       break;
-                               }
-                       }
-               }
-       }
-       else {
-               int y = e->xbutton.y;
-               for (l0 = panel->area.list; l0 ; l0 = l0->next) {
-                       tskbar = l0->data;
-                       if (!tskbar->area.on_screen) continue;
-                       if (y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
-                               break;
-               }
-               if (l0) {
-                       Task *tsk;
-                       for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
-                               tsk = l0->data;
-                               if (y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
-                                       task_drag = tsk;
-                                       break;
-                               }
-                       }
-               }
-       }
-*/
+
    XLowerWindow (server.dsp, panel->main_win);
 }
 
@@ -325,16 +294,6 @@ void event_button_release (XEvent *e)
                        XSendEvent(server.dsp, e->xbutton.window, False, ButtonReleaseMask, e);
                        return;
        }
-/*
-       if (wm_menu) {
-               if ((panel_horizontal && (e->xbutton.x < panel->area.paddingxlr || e->xbutton.x > panel->area.width-panel->area.paddingxlr || e->xbutton.y < panel->area.paddingy || e->xbutton.y > panel->area.paddingy+panel->g_taskbar.height)) || (!panel_horizontal && (e->xbutton.y < panel->area.paddingxlr || e->xbutton.y > panel->area.height-panel->area.paddingxlr || e->xbutton.x < panel->area.paddingy || e->xbutton.x > panel->area.paddingy+panel->g_taskbar.width))) {
-                       // forward the click to the desktop window (thanks conky)
-                       e->xbutton.window = server.root_win;
-                       XSendEvent(server.dsp, e->xbutton.window, False, ButtonReleaseMask, e);
-                       return;
-               }
-       }
-*/
 
    int action = TOGGLE_ICONIFY;
    switch (e->xbutton.button) {
@@ -387,97 +346,17 @@ void event_button_release (XEvent *e)
       else task_drag = 0;
    }
 
-   // switch desktop
-   if (panel_mode == MULTI_DESKTOP && action != mouse_tilt_left && action != mouse_tilt_right) {
-      if (tskbar->desktop != server.desktop && action != CLOSE)
-         set_desktop (tskbar->desktop);
-       }
-
-   // action on task
-   window_action( click_task(panel, e), action);
-
-   // to keep window below
-   XLowerWindow (server.dsp, panel->main_win);
-/*
-   int x = e->xbutton.x;
-   int y = e->xbutton.y;
-   // search taskbar
-   Taskbar *tskbar;
-   GSList *l0;
-       Clock clk = panel->clock;
-       if (panel_horizontal) {
-               if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width))
-                       clock_action(e->xbutton.button);
-               else {
-                       for (l0 = panel->area.list; l0 ; l0 = l0->next) {
-                               tskbar = l0->data;
-                               if (!tskbar->area.on_screen) continue;
-                               if (x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
-                                       goto suite;
-                       }
-               }
-       }
-       else {
-               if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height))
-                       clock_action(e->xbutton.button);
-               else {
-                       for (l0 = panel->area.list; l0 ; l0 = l0->next) {
-                               tskbar = l0->data;
-                               if (!tskbar->area.on_screen) continue;
-                               if (y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
-                                       goto suite;
-                       }
-               }
-       }
-
-   // TODO: check better solution to keep window below
-   XLowerWindow (server.dsp, panel->main_win);
-   task_drag = 0;
-   return;
-
-suite:
-   // drag and drop task
-   if (task_drag) {
-      if (tskbar != task_drag->area.parent && action == TOGGLE_ICONIFY) {
-         if (task_drag->desktop != ALLDESKTOP && panel_mode == MULTI_DESKTOP) {
-            windows_set_desktop(task_drag->win, tskbar->desktop);
-            if (tskbar->desktop == server.desktop)
-               set_active(task_drag->win);
-            task_drag = 0;
-         }
-         return;
-      }
-      else task_drag = 0;
-   }
-
    // switch desktop
    if (panel_mode == MULTI_DESKTOP) {
-      if (tskbar->desktop != server.desktop && action != CLOSE)
+      if (tskbar->desktop != server.desktop && action != CLOSE && action != DESKTOP_LEFT && action != DESKTOP_RIGHT)
          set_desktop (tskbar->desktop);
        }
 
    // action on task
-   Task *tsk;
-   GSList *l;
-   for (l = tskbar->area.list ; l ; l = l->next) {
-      tsk = l->data;
-               if (panel_horizontal) {
-                       if (x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
-                               window_action (tsk, action);
-                               break;
-                       }
-               }
-               else {
-                       if (y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
-                               window_action (tsk, action);
-                               break;
-                       }
-               }
-   }
+   window_action( click_task(panel, e), action);
 
    // to keep window below
    XLowerWindow (server.dsp, panel->main_win);
-       */
 }
 
 
@@ -509,6 +388,35 @@ void event_property_notify (XEvent *e)
       // Change desktop
       else if (at == server.atom._NET_CURRENT_DESKTOP) {
          server.desktop = server_get_current_desktop ();
+                       for (i=0 ; i < nb_panel ; i++) {
+                          Panel *panel = &panel1[i];
+                               if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) {
+                                       // redraw taskbar
+                                       panel_refresh = 1;
+                                       Taskbar *tskbar;
+                                       Task *tsk;
+                                       GSList *l;
+                                       for (j=0 ; j < panel->nb_desktop ; j++) {
+                                               tskbar = &panel->taskbar[j];
+                                               if (tskbar->area.is_active) {
+                                                       tskbar->area.is_active = 0;
+                                                       tskbar->area.redraw = 1;
+                                                       for (l = tskbar->area.list; l ; l = l->next) {
+                                                               tsk = l->data;
+                                                               tsk->area.redraw = 1;
+                                                       }
+                                               }
+                                               if (j == server.desktop) {
+                                                       tskbar->area.is_active = 1;
+                                                       tskbar->area.redraw = 1;
+                                                       for (l = tskbar->area.list; l ; l = l->next) {
+                                                               tsk = l->data;
+                                                               tsk->area.redraw = 1;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
          if (panel_mode != MULTI_DESKTOP) {
                                visible_object();
          }
@@ -752,35 +660,32 @@ int main (int argc, char *argv[])
 {
    XEvent e;
    fd_set fd;
-   int x11_fd, i, c;
+   int x11_fd, i;
    struct timeval tv;
    Panel *panel;
        GSList *it;
 
-   init ();
+   init (argc, argv);
 
 load_config:
    i = 0;
-   c = getopt (argc, argv, "c:");
        init_config();
-   if (c != -1) {
-      i = config_read_file (optarg);
-          c = getopt (argc, argv, "j:");
-          if (c != -1) {
-                       // usage: tint2 [-c] <config_file> -j <file> for internal use
-          printf("file %s\n", optarg);
-             cleanup();
-          exit(0);
-               }
+   if (config_path)
+      i = config_read_file (config_path);
+       else
+               i = config_read ();
+       if (!i) {
+               fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
+               cleanup();
+               exit(1);
        }
-   if (!i)
-      i = config_read ();
-   if (!i) {
-      fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
-      cleanup();
-      exit(1);
-   }
    config_finish();
+       if (thumbnail_path) {
+               // usage: tint2 -j <file> for internal use
+               printf("file %s\n", thumbnail_path);
+               cleanup();
+               exit(0);
+       }
 
    x11_fd = ConnectionNumber(server.dsp);
    XSync(server.dsp, False);
This page took 0.029246 seconds and 4 git commands to generate.