From 01fb4342ea56d467ad46a68a411ffb07b4d5d326 Mon Sep 17 00:00:00 2001 From: William Wold Date: Thu, 20 Jun 2019 18:18:30 +0000 Subject: Add Wayland backend --- mate-panel/Makefile.am | 4 ++++ mate-panel/main.c | 10 ++++++++ mate-panel/panel-toplevel.c | 20 ++++++++++++++++ mate-panel/wayland-backend.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ mate-panel/wayland-backend.h | 18 ++++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 mate-panel/wayland-backend.c create mode 100644 mate-panel/wayland-backend.h (limited to 'mate-panel') diff --git a/mate-panel/Makefile.am b/mate-panel/Makefile.am index e4bc90ac..4255db34 100644 --- a/mate-panel/Makefile.am +++ b/mate-panel/Makefile.am @@ -61,6 +61,8 @@ panel_sources = \ panel-reset.c if ENABLE_WAYLAND +panel_sources += \ + wayland-backend.c endif if ENABLE_X11 @@ -120,6 +122,8 @@ panel_headers = \ panel-schemas.h if ENABLE_WAYLAND +panel_headers += \ + wayland-backend.h endif if ENABLE_X11 diff --git a/mate-panel/main.c b/mate-panel/main.c index 82d475c1..db1fafb4 100644 --- a/mate-panel/main.c +++ b/mate-panel/main.c @@ -37,6 +37,10 @@ #include "xstuff.h" #endif +#ifdef HAVE_WAYLAND +#include "wayland-backend.h" +#endif + /* globals */ GSList *panels = NULL; GSList *panel_list = NULL; @@ -181,6 +185,12 @@ main (int argc, char **argv) gboolean found_backend = FALSE; +#ifdef HAVE_WAYLAND + if (GDK_IS_WAYLAND_DISPLAY (display)) { + found_backend = TRUE; + } +#endif + #ifdef HAVE_X11 if (GDK_IS_X11_DISPLAY (display)) { xstuff_init (); diff --git a/mate-panel/panel-toplevel.c b/mate-panel/panel-toplevel.c index 8a7b6c7b..223d72b0 100644 --- a/mate-panel/panel-toplevel.c +++ b/mate-panel/panel-toplevel.c @@ -57,6 +57,9 @@ #include "panel-xutils.h" #include "panel-struts.h" #endif +#ifdef HAVE_WAYLAND +#include "wayland-backend.h" +#endif #define DEFAULT_SIZE 48 #define DEFAULT_AUTO_HIDE_SIZE 1 @@ -1557,6 +1560,11 @@ static gboolean panel_toplevel_update_struts(PanelToplevel* toplevel, gboolean e } #endif // HAVE_X11 +#ifdef HAVE_WAYLAND + if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (toplevel)))) { + wayland_panel_toplevel_update_placement (toplevel); + } +#endif // HAVE_WAYLAND return geometry_changed; } @@ -4815,6 +4823,12 @@ panel_toplevel_init (PanelToplevel *toplevel) toplevel); update_style_classes (toplevel); + +#ifdef HAVE_WAYLAND + if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) { + wayland_panel_toplevel_init (toplevel); + } +#endif // HAVE_WAYLAND } PanelWidget * @@ -5059,6 +5073,12 @@ panel_toplevel_set_orientation (PanelToplevel *toplevel, g_object_notify (G_OBJECT (toplevel), "orientation"); g_object_thaw_notify (G_OBJECT (toplevel)); + +#ifdef HAVE_WAYLAND + if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (toplevel)))) { + wayland_panel_toplevel_update_placement (toplevel); + } +#endif // HAVE_WAYLAND } PanelOrientation diff --git a/mate-panel/wayland-backend.c b/mate-panel/wayland-backend.c new file mode 100644 index 00000000..0d797f33 --- /dev/null +++ b/mate-panel/wayland-backend.c @@ -0,0 +1,57 @@ +#include + +#include + +#include "wayland-backend.h" + +void +wayland_panel_toplevel_init (PanelToplevel* toplevel) +{ + GtkWindow* window; + + window = GTK_WINDOW (toplevel); + gtk_layer_init_for_window (window); + gtk_layer_set_layer (window, GTK_LAYER_SHELL_LAYER_TOP); + gtk_layer_set_namespace (window, "panel"); + gtk_layer_auto_exclusive_zone_enable (window); + wayland_panel_toplevel_update_placement (toplevel); +} + +void +wayland_panel_toplevel_update_placement (PanelToplevel* toplevel) +{ + GtkWindow* window; + gboolean expand; + PanelOrientation orientation; + gboolean anchor[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]; + + window = GTK_WINDOW (toplevel); + expand = panel_toplevel_get_expand (toplevel); + orientation = panel_toplevel_get_orientation (toplevel); + for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) + anchor[i] = expand; + + switch (orientation) { + case PANEL_ORIENTATION_LEFT: + anchor[GTK_LAYER_SHELL_EDGE_LEFT] = TRUE; + anchor[GTK_LAYER_SHELL_EDGE_RIGHT] = FALSE; + break; + case PANEL_ORIENTATION_RIGHT: + anchor[GTK_LAYER_SHELL_EDGE_RIGHT] = TRUE; + anchor[GTK_LAYER_SHELL_EDGE_LEFT] = FALSE; + break; + case PANEL_ORIENTATION_TOP: + anchor[GTK_LAYER_SHELL_EDGE_TOP] = TRUE; + anchor[GTK_LAYER_SHELL_EDGE_BOTTOM] = FALSE; + break; + case PANEL_ORIENTATION_BOTTOM: + anchor[GTK_LAYER_SHELL_EDGE_BOTTOM] = TRUE; + anchor[GTK_LAYER_SHELL_EDGE_TOP] = FALSE; + break; + default: + g_warning ("Invalid panel orientation %d", orientation); + } + + for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) + gtk_layer_set_anchor (window, i, anchor[i]); +} diff --git a/mate-panel/wayland-backend.h b/mate-panel/wayland-backend.h new file mode 100644 index 00000000..ae6a837f --- /dev/null +++ b/mate-panel/wayland-backend.h @@ -0,0 +1,18 @@ +#ifndef __WAYLAND_BACKEND_H__ +#define __WAYLAND_BACKEND_H__ + +#include + +#ifndef HAVE_WAYLAND +#error file should only be included when HAVE_WAYLAND is enabled +#endif + +#include +#include + +#include "panel-toplevel.h" + +void wayland_panel_toplevel_init (PanelToplevel* toplevel); +void wayland_panel_toplevel_update_placement (PanelToplevel* toplevel); + +#endif /* __WAYLAND_BACKEND_H__ */ -- cgit v1.2.1