Skip to content

Commit 0620ca3

Browse files
committed
WIP: working layer-shell popups via gtk-layer-shell library
1 parent 26c1624 commit 0620ca3

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

include/bar.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Bar {
5757
void onConfigure(GdkEventConfigure *ev);
5858
void onRealize();
5959
void onMap(GdkEventAny *ev);
60+
void initLayerSurface();
6061
void setExclusiveZone(uint32_t width, uint32_t height);
6162
auto setupWidgets() -> void;
6263
void getModules(const Factory &, const std::string &);

src/bar.cpp

+61-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifdef HAVE_GTK_LAYER_SHELL
2+
#include <gtk-layer-shell.h>
3+
#endif
14
#include "bar.hpp"
25
#include "client.hpp"
36
#include "factory.hpp"
@@ -98,6 +101,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
98101
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
99102
}
100103

104+
initLayerSurface();
101105
setupWidgets();
102106

103107
if (window.get_realized()) {
@@ -131,11 +135,59 @@ void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
131135
tmp_width = ev->width;
132136
}
133137
}
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
134145
if (tmp_width != width_ || tmp_height != height_) {
135146
zwlr_layer_surface_v1_set_size(layer_surface, tmp_width, tmp_height);
136147
}
148+
#else
149+
setExclusiveZone(tmp_width, tmp_height);
150+
#endif
137151
}
138152

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
139191
void waybar::Bar::onRealize() {
140192
auto gdk_window = window.get_window()->gobj();
141193
gdk_wayland_window_set_use_custom_surface(gdk_window);
@@ -146,10 +198,10 @@ void waybar::Bar::onMap(GdkEventAny* ev) {
146198
surface = gdk_wayland_window_get_wl_surface(gdk_window);
147199

148200
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());
151201
auto layer =
152202
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());
153205
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
154206
client->layer_shell, surface, wl_output, layer, "waybar");
155207

@@ -169,6 +221,7 @@ void waybar::Bar::onMap(GdkEventAny* ev) {
169221
wl_surface_commit(surface);
170222
wl_display_roundtrip(client->wl_display);
171223
}
224+
#endif
172225

173226
void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) {
174227
auto zone = 0;
@@ -184,7 +237,11 @@ void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) {
184237
}
185238
}
186239
spdlog::debug("Set exclusive zone {} for output {}", zone, output->name);
240+
#ifndef HAVE_GTK_LAYER_SHELL
187241
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, zone);
242+
#else
243+
gtk_layer_set_exclusive_zone(window.gobj(), zone);
244+
#endif
188245
}
189246

190247
// Converting string to button code rn as to avoid doing it later
@@ -285,7 +342,9 @@ auto waybar::Bar::toggle() -> void {
285342
window.get_style_context()->remove_class("hidden");
286343
}
287344
setExclusiveZone(width_, height_);
345+
#ifndef HAVE_GTK_LAYER_SHELL
288346
wl_surface_commit(surface);
347+
#endif
289348
}
290349

291350
void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {

0 commit comments

Comments
 (0)