summaryrefslogtreecommitdiff
path: root/src/daemon/wayland.c
blob: 1659bd3ab6a780c4bad4954be13f230ecf768631 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright (C) 2020 William Wold <wm@wmww.sh>
 * Copyright (C) 2020-2021 MATE Developers
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#include "config.h"

#ifndef HAVE_WAYLAND
#error file should only be built when HAVE_WAYLAND is enabled
#endif

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>

#include <gtk-layer-shell/gtk-layer-shell.h>

#include "wayland.h"

void wayland_init_notification (GtkWindow* nw)
{
	gtk_layer_init_for_window (nw);
	gtk_layer_set_layer (nw, GTK_LAYER_SHELL_LAYER_TOP);
	gtk_layer_set_namespace (nw, "notification");
}

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);
	}
}