#include <pcre.h>
#include <sys/time.h>
+#include "libi3.h"
#include "queue.h"
/*
char *class_class;
char *class_instance;
- /** The name of the window as it will be passed to X11 (in UCS2 if the
- * application supports _NET_WM_NAME, in COMPOUND_TEXT otherwise). */
- char *name_x;
+ /** The name of the window. */
+ i3String *name;
/** The WM_WINDOW_ROLE of this window (for example, the pidgin buddy window
* sets "buddy list"). Useful to match specific windows in assignments or
/** Flag to force re-rendering the decoration upon changes */
bool name_x_changed;
- /** The name of the window as used in JSON (in UTF-8 if the application
- * supports _NET_WM_NAME, in COMPOUND_TEXT otherwise) */
- char *name_json;
-
- /** The length of the name in glyphs (not bytes) */
- size_t name_len;
-
/** Whether the application used _NET_WM_NAME */
bool uses_net_wm_name;
dump_rect(gen, "geometry", con->geometry);
ystr("name");
- if (con->window && con->window->name_json)
- ystr(con->window->name_json);
+ if (con->window && con->window->name)
+ ystr(i3string_as_utf8(con->window->name));
else
ystr(con->name);
}
if (match->title != NULL) {
- if (window->name_json != NULL &&
- regex_matches(match->title, window->name_json)) {
- LOG("title matches (%s)\n", window->name_json);
+ if (window->name != NULL &&
+ regex_matches(match->title, i3string_as_utf8(window->name))) {
+ LOG("title matches (%s)\n", i3string_as_utf8(window->name));
} else {
return false;
}
}
FREE(con->window->class_class);
FREE(con->window->class_instance);
- FREE(con->window->name_x);
- FREE(con->window->name_json);
+ i3string_free(con->window->name);
free(con->window);
}
return;
}
- /* Save the old pointer to make the update atomic */
- char *new_name;
- if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
- (char*)xcb_get_property_value(prop)) == -1) {
- perror("asprintf()");
- DLOG("Could not get window name\n");
- free(prop);
- return;
- }
- /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
- size_t len;
- xcb_char2b_t *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
- if (ucs2_name == NULL) {
- LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
- FREE(new_name);
- free(prop);
- return;
- }
- FREE(win->name_x);
- FREE(win->name_json);
- win->name_json = new_name;
- win->name_x = (char*)ucs2_name;
- win->name_len = len;
+ i3string_free(win->name);
+ win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
+ xcb_get_property_value_length(prop));
win->name_x_changed = true;
- LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
+ LOG("_NET_WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
win->uses_net_wm_name = true;
return;
}
- char *new_name;
- if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
- (char*)xcb_get_property_value(prop)) == -1) {
- perror("asprintf()");
- DLOG("Could not get legacy window name\n");
- free(prop);
- return;
- }
+ i3string_free(win->name);
+ win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
+ xcb_get_property_value_length(prop));
- LOG("WM_NAME changed to \"%s\"\n", new_name);
+ LOG("WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
LOG("Using legacy window title. Note that in order to get Unicode window "
"titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
- FREE(win->name_x);
- FREE(win->name_json);
- win->name_x = new_name;
- win->name_json = sstrdup(new_name);
- win->name_len = strlen(new_name);
win->name_x_changed = true;
if (before_mgmt) {
int text_offset_y = (con->deco_rect.height - config.font.height) / 2;
struct Window *win = con->window;
- if (win == NULL || win->name_x == NULL) {
+ if (win == NULL || win->name == NULL) {
/* this is a non-leaf container, we need to make up a good description */
// TODO: use a good description instead of just "another container"
draw_text("another container", strlen("another container"), false,
//DLOG("indent_level = %d, indent_mult = %d\n", indent_level, indent_mult);
int indent_px = (indent_level * 5) * indent_mult;
- draw_text(win->name_x, win->name_len, win->uses_net_wm_name,
+ draw_text((char *)i3string_as_ucs2(win->name), i3string_get_num_glyphs(win->name), true,
parent->pixmap, parent->pm_gc,
con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y,
con->deco_rect.width - 2 - indent_px);