Disable invalid edge/monitor combinations in configuration dialog.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Thu, 13 Nov 2014 15:34:34 +0000 (17:34 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Thu, 13 Nov 2014 15:34:34 +0000 (17:34 +0200)
That should get rid of possibility to create panels stacked one over other.

ChangeLog
src/configurator.c
src/panel.c
src/private.h

index 546d543..abc1bcf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,9 @@
 * Implemented disabling for "Reserve space" button if another monitor
     lies beyond the edge so reservation will cover it. Also reservation
     will not be applied in such cases even if set in config manually.
+* Some edge and monitors selections in panel configuration dialog may be
+    insensitive now if appropriate edge and monitor combination is not
+    available, to avoid panels stacking one over another.
 
 0.7.2
 -------------------------------------------------------------------------
index 103ad68..49aec41 100644 (file)
@@ -147,7 +147,6 @@ static void set_edge(LXPanel* panel, int edge)
     gtk_widget_queue_resize(GTK_WIDGET(panel));
     _panel_set_panel_configuration_changed(panel);
     UPDATE_GLOBAL_STRING(p, "edge", num2str(edge_pair, edge, "none"));
-    //FIXME: update monitors and strut sensitivities
     update_strut_control_button(panel);
 }
 
@@ -203,6 +202,18 @@ static void update_mon_sensitivity(GtkCellLayout *layout, GtkCellRenderer *cell,
     gtk_tree_path_free(path);
 }
 
+static void update_edges_buttons(Panel *p)
+{
+    gtk_widget_set_sensitive(p->edge_bottom_button,
+                             panel_edge_available(p, EDGE_BOTTOM, p->monitor));
+    gtk_widget_set_sensitive(p->edge_top_button,
+                             panel_edge_available(p, EDGE_TOP, p->monitor));
+    gtk_widget_set_sensitive(p->edge_left_button,
+                             panel_edge_available(p, EDGE_LEFT, p->monitor));
+    gtk_widget_set_sensitive(p->edge_right_button,
+                             panel_edge_available(p, EDGE_RIGHT, p->monitor));
+}
+
 static void set_monitor_cb(GtkComboBox *cb, LXPanel *panel)
 {
     Panel *p = panel->priv;
@@ -212,7 +223,8 @@ static void set_monitor_cb(GtkComboBox *cb, LXPanel *panel)
     gtk_widget_queue_resize(GTK_WIDGET(panel));
     _panel_set_panel_configuration_changed(panel);
     UPDATE_GLOBAL_INT(p, "monitor", p->monitor);
-    //FIXME: update edge and strut sensitivities
+    /* update edge and strut sensitivities */
+    update_edges_buttons(p);
     update_strut_control_button(panel);
 }
 
@@ -1015,17 +1027,22 @@ void panel_configure( LXPanel* panel, int sel_page )
 
     /* position */
     w = (GtkWidget*)gtk_builder_get_object( builder, "edge_bottom" );
+    p->edge_bottom_button = w;
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), edge_selector(p, EDGE_BOTTOM));
     g_signal_connect(w, "toggled", G_CALLBACK(edge_bottom_toggle), panel);
     w = (GtkWidget*)gtk_builder_get_object( builder, "edge_top" );
+    p->edge_top_button = w;
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), edge_selector(p, EDGE_TOP));
     g_signal_connect(w, "toggled", G_CALLBACK(edge_top_toggle), panel);
     w = (GtkWidget*)gtk_builder_get_object( builder, "edge_left" );
+    p->edge_left_button = w;
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), edge_selector(p, EDGE_LEFT));
     g_signal_connect(w, "toggled", G_CALLBACK(edge_left_toggle), panel);
     w = (GtkWidget*)gtk_builder_get_object( builder, "edge_right" );
+    p->edge_right_button = w;
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), edge_selector(p, EDGE_RIGHT));
     g_signal_connect(w, "toggled", G_CALLBACK(edge_right_toggle), panel);
+    update_edges_buttons(p);
 
     /* monitor */
     monitors = 1;
index b90c033..184690f 100644 (file)
@@ -212,6 +212,14 @@ static void lxpanel_size_allocate(GtkWidget *widget, GtkAllocation *a)
         p->width = (p->orientation == GTK_ORIENTATION_HORIZONTAL) ? a->width : a->height;
     if (p->heighttype == HEIGHT_REQUEST)
         p->height = (p->orientation == GTK_ORIENTATION_HORIZONTAL) ? a->height : a->width;
+
+#if GTK_CHECK_VERSION(2, 20, 0)
+    if (!gtk_widget_get_realized(widget))
+#else
+    if (!GTK_WIDGET_REALIZED(widget))
+#endif
+        return;
+
     rect = *a;
     /* get real coords since a contains 0, 0 */
     gdk_window_get_origin(gtk_widget_get_window(widget), &x, &y);
@@ -225,18 +233,14 @@ static void lxpanel_size_allocate(GtkWidget *widget, GtkAllocation *a)
         p->ah = a->height;
         /* FIXME: should we "correct" requested sizes? */
         gtk_window_move(GTK_WINDOW(widget), p->ax, p->ay);
-        _panel_set_wm_strut(LXPANEL(widget));
+        _panel_set_wm_strut(panel);
+        _panel_queue_update_background(panel);
     }
-    else if (p->background_update_queued)
+    if (p->background_update_queued)
     {
         g_source_remove(p->background_update_queued);
         p->background_update_queued = 0;
-#if GTK_CHECK_VERSION(2, 20, 0)
-        if (gtk_widget_get_realized(widget))
-#else
-        if (GTK_WIDGET_REALIZED(widget))
-#endif
-            _panel_update_background(LXPANEL(widget));
+        _panel_update_background(LXPANEL(widget));
     }
 }
 
@@ -399,6 +403,9 @@ gboolean _panel_edge_can_strut(LXPanel *panel, int edge, gint monitor, gulong *s
     }
 
     screen = gtk_widget_get_screen(GTK_WIDGET(panel));
+    n = gdk_screen_get_n_monitors(screen);
+    if (monitor >= n) /* hidden now */
+        return FALSE;
     gdk_screen_get_monitor_geometry(screen, monitor, &rect);
     switch (edge)
     {
@@ -427,7 +434,6 @@ gboolean _panel_edge_can_strut(LXPanel *panel, int edge, gint monitor, gulong *s
     if (rect.height == 0 || rect.width == 0) ; /* on a border of monitor */
     else
     {
-        n = gdk_screen_get_n_monitors(screen);
         for (i = 0; i < n; i++)
         {
             if (i == monitor)
@@ -612,7 +618,7 @@ void panel_update_background(Panel * p)
 static void _panel_update_background(LXPanel * p)
 {
     GtkWidget *w = GTK_WIDGET(p);
-    GList *plugins, *l;
+    GList *plugins = NULL, *l;
 
     /* Redraw the top level widget. */
     _panel_determine_background_pixmap(p, w);
@@ -620,7 +626,8 @@ static void _panel_update_background(LXPanel * p)
     gtk_widget_queue_draw(w);
 
     /* Loop over all plugins redrawing each plugin. */
-    plugins = gtk_container_get_children(GTK_CONTAINER(p->priv->box));
+    if (p->priv->box != NULL)
+        plugins = gtk_container_get_children(GTK_CONTAINER(p->priv->box));
     for (l = plugins; l != NULL; l = l->next)
         plugin_widget_set_background(l->data, p);
     g_list_free(plugins);
@@ -1310,9 +1317,6 @@ panel_start_gui(LXPanel *panel, config_setting_t *list)
     XChangeProperty(xdisplay, p->topxwin, a_NET_WM_STATE, XA_ATOM,
           32, PropModeReplace, (unsigned char *) state, 3);
 
-    //_calculate_position(panel);
-    //gdk_window_move_resize(gtk_widget_get_window(w), p->ax, p->ay, p->aw, p->ah);
-    //_panel_set_wm_strut(panel);
     p->initialized = TRUE;
 
     if (list) for (i = 1; (s = config_setting_get_elem(list, i)) != NULL; )
@@ -1322,9 +1326,6 @@ panel_start_gui(LXPanel *panel, config_setting_t *list)
         else /* remove invalid data from config */
             config_setting_remove_elem(list, i);
 
-    /* update backgrond of panel and all plugins */
-    _panel_update_background(panel);
-
     RET();
 }
 
index 8c20275..072b830 100644 (file)
@@ -135,6 +135,10 @@ struct _Panel {
     GtkWidget* height_control;         /* Height control in preference dialog */
     GtkWidget* width_control;          /* Width control in preference dialog */
     GtkWidget* strut_control;          /* Reserve space in preference dialog */
+    GtkWidget* edge_bottom_button;
+    GtkWidget* edge_top_button;
+    GtkWidget* edge_left_button;
+    GtkWidget* edge_right_button;
 
     guint initialized : 1;              /* Should be grouped better later, */
     guint ah_far : 1;                   /* placed here for binary compatibility */