Added ability to choose wether layer-shell should be used or not (#261)

This commit is contained in:
Erik Reider
2023-05-14 13:11:50 +02:00
committed by GitHub
parent 28ed6342cc
commit 81613a2554
6 changed files with 75 additions and 45 deletions

View File

@@ -3,6 +3,7 @@
"positionX": "right",
"positionY": "top",
"layer": "top",
"layer-shell": true,
"cssPriority": "application",
"control-center-margin-top": 0,
"control-center-margin-bottom": 0,

View File

@@ -351,6 +351,11 @@ namespace SwayNotificationCenter {
get; set; default = Layer.TOP;
}
/**
* Wether or not the windows should be opened as layer-shell surfaces
*/
public bool layer_shell { get; set; default = true; }
/** The CSS loading priority */
public CssPriority cssPriority { // vala-lint=naming-convention
get; set; default = CssPriority.APPLICATION;

View File

@@ -20,6 +20,11 @@
"default": "top",
"enum": ["background", "bottom", "top", "overlay"]
},
"layer-shell": {
"type": "boolean",
"description": "Wether or not the windows should be opened as layer-shell surfaces. Note: Requires swaync restart to apply",
"default": true
},
"cssPriority": {
"type": "string",
"description": "Which GTK priority to use when loading the default and user CSS files. Pick \"user\" to override XDG_CONFIG_HOME/gtk-3.0/gtk.css",

View File

@@ -38,19 +38,21 @@ namespace SwayNotificationCenter {
this.swaync_daemon.reloading_css.connect (reload_notifications_style);
if (!GtkLayerShell.is_supported ()) {
stderr.printf ("GTKLAYERSHELL IS NOT SUPPORTED!\n");
stderr.printf ("Swaync only works on Wayland!\n");
stderr.printf ("If running waylans session, try running:\n");
stderr.printf ("\tGDK_BACKEND=wayland swaync\n");
Process.exit (1);
if (swaync_daemon.use_layer_shell) {
if (!GtkLayerShell.is_supported ()) {
stderr.printf ("GTKLAYERSHELL IS NOT SUPPORTED!\n");
stderr.printf ("Swaync only works on Wayland!\n");
stderr.printf ("If running waylans session, try running:\n");
stderr.printf ("\tGDK_BACKEND=wayland swaync\n");
Process.exit (1);
}
GtkLayerShell.init_for_window (this);
GtkLayerShell.set_namespace (this, "swaync-control-center");
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, true);
}
GtkLayerShell.init_for_window (this);
GtkLayerShell.set_namespace (this, "swaync-control-center");
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, true);
viewport.size_allocate.connect (size_alloc);
@@ -255,34 +257,36 @@ namespace SwayNotificationCenter {
/** Resets the UI positions */
private void set_anchor () {
// Grabs the keyboard input until closed
bool keyboard_shortcuts = ConfigModel.instance.keyboard_shortcuts;
if (swaync_daemon.use_layer_shell) {
// Grabs the keyboard input until closed
bool keyboard_shortcuts = ConfigModel.instance.keyboard_shortcuts;
#if HAVE_LATEST_GTK_LAYER_SHELL
var mode = keyboard_shortcuts ?
GtkLayerShell.KeyboardMode.EXCLUSIVE :
GtkLayerShell.KeyboardMode.NONE;
GtkLayerShell.set_keyboard_mode (this, mode);
var mode = keyboard_shortcuts ?
GtkLayerShell.KeyboardMode.EXCLUSIVE :
GtkLayerShell.KeyboardMode.NONE;
GtkLayerShell.set_keyboard_mode (this, mode);
#else
GtkLayerShell.set_keyboard_interactivity (this, keyboard_shortcuts);
GtkLayerShell.set_keyboard_interactivity (this, keyboard_shortcuts);
#endif
// Set layer
GtkLayerShell.Layer layer = GtkLayerShell.Layer.TOP;
switch (ConfigModel.instance.layer) {
case Layer.BACKGROUND:
layer = GtkLayerShell.Layer.BACKGROUND;
break;
case Layer.BOTTOM:
layer = GtkLayerShell.Layer.BOTTOM;
break;
case Layer.TOP:
layer = GtkLayerShell.Layer.TOP;
break;
case Layer.OVERLAY:
layer = GtkLayerShell.Layer.OVERLAY;
break;
// Set layer
GtkLayerShell.Layer layer = GtkLayerShell.Layer.TOP;
switch (ConfigModel.instance.layer) {
case Layer.BACKGROUND:
layer = GtkLayerShell.Layer.BACKGROUND;
break;
case Layer.BOTTOM:
layer = GtkLayerShell.Layer.BOTTOM;
break;
case Layer.TOP:
layer = GtkLayerShell.Layer.TOP;
break;
case Layer.OVERLAY:
layer = GtkLayerShell.Layer.OVERLAY;
break;
}
GtkLayerShell.set_layer (this, layer);
}
GtkLayerShell.set_layer (this, layer);
// Set the box margins
box.set_margin_top (ConfigModel.instance.control_center_margin_top);

View File

@@ -43,16 +43,18 @@ namespace SwayNotificationCenter {
private const int MAX_HEIGHT = 600;
private NotificationWindow () {
if (!GtkLayerShell.is_supported ()) {
stderr.printf ("GTKLAYERSHELL IS NOT SUPPORTED!\n");
stderr.printf ("Swaync only works on Wayland!\n");
stderr.printf ("If running waylans session, try running:\n");
stderr.printf ("\tGDK_BACKEND=wayland swaync\n");
Process.exit (1);
if (swaync_daemon.use_layer_shell) {
if (!GtkLayerShell.is_supported ()) {
stderr.printf ("GTKLAYERSHELL IS NOT SUPPORTED!\n");
stderr.printf ("Swaync only works on Wayland!\n");
stderr.printf ("If running waylans session, try running:\n");
stderr.printf ("\tGDK_BACKEND=wayland swaync\n");
Process.exit (1);
}
GtkLayerShell.init_for_window (this);
GtkLayerShell.set_namespace (this, "swaync-notification-window");
GtkLayerShell.set_layer (this, GtkLayerShell.Layer.OVERLAY);
}
GtkLayerShell.init_for_window (this);
GtkLayerShell.set_namespace (this, "swaync-notification-window");
GtkLayerShell.set_layer (this, GtkLayerShell.Layer.OVERLAY);
this.set_anchor ();
// -1 should set it to the content size unless it exceeds max_height
@@ -68,18 +70,21 @@ namespace SwayNotificationCenter {
private void set_anchor () {
switch (ConfigModel.instance.positionX) {
case PositionX.LEFT:
if (!swaync_daemon.use_layer_shell) break;
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.RIGHT, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.LEFT, true);
break;
case PositionX.CENTER:
if (!swaync_daemon.use_layer_shell) break;
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.RIGHT, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.LEFT, false);
break;
default:
if (!swaync_daemon.use_layer_shell) break;
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.LEFT, false);
GtkLayerShell.set_anchor (
@@ -90,6 +95,7 @@ namespace SwayNotificationCenter {
default:
case PositionY.TOP:
list_reverse = false;
if (!swaync_daemon.use_layer_shell) break;
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.BOTTOM, false);
GtkLayerShell.set_anchor (
@@ -97,17 +103,19 @@ namespace SwayNotificationCenter {
break;
case PositionY.CENTER:
list_reverse = false;
if (!swaync_daemon.use_layer_shell) break;
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.BOTTOM, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.TOP, false);
break;
case PositionY.BOTTOM:
list_reverse = true;
if (!swaync_daemon.use_layer_shell) break;
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.TOP, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.BOTTOM, true);
list_reverse = true;
break;
}
}

View File

@@ -21,9 +21,14 @@ namespace SwayNotificationCenter {
[DBus (visible = false)]
public signal void reloading_css ();
// Only set on swaync start due to some limitations of GtkLayerShell
[DBus (visible = false)]
public bool use_layer_shell { get; private set; }
public SwayncDaemon () {
// Init noti_daemon
this.noti_daemon = new NotiDaemon (this);
this.use_layer_shell = ConfigModel.instance.layer_shell;
Bus.own_name (BusType.SESSION, "org.freedesktop.Notifications",
BusNameOwnerFlags.NONE,
on_noti_bus_aquired,
@@ -122,6 +127,7 @@ namespace SwayNotificationCenter {
[DBus (visible = false)]
public void show_blank_windows (Gdk.Monitor ? monitor) {
if (!use_layer_shell) return;
foreach (unowned BlankWindow win in blank_windows.data) {
if (win.monitor != monitor) win.show ();
}
@@ -129,6 +135,7 @@ namespace SwayNotificationCenter {
[DBus (visible = false)]
public void hide_blank_windows () {
if (!use_layer_shell) return;
foreach (unowned BlankWindow win in blank_windows.data) {
win.hide ();
}