24 cairo_surface_destroy(win->
icon);
35 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
36 DLOG(
"WM_CLASS not set.\n");
44 const size_t prop_length = xcb_get_property_value_length(prop);
45 char *new_class = xcb_get_property_value(prop);
46 const size_t class_class_index = strnlen(new_class, prop_length) + 1;
52 if (class_class_index < prop_length) {
53 win->
class_class =
sstrndup(new_class + class_class_index, prop_length - class_class_index);
57 LOG(
"WM_CLASS changed to %s (instance), %s (class)\n",
69 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
70 DLOG(
"_NET_WM_NAME not specified, not changing\n");
78 const int len = xcb_get_property_value_length(prop);
79 char *name =
sstrndup(xcb_get_property_value(prop), len);
105 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
106 DLOG(
"WM_NAME not set (_NET_WM_NAME is what you want anyways).\n");
118 const int len = xcb_get_property_value_length(prop);
119 char *name =
sstrndup(xcb_get_property_value(prop), len);
131 LOG(
"Using legacy window title. Note that in order to get Unicode window "
132 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
145 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
154 const int len = xcb_get_property_value_length(prop);
155 char *qubes_vmname =
sstrndup(xcb_get_property_value(prop), len);
177 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
183 win->
qubes_label = *(
int*) xcb_get_property_value(prop);
201 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
202 DLOG(
"CLIENT_LEADER not set on window 0x%08x.\n", win->
id);
208 xcb_window_t *leader = xcb_get_property_value(prop);
209 if (leader == NULL) {
214 DLOG(
"Client leader changed to %08x\n", *leader);
226 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
227 DLOG(
"TRANSIENT_FOR not set on window 0x%08x.\n", win->
id);
233 xcb_window_t transient_for;
234 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
239 DLOG(
"Transient for changed to 0x%08x (window 0x%08x)\n", transient_for, win->
id);
251 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
252 DLOG(
"_NET_WM_STRUT_PARTIAL not set.\n");
258 if (!(strut = xcb_get_property_value(prop))) {
263 DLOG(
"Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
264 strut[0], strut[1], strut[2], strut[3]);
276 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
277 DLOG(
"WM_WINDOW_ROLE not set.\n");
283 sasprintf(&new_role,
"%.*s", xcb_get_property_value_length(prop),
284 (
char *)xcb_get_property_value(prop));
286 win->
role = new_role;
287 LOG(
"WM_WINDOW_ROLE changed to \"%s\"\n", win->
role);
299 if (new_type == XCB_NONE) {
300 DLOG(
"cannot read _NET_WM_WINDOW_TYPE from window.\n");
315 bool changed =
false;
316 xcb_size_hints_t size_hints;
321 success = xcb_icccm_get_wm_size_hints_from_reply(&size_hints, reply);
323 success = xcb_icccm_get_wm_normal_hints_reply(
conn, xcb_icccm_get_wm_normal_hints_unchecked(
conn, win->
id), &size_hints, NULL);
326 DLOG(
"Could not get WM_NORMAL_HINTS\n");
330#define ASSIGN_IF_CHANGED(original, new) \
332 if (original != new) { \
338 if ((size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)) {
339 DLOG(
"Minimum size: %d (width) x %d (height)\n", size_hints.min_width, size_hints.min_height);
345 if ((size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)) {
346 DLOG(
"Maximum size: %d (width) x %d (height)\n", size_hints.max_width, size_hints.max_height);
348 int max_width =
max(0, size_hints.max_width);
349 int max_height =
max(0, size_hints.max_height);
354 DLOG(
"Clearing maximum size\n");
360 if ((size_hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)) {
361 DLOG(
"Size increments: %d (width) x %d (height)\n", size_hints.width_inc, size_hints.height_inc);
363 if (size_hints.width_inc > 0 && size_hints.width_inc < 0xFFFF) {
369 if (size_hints.height_inc > 0 && size_hints.height_inc < 0xFFFF) {
375 DLOG(
"Clearing size increments\n");
382 if (size_hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE &&
384 DLOG(
"Base size: %d (width) x %d (height)\n", size_hints.base_width, size_hints.base_height);
389 DLOG(
"Clearing base size\n");
396 (size_hints.flags & XCB_ICCCM_SIZE_HINT_US_POSITION || size_hints.flags & XCB_ICCCM_SIZE_HINT_P_POSITION) &&
397 (size_hints.flags & XCB_ICCCM_SIZE_HINT_US_SIZE || size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)) {
398 DLOG(
"Setting geometry x=%d y=%d w=%d h=%d\n", size_hints.x, size_hints.y, size_hints.width, size_hints.height);
399 geom->x = size_hints.x;
400 geom->y = size_hints.y;
401 geom->width = size_hints.width;
402 geom->height = size_hints.height;
406 if (size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT &&
407 (size_hints.min_aspect_num >= 0) && (size_hints.min_aspect_den > 0) &&
408 (size_hints.max_aspect_num >= 0) && (size_hints.max_aspect_den > 0)) {
410 double min_aspect = (double)size_hints.min_aspect_num / size_hints.min_aspect_den;
411 double max_aspect = (double)size_hints.max_aspect_num / size_hints.max_aspect_den;
412 DLOG(
"Aspect ratio set: minimum %f, maximum %f\n", min_aspect, max_aspect);
422 DLOG(
"Clearing aspect ratios\n");
436 if (urgency_hint != NULL) {
437 *urgency_hint =
false;
440 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
441 DLOG(
"WM_HINTS not set.\n");
446 xcb_icccm_wm_hints_t hints;
448 if (!xcb_icccm_get_wm_hints_from_reply(&hints, prop)) {
449 DLOG(
"Could not get WM_HINTS\n");
454 if (hints.flags & XCB_ICCCM_WM_HINT_INPUT) {
456 LOG(
"WM_HINTS.input changed to \"%d\"\n", hints.input);
459 if (urgency_hint != NULL) {
460 *urgency_hint = (xcb_icccm_wm_hints_get_urgency(&hints) != 0);
470#define MWM_HINTS_FLAGS_FIELD 0
471#define MWM_HINTS_DECORATIONS_FIELD 2
473#define MWM_HINTS_DECORATIONS (1 << 1)
474#define MWM_DECOR_ALL (1 << 0)
475#define MWM_DECOR_BORDER (1 << 1)
476#define MWM_DECOR_TITLE (1 << 3)
525 assert(motif_border_style != NULL);
527 if (xcb_get_property_value_length(prop) == 0) {
541 uint32_t *motif_hints = (uint32_t *)xcb_get_property_value(prop);
552#undef MWM_HINTS_FLAGS_FIELD
553#undef MWM_HINTS_DECORATIONS_FIELD
554#undef MWM_HINTS_DECORATIONS
556#undef MWM_DECOR_BORDER
557#undef MWM_DECOR_TITLE
564 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
565 DLOG(
"WM_CLIENT_MACHINE not set.\n");
571 win->
machine =
sstrndup((
char *)xcb_get_property_value(prop), xcb_get_property_value_length(prop));
572 LOG(
"WM_CLIENT_MACHINE changed to \"%s\"\n", win->
machine);
578 uint32_t *data = NULL;
579 uint32_t width = 0, height = 0;
583 if (!prop || prop->type != XCB_ATOM_CARDINAL || prop->format != 32) {
584 DLOG(
"_NET_WM_ICON is not set\n");
589 uint32_t prop_value_len = xcb_get_property_value_length(prop);
590 uint32_t *prop_value = (uint32_t *)xcb_get_property_value(prop);
597 while (prop_value_len > (
sizeof(uint32_t) * 2) && prop_value &&
598 prop_value[0] && prop_value[1]) {
599 const uint32_t cur_width = prop_value[0];
600 const uint32_t cur_height = prop_value[1];
604 const uint64_t cur_len = cur_width * (uint64_t)cur_height;
605 const uint64_t expected_len = (cur_len + 2) * 4;
607 if (expected_len > prop_value_len) {
611 DLOG(
"Found _NET_WM_ICON of size: (%d,%d)\n", cur_width, cur_height);
613 const bool at_least_preferred_size = (cur_width >= pref_size &&
614 cur_height >= pref_size);
615 const bool smaller_than_current = (cur_width < width ||
616 cur_height < height);
617 const bool larger_than_current = (cur_width > width ||
618 cur_height > height);
619 const bool not_yet_at_preferred = (width < pref_size ||
622 (at_least_preferred_size &&
623 (smaller_than_current || not_yet_at_preferred)) ||
624 (!at_least_preferred_size &&
625 not_yet_at_preferred &&
626 larger_than_current)) {
633 if (width == pref_size && height == pref_size) {
638 prop_value_len -= expected_len;
639 prop_value = (uint32_t *)(((uint8_t *)prop_value) + expected_len);
643 DLOG(
"Could not get _NET_WM_ICON\n");
648 DLOG(
"Using icon of size (%d,%d) (preferred size: %d)\n",
649 width, height, pref_size);
653 uint32_t *icon =
smalloc(len * 4);
655 for (uint64_t i = 0; i < len; i++) {
657 const uint32_t pixel = data[2 + i];
658 a = (pixel >> 24) & 0xff;
659 r = (pixel >> 16) & 0xff;
660 g = (pixel >> 8) & 0xff;
661 b = (pixel >> 0) & 0xff;
668 icon[i] = ((uint32_t)a << 24) | (r << 16) | (g << 8) | b;
671 if (win->
icon != NULL) {
672 cairo_surface_destroy(win->
icon);
674 win->
icon = cairo_image_surface_create_for_data(
675 (
unsigned char *)icon,
680 static cairo_user_data_key_t free_data;
681 cairo_surface_set_user_data(win->
icon, &free_data, icon, free);
void ewmh_update_visible_name(xcb_window_t window, const char *name)
Updates _NET_WM_VISIBLE_NAME.
xcb_atom_t xcb_get_preferred_window_type(xcb_get_property_reply_t *reply)
Returns the first supported _NET_WM_WINDOW_TYPE atom.
void run_assignments(i3Window *window)
Checks the list of assignments for the given window and runs all matching ones (unless they have alre...
int render_deco_height(void)
Returns the height for the decorations.
xcb_connection_t * conn
XCB connection and root screen.
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists.
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
void window_update_qubes_label(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt)
Updates the qubes label by using _QUBES_LABEL (encoded in UTF-8) for the given window.
void window_update_icon(i3Window *win, xcb_get_property_reply_t *prop)
Updates the _NET_WM_ICON.
#define ASSIGN_IF_CHANGED(original, new)
void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *urgency_hint)
Updates the WM_HINTS (we only care about the input focus handling part).
void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop)
Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
void window_update_role(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_WINDOW_ROLE.
#define MWM_HINTS_DECORATIONS
void window_update_qubes_vmname(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt)
Updates the qubes vmname by using _QUBES_VMNAME (encoded in UTF-8) for the given window.
void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop)
Updates the name by using WM_NAME (encoded in COMPOUND_TEXT).
static border_style_t border_style_from_motif_value(uint32_t value)
void window_free(i3Window *win)
Frees an i3Window and all its members.
#define MWM_HINTS_FLAGS_FIELD
void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop)
Updates the TRANSIENT_FOR (logical parent window).
void window_update_machine(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_CLIENT_MACHINE.
void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop)
Updates the CLIENT_LEADER (logical parent window).
bool window_update_normal_hints(i3Window *win, xcb_get_property_reply_t *reply, xcb_get_geometry_reply_t *geom)
Updates the WM_NORMAL_HINTS.
#define MWM_HINTS_DECORATIONS_FIELD
void window_update_name(i3Window *win, xcb_get_property_reply_t *prop)
Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given window.
void window_update_class(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_CLASS (consisting of the class and instance) for the given window.
void window_update_type(i3Window *window, xcb_get_property_reply_t *reply)
Updates the _NET_WM_WINDOW_TYPE property.
bool window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style)
Updates the MOTIF_WM_HINTS.
struct _i3String i3String
Opaque data structure for storing strings.
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
void i3string_free(i3String *str)
Free an i3String.
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
char * sstrndup(const char *str, size_t size)
Safe-wrapper around strndup which exits if strndup returns NULL (meaning that there is no more memory...
#define I3STRING_FREE(str)
Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory.
i3String * i3string_from_utf8(const char *from_utf8)
Build an i3String from an UTF-8 encoded string.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
Stores the reserved pixels on each screen edge read from a _NET_WM_STRUT_PARTIAL.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
i3String * qubes_vmname
The name of the qubes vm.
bool uses_net_wm_name
Whether the application used _NET_WM_NAME.
i3String * name
The name of the window.
cairo_surface_t * icon
Window icon, as Cairo surface.
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
int qubes_label
The qubes label.
char * machine
WM_CLIENT_MACHINE of the window.
xcb_atom_t window_type
The _NET_WM_WINDOW_TYPE for this window.
Assignment ** ran_assignments
bool doesnt_accept_focus
Whether this window accepts focus.
xcb_window_t transient_for
char * role
The WM_WINDOW_ROLE of this window (for example, the pidgin buddy window sets "buddy list").
struct reservedpx reserved
Pixels the window reserves.
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
A 'Con' represents everything from the X11 root window down to a single X11 window.
char * title_format
The format with which the window's name should be displayed.