[gnome-shell] iconGrid: Subclass a C actor for BaseIcon



commit d21a0b186edf9832d48901e35c2927fd9cd70f1d
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Tue Mar 2 11:47:13 2021 +0100

    iconGrid: Subclass a C actor for BaseIcon
    
    We create a lot of BaseIcons for the appGrid, one for every app, and for
    all of those we have to hop through JS to get the preferred width. That
    makes it another obvious target for moving to C, so let's do that.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1755>

 js/ui/iconGrid.js      |  9 ++-------
 src/meson.build        |  2 ++
 src/shell-square-bin.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/shell-square-bin.h | 13 +++++++++++++
 4 files changed, 60 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 0272c0e233..ddebc308e1 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -1,7 +1,7 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported BaseIcon, IconGrid, IconGridLayout */
 
-const { Clutter, GLib, GObject, Meta, St } = imports.gi;
+const { Clutter, GLib, GObject, Meta, Shell, St } = imports.gi;
 
 const Params = imports.misc.params;
 const Main = imports.ui.main;
@@ -64,7 +64,7 @@ var DragLocation = {
 };
 
 var BaseIcon = GObject.registerClass(
-class BaseIcon extends St.Bin {
+class BaseIcon extends Shell.SquareBin {
     _init(label, params) {
         params = Params.parse(params, {
             createIcon: null,
@@ -113,11 +113,6 @@ class BaseIcon extends St.Bin {
         this._iconThemeChangedId = cache.connect('icon-theme-changed', this._onIconThemeChanged.bind(this));
     }
 
-    vfunc_get_preferred_width(_forHeight) {
-        // Return the actual height to keep the squared aspect
-        return this.get_preferred_height(-1);
-    }
-
     // This can be overridden by a subclass, or by the createIcon
     // parameter to _init()
     createIcon(_size) {
diff --git a/src/meson.build b/src/meson.build
index b06f7cab1e..d235c37438 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -105,6 +105,7 @@ libshell_public_headers = [
   'shell-mount-operation.h',
   'shell-perf-log.h',
   'shell-screenshot.h',
+  'shell-square-bin.h',
   'shell-stack.h',
   'shell-tray-icon.h',
   'shell-tray-manager.h',
@@ -149,6 +150,7 @@ libshell_sources = [
   'shell-screenshot.c',
   'shell-secure-text-buffer.c',
   'shell-secure-text-buffer.h',
+  'shell-square-bin.c',
   'shell-stack.c',
   'shell-tray-icon.c',
   'shell-tray-manager.c',
diff --git a/src/shell-square-bin.c b/src/shell-square-bin.c
new file mode 100644
index 0000000000..06587fb6ff
--- /dev/null
+++ b/src/shell-square-bin.c
@@ -0,0 +1,43 @@
+#include "config.h"
+
+#include "shell-square-bin.h"
+
+struct _ShellSquareBin
+{
+  /*< private >*/
+  StBin parent_instance;
+};
+
+G_DEFINE_TYPE (ShellSquareBin, shell_square_bin, ST_TYPE_BIN);
+
+static void
+shell_square_bin_get_preferred_width (ClutterActor *actor,
+                                      float         for_height,
+                                      float        *min_width_p,
+                                      float        *natural_width_p)
+{
+  float min_width, nat_width;
+
+  /* Return the actual height to keep the squared aspect */
+  clutter_actor_get_preferred_height (actor, -1,
+                                      &min_width, &nat_width);
+
+  if (min_width_p)
+    *min_width_p = min_width;
+
+  if (natural_width_p)
+    *natural_width_p = nat_width;
+}
+
+static void
+shell_square_bin_init (ShellSquareBin *self)
+{
+}
+
+static void
+shell_square_bin_class_init (ShellSquareBinClass *klass)
+{
+  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+
+  actor_class->get_preferred_width = shell_square_bin_get_preferred_width;
+}
diff --git a/src/shell-square-bin.h b/src/shell-square-bin.h
new file mode 100644
index 0000000000..2b7d4b2365
--- /dev/null
+++ b/src/shell-square-bin.h
@@ -0,0 +1,13 @@
+#ifndef __SHELL_SQUARE_BIN_H__
+#define __SHELL_SQUARE_BIN_H__
+
+#include <st/st.h>
+
+G_BEGIN_DECLS
+
+#define SHELL_TYPE_SQUARE_BIN (shell_square_bin_get_type ())
+G_DECLARE_FINAL_TYPE (ShellSquareBin, shell_square_bin, SHELL, SquareBin, StBin)
+
+G_END_DECLS
+
+#endif /* __SHELL_SQUARE_BIN_H__ */


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