[gnome-applets/wip/segeiger/window-picker-in-process] Another try to fix the width for height issue



commit e440e5e58adc6f4f387285d43c05bf23f0cb4b02
Author: Sebastian Geiger <sbastig gmx net>
Date:   Fri Jun 12 12:32:47 2015 +0200

    Another try to fix the width for height issue

 windowpicker/src/task-item.c |  115 ++++++++++++++++++++++++++++++-----------
 1 files changed, 84 insertions(+), 31 deletions(-)
---
diff --git a/windowpicker/src/task-item.c b/windowpicker/src/task-item.c
index 3069c2d..d58a1cf 100644
--- a/windowpicker/src/task-item.c
+++ b/windowpicker/src/task-item.c
@@ -183,13 +183,28 @@ static void task_item_set_visibility (TaskItem *item) {
     }
 }
 
+static GtkSizeRequestMode
+task_item_get_request_mode (GtkWidget* widget);
+
 static void
 task_item_get_preferred_width (GtkWidget *widget,
                                gint      *minimal_width,
                                gint      *natural_width)
 {
-    g_message ("Setting preferred_width to: %d", DEFAULT_TASK_ITEM_WIDTH + 10);
-    *minimal_width = *natural_width = 46; //DEFAULT_TASK_ITEM_WIDTH + 16;
+    if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT) {
+        gint min_height;
+
+        GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, &min_height, NULL);
+        GTK_WIDGET_GET_CLASS (widget)->get_preferred_width_for_height (widget, min_height,
+                                                                       minimal_width, natural_width);
+    } else {
+        g_message ("[get_preferred_width] Setting preferred_width to: %d", DEFAULT_TASK_ITEM_WIDTH);
+        if (minimal_width)
+            *minimal_width = DEFAULT_TASK_ITEM_WIDTH;
+        if (natural_width)
+            *minimal_width = DEFAULT_TASK_ITEM_WIDTH;
+    }
+
 }
 
 static void
@@ -197,10 +212,23 @@ task_item_get_preferred_height (GtkWidget *widget,
                                 gint      *minimal_height,
                                 gint      *natural_height)
 {
-    /* This sets the MINIMUM height of the item. The actual height will be determined by
-     * task_item_get_preferred_height_for_width. */
-    g_message ("Setting preferred_height to: %d", DEFAULT_TASK_ITEM_HEIGHT + 10);
-    *minimal_height = *natural_height = 40; //DEFAULT_TASK_ITEM_HEIGHT + 10;
+
+
+    if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) {
+        gint min_width;
+
+        GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
+        GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
+                                                                       minimal_height, natural_height);
+    } else {
+        /* This sets the MINIMUM height of the item. The actual height will be determined by
+         * task_item_get_preferred_height_for_width. */
+        g_message ("[get_preferred_height] Setting preferred_height to: %d", DEFAULT_TASK_ITEM_HEIGHT);
+        if (minimal_height)
+            *minimal_height = DEFAULT_TASK_ITEM_HEIGHT;
+        if (natural_height)
+            *natural_height = DEFAULT_TASK_ITEM_HEIGHT;
+    }
 }
 
 static GtkSizeRequestMode
@@ -209,10 +237,21 @@ task_item_get_request_mode (GtkWidget* widget)
     WindowPickerApplet *applet = TASK_ITEM (widget)->priv->windowPickerApplet;
     GtkOrientation orientation = panel_applet_get_gtk_orientation (applet);
 
-    if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    static gboolean first = FALSE;
+
+    if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+        if (!first) {
+            first = TRUE;
+            g_message ("Horizontal -> Setting width for height mode");
+        }
         return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
-    else
+    } else {
+        if (!first) {
+            first = TRUE;
+            g_message ("Vertical -> Setting height for width mode");
+        }
         return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+    }
 }
 
 static void
@@ -224,8 +263,11 @@ task_item_get_preferred_height_for_width (GtkWidget *widget,
     WindowPickerApplet *applet = TASK_ITEM (widget)->priv->windowPickerApplet;
     GtkOrientation orientation = panel_applet_get_gtk_orientation (applet);
 
-    if (orientation == GTK_ORIENTATION_VERTICAL) {
-        g_message("Setting preferred minimum_height=natural_height=%d for width: %d", width + 6, width);
+    if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT) {
+        g_message("[get_preferred_height_for_width] Deferring to height");
+        GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
+    } else {
+        g_message("[get_preferred_height_for_width] Setting preferred minimum_height=natural_height=%d for 
width: %d", width + 6, width);
         *minimum_height = *natural_height = width + 6;
     }
 }
@@ -236,15 +278,42 @@ task_item_get_preferred_width_for_height (GtkWidget *widget,
                                           gint *minimum_width,
                                           gint *natural_width)
 {
-    WindowPickerApplet *applet = TASK_ITEM (widget)->priv->windowPickerApplet;
-    GtkOrientation orientation = panel_applet_get_gtk_orientation (applet);
-
-    if (orientation == GTK_ORIENTATION_HORIZONTAL) {
-        g_message("Setting preferred minimum_width=natural_width=%d for height: %d", height + 6, height);
+    if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) {
+        g_message("[preferred_width_for_height] Deferring to get_preferred_width");
+        GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
+    } else {
+        g_message("[preferred_width_for_height] Setting preferred minimum_width=natural_width=%d for height: 
%d", height + 6, height);
         *minimum_width = *natural_width = height + 6;
     }
 }
 
+static void on_size_allocate (
+        GtkWidget     *widget,
+        GtkAllocation *allocation,
+        WindowPickerApplet *applet)
+{
+    g_return_if_fail (TASK_IS_ITEM (widget));
+    TaskItem *item = TASK_ITEM (widget);
+    TaskItemPrivate *priv = item->priv;
+    priv->area.x = allocation->x;
+    priv->area.y = allocation->y;
+    priv->area.width = allocation->width;
+    priv->area.height = allocation->height;
+    g_message ("[on-size-allocate] New size for draw function: area.width: %d, area.height: %d", 
priv->area.width, priv->area.height);
+
+    GtkWidget *taskList = gtk_widget_get_parent (item);
+    gint taskListHeight = gtk_widget_get_allocated_height (taskList);
+    gint taskListWidth = gtk_widget_get_allocated_width (taskList);
+    g_message ("[on-size-allocate] TaskListWidth=%d, TaskListHeight: %d", taskListWidth, taskListHeight);
+
+    GtkWidget *outerBox = gtk_widget_get_parent (taskList);
+    gint outerBoxHeight = gtk_widget_get_allocated_height (outerBox);
+    gint outerBoxWidth = gtk_widget_get_allocated_width (outerBox);
+    g_message ("[on-size-allocate] OuterBoxWidth=%d, outerBoxHeight: %d", outerBoxWidth, outerBoxHeight);
+
+    update_hints (item);
+}
+
 static GdkPixbuf *task_item_sized_pixbuf_for_window (
     TaskItem   *item,
     WnckWindow *window,
@@ -392,22 +461,6 @@ static gboolean task_item_draw (
     return FALSE;
 }
 
-static void on_size_allocate (
-    GtkWidget     *widget,
-    GtkAllocation *allocation,
-    WindowPickerApplet *applet)
-{
-    g_return_if_fail (TASK_IS_ITEM (widget));
-    TaskItem *item = TASK_ITEM (widget);
-    TaskItemPrivate *priv = item->priv;
-    priv->area.x = allocation->x;
-    priv->area.y = allocation->y;
-    priv->area.width = allocation->width;
-    priv->area.height = allocation->height;
-    g_message ("New size for draw function: area.width: %d, area.height: %d", priv->area.width, 
priv->area.height);
-    update_hints (item);
-}
-
 static gboolean on_button_pressed (
     GtkWidget      *button,
     GdkEventButton *event,


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