Merge pull request #3528 from alebastr/sway-scene-fixes

Fixes for Sway modes and wlr_scene support
This commit is contained in:
Alexis Rouillard 2024-09-16 14:44:17 +02:00 committed by GitHub
commit 9cfb1e38fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 14 deletions

View File

@ -18,11 +18,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1724819573, "lastModified": 1726062873,
"narHash": "sha256-GnR7/ibgIH1vhoy8cYdmXE6iyZqKqFxQSVkFgosBh6w=", "narHash": "sha256-IiA3jfbR7K/B5+9byVi9BZGWTD4VSbWe8VLpp9B/iYk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "71e91c409d1e654808b2621f28a327acfdad8dc2", "rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -42,7 +42,7 @@ struct bar_margins {
}; };
struct bar_mode { struct bar_mode {
std::optional<bar_layer> layer; bar_layer layer;
bool exclusive; bool exclusive;
bool passthrough; bool passthrough;
bool visible; bool visible;

View File

@ -106,7 +106,7 @@ if libsndio.found()
endif endif
endif endif
gtk_layer_shell = dependency('gtk-layer-shell-0', version: ['>=0.6.0'], gtk_layer_shell = dependency('gtk-layer-shell-0', version: ['>=0.9.0'],
default_options: ['introspection=false', 'vapi=false'], default_options: ['introspection=false', 'vapi=false'],
fallback: ['gtk-layer-shell', 'gtk_layer_shell']) fallback: ['gtk-layer-shell', 'gtk_layer_shell'])
systemd = dependency('systemd', required: get_option('systemd')) systemd = dependency('systemd', required: get_option('systemd'))

View File

@ -37,19 +37,19 @@ const Bar::bar_mode_map Bar::PRESET_MODES = { //
.visible = true}}, .visible = true}},
{"hide", {"hide",
{// {//
.layer = bar_layer::TOP, .layer = bar_layer::OVERLAY,
.exclusive = false, .exclusive = false,
.passthrough = false, .passthrough = false,
.visible = true}}, .visible = true}},
{"invisible", {"invisible",
{// {//
.layer = std::nullopt, .layer = bar_layer::BOTTOM,
.exclusive = false, .exclusive = false,
.passthrough = true, .passthrough = true,
.visible = false}}, .visible = false}},
{"overlay", {"overlay",
{// {//
.layer = bar_layer::TOP, .layer = bar_layer::OVERLAY,
.exclusive = false, .exclusive = false,
.passthrough = true, .passthrough = true,
.visible = true}}}; .visible = true}}};
@ -59,7 +59,7 @@ const std::string Bar::MODE_INVISIBLE = "invisible";
const std::string_view DEFAULT_BAR_ID = "bar-0"; const std::string_view DEFAULT_BAR_ID = "bar-0";
/* Deserializer for enum bar_layer */ /* Deserializer for enum bar_layer */
void from_json(const Json::Value& j, std::optional<bar_layer>& l) { void from_json(const Json::Value& j, bar_layer& l) {
if (j == "bottom") { if (j == "bottom") {
l = bar_layer::BOTTOM; l = bar_layer::BOTTOM;
} else if (j == "top") { } else if (j == "top") {
@ -132,6 +132,7 @@ void from_json(const Json::Value& j, std::map<Key, Value>& m) {
waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
: output(w_output), : output(w_output),
config(w_config), config(w_config),
surface(nullptr),
window{Gtk::WindowType::WINDOW_TOPLEVEL}, window{Gtk::WindowType::WINDOW_TOPLEVEL},
x_global(0), x_global(0),
y_global(0), y_global(0),
@ -316,13 +317,13 @@ void waybar::Bar::setMode(const std::string& mode) {
void waybar::Bar::setMode(const struct bar_mode& mode) { void waybar::Bar::setMode(const struct bar_mode& mode) {
auto* gtk_window = window.gobj(); auto* gtk_window = window.gobj();
if (mode.layer == bar_layer::BOTTOM) { auto layer = GTK_LAYER_SHELL_LAYER_BOTTOM;
gtk_layer_set_layer(gtk_window, GTK_LAYER_SHELL_LAYER_BOTTOM); if (mode.layer == bar_layer::TOP) {
} else if (mode.layer == bar_layer::TOP) { layer = GTK_LAYER_SHELL_LAYER_TOP;
gtk_layer_set_layer(gtk_window, GTK_LAYER_SHELL_LAYER_TOP);
} else if (mode.layer == bar_layer::OVERLAY) { } else if (mode.layer == bar_layer::OVERLAY) {
gtk_layer_set_layer(gtk_window, GTK_LAYER_SHELL_LAYER_OVERLAY); layer = GTK_LAYER_SHELL_LAYER_OVERLAY;
} }
gtk_layer_set_layer(gtk_window, layer);
if (mode.exclusive) { if (mode.exclusive) {
gtk_layer_auto_exclusive_zone_enable(gtk_window); gtk_layer_auto_exclusive_zone_enable(gtk_window);
@ -339,6 +340,13 @@ void waybar::Bar::setMode(const struct bar_mode& mode) {
window.get_style_context()->add_class("hidden"); window.get_style_context()->add_class("hidden");
window.set_opacity(0); window.set_opacity(0);
} }
/*
* All the changes above require `wl_surface_commit`.
* gtk-layer-shell schedules a commit on the next frame event in GTK, but this could fail in
* certain scenarios, such as fully occluded bar.
*/
gtk_layer_try_force_commit(gtk_window);
wl_display_flush(Client::inst()->wl_display);
} }
void waybar::Bar::setPassThrough(bool passthrough) { void waybar::Bar::setPassThrough(bool passthrough) {