# Depend on the object files of all source-files in src/*.c and on all header files
AUTOGENERATED:=src/cfgparse.tab.c src/cfgparse.yy.c
-FILES:=src/ipc.c src/nc.c src/log.c src/util.c src/tree.c src/xcb.c src/manage.c src/workspace.c src/x.c src/floating.c src/click.c src/config.c src/handlers.c src/randr.c src/xinerama.c src/con.c src/load_layout.c src/render.c
+FILES:=src/ipc.c src/nc.c src/log.c src/util.c src/tree.c src/xcb.c src/manage.c src/workspace.c src/x.c src/floating.c src/click.c src/config.c src/handlers.c src/randr.c src/xinerama.c src/con.c src/load_layout.c src/render.c src/window.c
FILES:=$(FILES:.c=.o)
HEADERS:=$(filter-out include/loglevels.h,$(wildcard include/*.h))
#include "con.h"
#include "load_layout.h"
#include "render.h"
+#include "window.h"
#endif
struct Window {
xcb_window_t id;
- const char *class;
+ const char *class_class;
+ const char *class_instance;
+ const char *name_ucs2;
+ const char *name_utf8;
+ int name_len;
+ bool uses_net_wm_name;
};
struct Match {
int handle_destroy_notify_event(void *data, xcb_connection_t *conn,
xcb_destroy_notify_event_t *event);
+#endif
/**
* Called when a window changes its title
*
int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
xcb_window_t window, xcb_atom_t atom,
xcb_get_property_reply_t *prop);
-
+#if 0
/**
* We handle legacy window names (titles) which are in COMPOUND_TEXT
* encoding. However, we just pass them along, so when containing non-ASCII
extern TAILQ_HEAD(assignments_head, Assignment) assignments;
extern SLIST_HEAD(stack_wins_head, Stack_Window) stack_wins;
extern xcb_event_handlers_t evenths;
+extern xcb_property_handlers_t prophs;
extern uint8_t root_depth;
extern bool xkb_supported;
extern xcb_atom_t atoms[NUM_ATOMS];
--- /dev/null
+#ifndef _WINDOW_H
+#define _WINDOW_H
+
+void window_update_class(i3Window *win, xcb_get_property_reply_t *prop);
+void window_update_name(i3Window *win, xcb_get_property_reply_t *prop);
+
+#endif
static bool match_matches_window(Match *match, i3Window *window) {
/* TODO: pcre, full matching, … */
- if (match->class != NULL && strcasecmp(match->class, window->class) == 0) {
- LOG("match made by window class (%s)\n", window->class);
+ if (match->class != NULL && strcasecmp(match->class, window->class_class) == 0) {
+ LOG("match made by window class (%s)\n", window->class_class);
return true;
}
+ if (match->instance != NULL && strcasecmp(match->instance, window->class_instance) == 0) {
+ LOG("match made by window instance (%s)\n", window->class_instance);
+ return true;
+ }
+
+
if (match->id != XCB_NONE && window->id == match->id) {
LOG("match made by window id (%d)\n", window->id);
return true;
}
- LOG("window %d (%s) could not be matched\n", window->id, window->class);
+ LOG("window %d (%s) could not be matched\n", window->id, window->class_class);
return false;
}
Con *con;
Match *match;
LOG("searching con for window %p\n", window);
- LOG("class == %s\n", window->class);
+ LOG("class == %s\n", window->class_class);
TAILQ_FOREACH(con, &all_cons, all_cons)
TAILQ_FOREACH(match, &(con->swallow_head), matches) {
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
- *
- * © 2009-2010 Michael Stapelberg and contributors
- *
- * See file LICENSE for license information.
+ * © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
*
*/
#include <time.h>
return handle_unmap_notify_event(NULL, conn, &unmap);
}
-
+#endif
/*
* Called when a window changes its title
*
*/
int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
- if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
- DLOG("_NET_WM_NAME not specified, not changing\n");
- return 1;
- }
- Client *client = table_get(&by_child, window);
- if (client == NULL)
- return 1;
-
- /* Save the old pointer to make the update atomic */
- char *new_name;
- int new_len;
- asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop));
- /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
- char *ucs2_name = convert_utf8_to_ucs2(new_name, &new_len);
- LOG("_NET_WM_NAME changed to \"%s\"\n", new_name);
- free(new_name);
-
- /* Check if they are the same and don’t update if so.
- Note the use of new_len * 2 to check all bytes as each glyph takes 2 bytes.
- Also note the use of memcmp() instead of strncmp() because the latter stops on nullbytes,
- but UCS-2 uses nullbytes to fill up glyphs which only use one byte. */
- if ((new_len == client->name_len) &&
- (client->name != NULL) &&
- (memcmp(client->name, ucs2_name, new_len * 2) == 0)) {
- free(ucs2_name);
- return 1;
- }
-
- char *old_name = client->name;
- client->name = ucs2_name;
- client->name_len = new_len;
- client->uses_net_wm_name = true;
+ Con *con;
+ if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
+ return 1;
- FREE(old_name);
+ window_update_name(con->window, prop);
- /* If the client is a dock window, we don’t need to render anything */
- if (client->dock)
- return 1;
+ x_push_changes(croot);
- int mode = container_mode(client->container, true);
- if (mode == MODE_STACK || mode == MODE_TABBED)
- render_container(conn, client->container);
- else decorate_window(conn, client, client->frame, client->titlegc, 0, 0);
- xcb_flush(conn);
-
- return 1;
+ return 1;
}
-
+#if 0
/*
* We handle legacy window names (titles) which are in COMPOUND_TEXT encoding. However, we
* just pass them along, so when containing non-ASCII characters, those will be rendering
return 1;
}
+#endif
/*
* Updates the client’s WM_CLASS property
*/
int handle_windowclass_change(void *data, xcb_connection_t *conn, uint8_t state,
xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
- if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
- DLOG("prop == NULL\n");
- return 1;
- }
- Client *client = table_get(&by_child, window);
- if (client == NULL)
- return 1;
-
- /* We cannot use asprintf here since this property contains two
- * null-terminated strings (for compatibility reasons). Instead, we
- * use strdup() on both strings */
- char *new_class = xcb_get_property_value(prop);
-
- FREE(client->window_class_instance);
- FREE(client->window_class_class);
+ Con *con;
+ if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
+ return 1;
- client->window_class_instance = strdup(new_class);
- if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
- client->window_class_class = strdup(new_class + strlen(new_class) + 1);
- else client->window_class_class = NULL;
- LOG("WM_CLASS changed to %s (instance), %s (class)\n",
- client->window_class_instance, client->window_class_class);
+ window_update_class(con->window, prop);
- return 0;
+ return 0;
}
+#if 0
/*
* Expose event means we should redraw our windows (= title bar)
*
for (i = 0; i < len; ++i)
manage_window(children[i], cookies[i], true);
-
free(reply);
free(cookies);
}
goto out;
LOG("reparenting!\n");
+ uint32_t mask = 0;
+ uint32_t values[1];
+ mask = XCB_CW_EVENT_MASK;
+ values[0] = CHILD_EVENT_MASK;
+ xcb_change_window_attributes(conn, window, mask, values);
i3Window *cwindow = scalloc(sizeof(i3Window));
cwindow->id = window;
- class_cookie = xcb_get_any_property_unchecked(conn, false, window, WM_CLASS, 128);
- xcb_get_property_reply_t *preply;
- preply = xcb_get_property_reply(conn, class_cookie, NULL);
- if (preply == NULL || xcb_get_property_value_length(preply) == 0) {
- LOG("cannot get wm_class\n");
- } else cwindow->class = strdup(xcb_get_property_value(preply));
+ /* update as much information as possible so far (some replies may be NULL) */
+ window_update_class(cwindow, xcb_get_property_reply(conn, class_cookie, NULL));
+ window_update_name(cwindow, xcb_get_property_reply(conn, utf8_title_cookie, NULL));
Con *nc;
Match *match;
geom->border_width);
#endif
- /* Generate callback events for every property we watch */
free(geom);
out:
free(attr);
xcb_connection_t *conn;
xcb_event_handlers_t evenths;
+xcb_property_handlers_t prophs;
xcb_atom_t atoms[NUM_ATOMS];
xcb_window_t root;
REQUEST_ATOM(_NET_ACTIVE_WINDOW);
REQUEST_ATOM(_NET_WORKAREA);
+ memset(&evenths, 0, sizeof(xcb_event_handlers_t));
+ memset(&prophs, 0, sizeof(xcb_property_handlers_t));
xcb_event_handlers_init(conn, &evenths);
+ xcb_property_handlers_init(&prophs, &evenths);
xcb_event_set_key_press_handler(&evenths, handle_key_press, NULL);
xcb_event_set_button_press_handler(&evenths, handle_button_press, NULL);
xcb_event_set_expose_handler(&evenths, handle_expose_event, NULL);
+
/* Setup NetWM atoms */
#define GET_ATOM(name) \
do { \
GET_ATOM(_NET_ACTIVE_WINDOW);
GET_ATOM(_NET_WORKAREA);
+ xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL);
+
keysyms = xcb_key_symbols_alloc(conn);
xcb_get_numlock_mask(conn);
#include "all.h"
-//static iconv_t conversion_descriptor = 0;
+static iconv_t conversion_descriptor = 0;
struct keyvalue_table_head by_parent = TAILQ_HEAD_INITIALIZER(by_parent);
struct keyvalue_table_head by_child = TAILQ_HEAD_INITIALIZER(by_child);
}
}
-#if 0
/*
* Converts the given string to UCS-2 big endian for use with
* xcb_image_text_16(). The amount of real glyphs is stored in real_strlen,
return buffer;
}
+#if 0
/*
* Returns the client which comes next in focus stack (= was selected before) for
--- /dev/null
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ * i3 - an improved dynamic tiling window manager
+ * © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
+ *
+ */
+#include "all.h"
+
+void window_update_class(i3Window *win, xcb_get_property_reply_t *prop) {
+ if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
+ DLOG("empty property, not updating\n");
+ return;
+ }
+
+ /* We cannot use asprintf here since this property contains two
+ * null-terminated strings (for compatibility reasons). Instead, we
+ * use strdup() on both strings */
+ char *new_class = xcb_get_property_value(prop);
+
+ FREE(win->class_instance);
+ FREE(win->class_class);
+
+ win->class_instance = strdup(new_class);
+ if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
+ win->class_class = strdup(new_class + strlen(new_class) + 1);
+ else win->class_class = NULL;
+ LOG("WM_CLASS changed to %s (instance), %s (class)\n",
+ win->class_instance, win->class_class);
+}
+
+void window_update_name(i3Window *win, xcb_get_property_reply_t *prop) {
+ if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
+ DLOG("_NET_WM_NAME not specified, not changing\n");
+ return 1;
+ }
+
+ /* Save the old pointer to make the update atomic */
+ int new_len;
+ asprintf(&win->name_utf8, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop));
+ /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
+ win->name_ucs2 = convert_utf8_to_ucs2(win->name_utf8, &win->name_len);
+ LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_utf8);
+
+ win->uses_net_wm_name = true;
+}
return;
}
- if (con->window->class == NULL) {
+ if (con->window->name_ucs2 == NULL) {
LOG("not rendering decoration, not yet known\n");
return;
}
- LOG("should render text %s onto %p / %s\n", con->window->class, parent, parent->name);
+ LOG("should render text %s onto %p / %s\n", con->window->name_utf8, parent, parent->name);
xcb_change_gc_single(conn, parent->gc, XCB_GC_FOREGROUND, get_colorpixel("#FFFFFF"));
- xcb_image_text_8(
+ xcb_image_text_16(
conn,
- strlen(con->window->class),
+ con->window->name_len,
parent->frame,
parent->gc,
con->deco_rect.x,
con->deco_rect.y + 14,
- con->window->class
+ (xcb_char2b_t*)con->window->name_ucs2
);
}