Introduce restacking utilities

Aim is to clean up restacking logic and remove some duplicated code
This commit is contained in:
patrick96 2023-05-15 13:06:21 +02:00 committed by Patrick Ziegler
parent f78ec80df3
commit 76c7ee3bf6
4 changed files with 40 additions and 3 deletions

14
include/utils/restack.hpp Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <xcb/xcb.h>
#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

View File

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

View File

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

23
src/utils/restack.cpp Normal file
View File

@ -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<uint32_t, 2> value_list = {sibling, stack_mode};
conn.configure_window_checked(win, value_mask, value_list.data());
}
}
POLYBAR_NS_END