1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00
polybar/src/utils/i3.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

2016-11-02 15:22:45 -04:00
#include <xcb/xcb.h>
#include <i3ipc++/ipc.hpp>
#include "common.hpp"
#include "config.hpp"
#include "utils/i3.hpp"
#include "utils/socket.hpp"
#include "utils/string.hpp"
2016-11-26 00:13:20 -05:00
#include "x11/connection.hpp"
2016-11-30 10:56:48 -05:00
#include "x11/icccm.hpp"
2016-11-02 15:22:45 -04:00
2016-11-19 00:22:44 -05:00
POLYBAR_NS
2016-11-02 15:22:45 -04:00
namespace i3_util {
2016-12-13 22:42:21 -05:00
/**
* Get all workspaces for given output
*/
vector<shared_ptr<workspace_t>> workspaces(const connection_t& conn, const string& output) {
vector<shared_ptr<workspace_t>> result;
for (auto&& ws : conn.get_workspaces()) {
if (output.empty() || ws->output == output) {
result.emplace_back(forward<decltype(ws)>(ws));
}
}
return result;
}
/**
* Get currently focused workspace
*/
shared_ptr<workspace_t> focused_workspace(const connection_t& conn) {
for (auto&& ws : conn.get_workspaces()) {
if (ws->focused) {
return ws;
}
}
return nullptr;
}
2016-11-02 15:22:45 -04:00
/**
* Get all i3 root windows
*/
2016-11-25 07:55:15 -05:00
vector<xcb_window_t> root_windows(connection& conn, const string& output_name) {
2016-11-02 15:22:45 -04:00
vector<xcb_window_t> roots;
auto children = conn.query_tree(conn.screen()->root).children();
for (auto it = children.begin(); it != children.end(); it++) {
2016-11-30 10:56:48 -05:00
auto wm_name = icccm_util::get_wm_name(conn, *it);
if (wm_name.compare("[i3 con] output " + output_name) == 0) {
roots.emplace_back(*it);
2016-11-18 22:06:05 -05:00
}
2016-11-02 15:22:45 -04:00
}
return roots;
}
/**
* Restack given window above the i3 root window
* defined for the given monitor
*
* Fixes the issue with always-on-top window's
*/
bool restack_above_root(connection& conn, const monitor_t& mon, const xcb_window_t win) {
for (auto&& root : root_windows(conn, mon->name)) {
const uint32_t value_mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE;
const uint32_t value_list[2]{root, XCB_STACK_MODE_ABOVE};
conn.configure_window_checked(win, value_mask, value_list);
return true;
}
return false;
}
}
2016-11-19 00:22:44 -05:00
POLYBAR_NS_END