[gnome-applets] window-picker: port to WnckHandle



commit 7126599093a7d08a43838fa816a59bb6c2412c80
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Oct 2 15:10:53 2022 +0300

    window-picker: port to WnckHandle

 gnome-applets/window-picker/Makefile.am         |  1 +
 gnome-applets/window-picker/task-list.c         |  3 +--
 gnome-applets/window-picker/task-list.h         |  2 +-
 gnome-applets/window-picker/wp-applet-private.h | 35 +++++++++++++++++++++++++
 gnome-applets/window-picker/wp-applet.c         | 13 ++++++++-
 gnome-applets/window-picker/wp-task-title.c     | 22 +++++++---------
 gnome-applets/window-picker/wp-task-title.h     |  2 +-
 7 files changed, 61 insertions(+), 17 deletions(-)
---
diff --git a/gnome-applets/window-picker/Makefile.am b/gnome-applets/window-picker/Makefile.am
index bb4417bf2..ed9cb20dd 100644
--- a/gnome-applets/window-picker/Makefile.am
+++ b/gnome-applets/window-picker/Makefile.am
@@ -29,6 +29,7 @@ libwindow_picker_applet_la_LIBADD = \
        $(NULL)
 
 libwindow_picker_applet_la_SOURCES = \
+       wp-applet-private.h \
        wp-applet.c \
        wp-applet.h \
        wp-preferences-dialog.c \
diff --git a/gnome-applets/window-picker/task-list.c b/gnome-applets/window-picker/task-list.c
index a6bde4d0b..27d0bea13 100644
--- a/gnome-applets/window-picker/task-list.c
+++ b/gnome-applets/window-picker/task-list.c
@@ -337,8 +337,6 @@ task_list_class_init(TaskListClass *class) {
 }
 
 static void task_list_init (TaskList *list) {
-    list->screen = wnck_screen_get_default ();
-
     list->items = g_hash_table_new_full (NULL, NULL,
                                          NULL, (GDestroyNotify) gtk_widget_destroy);
 
@@ -358,6 +356,7 @@ GtkWidget *task_list_new (WpApplet *windowPickerApplet) {
 
     task_lists = g_slist_append (task_lists, taskList);
 
+    taskList->screen = wp_applet_get_default_screen (windowPickerApplet);
     taskList->windowPickerApplet = windowPickerApplet;
 
     g_signal_connect_object (windowPickerApplet, "placement-changed",
diff --git a/gnome-applets/window-picker/task-list.h b/gnome-applets/window-picker/task-list.h
index 1fe63a2f3..6b462538e 100644
--- a/gnome-applets/window-picker/task-list.h
+++ b/gnome-applets/window-picker/task-list.h
@@ -20,7 +20,7 @@
 #ifndef _TASK_LIST_H_
 #define _TASK_LIST_H_
 
-#include "wp-applet.h"
+#include "wp-applet-private.h"
 
 #include <glib-object.h>
 #include <gtk/gtk.h>
diff --git a/gnome-applets/window-picker/wp-applet-private.h b/gnome-applets/window-picker/wp-applet-private.h
new file mode 100644
index 000000000..c268fc425
--- /dev/null
+++ b/gnome-applets/window-picker/wp-applet-private.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 Sebastian Geiger
+ * Copyright (C) 2015 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *     Alberts Muktupāvels <alberts muktupavels gmail com>
+ *     Sebastian Geiger <sbastig gmx net>
+ */
+
+#ifndef WP_APPLET_PRIVATE_H
+#define WP_APPLET_PRIVATE_H
+
+#include <libwnck/libwnck.h>
+#include "wp-applet.h"
+
+G_BEGIN_DECLS
+
+WnckScreen *wp_applet_get_default_screen  (WpApplet *self);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-applets/window-picker/wp-applet.c b/gnome-applets/window-picker/wp-applet.c
index d282851d1..f22f107bc 100644
--- a/gnome-applets/window-picker/wp-applet.c
+++ b/gnome-applets/window-picker/wp-applet.c
@@ -22,7 +22,7 @@
  */
 
 #include "config.h"
-#include "wp-applet.h"
+#include "wp-applet-private.h"
 
 #include <gdk/gdk.h>
 #include <glib.h>
@@ -42,6 +42,8 @@ struct _WpApplet
 {
   GpApplet     parent;
 
+  WnckHandle  *handle;
+
   GSettings   *settings;
 
   GtkWidget   *preferences_dialog;
@@ -169,6 +171,8 @@ wp_applet_contructed (GObject *object)
   applet = WP_APPLET (object);
   gp_applet = GP_APPLET (object);
 
+  applet->handle = wnck_handle_new (WNCK_CLIENT_TYPE_PAGER);
+
   wp_applet_setup_list (applet);
   wp_applet_setup_title (applet);
 
@@ -202,6 +206,7 @@ wp_applet_dispose (GObject *object)
 
   g_clear_object (&applet->settings);
   g_clear_pointer (&applet->preferences_dialog, gtk_widget_destroy);
+  g_clear_object (&applet->handle);
 
   G_OBJECT_CLASS (wp_applet_parent_class)->dispose (object);
 }
@@ -336,6 +341,12 @@ wp_applet_init (WpApplet *applet)
   gtk_container_add (GTK_CONTAINER (applet), applet->container);
 }
 
+WnckScreen *
+wp_applet_get_default_screen (WpApplet *self)
+{
+  return wnck_handle_get_default_screen (self->handle);
+}
+
 GtkWidget *
 wp_applet_get_tasks (WpApplet *applet)
 {
diff --git a/gnome-applets/window-picker/wp-task-title.c b/gnome-applets/window-picker/wp-task-title.c
index 68ee986b5..246a23838 100644
--- a/gnome-applets/window-picker/wp-task-title.c
+++ b/gnome-applets/window-picker/wp-task-title.c
@@ -115,7 +115,7 @@ button_clicked_cb (GtkButton *button,
       WnckScreen *screen;
       WnckWindow *active_window;
 
-      screen = wnck_screen_get_default ();
+      screen = wp_applet_get_default_screen (title->applet);
       active_window = wnck_screen_get_active_window (screen);
 
       if (WNCK_IS_WINDOW (active_window) == FALSE)
@@ -147,13 +147,13 @@ button_clicked_cb (GtkButton *button,
 }
 
 static gboolean
-is_desktop_visible (void)
+is_desktop_visible (WpTaskTitle *title)
 {
   WnckScreen *screen;
   GList *windows;
   GList *w;
 
-  screen = wnck_screen_get_default ();
+  screen = wp_applet_get_default_screen (title->applet);
   windows = wnck_screen_get_windows (screen);
 
   for (w = windows; w; w = w->next)
@@ -237,7 +237,7 @@ update_title_visibility (WpTaskTitle *title)
       if (title->show_home_title == FALSE)
         return;
 
-      if (is_desktop_visible () == FALSE)
+      if (is_desktop_visible (title) == FALSE)
         return;
 
       if (title->session_proxy == NULL)
@@ -425,14 +425,12 @@ static void
 wp_task_title_dispose (GObject *object)
 {
   WpTaskTitle *title;
-  WnckScreen *screen;
 
   title = WP_TASK_TITLE (object);
-  screen = wnck_screen_get_default ();
 
   g_clear_object (&title->session_proxy);
 
-  g_signal_handlers_disconnect_by_func (screen, active_window_changed_cb, title);
+  G_OBJECT_CLASS (wp_task_title_parent_class)->dispose (object);
 }
 
 static void
@@ -568,7 +566,7 @@ wp_task_title_setup_wnck (WpTaskTitle *title)
 {
   WnckScreen *screen;
 
-  screen = wnck_screen_get_default ();
+  screen = wp_applet_get_default_screen (title->applet);
 
   g_signal_connect_object (screen, "active-window-changed",
                            G_CALLBACK (active_window_changed_cb), title,
@@ -580,10 +578,6 @@ wp_task_title_setup_wnck (WpTaskTitle *title)
 static void
 wp_task_title_init (WpTaskTitle *title)
 {
-  wp_task_title_setup_label (title);
-  wp_task_title_setup_button (title);
-  wp_task_title_setup_wnck (title);
-
   g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL,
                             "org.gnome.SessionManager",
                             "/org/gnome/SessionManager",
@@ -603,5 +597,9 @@ wp_task_title_new (gint      spacing,
 
   title->applet = applet;
 
+  wp_task_title_setup_label (title);
+  wp_task_title_setup_button (title);
+  wp_task_title_setup_wnck (title);
+
   return GTK_WIDGET (title);
 }
diff --git a/gnome-applets/window-picker/wp-task-title.h b/gnome-applets/window-picker/wp-task-title.h
index d97b54145..80de80e4c 100644
--- a/gnome-applets/window-picker/wp-task-title.h
+++ b/gnome-applets/window-picker/wp-task-title.h
@@ -25,7 +25,7 @@
 
 #include <gtk/gtk.h>
 
-#include "wp-applet.h"
+#include "wp-applet-private.h"
 
 G_BEGIN_DECLS
 


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