Clean up restacking code
Restacking algorithms now only need to provide the sibling window and stacking mode.
This commit is contained in:
parent
76c7ee3bf6
commit
59acb4150b
@ -25,7 +25,7 @@ namespace bspwm_util {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vector<xcb_window_t> root_windows(connection& conn);
|
vector<xcb_window_t> root_windows(connection& conn);
|
||||||
bool restack_to_root(connection& conn, const monitor_t& mon, const xcb_window_t win);
|
xcb_window_t get_restack_sibling(connection& conn, const monitor_t& mon);
|
||||||
|
|
||||||
string get_socket_path();
|
string get_socket_path();
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ namespace i3_util {
|
|||||||
shared_ptr<workspace_t> focused_workspace(const connection_t&);
|
shared_ptr<workspace_t> focused_workspace(const connection_t&);
|
||||||
|
|
||||||
vector<xcb_window_t> root_windows(connection& conn, const string& output_name = "");
|
vector<xcb_window_t> root_windows(connection& conn, const string& output_name = "");
|
||||||
bool restack_to_root(connection& conn, const xcb_window_t win);
|
xcb_window_t get_restack_sibling(connection& conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
#include "events/signal_emitter.hpp"
|
#include "events/signal_emitter.hpp"
|
||||||
#include "tags/dispatch.hpp"
|
#include "tags/dispatch.hpp"
|
||||||
#include "utils/bspwm.hpp"
|
#include "utils/bspwm.hpp"
|
||||||
#include "utils/restack.hpp"
|
|
||||||
#include "utils/color.hpp"
|
#include "utils/color.hpp"
|
||||||
#include "utils/math.hpp"
|
#include "utils/math.hpp"
|
||||||
|
#include "utils/restack.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
#include "utils/units.hpp"
|
#include "utils/units.hpp"
|
||||||
#include "x11/atoms.hpp"
|
#include "x11/atoms.hpp"
|
||||||
@ -492,23 +492,20 @@ void bar::restack_window() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto restacked = false;
|
xcb_window_t restack_sibling = XCB_NONE;
|
||||||
|
xcb_stack_mode_t stack_mode = XCB_STACK_MODE_ABOVE;
|
||||||
|
|
||||||
if (wm_restack == "generic") {
|
if (wm_restack == "generic") {
|
||||||
try {
|
|
||||||
auto children = m_connection.query_tree(m_connection.root()).children();
|
auto children = m_connection.query_tree(m_connection.root()).children();
|
||||||
if (children.begin() != children.end() && *children.begin() != m_opts.x_data.window) {
|
if (children.begin() != children.end() && *children.begin() != m_opts.x_data.window) {
|
||||||
restack_util::restack_relative(m_connection, m_opts.x_data.window, *children.begin(), XCB_STACK_MODE_BELOW);
|
restack_sibling = *children.begin();
|
||||||
}
|
stack_mode = XCB_STACK_MODE_BELOW;
|
||||||
restacked = true;
|
|
||||||
} catch (const exception& err) {
|
|
||||||
m_log.err("Failed to restack bar window (err=%s)", err.what());
|
|
||||||
}
|
}
|
||||||
} else if (wm_restack == "bspwm") {
|
} else if (wm_restack == "bspwm") {
|
||||||
restacked = bspwm_util::restack_to_root(m_connection, m_opts.monitor, m_opts.x_data.window);
|
restack_sibling = bspwm_util::get_restack_sibling(m_connection, m_opts.monitor);
|
||||||
#if ENABLE_I3
|
#if ENABLE_I3
|
||||||
} else if (wm_restack == "i3" && m_opts.override_redirect) {
|
} else if (wm_restack == "i3" && m_opts.override_redirect) {
|
||||||
restacked = i3_util::restack_to_root(m_connection, m_opts.x_data.window);
|
restack_sibling = i3_util::get_restack_sibling(m_connection);
|
||||||
} else if (wm_restack == "i3" && !m_opts.override_redirect) {
|
} else if (wm_restack == "i3" && !m_opts.override_redirect) {
|
||||||
m_log.warn("Ignoring restack of i3 window (not needed when `override-redirect = false`)");
|
m_log.warn("Ignoring restack of i3 window (not needed when `override-redirect = false`)");
|
||||||
wm_restack.clear();
|
wm_restack.clear();
|
||||||
@ -518,8 +515,13 @@ void bar::restack_window() {
|
|||||||
wm_restack.clear();
|
wm_restack.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restacked) {
|
if (restack_sibling != XCB_NONE) {
|
||||||
|
try {
|
||||||
|
restack_util::restack_relative(m_connection, m_opts.x_data.window, restack_sibling, stack_mode);
|
||||||
m_log.info("Successfully restacked bar window");
|
m_log.info("Successfully restacked bar window");
|
||||||
|
} catch (const exception& err) {
|
||||||
|
m_log.err("Failed to restack bar window (err=%s)", err.what());
|
||||||
|
}
|
||||||
} else if (!wm_restack.empty()) {
|
} else if (!wm_restack.empty()) {
|
||||||
m_log.err("Failed to restack bar window");
|
m_log.err("Failed to restack bar window");
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,15 @@
|
|||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
#include "utils/env.hpp"
|
#include "utils/env.hpp"
|
||||||
#include "x11/connection.hpp"
|
#include "x11/connection.hpp"
|
||||||
|
#include "x11/ewmh.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
namespace bspwm_util {
|
namespace bspwm_util {
|
||||||
/**
|
/**
|
||||||
* Get all bspwm root windows
|
* Get all bspwm root windows
|
||||||
*/
|
*/
|
||||||
vector<xcb_window_t> root_windows(connection& conn) {
|
vector<xcb_window_t> root_windows(connection& conn) {
|
||||||
vector<xcb_window_t> roots;
|
vector<xcb_window_t> roots;
|
||||||
auto children = conn.query_tree(conn.root()).children();
|
auto children = conn.query_tree(conn.root()).children();
|
||||||
|
|
||||||
@ -32,15 +33,15 @@ namespace bspwm_util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return roots;
|
return roots;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restack given window relative to the bspwm root window
|
* Restack given window relative to the bspwm root window
|
||||||
* for the given monitor.
|
* for the given monitor.
|
||||||
*
|
*
|
||||||
* Fixes the issue with always-on-top window's
|
* Fixes the issue with always-on-top window's
|
||||||
*/
|
*/
|
||||||
bool restack_to_root(connection& conn, const monitor_t& mon, const xcb_window_t win) {
|
xcb_window_t get_restack_sibling(connection& conn, const monitor_t& mon) {
|
||||||
for (auto&& root : root_windows(conn)) {
|
for (auto&& root : root_windows(conn)) {
|
||||||
auto geom = conn.get_geometry(root);
|
auto geom = conn.get_geometry(root);
|
||||||
|
|
||||||
@ -51,26 +52,20 @@ namespace bspwm_util {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned int value_mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE;
|
return root;
|
||||||
const unsigned int value_list[2]{root, XCB_STACK_MODE_ABOVE};
|
|
||||||
|
|
||||||
conn.configure_window_checked(win, value_mask, value_list);
|
|
||||||
conn.flush();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return XCB_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get path to the bspwm socket by the following order
|
* Get path to the bspwm socket by the following order
|
||||||
*
|
*
|
||||||
* 1. Value of environment variable BSPWM_SOCKET
|
* 1. Value of environment variable BSPWM_SOCKET
|
||||||
* 2. Value built from the bspwm socket path template
|
* 2. Value built from the bspwm socket path template
|
||||||
* 3. Value of the macro BSPWM_SOCKET_PATH
|
* 3. Value of the macro BSPWM_SOCKET_PATH
|
||||||
*/
|
*/
|
||||||
string get_socket_path() {
|
string get_socket_path() {
|
||||||
string env_path;
|
string env_path;
|
||||||
|
|
||||||
if (!(env_path = env_util::get("BSPWM_SOCKET")).empty()) {
|
if (!(env_path = env_util::get("BSPWM_SOCKET")).empty()) {
|
||||||
@ -90,13 +85,13 @@ namespace bspwm_util {
|
|||||||
free(host);
|
free(host);
|
||||||
|
|
||||||
return sa.sun_path;
|
return sa.sun_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a payload object with properly formatted data
|
* Generate a payload object with properly formatted data
|
||||||
* ready to be sent to the bspwm ipc controller
|
* ready to be sent to the bspwm ipc controller
|
||||||
*/
|
*/
|
||||||
payload_t make_payload(const string& cmd) {
|
payload_t make_payload(const string& cmd) {
|
||||||
payload_t payload{new payload_t::element_type{}};
|
payload_t payload{new payload_t::element_type{}};
|
||||||
auto size = sizeof(payload->data);
|
auto size = sizeof(payload->data);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -109,9 +104,9 @@ namespace bspwm_util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an ipc socket connection
|
* Create an ipc socket connection
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
@ -120,11 +115,11 @@ namespace bspwm_util {
|
|||||||
* ipc->send(make_payload("desktop -f eDP-1:^1"));
|
* ipc->send(make_payload("desktop -f eDP-1:^1"));
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
connection_t make_connection() {
|
connection_t make_connection() {
|
||||||
return socket_util::make_unix_connection(get_socket_path());
|
return socket_util::make_unix_connection(get_socket_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a connection and subscribe to events
|
* Create a connection and subscribe to events
|
||||||
* on the bspwm socket
|
* on the bspwm socket
|
||||||
*
|
*
|
||||||
@ -139,14 +134,14 @@ namespace bspwm_util {
|
|||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
connection_t make_subscriber() {
|
connection_t make_subscriber() {
|
||||||
auto conn = make_connection();
|
auto conn = make_connection();
|
||||||
auto payload = make_payload("subscribe report");
|
auto payload = make_payload("subscribe report");
|
||||||
if (conn->send(payload->data, payload->len, 0) == 0) {
|
if (conn->send(payload->data, payload->len, 0) == 0) {
|
||||||
throw system_error("Failed to initialize subscriber");
|
throw system_error("Failed to initialize subscriber");
|
||||||
}
|
}
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
} // namespace bspwm_util
|
} // namespace bspwm_util
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -71,14 +71,8 @@ namespace i3_util {
|
|||||||
*
|
*
|
||||||
* Fixes the issue with always-on-top window's
|
* Fixes the issue with always-on-top window's
|
||||||
*/
|
*/
|
||||||
bool restack_to_root(connection& conn, const xcb_window_t win) {
|
xcb_window_t get_restack_sibling(connection& conn) {
|
||||||
const unsigned int value_mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE;
|
return root_window(conn);
|
||||||
const unsigned int value_list[2]{root_window(conn), XCB_STACK_MODE_ABOVE};
|
|
||||||
if (value_list[0] != XCB_NONE) {
|
|
||||||
conn.configure_window_checked(win, value_mask, value_list);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} // namespace i3_util
|
} // namespace i3_util
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user