Commits

jjacky committed 1983fa5

added option TOGGLE_WINDOWS for dbl-click; added same options for single-click

- added option to hide/show opened windows (TOGGLE_WINDOWS) as action on dbl-click
- Preferences: added same options as dbl-click for (single) click on systray icon
- tooltip: a bit more consistency in the message, and added " +" after "kalu" when there are hidden windows

Comments (0)

Files changed (4)

                         debug ("config: checks_manual: %d", checks);
                     }
                 }
-                else if (strcmp (key, "OnDblClick") == 0)
+                else if (  strcmp (key, "OnSglClick") == 0
+                        || strcmp (key, "OnDblClick") == 0)
                 {
+                    on_click_t *on_click;
+                    if (strcmp (key, "OnSglClick") == 0)
+                    {
+                        on_click = &(config->on_sgl_click);
+                    }
+                    else
+                    {
+                        on_click = &(config->on_dbl_click);
+                    }
+                    
                     if (strcmp (value, "CHECK") == 0)
                     {
-                        config->on_dbl_click = DO_CHECK;
+                        *on_click = DO_CHECK;
                     }
                     else if (strcmp (value, "SYSUPGRADE") == 0)
                     {
-                        config->on_dbl_click = DO_SYSUPGRADE;
+                        *on_click = DO_SYSUPGRADE;
                     }
                     else if (strcmp (value, "NOTHING") == 0)
                     {
-                        config->on_dbl_click = DO_NOTHING;
+                        *on_click = DO_NOTHING;
+                    }
+                    else if (strcmp (value, "TOGGLE_WINDOWS") == 0)
+                    {
+                        *on_click = DO_TOGGLE_WINDOWS;
                     }
                     else
                     {
                         success = FALSE;
                         goto cleanup;
                     }
-                    debug ("config: on dbl-click: %s", config->on_dbl_click);
+                    debug ("config: %s: %s", key, *on_click);
                 }
                 else if (strcmp (key, "SaneSortOrder") == 0)
                 {
 typedef enum {
     DO_NOTHING = 0,
     DO_CHECK,
-    DO_SYSUPGRADE
-} on_dbl_click_t;
+    DO_SYSUPGRADE,
+    DO_TOGGLE_WINDOWS
+} on_click_t;
 
 typedef struct _templates_t {
     char *title;
     char            *cmdline_aur;
     alpm_list_t     *cmdline_post;
     gboolean         sane_sort_order;
-    on_dbl_click_t   on_dbl_click;
+    on_click_t       on_sgl_click;
+    on_click_t       on_dbl_click;
     
     templates_t     *tpl_upgrades;
     templates_t     *tpl_watched;
 }
 
 static inline void
-kalu_sysupgrade ()
+kalu_sysupgrade (void)
 {
     /* in case e.g. the menu was shown (sensitive) before an auto-check started */
     if (kalpm_state.is_busy)
 }
 
 static GPtrArray *open_windows = NULL;
+static gboolean has_hidden_windows = FALSE;
 
 void
 add_open_window (gpointer window)
     g_ptr_array_remove (open_windows, window);
 }
 
+static inline void
+toggle_open_windows (void)
+{
+    if (!open_windows || open_windows->len == 0)
+    {
+        return;
+    }
+    
+    g_ptr_array_foreach (open_windows,
+                         (GFunc) ((has_hidden_windows) ? gtk_widget_show : gtk_widget_hide),
+                         NULL);
+    has_hidden_windows = !has_hidden_windows;
+}
+
 static guint icon_press_timeout = 0;
 
+#define process_click_action(on_click)  do {        \
+        if (on_click == DO_SYSUPGRADE)              \
+        {                                           \
+            kalu_sysupgrade ();                     \
+        }                                           \
+        else if (on_click == DO_CHECK)              \
+        {                                           \
+            kalu_check (FALSE);                     \
+        }                                           \
+        else if (on_click == DO_TOGGLE_WINDOWS)     \
+        {                                           \
+            toggle_open_windows ();                 \
+        }                                           \
+    } while (0)
+
 static gboolean
 icon_press_click (gpointer data _UNUSED_)
 {
     icon_press_timeout = 0;
     
-    static gboolean is_minimized = FALSE;
-    g_ptr_array_foreach (open_windows,
-                         (GFunc) ((is_minimized) ? gtk_widget_show : gtk_widget_hide),
-                         NULL);
-    is_minimized = !is_minimized;
+    process_click_action (config->on_sgl_click);
     
     return FALSE;
 }
                 icon_press_timeout = 0;
             }
             
-            if (config->on_dbl_click == DO_SYSUPGRADE)
-            {
-                kalu_sysupgrade ();
-            }
-            else if (config->on_dbl_click == DO_CHECK)
-            {
-                kalu_check (FALSE);
-            }
+            process_click_action (config->on_dbl_click);
         }
         else if (event->type == GDK_BUTTON_PRESS)
         {
     return FALSE;
 }
 
+#undef process_click_action
+
 #define addstr(...)     do {                            \
         len = snprintf (s, (size_t) max, __VA_ARGS__);  \
         max -= len;                                     \
     gchar buf[420], *s = buf;
     gint max = 420, len;
     
+    addstr ("[kalu%s]", (has_hidden_windows) ? " +" : "");
+    
     if (kalpm_state.is_busy)
     {
-        gtk_tooltip_set_text (tooltip, "kalu - Checking/updating in progress...");
+        addstr (" Checking/updating in progress...");
+        gtk_tooltip_set_text (tooltip, buf);
         return TRUE;
     }
     else if (kalpm_state.last_check == NULL)
     {
-        gtk_tooltip_set_text (tooltip, "kalu");
+        gtk_tooltip_set_text (tooltip, buf);
         return TRUE;
     }
     
-    addstr ("[kalu] Last checked ");
+    addstr (" Last checked ");
     
     current = g_date_time_new_now_local ();
     timespan = g_date_time_difference (current, kalpm_state.last_check);
     
     if (max <= 0)
     {
-        sprintf (buf, "kalu");
+        sprintf (buf, "kalu: error setting tooltip");
     }
     gtk_tooltip_set_text (tooltip, buf);
     return TRUE;
     config->checks_auto   = CHECK_UPGRADES | CHECK_WATCHED | CHECK_AUR
                             | CHECK_WATCHED_AUR | CHECK_NEWS;
     config->action = UPGRADE_ACTION_KALU;
+    config->on_sgl_click = DO_CHECK;
     config->on_dbl_click = DO_SYSUPGRADE;
     config->sane_sort_order = TRUE;
     
 /* Misc */
 static GtkWidget *sane_sort_order           = NULL;
 static GtkWidget *syncdbs_in_tooltip        = NULL;
+static GtkWidget *on_sgl_click              = NULL;
 static GtkWidget *on_dbl_click              = NULL;
 
 /* we keep a copy of templates like so, so that we can use it when refreshing
         GTK_TOGGLE_BUTTON (syncdbs_in_tooltip));
     add_to_conf ("SyncDbsInTooltip = %d\n", new_config.syncdbs_in_tooltip);
     
+    new_config.on_sgl_click = gtk_combo_box_get_active (GTK_COMBO_BOX (on_sgl_click));
+    if (new_config.on_sgl_click == DO_SYSUPGRADE)
+    {
+        add_to_conf ("OnSglClick = SYSUPGRADE\n");
+    }
+    else if (new_config.on_sgl_click == DO_CHECK)
+    {
+        add_to_conf ("OnSglClick = CHECK\n");
+    }
+    else if (new_config.on_sgl_click == DO_TOGGLE_WINDOWS)
+    {
+        add_to_conf ("OnSglClick = TOGGLE_WINDOWS\n");
+    }
+    else /* if (new_config.on_sgl_click == DO_NOTHING) */
+    {
+        add_to_conf ("OnSglClick = NOTHING\n");
+    }
+    
     new_config.on_dbl_click = gtk_combo_box_get_active (GTK_COMBO_BOX (on_dbl_click));
     if (new_config.on_dbl_click == DO_SYSUPGRADE)
     {
     {
         add_to_conf ("OnDblClick = CHECK\n");
     }
+    else if (new_config.on_dbl_click == DO_TOGGLE_WINDOWS)
+    {
+        add_to_conf ("OnDblClick = TOGGLE_WINDOWS\n");
+    }
     else /* if (new_config.on_dbl_click == DO_NOTHING) */
     {
         add_to_conf ("OnDblClick = NOTHING\n");
     gtk_widget_show (syncdbs_in_tooltip);
     
     ++top;
+    label = gtk_label_new ("When clicking the systray icon :");
+    gtk_grid_attach (GTK_GRID (grid), label, 0, top, 1, 1);
+    gtk_widget_show (label);
+    
+    on_sgl_click = gtk_combo_box_text_new ();
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_sgl_click), "0",
+        "Do nothing");
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_sgl_click), "1",
+        "Check for Upgrades...");
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_sgl_click), "2",
+        "System upgrade...");
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_sgl_click), "3",
+        "Hide/show opened windows (except kalu's updater)");
+    gtk_grid_attach (GTK_GRID (grid), on_sgl_click, 1, top, 1, 1);
+    gtk_widget_show (on_sgl_click);
+    if (config->on_sgl_click == DO_CHECK)
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_sgl_click), 1);
+    }
+    else if (config->on_sgl_click == DO_SYSUPGRADE)
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_sgl_click), 2);
+    }
+    else if (config->on_sgl_click == DO_TOGGLE_WINDOWS)
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_sgl_click), 3);
+    }
+    else /* DO_NOTHING */
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_sgl_click), 0);
+    }
+    
+    ++top;
     label = gtk_label_new ("When double clicking the systray icon :");
     gtk_grid_attach (GTK_GRID (grid), label, 0, top, 1, 1);
     gtk_widget_show (label);
         "Check for Upgrades...");
     gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_dbl_click), "2",
         "System upgrade...");
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (on_dbl_click), "3",
+        "Hide/show opened windows (except kalu's updater)");
     gtk_grid_attach (GTK_GRID (grid), on_dbl_click, 1, top, 1, 1);
     gtk_widget_show (on_dbl_click);
     if (config->on_dbl_click == DO_CHECK)
     {
         gtk_combo_box_set_active (GTK_COMBO_BOX (on_dbl_click), 2);
     }
+    else if (config->on_dbl_click == DO_TOGGLE_WINDOWS)
+    {
+        gtk_combo_box_set_active (GTK_COMBO_BOX (on_dbl_click), 3);
+    }
     else /* DO_NOTHING */
     {
         gtk_combo_box_set_active (GTK_COMBO_BOX (on_dbl_click), 0);