2016-11-12 11:56:39 +00:00
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
2016-11-13 15:10:20 +00:00
|
|
|
#include "utils/math.hpp"
|
|
|
|
#include "x11/atoms.hpp"
|
2016-11-02 19:22:45 +00:00
|
|
|
#include "x11/window.hpp"
|
|
|
|
#include "x11/xutils.hpp"
|
|
|
|
|
2016-11-13 15:10:20 +00:00
|
|
|
#include "components/types.hpp"
|
2016-11-25 07:42:31 +00:00
|
|
|
#include "x11/color.hpp"
|
2016-11-13 15:10:20 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-19 03:03:18 +00:00
|
|
|
/**
|
|
|
|
* Create window and check for errors
|
|
|
|
*/
|
2016-11-12 11:56:39 +00:00
|
|
|
window window::create_checked(int16_t x, int16_t y, uint16_t w, uint16_t h, uint32_t mask, const xcb_params_cw_t* p) {
|
2016-11-19 03:03:18 +00:00
|
|
|
auto conn = connection();
|
|
|
|
|
2016-11-12 11:56:39 +00:00
|
|
|
if (*this == XCB_NONE) {
|
2016-11-19 03:03:18 +00:00
|
|
|
*this = conn.generate_id();
|
2016-11-12 11:56:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-20 22:29:42 +00:00
|
|
|
auto root = conn.screen()->root;
|
|
|
|
auto copy = XCB_COPY_FROM_PARENT;
|
2016-11-13 20:50:21 +00:00
|
|
|
uint32_t values[16]{0};
|
2016-11-12 11:56:39 +00:00
|
|
|
xutils::pack_values(mask, p, values);
|
2016-11-19 03:03:18 +00:00
|
|
|
conn.create_window_checked(copy, *this, root, x, y, w, h, 0, copy, copy, mask, values);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the window event mask
|
|
|
|
*/
|
|
|
|
window window::change_event_mask(uint32_t mask) {
|
|
|
|
change_attributes_checked(XCB_CW_EVENT_MASK, &mask);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add given event to the event mask unless already added
|
|
|
|
*/
|
|
|
|
window window::ensure_event_mask(uint32_t event) {
|
|
|
|
auto attributes = get_attributes();
|
|
|
|
|
|
|
|
if ((attributes->your_event_mask & event) != event) {
|
|
|
|
change_event_mask(attributes->your_event_mask | event);
|
|
|
|
}
|
2016-11-12 11:56:39 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-11-19 03:03:18 +00:00
|
|
|
/**
|
|
|
|
* Reconfigure the window geometry
|
|
|
|
*/
|
2016-11-12 11:56:39 +00:00
|
|
|
window window::reconfigure_geom(uint16_t w, uint16_t h, int16_t x, int16_t y) {
|
2016-11-13 20:50:21 +00:00
|
|
|
uint32_t mask{0};
|
|
|
|
uint32_t values[7]{0};
|
2016-11-12 11:56:39 +00:00
|
|
|
|
|
|
|
xcb_params_configure_window_t params;
|
|
|
|
XCB_AUX_ADD_PARAM(&mask, ¶ms, width, w);
|
|
|
|
XCB_AUX_ADD_PARAM(&mask, ¶ms, height, h);
|
|
|
|
XCB_AUX_ADD_PARAM(&mask, ¶ms, x, x);
|
|
|
|
XCB_AUX_ADD_PARAM(&mask, ¶ms, y, y);
|
|
|
|
|
|
|
|
xutils::pack_values(mask, ¶ms, values);
|
2016-11-19 03:03:18 +00:00
|
|
|
configure_checked(mask, values);
|
2016-11-12 11:56:39 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-11-19 03:03:18 +00:00
|
|
|
/**
|
|
|
|
* Reconfigure the window position
|
|
|
|
*/
|
2016-11-12 11:56:39 +00:00
|
|
|
window window::reconfigure_pos(int16_t x, int16_t y) {
|
2016-11-13 20:50:21 +00:00
|
|
|
uint32_t mask{0};
|
|
|
|
uint32_t values[2]{0};
|
2016-11-12 11:56:39 +00:00
|
|
|
|
|
|
|
xcb_params_configure_window_t params;
|
|
|
|
XCB_AUX_ADD_PARAM(&mask, ¶ms, x, x);
|
|
|
|
XCB_AUX_ADD_PARAM(&mask, ¶ms, y, y);
|
|
|
|
|
|
|
|
xutils::pack_values(mask, ¶ms, values);
|
2016-11-19 03:03:18 +00:00
|
|
|
configure_checked(mask, values);
|
2016-11-12 11:56:39 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-11-19 03:03:18 +00:00
|
|
|
/**
|
|
|
|
* Reconfigure the windows ewmh strut
|
|
|
|
*/
|
2016-11-13 20:50:21 +00:00
|
|
|
window window::reconfigure_struts(uint16_t w, uint16_t h, int16_t x, bool bottom) {
|
2016-11-13 15:10:20 +00:00
|
|
|
auto& conn = connection();
|
|
|
|
|
|
|
|
uint32_t none{0};
|
2016-11-13 20:50:21 +00:00
|
|
|
uint32_t values[12]{none};
|
2016-11-13 15:10:20 +00:00
|
|
|
|
|
|
|
if (bottom) {
|
2016-11-13 20:50:21 +00:00
|
|
|
values[static_cast<int>(strut::BOTTOM)] = h;
|
|
|
|
values[static_cast<int>(strut::BOTTOM_START_X)] = x;
|
2016-11-16 11:00:18 +00:00
|
|
|
values[static_cast<int>(strut::BOTTOM_END_X)] = x + w - 1;
|
2016-11-13 15:10:20 +00:00
|
|
|
} else {
|
2016-11-13 20:50:21 +00:00
|
|
|
values[static_cast<int>(strut::TOP)] = h;
|
|
|
|
values[static_cast<int>(strut::TOP_START_X)] = x;
|
2016-11-16 11:00:18 +00:00
|
|
|
values[static_cast<int>(strut::TOP_END_X)] = x + w - 1;
|
2016-11-13 15:10:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-13 20:50:21 +00:00
|
|
|
conn.change_property_checked(XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT, XCB_ATOM_CARDINAL, 32, 4, values);
|
|
|
|
conn.change_property_checked(XCB_PROP_MODE_REPLACE, *this, _NET_WM_STRUT_PARTIAL, XCB_ATOM_CARDINAL, 32, 12, values);
|
2016-11-13 15:10:20 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-11-19 03:03:18 +00:00
|
|
|
/**
|
|
|
|
* Trigger redraw by toggling visibility state
|
|
|
|
*/
|
2016-11-12 11:56:39 +00:00
|
|
|
void window::redraw() {
|
2016-11-19 03:03:18 +00:00
|
|
|
auto conn = connection();
|
|
|
|
xutils::visibility_notify(conn, *this, XCB_VISIBILITY_FULLY_OBSCURED);
|
|
|
|
xutils::visibility_notify(conn, *this, XCB_VISIBILITY_UNOBSCURED);
|
|
|
|
conn.flush();
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|