2016-11-19 03:03:18 +00:00
|
|
|
#include "x11/icccm.hpp"
|
2022-03-15 20:48:19 +00:00
|
|
|
|
2017-01-24 07:49:27 +00:00
|
|
|
#include "x11/atoms.hpp"
|
2016-11-19 03:03:18 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-11-19 03:03:18 +00:00
|
|
|
|
|
|
|
namespace icccm_util {
|
2017-01-24 07:49:27 +00:00
|
|
|
string get_wm_name(xcb_connection_t* c, xcb_window_t w) {
|
2016-12-15 08:29:14 +00:00
|
|
|
xcb_icccm_get_text_property_reply_t reply{};
|
2017-01-24 07:49:27 +00:00
|
|
|
if (xcb_icccm_get_wm_name_reply(c, xcb_icccm_get_wm_name(c, w), &reply, nullptr)) {
|
2016-11-30 12:38:40 +00:00
|
|
|
return get_reply_string(&reply);
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-30 12:38:40 +00:00
|
|
|
return "";
|
2016-11-19 03:03:18 +00:00
|
|
|
}
|
|
|
|
|
2022-10-02 10:13:32 +00:00
|
|
|
pair<string, string> get_wm_class(xcb_connection_t* c, xcb_window_t w) {
|
|
|
|
pair<string, string> result{"", ""};
|
|
|
|
xcb_icccm_get_wm_class_reply_t reply{};
|
|
|
|
if (xcb_icccm_get_wm_class_reply(c, xcb_icccm_get_wm_class(c, w), &reply, nullptr)) {
|
|
|
|
result = {string(reply.instance_name), string(reply.class_name)};
|
|
|
|
xcb_icccm_get_wm_class_reply_wipe(&reply);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-19 03:03:18 +00:00
|
|
|
string get_reply_string(xcb_icccm_get_text_property_reply_t* reply) {
|
2017-01-24 07:49:27 +00:00
|
|
|
string str;
|
|
|
|
if (reply) {
|
|
|
|
str = string(reply->name, reply->name_len);
|
|
|
|
xcb_icccm_get_text_property_reply_wipe(reply);
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-30 12:38:40 +00:00
|
|
|
return str;
|
2016-11-19 03:03:18 +00:00
|
|
|
}
|
2017-01-24 07:49:27 +00:00
|
|
|
|
|
|
|
void set_wm_name(xcb_connection_t* c, xcb_window_t w, const char* wmname, size_t l, const char* wmclass, size_t l2) {
|
|
|
|
xcb_icccm_set_wm_name(c, w, XCB_ATOM_STRING, 8, l, wmname);
|
|
|
|
xcb_icccm_set_wm_class(c, w, l2, wmclass);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_wm_protocols(xcb_connection_t* c, xcb_window_t w, vector<xcb_atom_t> flags) {
|
|
|
|
xcb_icccm_set_wm_protocols(c, w, WM_PROTOCOLS, flags.size(), flags.data());
|
|
|
|
}
|
2017-02-20 07:25:19 +00:00
|
|
|
|
|
|
|
bool get_wm_urgency(xcb_connection_t* c, xcb_window_t w) {
|
|
|
|
xcb_icccm_wm_hints_t hints;
|
|
|
|
if (xcb_icccm_get_wm_hints_reply(c, xcb_icccm_get_wm_hints(c, w), &hints, NULL)) {
|
2022-03-15 20:48:19 +00:00
|
|
|
if (xcb_icccm_wm_hints_get_urgency(&hints) == XCB_ICCCM_WM_HINT_X_URGENCY)
|
2017-02-20 07:25:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-21 20:23:52 +00:00
|
|
|
|
|
|
|
void set_wm_size_hints(xcb_connection_t* c, xcb_window_t w, int x, int y, int width, int height) {
|
2022-03-15 20:48:19 +00:00
|
|
|
xcb_size_hints_t hints{};
|
2022-02-21 20:23:52 +00:00
|
|
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, false, width, height);
|
|
|
|
xcb_icccm_size_hints_set_min_size(&hints, width, height);
|
|
|
|
xcb_icccm_size_hints_set_max_size(&hints, width, height);
|
|
|
|
xcb_icccm_size_hints_set_base_size(&hints, width, height);
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, false, x, y);
|
|
|
|
|
|
|
|
xcb_icccm_set_wm_size_hints(c, w, XCB_ATOM_WM_NORMAL_HINTS, &hints);
|
|
|
|
}
|
2022-03-15 20:48:19 +00:00
|
|
|
} // namespace icccm_util
|
2016-11-19 03:03:18 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|