summaryrefslogtreecommitdiff
path: root/applets/wncklet/window-list.c
diff options
context:
space:
mode:
authorWilliam Wold <[email protected]>2020-09-30 13:01:32 -0700
committerraveit65 <[email protected]>2020-10-21 20:35:15 +0200
commiteda5735ce6b52e8cf738077027581bfe2257c3cb (patch)
tree98f8c47aadb650ca2cf74421356753ebf1917445 /applets/wncklet/window-list.c
parentbd27321bd83f25ce504267e2098b1bed9e55bf16 (diff)
downloadmate-panel-eda5735ce6b52e8cf738077027581bfe2257c3cb.tar.bz2
mate-panel-eda5735ce6b52e8cf738077027581bfe2257c3cb.tar.xz
Wncklet applets: don't crash on Wayland
Diffstat (limited to 'applets/wncklet/window-list.c')
-rw-r--r--applets/wncklet/window-list.c151
1 files changed, 121 insertions, 30 deletions
diff --git a/applets/wncklet/window-list.c b/applets/wncklet/window-list.c
index bd4a9603..54105f60 100644
--- a/applets/wncklet/window-list.c
+++ b/applets/wncklet/window-list.c
@@ -8,9 +8,7 @@
*
*/
-#ifdef HAVE_CONFIG_H
- #include <config.h>
-#endif
+#include <config.h>
#include <string.h>
@@ -19,12 +17,17 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
#include <gio/gio.h>
-#ifdef HAVE_WINDOW_PREVIEWS
+
+#ifdef HAVE_X11
#include <gdk/gdkx.h>
-#endif
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+#endif // HAVE_X11
+
+#ifdef HAVE_WAYLAND
+#include <gdk/gdkwayland.h>
+#endif // HAVE_WAYLAND
#define MATE_DESKTOP_USE_UNSTABLE_API
#include <libmate-desktop/mate-desktop-utils.h>
@@ -34,9 +37,16 @@
#define WINDOW_LIST_ICON "mate-panel-window-list"
#define WINDOW_LIST_SCHEMA "org.mate.panel.applet.window-list"
+
#ifdef HAVE_WINDOW_PREVIEWS
#define WINDOW_LIST_PREVIEW_SCHEMA "org.mate.panel.applet.window-list-previews"
-#endif
+#endif // HAVE_WINDOW_PREVIEWS
+
+typedef enum {
+ TASKLIST_NEVER_GROUP,
+ TASKLIST_AUTO_GROUP,
+ TASKLIST_ALWAYS_GROUP
+} TasklistGroupingType;
typedef struct {
GtkWidget* applet;
@@ -48,7 +58,8 @@ typedef struct {
gint thumbnail_size;
#endif
gboolean include_all_workspaces;
- WnckTasklistGroupingType grouping;
+
+ TasklistGroupingType grouping;
gboolean move_unminimized_windows;
GtkOrientation orientation;
@@ -98,9 +109,65 @@ static void tasklist_update(TasklistData* tasklist)
gtk_widget_set_size_request(GTK_WIDGET(tasklist->tasklist), tasklist->size, -1);
}
- wnck_tasklist_set_grouping(WNCK_TASKLIST(tasklist->tasklist), tasklist->grouping);
- wnck_tasklist_set_include_all_workspaces(WNCK_TASKLIST(tasklist->tasklist), tasklist->include_all_workspaces);
- wnck_tasklist_set_switch_workspace_on_unminimize(WNCK_TASKLIST(tasklist->tasklist), tasklist->move_unminimized_windows);
+#ifdef HAVE_X11
+ if (WNCK_IS_TASKLIST(tasklist->tasklist))
+ {
+ WnckTasklistGroupingType grouping;
+ switch (tasklist->grouping)
+ {
+ case TASKLIST_NEVER_GROUP: grouping = WNCK_TASKLIST_NEVER_GROUP;
+ case TASKLIST_AUTO_GROUP: grouping = WNCK_TASKLIST_AUTO_GROUP;
+ case TASKLIST_ALWAYS_GROUP: grouping = WNCK_TASKLIST_ALWAYS_GROUP;
+ default: grouping = WNCK_TASKLIST_NEVER_GROUP;
+ }
+ wnck_tasklist_set_grouping(WNCK_TASKLIST(tasklist->tasklist), grouping);
+ wnck_tasklist_set_include_all_workspaces(WNCK_TASKLIST(tasklist->tasklist), tasklist->include_all_workspaces);
+ wnck_tasklist_set_switch_workspace_on_unminimize(WNCK_TASKLIST(tasklist->tasklist), tasklist->move_unminimized_windows);
+ }
+#endif // HAVE_X11
+
+ // Not implemented for Wayland
+}
+
+static void tasklist_apply_orientation(TasklistData* tasklist)
+{
+#ifdef HAVE_X11
+ if (WNCK_IS_TASKLIST(tasklist->tasklist))
+ {
+ wnck_tasklist_set_orientation(WNCK_TASKLIST(tasklist->tasklist), tasklist->orientation);
+ }
+#endif // HAVE_X11
+
+ // Not yet implemented for Wayland
+}
+
+static void tasklist_set_button_relief(TasklistData* tasklist, GtkReliefStyle relief)
+{
+#ifdef HAVE_X11
+ if (WNCK_IS_TASKLIST(tasklist->tasklist))
+ {
+ wnck_tasklist_set_button_relief(WNCK_TASKLIST(tasklist->tasklist), relief);
+ }
+#endif // HAVE_X11
+
+ // Not implemented for Wayland
+}
+
+static const int* tasklist_get_size_hint_list(TasklistData* tasklist, int* n_elements)
+{
+#ifdef HAVE_X11
+ if (WNCK_IS_TASKLIST(tasklist->tasklist))
+ {
+ return wnck_tasklist_get_size_hint_list(WNCK_TASKLIST(tasklist->tasklist), n_elements);
+ }
+ else
+#endif // HAVE_X11
+
+ {
+ // Not implemented for Wayland
+ *n_elements = 0;
+ return NULL;
+ }
}
static void response_cb(GtkWidget* widget, int id, TasklistData* tasklist)
@@ -141,7 +208,7 @@ static void applet_change_orient(MatePanelApplet* applet, MatePanelAppletOrient
return;
tasklist->orientation = new_orient;
- wnck_tasklist_set_orientation (WNCK_TASKLIST (tasklist->tasklist), new_orient);
+ tasklist_apply_orientation (tasklist);
tasklist_update(tasklist);
}
@@ -153,11 +220,12 @@ static void applet_change_background(MatePanelApplet* applet, MatePanelAppletBac
case PANEL_NO_BACKGROUND:
case PANEL_COLOR_BACKGROUND:
case PANEL_PIXMAP_BACKGROUND:
- wnck_tasklist_set_button_relief(WNCK_TASKLIST(tasklist->tasklist), GTK_RELIEF_NONE);
+ tasklist_set_button_relief(tasklist, GTK_RELIEF_NONE);
break;
}
}
+#ifdef HAVE_X11
#ifdef HAVE_WINDOW_PREVIEWS
static GdkPixbuf *preview_window_thumbnail (WnckWindow *wnck_window, TasklistData *tasklist)
{
@@ -326,7 +394,8 @@ static gboolean applet_leave_notify_event (WnckTasklist *tl, GList *wnck_windows
return FALSE;
}
-#endif
+#endif // HAVE_WINDOW_PREVIEWS
+#endif // HAVE_X11
static void applet_change_pixel_size(MatePanelApplet* applet, gint size, TasklistData* tasklist)
{
@@ -436,18 +505,18 @@ static void thumbnail_size_changed(GSettings *settings, gchar* key, TasklistData
}
#endif
-static GtkWidget* get_grouping_button(TasklistData* tasklist, WnckTasklistGroupingType type)
+static GtkWidget* get_grouping_button(TasklistData* tasklist, TasklistGroupingType type)
{
switch (type)
{
default:
- case WNCK_TASKLIST_NEVER_GROUP:
+ case TASKLIST_NEVER_GROUP:
return tasklist->never_group_radio;
break;
- case WNCK_TASKLIST_AUTO_GROUP:
+ case TASKLIST_AUTO_GROUP:
return tasklist->auto_group_radio;
break;
- case WNCK_TASKLIST_ALWAYS_GROUP:
+ case TASKLIST_ALWAYS_GROUP:
return tasklist->always_group_radio;
break;
}
@@ -455,7 +524,7 @@ static GtkWidget* get_grouping_button(TasklistData* tasklist, WnckTasklistGroupi
static void group_windows_changed(GSettings* settings, gchar* key, TasklistData* tasklist)
{
- WnckTasklistGroupingType type;
+ TasklistGroupingType type;
GtkWidget* button;
type = g_settings_get_enum (settings, key);
@@ -536,7 +605,7 @@ static void applet_size_allocate(GtkWidget *widget, GtkAllocation *allocation, T
int len;
const int* size_hints;
- size_hints = wnck_tasklist_get_size_hint_list (WNCK_TASKLIST (tasklist->tasklist), &len);
+ size_hints = tasklist_get_size_hint_list (tasklist, &len);
g_assert(len % 2 == 0);
@@ -563,6 +632,8 @@ static void applet_size_allocate(GtkWidget *widget, GtkAllocation *allocation, T
mate_panel_applet_set_size_hints(MATE_PANEL_APPLET(tasklist->applet), size_hints, len, 0);
}
+#ifdef HAVE_X11
+// Currently only used on X11, but should work on Wayland as well when needed
static GdkPixbuf* icon_loader_func(const char* icon, int size, unsigned int flags, void* data)
{
TasklistData* tasklist;
@@ -608,6 +679,7 @@ static GdkPixbuf* icon_loader_func(const char* icon, int size, unsigned int flag
return retval;
}
+#endif // HAVE_X11
gboolean window_list_applet_fill(MatePanelApplet* applet)
{
@@ -668,18 +740,37 @@ gboolean window_list_applet_fill(MatePanelApplet* applet)
break;
}
- tasklist->tasklist = wnck_tasklist_new();
+#ifdef HAVE_X11
+ if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
+ {
+ tasklist->tasklist = wnck_tasklist_new();
- wnck_tasklist_set_orientation (WNCK_TASKLIST (tasklist->tasklist), tasklist->orientation);
- wnck_tasklist_set_middle_click_close (WNCK_TASKLIST (tasklist->tasklist), TRUE);
- wnck_tasklist_set_icon_loader(WNCK_TASKLIST(tasklist->tasklist), icon_loader_func, tasklist, NULL);
+ wnck_tasklist_set_middle_click_close (WNCK_TASKLIST (tasklist->tasklist), TRUE);
+ wnck_tasklist_set_icon_loader(WNCK_TASKLIST(tasklist->tasklist), icon_loader_func, tasklist, NULL);
- g_signal_connect(G_OBJECT(tasklist->tasklist), "destroy", G_CALLBACK(destroy_tasklist), tasklist);
#ifdef HAVE_WINDOW_PREVIEWS
- g_signal_connect(G_OBJECT(tasklist->tasklist), "task_enter_notify", G_CALLBACK(applet_enter_notify_event), tasklist);
- g_signal_connect(G_OBJECT(tasklist->tasklist), "task_leave_notify", G_CALLBACK(applet_leave_notify_event), tasklist);
-#endif
+ g_signal_connect(G_OBJECT(tasklist->tasklist), "task_enter_notify", G_CALLBACK(applet_enter_notify_event), tasklist);
+ g_signal_connect(G_OBJECT(tasklist->tasklist), "task_leave_notify", G_CALLBACK(applet_leave_notify_event), tasklist);
+#endif // HAVE_WINDOW_PREVIEWS
+ }
+ else
+#endif // HAVE_X11
+
+#ifdef HAVE_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
+ {
+ tasklist->tasklist = gtk_label_new ("[Tasklist not supported on Wayland]");
+ }
+ else
+#endif // HAVE_WAYLAND
+
+ {
+ tasklist->tasklist = gtk_label_new ("[Tasklist not supported on this platform]");
+ }
+ tasklist_apply_orientation(tasklist);
+
+ g_signal_connect(G_OBJECT(tasklist->tasklist), "destroy", G_CALLBACK(destroy_tasklist), tasklist);
g_signal_connect(G_OBJECT(tasklist->applet), "size_allocate", G_CALLBACK(applet_size_allocate), tasklist);
gtk_container_add(GTK_CONTAINER(tasklist->applet), tasklist->tasklist);
@@ -863,7 +954,7 @@ static void setup_dialog(GtkBuilder* builder, TasklistData* tasklist)
GtkWidget* button;
#ifdef HAVE_WINDOW_PREVIEWS
GtkAdjustment *adjustment;
-#endif
+#endif // HAVE_WINDOW_PREVIEWS
tasklist->show_current_radio = WID("show_current_radio");
tasklist->show_all_radio = WID("show_all_radio");