restack: Make bspwm first try ewmh strategy

This commit is contained in:
patrick96 2023-05-15 14:12:20 +02:00 committed by Patrick Ziegler
parent 4f9f07eefd
commit 2c23f7a87f
7 changed files with 33 additions and 24 deletions

View File

@ -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<xcb_window_t> 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();

View File

@ -3,6 +3,7 @@
#include <i3ipc++/ipc.hpp>
#include "common.hpp"
#include "utils/restack.hpp"
#include "x11/extensions/randr.hpp"
POLYBAR_NS
@ -19,7 +20,7 @@ namespace i3_util {
shared_ptr<workspace_t> focused_workspace(const connection_t&);
vector<xcb_window_t> 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 {

View File

@ -10,12 +10,14 @@ POLYBAR_NS
namespace restack_util {
using params = std::pair<xcb_window_t, xcb_stack_mode_t>;
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

View File

@ -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),

View File

@ -38,7 +38,13 @@ vector<xcb_window_t> 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;
}
/**

View File

@ -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

View File

@ -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)
*