[gnome-applets/wip/segeiger/window-picker-in-process: 8/8] windowpicker/applet.c: Replace grid with box



commit 755ec16d2999ecc3385b22dfb03d77110cf3bebe
Author: Sebastian Geiger <sbastig gmx net>
Date:   Mon Jun 8 21:10:27 2015 +0200

    windowpicker/applet.c: Replace grid with box
    
    This fixes a problem on vertically aligned panels, that
    caused the task list to remain horizontal.
    
    This registers a callback to handle orientation changes of the panel.

 windowpicker/src/applet.c |   49 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/windowpicker/src/applet.c b/windowpicker/src/applet.c
index bf1f3f0..53bf7ca 100644
--- a/windowpicker/src/applet.c
+++ b/windowpicker/src/applet.c
@@ -132,6 +132,27 @@ setupPanelContextMenu (WindowPickerApplet *windowPickerApplet)
     g_object_unref (action_group);
 }
 
+static void
+on_applet_orientation_changed (PanelApplet *applet,
+                               guint orient,
+                               gpointer user_data)
+{
+    switch (orient) {
+        case PANEL_APPLET_ORIENT_UP:
+        case PANEL_APPLET_ORIENT_DOWN:
+            gtk_orientable_set_orientation (GTK_ORIENTABLE (applet), GTK_ORIENTATION_HORIZONTAL);
+            break;
+        case PANEL_APPLET_ORIENT_LEFT:
+        case PANEL_APPLET_ORIENT_RIGHT:
+            gtk_orientable_set_orientation (GTK_ORIENTABLE (applet), GTK_ORIENTATION_VERTICAL);
+            break;
+        default:
+            gtk_orientable_set_orientation (GTK_ORIENTABLE (applet), GTK_ORIENTATION_HORIZONTAL);
+            break;
+    }
+    gtk_widget_queue_resize (GTK_WIDGET (applet));
+}
+
 static gboolean
 load_window_picker (PanelApplet *applet) {
     WindowPickerApplet *windowPickerApplet = WINDOW_PICKER_APPLET(applet);
@@ -139,19 +160,32 @@ load_window_picker (PanelApplet *applet) {
     GSettings *settings = windowPickerApplet->priv->settings
                         = panel_applet_settings_new(applet, SETTINGS_SCHEMA);
 
-    GtkWidget *grid = gtk_grid_new ();
-    gtk_grid_set_row_spacing (GTK_GRID(grid), 10);
-    gtk_container_add (GTK_CONTAINER (applet), grid);
+    GtkWidget *outer_box;
+    GtkOrientation orientation;
+    switch(panel_applet_get_orient(applet)) {
+        case PANEL_APPLET_ORIENT_UP:
+        case PANEL_APPLET_ORIENT_DOWN:
+            orientation = GTK_ORIENTATION_HORIZONTAL;
+            break;
+        case PANEL_APPLET_ORIENT_LEFT:
+        case PANEL_APPLET_ORIENT_RIGHT:
+            orientation = GTK_ORIENTATION_VERTICAL;
+            break;
+        default:
+            orientation = GTK_ORIENTATION_HORIZONTAL;
+    }
+    outer_box = gtk_box_new (orientation, 0);
+    gtk_container_add (GTK_CONTAINER (applet), outer_box);
     gtk_container_set_border_width (GTK_CONTAINER (applet), 0);
-    gtk_container_set_border_width (GTK_CONTAINER (grid), 0);
+    gtk_container_set_border_width (GTK_CONTAINER (outer_box), 0);
 
     priv->tasks = task_list_new (windowPickerApplet);
     gtk_widget_set_vexpand (priv->tasks, TRUE);
-    gtk_grid_attach (GTK_GRID(grid), priv->tasks, 0, 0, 1, 1);
+    gtk_box_pack_start (GTK_BOX (outer_box), priv->tasks, TRUE, TRUE, 0);
 
     priv->title = task_title_new (windowPickerApplet);
     gtk_widget_set_hexpand (priv->title, TRUE);
-    gtk_grid_attach (GTK_GRID(grid), priv->title, 1, 0, 1, 1);
+    gtk_box_pack_start (GTK_BOX (outer_box), priv->title, TRUE, TRUE, 0);
 
     priv->show_all_windows = g_settings_get_boolean (settings, KEY_SHOW_ALL_WINDOWS);
     g_settings_bind (settings, KEY_SHOW_ALL_WINDOWS,
@@ -183,6 +217,9 @@ load_window_picker (PanelApplet *applet) {
 
     panel_applet_set_flags(applet, flags);
 
+    g_signal_connect(PANEL_APPLET(windowPickerApplet), "change-orient",
+                     G_CALLBACK(on_applet_orientation_changed), NULL);
+
     gtk_widget_show_all(GTK_WIDGET (applet));
 
     return TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]