aboutsummaryrefslogtreecommitdiffstats
path: root/community/rofi-wayland/0002-Wayland-Implement-partial-support-for-offset-propert.patch
blob: f5808fb26011761f379d6ab02cd33c6ad137885a (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
85
86
87
88
89
90
91
92
93
From e963c3174a6e7d6d9f9617666bbec8b13077f13c Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Wed, 13 Oct 2021 01:42:32 +0200
Subject: [PATCH] [Wayland] Implement partial support for offset properties
 on window

...using zwlr_layer_surface_v1::set_margin. It's only partial because
surface margin has effect only when the the window is located on edge of
the screen, not in center. Also the anchor property is not implemented,
the anchor point is always the edge of the window corresponding to the
location property.
---
 include/wayland.h        |  4 +++-
 source/wayland/display.c | 12 +++++++++++-
 source/wayland/view.c    | 12 ++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/include/wayland.h b/include/wayland.h
index 7a077d0d..c25c02ab 100644
--- a/include/wayland.h
+++ b/include/wayland.h
@@ -41,6 +41,8 @@ cairo_surface_t *display_buffer_pool_get_next_buffer(display_buffer_pool *pool);
 void display_surface_commit(cairo_surface_t *surface);
 
 gboolean display_get_surface_dimensions(int *width, int *height);
-void display_set_surface_dimensions(int width, int height, int loc);
+void display_set_surface_dimensions(int width, int height,
+                                    int x_margin, int y_margin,
+                                    int loc);
 
 #endif
diff --git a/source/wayland/display.c b/source/wayland/display.c
index b8efb9b0..9b1efd33 100644
--- a/source/wayland/display.c
+++ b/source/wayland/display.c
@@ -1278,7 +1278,9 @@ gboolean display_get_surface_dimensions(int *width, int *height) {
   return FALSE;
 }
 
-void display_set_surface_dimensions(int width, int height, int loc) {
+void display_set_surface_dimensions(
+    int width, int height, int x_margin, int y_margin, int loc) {
+
   wayland->layer_width = width;
   wayland->layer_height = height;
   zwlr_layer_surface_v1_set_size(wayland->wlr_surface, width, height);
@@ -1328,6 +1330,14 @@ void display_set_surface_dimensions(int width, int height, int loc) {
   }
 
   zwlr_layer_surface_v1_set_anchor(wayland->wlr_surface, wlr_anchor);
+
+  // NOTE: Setting margin for edges we are not anchored to has no effect, so we
+  // can safely set contradictory margins (e.g. top vs bottom) - at most one of
+  // the margins on a given axis will have effect.
+  // This also means that margin has no effect if the window is centered. :(
+  zwlr_layer_surface_v1_set_margin(wayland->wlr_surface,
+                                   y_margin, -x_margin,
+                                   -y_margin, x_margin);
 }
 
 static void wayland_display_early_cleanup(void) {}
diff --git a/source/wayland/view.c b/source/wayland/view.c
index 85a8b010..e6293dd7 100644
--- a/source/wayland/view.c
+++ b/source/wayland/view.c
@@ -121,12 +121,24 @@ static int rofi_get_location(RofiViewState *state) {
                                  loc_transtable[config.location]);
 }
 
+static int rofi_get_offset_px(RofiViewState *state, RofiOrientation ori) {
+  char *property = ori == ROFI_ORIENTATION_HORIZONTAL ? "x-offset" : "y-offset";
+
+  RofiDistance offset = rofi_theme_get_distance(WIDGET(state->main_window),
+                                                property, 0);
+  return distance_get_pixel(offset, ori);
+}
+
 static void wayland_rofi_view_window_update_size(RofiViewState *state) {
   if (state == NULL) {
     return;
   }
+  int offset_x = rofi_get_offset_px(state, ROFI_ORIENTATION_HORIZONTAL);
+  int offset_y = rofi_get_offset_px(state, ROFI_ORIENTATION_VERTICAL);
+
   widget_resize(WIDGET(state->main_window), state->width, state->height);
   display_set_surface_dimensions(state->width, state->height,
+                                 offset_x, offset_y,
                                  rofi_get_location(state));
 }
 
-- 
2.33.0