[libwnck/wip/muktupavels/wnck-handle: 3/8] handle: add set_default_icon_size and set_default_mini_icon_size




commit 062e875b49ce020418dd39d3f56dd4e8bfce4ac7
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Aug 19 18:23:57 2019 +0300

    handle: add set_default_icon_size and set_default_mini_icon_size
    
    And deprecate old functions.

 libwnck/application.c         |  8 ++++--
 libwnck/class-group.c         |  9 ++++--
 libwnck/private.h             |  4 ---
 libwnck/tasklist.c            | 67 +++++++++++++++++++++++++++++++------------
 libwnck/util.c                | 16 ++---------
 libwnck/util.h                |  3 ++
 libwnck/window.c              |  7 +++--
 libwnck/wnck-handle-private.h |  6 ----
 libwnck/wnck-handle.c         | 32 ++++++++++++++++++---
 libwnck/wnck-handle.h         |  8 +++++-
 libwnck/xutils.h              |  1 +
 11 files changed, 108 insertions(+), 53 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index 8d78209..dc1e1c0 100644
--- a/libwnck/application.c
+++ b/libwnck/application.c
@@ -25,6 +25,7 @@
 #include <glib/gi18n-lib.h>
 #include "application.h"
 #include "private.h"
+#include "wnck-handle-private.h"
 #include "wnck-icon-cache-private.h"
 
 /**
@@ -328,15 +329,18 @@ wnck_application_get_pid (WnckApplication *app)
 static void
 get_icons (WnckApplication *app)
 {
+  WnckHandle *handle;
   GdkPixbuf *icon;
   GdkPixbuf *mini_icon;
   gsize normal_size;
   gsize mini_size;
 
+  handle = wnck_screen_get_handle (app->priv->screen);
+
   icon = NULL;
   mini_icon = NULL;
-  normal_size = _wnck_get_default_icon_size ();
-  mini_size = _wnck_get_default_mini_icon_size ();
+  normal_size = _wnck_handle_get_default_icon_size (handle);
+  mini_size = _wnck_handle_get_default_mini_icon_size (handle);
 
   if (_wnck_read_icons (app->priv->screen,
                         app->priv->xwindow,
diff --git a/libwnck/class-group.c b/libwnck/class-group.c
index f4afc31..5a1aec2 100644
--- a/libwnck/class-group.c
+++ b/libwnck/class-group.c
@@ -26,6 +26,7 @@
 #include "class-group.h"
 #include "window.h"
 #include "private.h"
+#include "wnck-handle-private.h"
 
 /**
  * SECTION:class-group
@@ -455,10 +456,14 @@ set_icon (WnckClassGroup *class_group)
 
   if (!icon || !mini_icon)
     {
+      WnckHandle *handle;
+
+      handle = wnck_screen_get_handle (class_group->priv->screen);
+
       _wnck_get_fallback_icons (&icon,
-                                _wnck_get_default_icon_size (),
+                                _wnck_handle_get_default_icon_size (handle),
                                 &mini_icon,
-                                _wnck_get_default_mini_icon_size ());
+                                _wnck_handle_get_default_mini_icon_size (handle));
       icons_reffed = TRUE;
     }
 
diff --git a/libwnck/private.h b/libwnck/private.h
index 4e35c98..8404d8f 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -41,9 +41,6 @@ G_BEGIN_DECLS
 
 WnckHandle *_wnck_get_handle (void);
 
-gsize _wnck_get_default_icon_size (void);
-gsize _wnck_get_default_mini_icon_size (void);
-
 void _wnck_application_process_property_notify (WnckApplication *app,
                                                 XEvent          *xevent);
 void _wnck_window_process_property_notify (WnckWindow *window,
@@ -98,7 +95,6 @@ void             _wnck_application_shutdown_all (void);
 
 WnckClassGroup  *_wnck_class_group_create        (WnckScreen     *screen,
                                                   const char     *res_class);
-
 void             _wnck_class_group_destroy       (WnckClassGroup *class_group);
 void             _wnck_class_group_add_window    (WnckClassGroup *class_group,
                                                   WnckWindow     *window);
diff --git a/libwnck/tasklist.c b/libwnck/tasklist.c
index 8791b10..4166d76 100644
--- a/libwnck/tasklist.c
+++ b/libwnck/tasklist.c
@@ -32,6 +32,7 @@
 #include "class-group.h"
 #include "window-action-menu.h"
 #include "wnck-image-menu-item-private.h"
+#include "wnck-handle-private.h"
 #include "workspace.h"
 #include "xutils.h"
 #include "private.h"
@@ -92,7 +93,6 @@ typedef struct _WnckTaskClass   WnckTaskClass;
 
 #define DEFAULT_GROUPING_LIMIT 80
 
-#define MINI_ICON_SIZE _wnck_get_default_mini_icon_size ()
 #define TASKLIST_BUTTON_PADDING 4
 #define TASKLIST_TEXT_MAX_WIDTH 25 /* maximum width in characters */
 
@@ -108,6 +108,8 @@ struct _WnckButton
 {
   GtkToggleButton  parent;
 
+  WnckHandle      *handle;
+
   GtkWidget       *image;
   gboolean         show_image;
 
@@ -480,7 +482,7 @@ wnck_button_size_allocate (GtkWidget     *widget,
   min_width = get_css_width (widget);
   min_width += get_css_width (gtk_bin_get_child (GTK_BIN (widget)));
 
-  min_image_width = MINI_ICON_SIZE +
+  min_image_width = _wnck_handle_get_default_mini_icon_size (self->handle) +
                     min_width +
                     2 * TASKLIST_BUTTON_PADDING;
 
@@ -610,6 +612,13 @@ wnck_button_new (void)
   return g_object_new (WNCK_TYPE_BUTTON, NULL);
 }
 
+static void
+wnck_button_set_handle (WnckButton *self,
+                        WnckHandle *handle)
+{
+  self->handle = handle;
+}
+
 static void
 wnck_button_set_image_from_pixbuf (WnckButton *self,
                                    GdkPixbuf  *pixbuf)
@@ -1765,12 +1774,14 @@ get_n_buttons (WnckTasklist *self)
 }
 
 static void
-get_minimum_button_size (int *minimum_width,
-                         int *minimum_height)
+get_minimum_button_size (WnckHandle *handle,
+                         int        *minimum_width,
+                         int        *minimum_height)
 {
   GtkWidget *button;
 
   button = wnck_button_new ();
+  wnck_button_set_handle (WNCK_BUTTON (button), handle);
   gtk_widget_show (button);
 
   if (minimum_width != NULL)
@@ -1805,9 +1816,12 @@ get_preferred_size (WnckTasklist   *self,
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
+      WnckHandle *handle;
       int min_button_width;
 
-      get_minimum_button_size (&min_button_width, NULL);
+      handle = wnck_screen_get_handle (self->priv->screen);
+
+      get_minimum_button_size (handle, &min_button_width, NULL);
 
       if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
         {
@@ -3610,9 +3624,12 @@ wnck_dimm_icon (GdkPixbuf *pixbuf)
 }
 
 static GdkPixbuf *
-wnck_task_scale_icon (GdkPixbuf *orig, gboolean minimized)
+wnck_task_scale_icon (WnckHandle *handle,
+                      GdkPixbuf  *orig,
+                      gboolean    minimized)
 {
   int w, h;
+  gsize mini_icon_size;
   GdkPixbuf *pixbuf;
 
   if (!orig)
@@ -3621,7 +3638,9 @@ wnck_task_scale_icon (GdkPixbuf *orig, gboolean minimized)
   w = gdk_pixbuf_get_width (orig);
   h = gdk_pixbuf_get_height (orig);
 
-  if (h != (int) MINI_ICON_SIZE ||
+  mini_icon_size = _wnck_handle_get_default_mini_icon_size (handle);
+
+  if (h != (int) mini_icon_size ||
       !gdk_pixbuf_get_has_alpha (orig))
     {
       double scale;
@@ -3629,10 +3648,10 @@ wnck_task_scale_icon (GdkPixbuf *orig, gboolean minimized)
       pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
                               TRUE,
                               8,
-                              MINI_ICON_SIZE * w / (double) h,
-                              MINI_ICON_SIZE);
+                              mini_icon_size * w / (double) h,
+                              mini_icon_size);
 
-      scale = MINI_ICON_SIZE / (double) gdk_pixbuf_get_height (orig);
+      scale = mini_icon_size / (double) gdk_pixbuf_get_height (orig);
 
       gdk_pixbuf_scale (orig,
                        pixbuf,
@@ -3664,23 +3683,27 @@ wnck_task_scale_icon (GdkPixbuf *orig, gboolean minimized)
 static GdkPixbuf *
 wnck_task_get_icon (WnckTask *task)
 {
+  WnckHandle *handle;
   WnckWindowState state;
   GdkPixbuf *pixbuf;
 
+  handle = wnck_screen_get_handle (task->tasklist->priv->screen);
   pixbuf = NULL;
 
   switch (task->type)
     {
     case WNCK_TASK_CLASS_GROUP:
-      pixbuf = wnck_task_scale_icon (wnck_class_group_get_mini_icon (task->class_group),
-                                    FALSE);
+      pixbuf = wnck_task_scale_icon (handle,
+                                     wnck_class_group_get_mini_icon (task->class_group),
+                                     FALSE);
       break;
 
     case WNCK_TASK_WINDOW:
       state = wnck_window_get_state (task->window);
 
-      pixbuf =  wnck_task_scale_icon (wnck_window_get_mini_icon (task->window),
-                                     state & WNCK_WINDOW_STATE_MINIMIZED);
+      pixbuf =  wnck_task_scale_icon (handle,
+                                      wnck_window_get_mini_icon (task->window),
+                                      state & WNCK_WINDOW_STATE_MINIMIZED);
       break;
 
     case WNCK_TASK_STARTUP_SEQUENCE:
@@ -3692,16 +3715,19 @@ wnck_task_get_icon (WnckTask *task)
           icon = sn_startup_sequence_get_icon_name (task->startup_sequence);
           if (icon != NULL)
             {
+              gsize mini_icon_size;
               GdkPixbuf *loaded;
 
+              mini_icon_size = _wnck_handle_get_default_mini_icon_size (handle);
+
               loaded =  (* task->tasklist->priv->icon_loader) (icon,
-                                                               MINI_ICON_SIZE,
+                                                               mini_icon_size,
                                                                0,
                                                                task->tasklist->priv->icon_loader_data);
 
               if (loaded != NULL)
                 {
-                  pixbuf = wnck_task_scale_icon (loaded, FALSE);
+                  pixbuf = wnck_task_scale_icon (handle, loaded, FALSE);
                   g_object_unref (G_OBJECT (loaded));
                 }
             }
@@ -3709,8 +3735,11 @@ wnck_task_get_icon (WnckTask *task)
 
       if (pixbuf == NULL)
         {
-          _wnck_get_fallback_icons (NULL, 0,
-                                    &pixbuf, MINI_ICON_SIZE);
+          gsize mini_icon_size;
+
+          mini_icon_size = _wnck_handle_get_default_mini_icon_size (handle);
+
+          _wnck_get_fallback_icons (NULL, 0, &pixbuf, mini_icon_size);
         }
 #endif
       break;
@@ -4251,6 +4280,8 @@ wnck_task_create_widgets (WnckTask *task, GtkReliefStyle relief)
   };
 
   task->button = wnck_button_new ();
+  wnck_button_set_handle (WNCK_BUTTON (task->button),
+                          wnck_screen_get_handle (task->tasklist->priv->screen));
 
   gtk_button_set_relief (GTK_BUTTON (task->button), relief);
 
diff --git a/libwnck/util.c b/libwnck/util.c
index c2c4147..51e75ba 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -686,13 +686,7 @@ _wnck_get_handle (void)
 void
 wnck_set_default_icon_size (gsize size)
 {
-  _wnck_handle_set_default_icon_size (_wnck_get_handle (), size);
-}
-
-gsize
-_wnck_get_default_icon_size (void)
-{
-  return _wnck_handle_get_default_icon_size (_wnck_get_handle ());
+  wnck_handle_set_default_icon_size (_wnck_get_handle(), size);
 }
 
 /**
@@ -711,7 +705,7 @@ wnck_set_default_mini_icon_size (gsize size)
   WnckScreen *screen;
   GList *l;
 
-  _wnck_handle_set_default_mini_icon_size (_wnck_get_handle (), size);
+  wnck_handle_set_default_mini_icon_size (_wnck_get_handle (), size);
 
   default_screen = DefaultScreen (_wnck_get_default_display ());
   screen = _wnck_screen_get_existing (default_screen);
@@ -732,12 +726,6 @@ wnck_set_default_mini_icon_size (gsize size)
     }
 }
 
-gsize
-_wnck_get_default_mini_icon_size (void)
-{
-  return _wnck_handle_get_default_mini_icon_size (_wnck_get_handle ());
-}
-
 /**
  * _make_gtk_label_bold:
  * @label: The label.
diff --git a/libwnck/util.h b/libwnck/util.h
index f17d37a..91a4e08 100644
--- a/libwnck/util.h
+++ b/libwnck/util.h
@@ -106,7 +106,10 @@ void wnck_set_client_type (WnckClientType ewmh_sourceindication_client_type);
 #define WNCK_DEFAULT_ICON_SIZE 32
 #define WNCK_DEFAULT_MINI_ICON_SIZE 16
 
+G_DEPRECATED_FOR(wnck_handle_set_default_icon_size)
 void wnck_set_default_icon_size      (gsize size);
+
+G_DEPRECATED_FOR(wnck_handle_set_default_mini_icon_size)
 void wnck_set_default_mini_icon_size (gsize size);
 
 void wnck_shutdown        (void);
diff --git a/libwnck/window.c b/libwnck/window.c
index b26c020..294f556 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -2117,15 +2117,18 @@ wnck_window_transient_is_most_recently_activated (WnckWindow *window)
 static void
 get_icons (WnckWindow *window)
 {
+  WnckHandle *handle;
   GdkPixbuf *icon;
   GdkPixbuf *mini_icon;
   gsize normal_size;
   gsize mini_size;
 
+  handle = wnck_screen_get_handle (window->priv->screen);
+
   icon = NULL;
   mini_icon = NULL;
-  normal_size = _wnck_get_default_icon_size ();
-  mini_size = _wnck_get_default_mini_icon_size ();
+  normal_size = _wnck_handle_get_default_icon_size (handle);
+  mini_size = _wnck_handle_get_default_mini_icon_size (handle);
 
   if (_wnck_read_icons (window->priv->screen,
                         window->priv->xwindow,
diff --git a/libwnck/wnck-handle-private.h b/libwnck/wnck-handle-private.h
index 3cbe0e6..f77b4ba 100644
--- a/libwnck/wnck-handle-private.h
+++ b/libwnck/wnck-handle-private.h
@@ -25,14 +25,8 @@ G_BEGIN_DECLS
 
 WnckClientType  _wnck_handle_get_client_type            (WnckHandle     *self);
 
-void            _wnck_handle_set_default_icon_size      (WnckHandle     *self,
-                                                         gsize           icon_size);
-
 gsize           _wnck_handle_get_default_icon_size      (WnckHandle     *self);
 
-void            _wnck_handle_set_default_mini_icon_size (WnckHandle     *self,
-                                                         gsize           icon_size);
-
 gsize           _wnck_handle_get_default_mini_icon_size (WnckHandle     *self);
 
 G_END_DECLS
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
index dd068bb..69438ae 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -259,28 +259,52 @@ _wnck_handle_get_client_type (WnckHandle *self)
   return self->client_type;
 }
 
+/**
+ * wnck_handle_set_default_icon_size:
+ * @self: a #WnckHandle
+ * @icon_size: the default size for windows and application standard icons.
+ *
+ * The default main icon size is %WNCK_DEFAULT_ICON_SIZE. This function allows
+ * to change this value.
+ */
 void
-_wnck_handle_set_default_icon_size (WnckHandle *self,
-                                    gsize       icon_size)
+wnck_handle_set_default_icon_size (WnckHandle *self,
+                                   gsize       icon_size)
 {
+  g_return_if_fail (WNCK_IS_HANDLE (self));
+
   self->default_icon_size = icon_size;
 }
 
 gsize
 _wnck_handle_get_default_icon_size (WnckHandle *self)
 {
+  g_return_val_if_fail (WNCK_IS_HANDLE (self), WNCK_DEFAULT_ICON_SIZE);
+
   return self->default_icon_size;
 }
 
+/**
+ * wnck_handle_set_default_mini_icon_size:
+ * @self: a #WnckHandle
+ * @icon_size: the default size for windows and application mini icons.
+ *
+ * The default main icon size is %WNCK_DEFAULT_MINI_ICON_SIZE. This function
+ * allows to change this value.
+ */
 void
-_wnck_handle_set_default_mini_icon_size (WnckHandle *self,
-                                         gsize       icon_size)
+wnck_handle_set_default_mini_icon_size (WnckHandle *self,
+                                        gsize       icon_size)
 {
+  g_return_if_fail (WNCK_IS_HANDLE (self));
+
   self->default_mini_icon_size = icon_size;
 }
 
 gsize
 _wnck_handle_get_default_mini_icon_size (WnckHandle *self)
 {
+  g_return_val_if_fail (WNCK_IS_HANDLE (self), WNCK_DEFAULT_MINI_ICON_SIZE);
+
   return self->default_mini_icon_size;
 }
diff --git a/libwnck/wnck-handle.h b/libwnck/wnck-handle.h
index 08c100c..1f7aae1 100644
--- a/libwnck/wnck-handle.h
+++ b/libwnck/wnck-handle.h
@@ -30,7 +30,13 @@ G_BEGIN_DECLS
 #define WNCK_TYPE_HANDLE (wnck_handle_get_type ())
 G_DECLARE_FINAL_TYPE (WnckHandle, wnck_handle, WNCK, HANDLE, GObject)
 
-WnckHandle *wnck_handle_new (WnckClientType client_type);
+WnckHandle *wnck_handle_new                        (WnckClientType  client_type);
+
+void        wnck_handle_set_default_icon_size      (WnckHandle     *self,
+                                                    gsize           icon_size);
+
+void        wnck_handle_set_default_mini_icon_size (WnckHandle     *self,
+                                                    gsize           icon_size);
 
 G_END_DECLS
 
diff --git a/libwnck/xutils.h b/libwnck/xutils.h
index 951bd49..cd1f63b 100644
--- a/libwnck/xutils.h
+++ b/libwnck/xutils.h
@@ -32,6 +32,7 @@
 G_BEGIN_DECLS
 
 /* forward decls */
+typedef struct _WnckHandle WnckHandle;
 typedef struct _WnckScreen WnckScreen;
 
 #define WNCK_APP_WINDOW_EVENT_MASK (PropertyChangeMask | StructureNotifyMask)


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