diff options
author | Luke from DC <[email protected]> | 2023-07-05 20:03:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2023-07-05 20:03:48 +0000 |
commit | 053c2360959db9978f7d8989c467ccf6b7780142 (patch) | |
tree | 5aeadd9cf1f5428d5bd9ab3619cf0f6b712284f1 /mate-volume-control | |
parent | 4e1ddb28915a5789ae31e8912ad995fb4a0af293 (diff) | |
download | mate-media-053c2360959db9978f7d8989c467ccf6b7780142.tar.bz2 mate-media-053c2360959db9978f7d8989c467ccf6b7780142.tar.xz |
position popup slider properly in wayland and make wayland optional (#196)
* Wayland: fix position of volume slider using GtkLayerShell edge and margin settings
*Unused edge anchors and margins set to zero to avoid glitches when orientation changes
* Build options:
*(default) out of process, no wayland support as wayland support is experimental
*in-process, no wayland support (--enable-in-process --disable-wayland)
* wayland dependencies not checked for or used
*in-process with wayland support (--enable-wayland also calls --in-process)
* wayland dependencies checked for and required
Diffstat (limited to 'mate-volume-control')
-rw-r--r-- | mate-volume-control/Makefile.am | 75 | ||||
-rw-r--r-- | mate-volume-control/applet-main.c | 8 | ||||
-rw-r--r-- | mate-volume-control/gvc-applet.c | 18 | ||||
-rw-r--r-- | mate-volume-control/gvc-stream-applet-icon.c | 79 | ||||
-rw-r--r-- | mate-volume-control/org.mate.applets.GvcApplet.mate-panel-applet.desktop.in.in | 2 | ||||
-rw-r--r-- | mate-volume-control/org.mate.panel.applet.GvcAppletFactory.service.in | 3 |
6 files changed, 169 insertions, 16 deletions
diff --git a/mate-volume-control/Makefile.am b/mate-volume-control/Makefile.am index b3a5994..881b78d 100644 --- a/mate-volume-control/Makefile.am +++ b/mate-volume-control/Makefile.am @@ -3,11 +3,11 @@ bin_PROGRAMS = \ mate-volume-control-status-icon \ mate-volume-control \ $(NULL) -else +else !ENABLE_STATUSICON bin_PROGRAMS = \ mate-volume-control \ $(NULL) -endif +endif !ENABLE_STATUSICON AM_CPPFLAGS = \ $(WARN_CFLAGS) \ @@ -20,27 +20,40 @@ AM_CPPFLAGS = \ -I$(srcdir) \ $(NULL) +applets_in_files = org.mate.applets.GvcApplet.mate-panel-applet.desktop.in +service_in_files = org.mate.panel.applet.GvcAppletFactory.service.in + if ENABLE_PANELAPPLET -APPLET_LOCATION = $(libdir)/libmate-volume-control-applet.so appletsdir = $(datadir)/mate-panel/applets -applets_in_files = org.mate.applets.GvcApplet.mate-panel-applet.desktop.in applets_DATA = $(applets_in_files:.mate-panel-applet.desktop.in=.mate-panel-applet) + +if IN_PROCESS +APPLET_LOCATION = $(libdir)/libmate-volume-control-applet.so mate_volume_control_applet_libdir= $(libdir) mate_volume_control_applet_lib_LTLIBRARIES=libmate-volume-control-applet.la +IN_PROCESS = true +else !IN_PROCESS +APPLET_LOCATION = $(libexecdir)/mate-volume-control-applet +servicedir = $(datadir)/dbus-1/services +service_DATA = $(service_in_files:.service.in=.service) +IN_PROCESS = false + +$(service_in_files:.service.in=.service): $(service_in_files) + $(AM_V_GEN)sed \ + -e "s|\@LOCATION\@|$(APPLET_LOCATION)|" \ + $< > $@ +endif !IN_PROCESS $(applets_in_files): $(applets_in_files).in Makefile $(AM_V_GEN)sed \ -e "s|\@APPLET_LOCATION\@|$(APPLET_LOCATION)|" \ + -e "s|\@IN_PROCESS\@|$(IN_PROCESS)|" \ $< > $@ $(applets_DATA): $(applets_in_files) Makefile $(AM_V_GEN) $(MSGFMT) --desktop --keyword=Name --keyword=Description --template $< -d $(top_srcdir)/po -o $@ -EXTRA_DIST = \ - $(applets_in_files).in \ - $(service_in_files) - -endif +endif ENABLE_PANELAPPLET noinst_LTLIBRARIES = libmatevolumecontrol.la libmatevolumecontrol_la_SOURCES = \ @@ -64,10 +77,10 @@ mate_volume_control_status_icon_SOURCES = \ $(NULL) mate_volume_control_status_icon_CFLAGS = $(WARN_CFLAGS) -endif +endif ENABLE_STATUSICON if ENABLE_PANELAPPLET - +if IN_PROCESS libmate_volume_control_applet_la_LDFLAGS = \ -module -avoid-version \ $(WARN_LDFLAGS) \ @@ -91,7 +104,40 @@ libmate_volume_control_applet_la_LIBADD = \ $(VOLUME_CONTROL_LIBS) \ $(NULL) -endif +if ENABLE_WAYLAND +libmate_volume_control_applet_la_LIBADD += \ + $(WAYLAND_LIBS) + +AM_CPPFLAGS += \ + $(WAYLAND_CFLAGS) +endif ENABLE_WAYLAND + +else !IN_PROCESS +libexec_PROGRAMS = mate-volume-control-applet +mate_volume_control_applet_LDADD = \ + -lm \ + libmatevolumecontrol.la \ + $(VOLUME_CONTROL_LIBS) \ + $(MATEDESKTOP_LIBS) \ + $(NULL) + +mate_volume_control_applet_SOURCES = \ + gvc-stream-applet-icon.h \ + gvc-stream-applet-icon.c \ + gvc-applet.h \ + gvc-applet.c \ + applet-main.c \ + $(NULL) +mate_volume_control_applet_CFLAGS = $(WARN_CFLAGS) + +mate_volume_control_applet_LDFLAGS = \ + -module -avoid-version \ + $(WARN_LDFLAGS) \ + $(AM_LDFLAGS) \ + $(NULL) + +endif !IN_PROCESS +endif ENABLE_PANELAPPLET mate_volume_control_LDADD = \ -lm \ @@ -124,11 +170,14 @@ BUILT_SOURCES = \ CLEANFILES = \ $(applets_in_files) \ - $(BUILT_SOURCES) \ $(NULL) MAINTAINERCLEANFILES = \ *~ \ Makefile.in +EXTRA_DIST = \ + $(applets_in_files).in \ + $(service_in_files) + -include $(top_srcdir)/git.mk diff --git a/mate-volume-control/applet-main.c b/mate-volume-control/applet-main.c index 961275f..fe447b4 100644 --- a/mate-volume-control/applet-main.c +++ b/mate-volume-control/applet-main.c @@ -87,9 +87,17 @@ applet_factory (MatePanelApplet* applet, const char* iid, gpointer data) return retval; } +#ifdef IN_PROCESS /* needed by mate-panel applet library */ MATE_PANEL_APPLET_IN_PROCESS_FACTORY("GvcAppletFactory", PANEL_TYPE_APPLET, "Volume Control applet", applet_factory, NULL) +#else +MATE_PANEL_APPLET_OUT_PROCESS_FACTORY("GvcAppletFactory", + PANEL_TYPE_APPLET, + "Volume Control applet", + applet_factory, + NULL) +#endif diff --git a/mate-volume-control/gvc-applet.c b/mate-volume-control/gvc-applet.c index 35d7e6e..3b05afe 100644 --- a/mate-volume-control/gvc-applet.c +++ b/mate-volume-control/gvc-applet.c @@ -508,8 +508,14 @@ menu_activate_open_volume_control (GtkAction *action, GvcApplet *applet) gboolean gvc_applet_fill (GvcApplet *applet, MatePanelApplet* applet_widget) { - mate_panel_applet_set_flags (applet_widget, MATE_PANEL_APPLET_EXPAND_MINOR); +#ifndef IN_PROCESS + GdkEventMask event_mask; + GdkWindow *window; + g_set_application_name (_("Volume Control Applet")); + gtk_window_set_default_icon_name (APPLET_ICON); + mate_panel_applet_set_flags (applet_widget, MATE_PANEL_APPLET_EXPAND_MINOR); +#endif applet->priv->applet = applet_widget; /*FIXME: We haved to set this up BEFORE packing in icons. find a way to update this when the applet is moved that works*/ switch (mate_panel_applet_get_orient (applet->priv->applet)) { @@ -539,6 +545,16 @@ gvc_applet_fill (GvcApplet *applet, MatePanelApplet* applet_widget) gtk_container_add (GTK_CONTAINER (applet->priv->applet), GTK_WIDGET (applet->priv->box)); gtk_widget_show_all (GTK_WIDGET (applet->priv->applet)); +#ifndef IN_PROCESS + /* Enable 'scroll-event' signal to get through */ + window = gtk_widget_get_window (GTK_WIDGET (applet->priv->icon_input)); + event_mask = gdk_window_get_events (window); + gdk_window_set_events (window, event_mask | GDK_SCROLL_MASK); + + window = gtk_widget_get_window (GTK_WIDGET (applet->priv->icon_output)); + event_mask = gdk_window_get_events (window); + gdk_window_set_events (window, event_mask | GDK_SCROLL_MASK); +#endif /* Update icons on size/orientation changes*/ g_object_connect (applet->priv->applet, "signal::change_size", gvc_applet_set_size, applet, diff --git a/mate-volume-control/gvc-stream-applet-icon.c b/mate-volume-control/gvc-stream-applet-icon.c index c910150..dc79b86 100644 --- a/mate-volume-control/gvc-stream-applet-icon.c +++ b/mate-volume-control/gvc-stream-applet-icon.c @@ -20,12 +20,18 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * */ +#include <config.h> #include <glib.h> #include <glib/gi18n.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> +#if defined(ENABLE_WAYLAND) && defined(GDK_WINDOWING_WAYLAND) +#include <gdk/gdkwayland.h> +#include <gtk-layer-shell/gtk-layer-shell.h> +#endif + #include <libmatemixer/matemixer.h> #include <mate-panel-applet.h> @@ -92,12 +98,83 @@ popup_dock (GvcStreamAppletIcon *icon, guint time) gvc_channel_bar_set_orientation (GVC_CHANNEL_BAR (icon->priv->bar), GTK_ORIENTATION_VERTICAL); } - monitor_num = gdk_display_get_monitor_at_point (gdk_screen_get_display (screen), allocation.x, allocation.y); + display = gdk_screen_get_display (screen); + monitor_num = gdk_display_get_monitor_at_point (display, allocation.x, allocation.y); gdk_monitor_get_geometry (monitor_num, &monitor); gtk_container_foreach (GTK_CONTAINER (icon->priv->dock), (GtkCallback) gtk_widget_show_all, NULL); gtk_widget_get_preferred_size (icon->priv->dock, &dock_req, NULL); +#if defined(ENABLE_WAYLAND) && defined(GDK_WINDOWING_WAYLAND) + if (GDK_IS_WAYLAND_DISPLAY (display)) + { + gboolean top, bottom, left, right; + GtkWidget *toplevel; + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon)); + + if (!gtk_layer_is_layer_window (GTK_WINDOW (icon->priv->dock))) + { + gtk_layer_init_for_window (GTK_WINDOW (icon->priv->dock)); + gtk_layer_set_layer (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_LAYER_BOTTOM); + gtk_layer_set_keyboard_mode (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND); + } + + top = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_TOP); + bottom = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_BOTTOM); + left = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_LEFT); + right = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_RIGHT); + + /*Set anchors to the edges (will hold to panel edge) and position along the panel + *Unset margins and anchors from any other position so as to avoid rendering issues + *when orientation changes as when the panel is moved + */ + + if (top && left && right) + { + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, allocation.x); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, 0); + } + if (bottom && left && right) + { + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, allocation.x); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, 0); + } + if (left && bottom && top && !right) + { + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, allocation.y); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, 0); + } + if (right && bottom && top && !left) + { + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_TOP, allocation.y); + gtk_layer_set_margin (GTK_WINDOW (icon->priv->dock), GTK_LAYER_SHELL_EDGE_LEFT, 0); + } + gtk_widget_show_all (icon->priv->dock); + + /* Grab focus */ + gtk_grab_add (icon->priv->dock); + gtk_widget_grab_focus (icon->priv->dock); + + return TRUE; + } +#endif /* wayland support */ + if (icon->priv->orient == MATE_PANEL_APPLET_ORIENT_LEFT || icon->priv->orient == MATE_PANEL_APPLET_ORIENT_RIGHT) { if (allocation.x + allocation.width + dock_req.width <= monitor.x + monitor.width) x = allocation.x + allocation.width; diff --git a/mate-volume-control/org.mate.applets.GvcApplet.mate-panel-applet.desktop.in.in b/mate-volume-control/org.mate.applets.GvcApplet.mate-panel-applet.desktop.in.in index 3748f03..b222529 100644 --- a/mate-volume-control/org.mate.applets.GvcApplet.mate-panel-applet.desktop.in.in +++ b/mate-volume-control/org.mate.applets.GvcApplet.mate-panel-applet.desktop.in.in @@ -1,6 +1,6 @@ [Applet Factory] Id=GvcAppletFactory -InProcess=true +InProcess=@IN_PROCESS@ Location=@APPLET_LOCATION@ Name=Volume Control Factory Description=Volume Control Factory diff --git a/mate-volume-control/org.mate.panel.applet.GvcAppletFactory.service.in b/mate-volume-control/org.mate.panel.applet.GvcAppletFactory.service.in new file mode 100644 index 0000000..9e19920 --- /dev/null +++ b/mate-volume-control/org.mate.panel.applet.GvcAppletFactory.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.mate.panel.applet.GvcAppletFactory +Exec=@LOCATION@ |