[Xfce4-commits] [xfce/xfce4-panel] 08/73: pager: fixed wnck pager aspect ratio in deskbar mode

noreply at xfce.org noreply at xfce.org
Sun Feb 26 16:33:49 CET 2017


This is an automated email from the git hooks/post-receive script.

andrzejr pushed a commit to branch master
in repository xfce/xfce4-panel.

commit d50965d9f28c157876ad0df0c5501d21e0ffbbbf
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Fri Dec 20 03:38:39 2013 +0000

    pager: fixed wnck pager aspect ratio in deskbar mode
    
    Previously we were relying on new api added in libwnck-2.31.
    Unfortunately, stable version of libwnck was never released and the API
    was not added to libwnck-3.
    
    This commit changes the method of setting the aspect ratio.
    Aspect ratio is now calculated in the plugin using screen dimensions.
    
    One minor limitation of this method is that we are not accounting
    for wnck pager frames, so the aspect ratio may be slightly inaccurate.
---
 plugins/pager/pager.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 175 insertions(+), 15 deletions(-)

diff --git a/plugins/pager/pager.c b/plugins/pager/pager.c
index 950fad9..a359ff8 100644
--- a/plugins/pager/pager.c
+++ b/plugins/pager/pager.c
@@ -52,6 +52,8 @@ static void     pager_plugin_set_property                 (GObject           *ob
                                                            guint              prop_id,
                                                            const GValue      *value,
                                                            GParamSpec        *pspec);
+static void     pager_plugin_size_request                 (GtkWidget         *widget,
+                                                           GtkRequisition    *requisition);
 static gboolean pager_plugin_scroll_event                 (GtkWidget         *widget,
                                                            GdkEventScroll    *event);
 static void     pager_plugin_screen_changed               (GtkWidget         *widget,
@@ -65,6 +67,20 @@ static void     pager_plugin_mode_changed                 (XfcePanelPlugin     *
 static void     pager_plugin_configure_workspace_settings (GtkWidget         *button);
 static void     pager_plugin_configure_plugin             (XfcePanelPlugin   *panel_plugin);
 static void     pager_plugin_screen_layout_changed        (PagerPlugin       *plugin);
+static void     pager_plugin_get_preferred_width            (GtkWidget           *widget,
+                                                             gint                *minimum_width,
+                                                             gint                *natural_width);
+static void     pager_plugin_get_preferred_width_for_height (GtkWidget           *widget,
+                                                             gint                 height,
+                                                             gint                *minimum_width,
+                                                             gint                *natural_width);
+static void     pager_plugin_get_preferred_height           (GtkWidget           *widget,
+                                                             gint                *minimum_height,
+                                                             gint                *natural_height);
+static void     pager_plugin_get_preferred_height_for_width (GtkWidget           *widget,
+                                                             gint                 width,
+                                                             gint                *minimum_height,
+                                                             gint                *natural_height);
 
 
 
@@ -85,6 +101,7 @@ struct _PagerPlugin
   guint          scrolling : 1;
   guint          miniature_view : 1;
   gint           rows;
+  gfloat         ratio;
 };
 
 enum
@@ -116,6 +133,11 @@ pager_plugin_class_init (PagerPluginClass *klass)
 
   widget_class = GTK_WIDGET_CLASS (klass);
   widget_class->scroll_event = pager_plugin_scroll_event;
+  //widget_class->size_request = pager_plugin_size_request;
+  //widget_class->get_preferred_width             = pager_plugin_get_preferred_width;
+  widget_class->get_preferred_width_for_height  = pager_plugin_get_preferred_width_for_height;
+  //widget_class->get_preferred_height            = pager_plugin_get_preferred_height;
+  widget_class->get_preferred_height_for_width  = pager_plugin_get_preferred_height_for_width;
 
   plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
   plugin_class->construct = pager_plugin_construct;
@@ -155,6 +177,7 @@ pager_plugin_init (PagerPlugin *plugin)
   plugin->scrolling = TRUE;
   plugin->miniature_view = TRUE;
   plugin->rows = 1;
+  plugin->ratio = 1.0;
   plugin->pager = NULL;
 }
 
@@ -302,13 +325,8 @@ pager_plugin_screen_layout_changed (PagerPlugin *plugin)
       if (!wnck_pager_set_n_rows (WNCK_PAGER (plugin->pager), plugin->rows))
         g_message ("Setting the pager rows returned false. Maybe the setting is not applied.");
 
-#if 0
-      wnck_pager_set_layout_policy (WNCK_PAGER (plugin->pager),
-                                    (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL) ?
-                                    WNCK_PAGER_LAYOUT_POLICY_WIDTH_FOR_HEIGHT :
-                                    WNCK_PAGER_LAYOUT_POLICY_HEIGHT_FOR_WIDTH);
-#endif
       wnck_pager_set_orientation (WNCK_PAGER (plugin->pager), orientation);
+      plugin->ratio = (gfloat) gdk_screen_width () / (gfloat) gdk_screen_height ();
     }
   else
     {
@@ -418,15 +436,7 @@ pager_plugin_mode_changed (XfcePanelPlugin     *panel_plugin,
     GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
 
   if (plugin->miniature_view)
-    {
-#if 0
-      wnck_pager_set_layout_policy (WNCK_PAGER (plugin->pager),
-                                    (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL) ?
-                                    WNCK_PAGER_LAYOUT_POLICY_WIDTH_FOR_HEIGHT :
-                                    WNCK_PAGER_LAYOUT_POLICY_HEIGHT_FOR_WIDTH);
-#endif
-      wnck_pager_set_orientation (WNCK_PAGER (plugin->pager), orientation);
-    }
+    wnck_pager_set_orientation (WNCK_PAGER (plugin->pager), orientation);
   else
     pager_buttons_set_orientation (XFCE_PAGER_BUTTONS (plugin->pager), orientation);
 }
@@ -558,3 +568,153 @@ pager_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
 
   gtk_widget_show (GTK_WIDGET (dialog));
 }
+
+
+#if 0
+static void
+pager_plugin_size_request (GtkWidget      *widget,
+                           GtkRequisition *requisition)
+{
+  PagerPlugin         *plugin = XFCE_PAGER_PLUGIN (widget);
+  XfcePanelPluginMode  mode;
+  gint                 n_workspaces, n_cols;
+
+  if (plugin->miniature_view)
+    {
+      mode   = xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin));
+      n_workspaces = wnck_screen_get_workspace_count (plugin->wnck_screen);
+      n_cols = MAX (1, (n_workspaces + plugin->rows - 1) / plugin->rows);
+      if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+        {
+          requisition->height = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+          requisition->width = (gint) (requisition->height / plugin->rows * plugin->ratio * n_cols);
+        }
+      else if (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+        {
+          requisition->width = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+          requisition->height = (gint) (requisition->width / plugin->rows / plugin->ratio * n_cols);
+        }
+      else /* (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) */
+        {
+          requisition->width = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+          requisition->height = (gint) (requisition->width / n_cols / plugin->ratio * plugin->rows);
+        }
+    }
+  else
+    {
+      gtk_widget_size_request (plugin->pager, requisition);
+    }
+}
+#endif
+
+
+static void
+pager_plugin_get_preferred_width (GtkWidget *widget,
+                                  gint      *minimum_width,
+                                  gint      *natural_width)
+{
+  PagerPlugin         *plugin = XFCE_PAGER_PLUGIN (widget);
+  XfcePanelPluginMode  mode;
+  gint                 n_workspaces, n_cols;
+
+  if (plugin->miniature_view)
+    {
+      mode   = xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin));
+      n_workspaces = wnck_screen_get_workspace_count (plugin->wnck_screen);
+      n_cols = MAX (1, (n_workspaces + plugin->rows - 1) / plugin->rows);
+      if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+        *minimum_width = *natural_width = 1; //(gint) (requisition->height / plugin->rows * plugin->ratio * n_cols);
+      else if (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+        *minimum_width = *natural_width = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+      else /* (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) */
+        *minimum_width = *natural_width = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+    }
+  else
+    {
+      gtk_widget_get_preferred_width (plugin->pager, minimum_width, natural_width);
+    }
+}
+
+static void
+pager_plugin_get_preferred_width_for_height (GtkWidget *widget,
+                                             gint       height,
+                                             gint      *minimum_width,
+                                             gint      *natural_width)
+{
+  PagerPlugin         *plugin = XFCE_PAGER_PLUGIN (widget);
+  XfcePanelPluginMode  mode;
+  gint                 n_workspaces, n_cols;
+
+  if (plugin->miniature_view)
+    {
+      mode   = xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin));
+      n_workspaces = wnck_screen_get_workspace_count (plugin->wnck_screen);
+      n_cols = MAX (1, (n_workspaces + plugin->rows - 1) / plugin->rows);
+      if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+        *minimum_width = *natural_width = (gint) (height / plugin->rows * plugin->ratio * n_cols);
+      else if (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+        *minimum_width = *natural_width = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+      else /* (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) */
+        *minimum_width = *natural_width = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+    }
+  else
+    {
+      gtk_widget_get_preferred_width_for_height (plugin->pager, height, minimum_width, natural_width);
+    }
+}
+
+static void
+pager_plugin_get_preferred_height (GtkWidget *widget,
+                                  gint      *minimum_height,
+                                  gint      *natural_height)
+{
+  PagerPlugin         *plugin = XFCE_PAGER_PLUGIN (widget);
+  XfcePanelPluginMode  mode;
+  gint                 n_workspaces, n_cols;
+
+  if (plugin->miniature_view)
+    {
+      mode   = xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin));
+      n_workspaces = wnck_screen_get_workspace_count (plugin->wnck_screen);
+      n_cols = MAX (1, (n_workspaces + plugin->rows - 1) / plugin->rows);
+      if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+        *minimum_height = *natural_height = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+      else if (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+        *minimum_height = *natural_height = 1; //(gint) (requisition->width / plugin->rows / plugin->ratio * n_cols);
+      else /* (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) */
+        *minimum_height = *natural_height = 1; //(gint) (requisition->width / n_cols / plugin->ratio * plugin->rows);
+    }
+  else
+    {
+      gtk_widget_get_preferred_height (plugin->pager, minimum_height, natural_height);
+    }
+}
+
+static void
+pager_plugin_get_preferred_height_for_width (GtkWidget *widget,
+                                             gint       width,
+                                             gint      *minimum_height,
+                                             gint      *natural_height)
+{
+  PagerPlugin         *plugin = XFCE_PAGER_PLUGIN (widget);
+  XfcePanelPluginMode  mode;
+  gint                 n_workspaces, n_cols;
+
+  if (plugin->miniature_view)
+    {
+      mode   = xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin));
+      n_workspaces = wnck_screen_get_workspace_count (plugin->wnck_screen);
+      n_cols = MAX (1, (n_workspaces + plugin->rows - 1) / plugin->rows);
+      if (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+        *minimum_height = *natural_height = xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin));
+      else if (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+        *minimum_height = *natural_height = (gint) (width / plugin->rows / plugin->ratio * n_cols);
+      else /* (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) */
+        *minimum_height = *natural_height = (gint) (width / n_cols / plugin->ratio * plugin->rows);
+    }
+  else
+    {
+      gtk_widget_get_preferred_height_for_width (plugin->pager, width, minimum_height, natural_height);
+    }
+}
+

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list