polybar/src/x11/window.cpp

79 lines
2.2 KiB
C++
Raw Normal View History

#include "x11/window.hpp"
2016-12-26 08:40:15 +00:00
#include "components/types.hpp"
2016-12-31 14:42:46 +00:00
#include "utils/memory.hpp"
#include "x11/atoms.hpp"
2016-12-26 08:40:15 +00:00
#include "x11/connection.hpp"
#include "x11/extensions/randr.hpp"
2016-11-02 19:22:45 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-11-02 19:22:45 +00:00
/**
* Reconfigure the window geometry
*/
2017-01-19 10:11:28 +00:00
window window::reconfigure_geom(unsigned short int w, unsigned short int h, short int x, short int y) {
unsigned int mask{0};
unsigned int values[7]{0};
2016-12-15 08:29:14 +00:00
xcb_params_configure_window_t params{};
XCB_AUX_ADD_PARAM(&mask, &params, width, w);
XCB_AUX_ADD_PARAM(&mask, &params, height, h);
XCB_AUX_ADD_PARAM(&mask, &params, x, x);
XCB_AUX_ADD_PARAM(&mask, &params, y, y);
connection::pack_values(mask, &params, values);
configure_checked(mask, values);
return *this;
}
/**
* Reconfigure the window position
*/
2017-01-19 10:11:28 +00:00
window window::reconfigure_pos(short int x, short int y) {
unsigned int mask{0};
unsigned int values[2]{0};
2016-12-15 08:29:14 +00:00
xcb_params_configure_window_t params{};
XCB_AUX_ADD_PARAM(&mask, &params, x, x);
XCB_AUX_ADD_PARAM(&mask, &params, y, y);
connection::pack_values(mask, &params, values);
configure_checked(mask, values);
2016-11-02 19:22:45 +00:00
return *this;
}
/**
* Reconfigure the windows ewmh strut
*
* Ref: https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm45381391268672
*
* @param w Width of the bar window
* @param strut Size of the reserved space. Height of the window, corrected for unaligned monitors
* @param x The absolute x-position of the bar window (top-left corner)
* @param bottom Whether the bar is at the bottom of the screen
*/
window window::reconfigure_struts(uint32_t w, uint32_t strut, uint32_t x, bool bottom) {
std::array<uint32_t, 12> values{};
if (bottom) {
values[to_integral(strut::BOTTOM)] = strut;
values[to_integral(strut::BOTTOM_START_X)] = x;
values[to_integral(strut::BOTTOM_END_X)] = x + w - 1;
} else {
values[to_integral(strut::TOP)] = strut;
values[to_integral(strut::TOP_START_X)] = x;
values[to_integral(strut::TOP_END_X)] = x + w - 1;
}
2016-12-15 02:30:41 +00:00
connection().change_property_checked(
XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT, XCB_ATOM_CARDINAL, 32, 4, values.data());
connection().change_property_checked(
XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT_PARTIAL, XCB_ATOM_CARDINAL, 32, 12, values.data());
return *this;
}
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END