From 2c23f7a87fc2bfca328967d4f84fa62c6adbb8a3 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 15 May 2023 14:12:20 +0200
Subject: [PATCH] restack: Make bspwm first try ewmh strategy
---
include/utils/bspwm.hpp | 3 ++-
include/utils/i3.hpp | 3 ++-
include/utils/restack.hpp | 18 ++++++++++--------
src/components/bar.cpp | 15 ++++++++-------
src/utils/bspwm.cpp | 12 +++++++++---
src/utils/i3.cpp | 4 ++--
src/utils/restack.cpp | 2 --
7 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/include/utils/bspwm.hpp b/include/utils/bspwm.hpp
index 8499b011..cdd26a38 100644
--- a/include/utils/bspwm.hpp
+++ b/include/utils/bspwm.hpp
@@ -5,6 +5,7 @@
#include "common.hpp"
#include "settings.hpp"
+#include "utils/restack.hpp"
#include "utils/socket.hpp"
#include "utils/string.hpp"
#include "x11/extensions/randr.hpp"
@@ -25,7 +26,7 @@ namespace bspwm_util {
};
vector root_windows(connection& conn);
- xcb_window_t get_restack_sibling(connection& conn, const monitor_t& mon);
+ restack_util::params get_restack_params(connection& conn, const monitor_t& mon, xcb_window_t bar_window);
string get_socket_path();
diff --git a/include/utils/i3.hpp b/include/utils/i3.hpp
index b43805e2..3172084a 100644
--- a/include/utils/i3.hpp
+++ b/include/utils/i3.hpp
@@ -3,6 +3,7 @@
#include
#include "common.hpp"
+#include "utils/restack.hpp"
#include "x11/extensions/randr.hpp"
POLYBAR_NS
@@ -19,7 +20,7 @@ namespace i3_util {
shared_ptr focused_workspace(const connection_t&);
vector root_windows(connection& conn, const string& output_name = "");
- xcb_window_t get_restack_sibling(connection& conn);
+ restack_util::params get_restack_params(connection& conn);
}
namespace {
diff --git a/include/utils/restack.hpp b/include/utils/restack.hpp
index f7ec9b6c..6f56a69b 100644
--- a/include/utils/restack.hpp
+++ b/include/utils/restack.hpp
@@ -8,14 +8,16 @@
POLYBAR_NS
namespace restack_util {
- using params = std::pair;
+using params = std::pair;
- void restack_relative(connection& conn, xcb_window_t win, xcb_window_t sibling, xcb_stack_mode_t stack_mode);
- string stack_mode_to_string(xcb_stack_mode_t mode);
- bool are_siblings(connection& conn, xcb_window_t win, xcb_window_t sibling);
- params get_bottom_params(connection& conn, xcb_window_t bar_window);
- params get_ewmh_params(connection& conn);
- params get_generic_params(connection& conn, xcb_window_t bar_window);
-}
+static constexpr params NONE_PARAMS = {XCB_NONE, XCB_STACK_MODE_ABOVE};
+
+void restack_relative(connection& conn, xcb_window_t win, xcb_window_t sibling, xcb_stack_mode_t stack_mode);
+string stack_mode_to_string(xcb_stack_mode_t mode);
+bool are_siblings(connection& conn, xcb_window_t win, xcb_window_t sibling);
+params get_bottom_params(connection& conn, xcb_window_t bar_window);
+params get_ewmh_params(connection& conn);
+params get_generic_params(connection& conn, xcb_window_t bar_window);
+} // namespace restack_util
POLYBAR_NS_END
diff --git a/src/components/bar.cpp b/src/components/bar.cpp
index 4ae12a49..a973cb12 100644
--- a/src/components/bar.cpp
+++ b/src/components/bar.cpp
@@ -497,20 +497,19 @@ void bar::restack_window() {
xcb_window_t bar_window = m_opts.x_data.window;
- xcb_window_t restack_sibling = XCB_NONE;
- xcb_stack_mode_t stack_mode = XCB_STACK_MODE_ABOVE;
+ restack_util::params restack_params;
if (wm_restack == "generic") {
- std::tie(restack_sibling, stack_mode) = restack_util::get_generic_params(m_connection, bar_window);
+ restack_params = restack_util::get_generic_params(m_connection, bar_window);
} else if (wm_restack == "ewmh") {
- std::tie(restack_sibling, stack_mode) = restack_util::get_ewmh_params(m_connection);
+ restack_params = restack_util::get_ewmh_params(m_connection);
} else if (wm_restack == "bottom") {
- std::tie(restack_sibling, stack_mode) = restack_util::get_bottom_params(m_connection, bar_window);
+ restack_params = restack_util::get_bottom_params(m_connection, bar_window);
} else if (wm_restack == "bspwm") {
- restack_sibling = bspwm_util::get_restack_sibling(m_connection, m_opts.monitor);
+ restack_params = bspwm_util::get_restack_params(m_connection, m_opts.monitor, bar_window);
#if ENABLE_I3
} else if (wm_restack == "i3" && m_opts.override_redirect) {
- restack_sibling = i3_util::get_restack_sibling(m_connection);
+ restack_params = i3_util::get_restack_params(m_connection);
} else if (wm_restack == "i3" && !m_opts.override_redirect) {
m_log.warn("Ignoring restack of i3 window (not needed when `override-redirect = false`)");
wm_restack.clear();
@@ -520,6 +519,8 @@ void bar::restack_window() {
wm_restack.clear();
}
+ auto [restack_sibling, stack_mode] = restack_params;
+
if (restack_sibling != XCB_NONE) {
try {
m_log.info("bar: Restacking bar window relative to %s with stacking mode %s", m_connection.id(restack_sibling),
diff --git a/src/utils/bspwm.cpp b/src/utils/bspwm.cpp
index 9a3a9885..9d05a138 100644
--- a/src/utils/bspwm.cpp
+++ b/src/utils/bspwm.cpp
@@ -38,7 +38,13 @@ vector root_windows(connection& conn) {
/**
* Returns window against which to restack.
*/
-xcb_window_t get_restack_sibling(connection& conn, const monitor_t& mon) {
+restack_util::params get_restack_params(connection& conn, const monitor_t& mon, xcb_window_t bar_window) {
+ auto ewmh_params = restack_util::get_ewmh_params(conn);
+
+ if (restack_util::are_siblings(conn, bar_window, ewmh_params.first)) {
+ return ewmh_params;
+ }
+
for (auto&& root : root_windows(conn)) {
auto geom = conn.get_geometry(root);
@@ -49,10 +55,10 @@ xcb_window_t get_restack_sibling(connection& conn, const monitor_t& mon) {
continue;
}
- return root;
+ return {root, XCB_STACK_MODE_ABOVE};
}
- return XCB_NONE;
+ return restack_util::NONE_PARAMS;
}
/**
diff --git a/src/utils/i3.cpp b/src/utils/i3.cpp
index b532edf7..87a41871 100644
--- a/src/utils/i3.cpp
+++ b/src/utils/i3.cpp
@@ -68,8 +68,8 @@ namespace i3_util {
/**
* Returns window against which to restack.
*/
- xcb_window_t get_restack_sibling(connection& conn) {
- return root_window(conn);
+ restack_util::params get_restack_params(connection& conn) {
+ return {root_window(conn), XCB_STACK_MODE_ABOVE};
}
} // namespace i3_util
diff --git a/src/utils/restack.cpp b/src/utils/restack.cpp
index b65f47b8..85d2280c 100644
--- a/src/utils/restack.cpp
+++ b/src/utils/restack.cpp
@@ -4,8 +4,6 @@ POLYBAR_NS
namespace restack_util {
-static constexpr params NONE_PARAMS = {XCB_NONE, XCB_STACK_MODE_ABOVE};
-
/**
* Restacks the given window relative to a given sibling with some stack order (above, below)
*