1
+ #ifdef HAVE_GTK_LAYER_SHELL
2
+ #include < gtk-layer-shell.h>
3
+ #endif
1
4
#include " bar.hpp"
2
5
#include " client.hpp"
3
6
#include " factory.hpp"
@@ -98,6 +101,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
98
101
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
99
102
}
100
103
104
+ initLayerSurface ();
101
105
setupWidgets ();
102
106
103
107
if (window.get_realized ()) {
@@ -131,11 +135,59 @@ void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
131
135
tmp_width = ev->width ;
132
136
}
133
137
}
138
+ spdlog::debug (" onConfigure: set size (width: {} -> {}, height: {} -> {}) for output {}" ,
139
+ width_,
140
+ tmp_width,
141
+ height_,
142
+ tmp_height,
143
+ output->name );
144
+ #ifndef HAVE_GTK_LAYER_SHELL
134
145
if (tmp_width != width_ || tmp_height != height_) {
135
146
zwlr_layer_surface_v1_set_size (layer_surface, tmp_width, tmp_height);
136
147
}
148
+ #else
149
+ setExclusiveZone (tmp_width, tmp_height);
150
+ #endif
137
151
}
138
152
153
+ void waybar::Bar::initLayerSurface () {
154
+ #ifdef HAVE_GTK_LAYER_SHELL
155
+ auto gtk_window = window.gobj ();
156
+ // this has to be executed before GtkWindow.realize
157
+ gtk_layer_init_for_window (gtk_window);
158
+ gtk_layer_set_keyboard_interactivity (gtk_window, FALSE );
159
+ auto layer = config[" layer" ] == " top" ? GTK_LAYER_SHELL_LAYER_TOP : GTK_LAYER_SHELL_LAYER_BOTTOM;
160
+ gtk_layer_set_layer (gtk_window, layer);
161
+ gtk_layer_set_monitor (gtk_window, output->monitor ->gobj ());
162
+ gtk_layer_set_namespace (gtk_window, " waybar" );
163
+
164
+ gtk_layer_set_anchor (
165
+ gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
166
+ gtk_layer_set_anchor (
167
+ gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
168
+ gtk_layer_set_anchor (
169
+ gtk_window, GTK_LAYER_SHELL_EDGE_TOP, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP);
170
+ gtk_layer_set_anchor (
171
+ gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM);
172
+
173
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, margins_.left );
174
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, margins_.right );
175
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_TOP, margins_.top );
176
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, margins_.bottom );
177
+ #endif
178
+ }
179
+
180
+ #ifdef HAVE_GTK_LAYER_SHELL
181
+ void waybar::Bar::onRealize () {}
182
+
183
+ void waybar::Bar::onMap (GdkEventAny* ev) {
184
+ auto gdk_window = window.get_window ()->gobj ();
185
+ surface = gdk_wayland_window_get_wl_surface (gdk_window);
186
+ // window.set_size_request(width_, height_);
187
+ // window.resize(width_, height_);
188
+ // setExclusiveZone(width_, height_);
189
+ }
190
+ #else
139
191
void waybar::Bar::onRealize () {
140
192
auto gdk_window = window.get_window ()->gobj ();
141
193
gdk_wayland_window_set_use_custom_surface (gdk_window);
@@ -146,10 +198,10 @@ void waybar::Bar::onMap(GdkEventAny* ev) {
146
198
surface = gdk_wayland_window_get_wl_surface (gdk_window);
147
199
148
200
auto client = waybar::Client::inst ();
149
- // owned by output->monitor; no need to destroy
150
- auto wl_output = gdk_wayland_monitor_get_wl_output (output->monitor ->gobj ());
151
201
auto layer =
152
202
config[" layer" ] == " top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
203
+ // owned by output->monitor; no need to destroy
204
+ auto wl_output = gdk_wayland_monitor_get_wl_output (output->monitor ->gobj ());
153
205
layer_surface = zwlr_layer_shell_v1_get_layer_surface (
154
206
client->layer_shell , surface, wl_output, layer, " waybar" );
155
207
@@ -169,6 +221,7 @@ void waybar::Bar::onMap(GdkEventAny* ev) {
169
221
wl_surface_commit (surface);
170
222
wl_display_roundtrip (client->wl_display );
171
223
}
224
+ #endif
172
225
173
226
void waybar::Bar::setExclusiveZone (uint32_t width, uint32_t height) {
174
227
auto zone = 0 ;
@@ -184,7 +237,11 @@ void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) {
184
237
}
185
238
}
186
239
spdlog::debug (" Set exclusive zone {} for output {}" , zone, output->name );
240
+ #ifndef HAVE_GTK_LAYER_SHELL
187
241
zwlr_layer_surface_v1_set_exclusive_zone (layer_surface, zone);
242
+ #else
243
+ gtk_layer_set_exclusive_zone (window.gobj (), zone);
244
+ #endif
188
245
}
189
246
190
247
// Converting string to button code rn as to avoid doing it later
@@ -285,7 +342,9 @@ auto waybar::Bar::toggle() -> void {
285
342
window.get_style_context ()->remove_class (" hidden" );
286
343
}
287
344
setExclusiveZone (width_, height_);
345
+ #ifndef HAVE_GTK_LAYER_SHELL
288
346
wl_surface_commit (surface);
347
+ #endif
289
348
}
290
349
291
350
void waybar::Bar::getModules (const Factory& factory, const std::string& pos) {
0 commit comments