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,10 @@ 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
+ #ifdef HAVE_GTK_LAYER_SHELL
105
+ use_gls_ = config[" gtk-layer-shell" ].isBool () ? config[" gtk-layer-shell" ].asBool () : true ;
106
+ initLayerSurface ();
107
+ #endif
101
108
setupWidgets ();
102
109
103
110
if (window.get_realized ()) {
@@ -131,11 +138,51 @@ void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
131
138
tmp_width = ev->width ;
132
139
}
133
140
}
134
- if (tmp_width != width_ || tmp_height != height_) {
141
+ spdlog::debug (" onConfigure: set size (width: {} -> {}, height: {} -> {}) for output {}" ,
142
+ width_,
143
+ tmp_width,
144
+ height_,
145
+ tmp_height,
146
+ output->name );
147
+ if (use_gls_) {
148
+ width_ = tmp_width;
149
+ height_ = tmp_height;
150
+ setExclusiveZone (tmp_width, tmp_height);
151
+ } else if (tmp_width != width_ || tmp_height != height_) {
135
152
setSurfaceSize (tmp_width, tmp_height);
136
153
}
137
154
}
138
155
156
+ void waybar::Bar::initLayerSurface () {
157
+ #ifdef HAVE_GTK_LAYER_SHELL
158
+ if (use_gls_) {
159
+ auto gtk_window = window.gobj ();
160
+ // this has to be executed before GtkWindow.realize
161
+ gtk_layer_init_for_window (gtk_window);
162
+ gtk_layer_set_keyboard_interactivity (gtk_window, FALSE );
163
+ auto layer =
164
+ config[" layer" ] == " top" ? GTK_LAYER_SHELL_LAYER_TOP : GTK_LAYER_SHELL_LAYER_BOTTOM;
165
+ gtk_layer_set_layer (gtk_window, layer);
166
+ gtk_layer_set_monitor (gtk_window, output->monitor ->gobj ());
167
+ gtk_layer_set_namespace (gtk_window, " waybar" );
168
+
169
+ gtk_layer_set_anchor (
170
+ gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
171
+ gtk_layer_set_anchor (
172
+ gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
173
+ gtk_layer_set_anchor (
174
+ gtk_window, GTK_LAYER_SHELL_EDGE_TOP, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP);
175
+ gtk_layer_set_anchor (
176
+ gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM);
177
+
178
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, margins_.left );
179
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, margins_.right );
180
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_TOP, margins_.top );
181
+ gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, margins_.bottom );
182
+ }
183
+ #endif
184
+ }
185
+
139
186
void waybar::Bar::onRealize () {
140
187
auto gdk_window = window.get_window ()->gobj ();
141
188
gdk_wayland_window_set_use_custom_surface (gdk_window);
@@ -145,29 +192,31 @@ void waybar::Bar::onMap(GdkEventAny* ev) {
145
192
auto gdk_window = window.get_window ()->gobj ();
146
193
surface = gdk_wayland_window_get_wl_surface (gdk_window);
147
194
148
- 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
- auto layer =
152
- 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 (
154
- client->layer_shell , surface, wl_output, layer, " waybar" );
195
+ if (!use_gls_) {
196
+ auto client = waybar::Client::inst ();
197
+ auto layer =
198
+ config[" layer" ] == " top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
199
+ // owned by output->monitor; no need to destroy
200
+ auto wl_output = gdk_wayland_monitor_get_wl_output (output->monitor ->gobj ());
201
+ layer_surface = zwlr_layer_shell_v1_get_layer_surface (
202
+ client->layer_shell , surface, wl_output, layer, " waybar" );
155
203
156
- zwlr_layer_surface_v1_set_keyboard_interactivity (layer_surface, false );
157
- zwlr_layer_surface_v1_set_anchor (layer_surface, anchor_);
158
- zwlr_layer_surface_v1_set_margin (
159
- layer_surface, margins_.top , margins_.right , margins_.bottom , margins_.left );
160
- setSurfaceSize (width_, height_);
161
- setExclusiveZone (width_, height_);
204
+ zwlr_layer_surface_v1_set_keyboard_interactivity (layer_surface, false );
205
+ zwlr_layer_surface_v1_set_anchor (layer_surface, anchor_);
206
+ zwlr_layer_surface_v1_set_margin (
207
+ layer_surface, margins_.top , margins_.right , margins_.bottom , margins_.left );
208
+ setSurfaceSize (width_, height_);
209
+ setExclusiveZone (width_, height_);
162
210
163
- static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
164
- .configure = layerSurfaceHandleConfigure,
165
- .closed = layerSurfaceHandleClosed,
166
- };
167
- zwlr_layer_surface_v1_add_listener (layer_surface, &layer_surface_listener, this );
211
+ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
212
+ .configure = layerSurfaceHandleConfigure,
213
+ .closed = layerSurfaceHandleClosed,
214
+ };
215
+ zwlr_layer_surface_v1_add_listener (layer_surface, &layer_surface_listener, this );
168
216
169
- wl_surface_commit (surface);
170
- wl_display_roundtrip (client->wl_display );
217
+ wl_surface_commit (surface);
218
+ wl_display_roundtrip (client->wl_display );
219
+ }
171
220
}
172
221
173
222
void waybar::Bar::setExclusiveZone (uint32_t width, uint32_t height) {
@@ -184,7 +233,15 @@ void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) {
184
233
}
185
234
}
186
235
spdlog::debug (" Set exclusive zone {} for output {}" , zone, output->name );
187
- zwlr_layer_surface_v1_set_exclusive_zone (layer_surface, zone);
236
+
237
+ #ifdef HAVE_GTK_LAYER_SHELL
238
+ if (use_gls_) {
239
+ gtk_layer_set_exclusive_zone (window.gobj (), zone);
240
+ } else
241
+ #endif
242
+ {
243
+ zwlr_layer_surface_v1_set_exclusive_zone (layer_surface, zone);
244
+ }
188
245
}
189
246
190
247
void waybar::Bar::setSurfaceSize (uint32_t width, uint32_t height) {
0 commit comments