1
+ #ifdef HAVE_GTK_LAYER_SHELL
2
+ #include < gtk-layer-shell.h>
3
+ #endif
4
+
1
5
#include " bar.hpp"
2
6
#include " client.hpp"
3
7
#include " factory.hpp"
@@ -8,7 +12,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
8
12
config(w_config),
9
13
window{Gtk::WindowType::WINDOW_TOPLEVEL},
10
14
surface (nullptr ),
11
- layer_surface (nullptr ),
15
+ layer_surface_ (nullptr ),
12
16
anchor_(ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP),
13
17
left_(Gtk::ORIENTATION_HORIZONTAL, 0 ),
14
18
center_(Gtk::ORIENTATION_HORIZONTAL, 0 ),
@@ -28,11 +32,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
28
32
height_ = config[" height" ].isUInt () ? config[" height" ].asUInt () : height_;
29
33
width_ = config[" width" ].isUInt () ? config[" width" ].asUInt () : width_;
30
34
31
- window.signal_realize ().connect_notify (sigc::mem_fun (*this , &Bar::onRealize));
32
- window.signal_map_event ().connect_notify (sigc::mem_fun (*this , &Bar::onMap));
33
- window.signal_configure_event ().connect_notify (sigc::mem_fun (*this , &Bar::onConfigure));
34
- window.set_size_request (width_, height_);
35
-
36
35
if (config[" position" ] == " bottom" ) {
37
36
anchor_ = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
38
37
} else if (config[" position" ] == " left" ) {
@@ -98,6 +97,17 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
98
97
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
99
98
}
100
99
100
+ #ifdef HAVE_GTK_LAYER_SHELL
101
+ use_gls_ = config[" gtk-layer-shell" ].isBool () ? config[" gtk-layer-shell" ].asBool () : true ;
102
+ if (use_gls_) {
103
+ initGtkLayerShell ();
104
+ }
105
+ #endif
106
+
107
+ window.signal_realize ().connect_notify (sigc::mem_fun (*this , &Bar::onRealize));
108
+ window.signal_map_event ().connect_notify (sigc::mem_fun (*this , &Bar::onMap));
109
+ window.signal_configure_event ().connect_notify (sigc::mem_fun (*this , &Bar::onConfigure));
110
+ window.set_size_request (width_, height_);
101
111
setupWidgets ();
102
112
103
113
if (window.get_realized ()) {
@@ -131,11 +141,43 @@ void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
131
141
tmp_width = ev->width ;
132
142
}
133
143
}
134
- if (tmp_width != width_ || tmp_height != height_) {
144
+ if (use_gls_) {
145
+ width_ = tmp_width;
146
+ height_ = tmp_height;
147
+ spdlog::debug (" Set surface size {}x{} for output {}" , width_, height_, output->name );
148
+ setExclusiveZone (tmp_width, tmp_height);
149
+ } else if (tmp_width != width_ || tmp_height != height_) {
135
150
setSurfaceSize (tmp_width, tmp_height);
136
151
}
137
152
}
138
153
154
+ #ifdef HAVE_GTK_LAYER_SHELL
155
+ void waybar::Bar::initGtkLayerShell () {
156
+ auto gtk_window = window.gobj ();
157
+ // this has to be executed before GtkWindow.realize
158
+ gtk_layer_init_for_window (gtk_window);
159
+ gtk_layer_set_keyboard_interactivity (gtk_window, FALSE );
160
+ auto layer = config[" layer" ] == " top" ? GTK_LAYER_SHELL_LAYER_TOP : GTK_LAYER_SHELL_LAYER_BOTTOM;
161
+ gtk_layer_set_layer (gtk_window, layer);
162
+ gtk_layer_set_monitor (gtk_window, output->monitor ->gobj ());
163
+ gtk_layer_set_namespace (gtk_window, " waybar" );
164
+
165
+ gtk_layer_set_anchor (
166
+ gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
167
+ gtk_layer_set_anchor (
168
+ gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
169
+ gtk_layer_set_anchor (
170
+ gtk_window, GTK_LAYER_SHELL_EDGE_TOP, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP);
171
+ gtk_layer_set_anchor (
172
+ gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM);
173
+
174
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, margins_.left );
175
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, margins_.right );
176
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_TOP, margins_.top );
177
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, margins_.bottom );
178
+ }
179
+ #endif
180
+
139
181
void waybar::Bar::onRealize () {
140
182
auto gdk_window = window.get_window ()->gobj ();
141
183
gdk_wayland_window_set_use_custom_surface (gdk_window);
@@ -145,26 +187,30 @@ void waybar::Bar::onMap(GdkEventAny* ev) {
145
187
auto gdk_window = window.get_window ()->gobj ();
146
188
surface = gdk_wayland_window_get_wl_surface (gdk_window);
147
189
190
+ if (use_gls_) {
191
+ return ;
192
+ }
193
+
148
194
auto client = waybar::Client::inst ();
149
195
// owned by output->monitor; no need to destroy
150
196
auto wl_output = gdk_wayland_monitor_get_wl_output (output->monitor ->gobj ());
151
197
auto layer =
152
198
config[" layer" ] == " top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
153
- layer_surface = zwlr_layer_shell_v1_get_layer_surface (
199
+ layer_surface_ = zwlr_layer_shell_v1_get_layer_surface (
154
200
client->layer_shell , surface, wl_output, layer, " waybar" );
155
201
156
- zwlr_layer_surface_v1_set_keyboard_interactivity (layer_surface , false );
157
- zwlr_layer_surface_v1_set_anchor (layer_surface , anchor_);
202
+ zwlr_layer_surface_v1_set_keyboard_interactivity (layer_surface_ , false );
203
+ zwlr_layer_surface_v1_set_anchor (layer_surface_ , anchor_);
158
204
zwlr_layer_surface_v1_set_margin (
159
- layer_surface , margins_.top , margins_.right , margins_.bottom , margins_.left );
205
+ layer_surface_ , margins_.top , margins_.right , margins_.bottom , margins_.left );
160
206
setSurfaceSize (width_, height_);
161
207
setExclusiveZone (width_, height_);
162
208
163
209
static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
164
210
.configure = layerSurfaceHandleConfigure,
165
211
.closed = layerSurfaceHandleClosed,
166
212
};
167
- zwlr_layer_surface_v1_add_listener (layer_surface , &layer_surface_listener, this );
213
+ zwlr_layer_surface_v1_add_listener (layer_surface_ , &layer_surface_listener, this );
168
214
169
215
wl_surface_commit (surface);
170
216
wl_display_roundtrip (client->wl_display );
@@ -184,7 +230,15 @@ void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) {
184
230
}
185
231
}
186
232
spdlog::debug (" Set exclusive zone {} for output {}" , zone, output->name );
187
- zwlr_layer_surface_v1_set_exclusive_zone (layer_surface, zone);
233
+
234
+ #ifdef HAVE_GTK_LAYER_SHELL
235
+ if (use_gls_) {
236
+ gtk_layer_set_exclusive_zone (window.gobj (), zone);
237
+ } else
238
+ #endif
239
+ {
240
+ zwlr_layer_surface_v1_set_exclusive_zone (layer_surface_, zone);
241
+ }
188
242
}
189
243
190
244
void waybar::Bar::setSurfaceSize (uint32_t width, uint32_t height) {
@@ -200,7 +254,7 @@ void waybar::Bar::setSurfaceSize(uint32_t width, uint32_t height) {
200
254
width += margins_.right + margins_.left ;
201
255
}
202
256
spdlog::debug (" Set surface size {}x{} for output {}" , width, height, output->name );
203
- zwlr_layer_surface_v1_set_size (layer_surface , width, height);
257
+ zwlr_layer_surface_v1_set_size (layer_surface_ , width, height);
204
258
}
205
259
206
260
// Converting string to button code rn as to avoid doing it later
@@ -284,9 +338,9 @@ void waybar::Bar::layerSurfaceHandleConfigure(void* data, struct zwlr_layer_surf
284
338
285
339
void waybar::Bar::layerSurfaceHandleClosed (void * data, struct zwlr_layer_surface_v1 * /* surface*/ ) {
286
340
auto o = static_cast <waybar::Bar*>(data);
287
- if (o->layer_surface ) {
288
- zwlr_layer_surface_v1_destroy (o->layer_surface );
289
- o->layer_surface = nullptr ;
341
+ if (o->layer_surface_ ) {
342
+ zwlr_layer_surface_v1_destroy (o->layer_surface_ );
343
+ o->layer_surface_ = nullptr ;
290
344
}
291
345
o->modules_left_ .clear ();
292
346
o->modules_center_ .clear ();
0 commit comments