summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wold <[email protected]>2020-09-14 02:38:48 -0700
committerraveit65 <[email protected]>2020-10-24 16:49:14 +0200
commit590bedf604ccc05cb9e41c3fc15d93ff827e7f65 (patch)
treed2f912b0867e8c8efcc22a1d3198dc6b3eb4150e
parent550f2a11921b48bc1c876b5e7fcc42cc2a4da07f (diff)
downloadmate-notification-daemon-590bedf604ccc05cb9e41c3fc15d93ff827e7f65.tar.bz2
mate-notification-daemon-590bedf604ccc05cb9e41c3fc15d93ff827e7f65.tar.xz
Implement placement on Wayland
-rw-r--r--src/daemon/daemon.c13
-rw-r--r--src/daemon/engines.c17
-rw-r--r--src/daemon/wayland.c42
-rw-r--r--src/daemon/wayland.h1
4 files changed, 60 insertions, 13 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 7981bb0..c42b2e6 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -45,11 +45,6 @@
#include <libwnck/libwnck.h>
#endif // HAVE_X11
-#ifdef HAVE_WAYLAND
-#include <gdk/gdkwayland.h>
-#include "wayland.h"
-#endif // HAVE_WAYLAND
-
#include "daemon.h"
#include "engines.h"
#include "stack.h"
@@ -1374,14 +1369,6 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object,
{
nw = theme_create_notification (url_clicked_cb);
g_object_set_data (G_OBJECT (nw), "_notify_daemon", daemon);
-
-#if HAVE_WAYLAND
- if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
- {
- wayland_init_notification (nw);
- }
-#endif // HAVE_WAYLAND
-
gtk_widget_realize (GTK_WIDGET (nw));
new_notification = TRUE;
diff --git a/src/daemon/engines.c b/src/daemon/engines.c
index db50e8b..3a0334e 100644
--- a/src/daemon/engines.c
+++ b/src/daemon/engines.c
@@ -26,6 +26,11 @@
#include "daemon.h"
#include "engines.h"
+#ifdef HAVE_WAYLAND
+#include <gdk/gdkwayland.h>
+#include "wayland.h"
+#endif // HAVE_WAYLAND
+
typedef struct {
GModule* module;
guint ref_count;
@@ -206,6 +211,12 @@ GtkWindow* theme_create_notification(UrlClickedCb url_clicked_cb)
GtkWindow* nw = engine->create_notification(url_clicked_cb);
g_object_set_data_full(G_OBJECT(nw), "_theme_engine", engine, (GDestroyNotify) theme_engine_unref);
engine->ref_count++;
+#if HAVE_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
+ {
+ wayland_init_notification (nw);
+ }
+#endif // HAVE_WAYLAND
return nw;
}
@@ -313,6 +324,12 @@ void theme_clear_notification_actions(GtkWindow* nw)
void theme_move_notification(GtkWindow* nw, int x, int y)
{
+#if HAVE_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
+ {
+ wayland_move_notification (nw, x, y);
+ }
+#endif // HAVE_WAYLAND
ThemeEngine* engine = g_object_get_data(G_OBJECT(nw), "_theme_engine");
engine->move_notification(nw, x, y);
}
diff --git a/src/daemon/wayland.c b/src/daemon/wayland.c
index 837e8a2..dbf1f30 100644
--- a/src/daemon/wayland.c
+++ b/src/daemon/wayland.c
@@ -37,3 +37,45 @@ void wayland_init_notification (GtkWindow* nw)
{
gtk_layer_init_for_window (nw);
}
+
+void wayland_move_notification (GtkWindow* nw, int x, int y)
+{
+ GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (nw));
+ GdkMonitor *monitor = gdk_display_get_monitor_at_window (
+ gdk_window_get_display (window),
+ window);
+ GdkRectangle workarea;
+ gdk_monitor_get_workarea (monitor, &workarea);
+ GtkRequisition req;
+ gtk_widget_get_preferred_size (GTK_WIDGET (nw), NULL, &req);
+ int left_gap = x;
+ int top_gap = y;
+ int right_gap = workarea.width - x - req.width;
+ int bottom_gap = workarea.height - y - req.height;
+
+ if (left_gap < right_gap)
+ {
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_RIGHT, FALSE);
+ gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_LEFT, left_gap);
+ }
+ else
+ {
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_LEFT, FALSE);
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
+ gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_RIGHT, right_gap);
+ }
+
+ if (top_gap < bottom_gap)
+ {
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_TOP, TRUE);
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE);
+ gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_TOP, top_gap);
+ }
+ else
+ {
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_TOP, FALSE);
+ gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE);
+ gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_BOTTOM, bottom_gap);
+ }
+}
diff --git a/src/daemon/wayland.h b/src/daemon/wayland.h
index 816eb74..5a58ec9 100644
--- a/src/daemon/wayland.h
+++ b/src/daemon/wayland.h
@@ -30,5 +30,6 @@
#include <gtk/gtk.h>
void wayland_init_notification (GtkWindow* nw);
+void wayland_move_notification (GtkWindow* nw, int x, int y);
#endif /* _WAYLAND_H */