diff --git a/include/utils/restack.hpp b/include/utils/restack.hpp new file mode 100644 index 00000000..bf3eaca8 --- /dev/null +++ b/include/utils/restack.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +#include "x11/connection.hpp" +#include "x11/ewmh.hpp" + +POLYBAR_NS + +namespace restack_util { + void restack_relative(connection& conn, xcb_window_t win, xcb_window_t sibling, xcb_stack_mode_t stack_mode); +} + +POLYBAR_NS_END diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f68cb8df..41906b86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -120,6 +120,7 @@ set(POLY_SOURCES ${src_dir}/utils/inotify.cpp ${src_dir}/utils/io.cpp ${src_dir}/utils/process.cpp + ${src_dir}/utils/restack.cpp ${src_dir}/utils/socket.cpp ${src_dir}/utils/string.cpp ${src_dir}/utils/units.cpp diff --git a/src/components/bar.cpp b/src/components/bar.cpp index d47c6dfc..46da6f61 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -11,6 +11,7 @@ #include "events/signal_emitter.hpp" #include "tags/dispatch.hpp" #include "utils/bspwm.hpp" +#include "utils/restack.hpp" #include "utils/color.hpp" #include "utils/math.hpp" #include "utils/string.hpp" @@ -497,9 +498,7 @@ void bar::restack_window() { try { auto children = m_connection.query_tree(m_connection.root()).children(); if (children.begin() != children.end() && *children.begin() != m_opts.x_data.window) { - const unsigned int value_mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE; - const unsigned int value_list[2]{*children.begin(), XCB_STACK_MODE_BELOW}; - m_connection.configure_window_checked(m_opts.x_data.window, value_mask, value_list); + restack_util::restack_relative(m_connection, m_opts.x_data.window, *children.begin(), XCB_STACK_MODE_BELOW); } restacked = true; } catch (const exception& err) { diff --git a/src/utils/restack.cpp b/src/utils/restack.cpp new file mode 100644 index 00000000..af3cb7e3 --- /dev/null +++ b/src/utils/restack.cpp @@ -0,0 +1,23 @@ +#include "utils/restack.hpp" + +POLYBAR_NS + +namespace restack_util { + /** + * Restacks the given window relative to a given sibling with some stack order (above, below) + * + * Both windows need to be siblings (have the same parent window). + * + * @param win The window to restack + * @param sibling The window relative to which restacking happens + * @param stack_mode The restacking mode (above, below) + * @throw Some xpp error if restacking fails + */ + void restack_relative(connection& conn, xcb_window_t win, xcb_window_t sibling, xcb_stack_mode_t stack_mode) { + const unsigned int value_mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE; + const std::array value_list = {sibling, stack_mode}; + conn.configure_window_checked(win, value_mask, value_list.data()); + } +} + +POLYBAR_NS_END