1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2020 William Wold <wm@wmww.sh>
4 * Copyright (C) 2020-2021 MATE Developers
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
20 */
21
22 #include "config.h"
23
24 #ifndef HAVE_WAYLAND
25 #error file should only be built when HAVE_WAYLAND is enabled
26 #endif
27
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <stdio.h>
32
33 #include <gtk-layer-shell/gtk-layer-shell.h>
34
35 #include "wayland.h"
36
wayland_init_notification(GtkWindow * nw)37 void wayland_init_notification (GtkWindow* nw)
38 {
39 gtk_layer_init_for_window (nw);
40 gtk_layer_set_layer (nw, GTK_LAYER_SHELL_LAYER_TOP);
41 gtk_layer_set_namespace (nw, "notification");
42 }
43
wayland_move_notification(GtkWindow * nw,int x,int y)44 void wayland_move_notification (GtkWindow* nw, int x, int y)
45 {
46 GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (nw));
47 GdkMonitor *monitor = gdk_display_get_monitor_at_window (
48 gdk_window_get_display (window),
49 window);
50 GdkRectangle workarea;
51 gdk_monitor_get_workarea (monitor, &workarea);
52 GtkRequisition req;
53 gtk_widget_get_preferred_size (GTK_WIDGET (nw), NULL, &req);
54 int left_gap = x;
55 int top_gap = y;
56 int right_gap = workarea.width - x - req.width;
57 int bottom_gap = workarea.height - y - req.height;
58
59 if (left_gap < right_gap)
60 {
61 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
62 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_RIGHT, FALSE);
63 gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_LEFT, left_gap);
64 }
65 else
66 {
67 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_LEFT, FALSE);
68 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
69 gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_RIGHT, right_gap);
70 }
71
72 if (top_gap < bottom_gap)
73 {
74 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_TOP, TRUE);
75 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE);
76 gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_TOP, top_gap);
77 }
78 else
79 {
80 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_TOP, FALSE);
81 gtk_layer_set_anchor (nw, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE);
82 gtk_layer_set_margin (nw, GTK_LAYER_SHELL_EDGE_BOTTOM, bottom_gap);
83 }
84 }
85