correctly update/display window title/class
This commit is contained in:
parent
bcfb0d2505
commit
fd8735a6fd
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ include $(TOPDIR)/common.mk
|
|||
|
||||
# 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))
|
||||
|
||||
|
|
|
@ -48,5 +48,6 @@
|
|||
#include "con.h"
|
||||
#include "load_layout.h"
|
||||
#include "render.h"
|
||||
#include "window.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -247,7 +247,12 @@ struct xoutput {
|
|||
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 {
|
||||
|
|
|
@ -107,6 +107,7 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti
|
|||
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
|
||||
*
|
||||
|
@ -114,7 +115,7 @@ int handle_destroy_notify_event(void *data, xcb_connection_t *conn,
|
|||
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
|
||||
|
|
|
@ -33,6 +33,7 @@ extern TAILQ_HEAD(autostarts_head, Autostart) autostarts;
|
|||
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];
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#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
|
14
src/con.c
14
src/con.c
|
@ -184,17 +184,23 @@ Con *con_by_frame_id(xcb_window_t frame) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -208,7 +214,7 @@ Con *con_for_window(i3Window *window, Match **store_match) {
|
|||
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) {
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
* 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>
|
||||
|
@ -568,61 +565,24 @@ int handle_destroy_notify_event(void *data, xcb_connection_t *conn, xcb_destroy_
|
|||
|
||||
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;
|
||||
|
||||
FREE(old_name);
|
||||
|
||||
/* If the client is a dock window, we don’t need to render anything */
|
||||
if (client->dock)
|
||||
return 1;
|
||||
|
||||
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);
|
||||
|
||||
Con *con;
|
||||
if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
|
||||
return 1;
|
||||
}
|
||||
|
||||
window_update_name(con->window, prop);
|
||||
|
||||
x_push_changes(croot);
|
||||
|
||||
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
|
||||
|
@ -689,6 +649,7 @@ int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t
|
|||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Updates the client’s WM_CLASS property
|
||||
|
@ -696,32 +657,16 @@ int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t
|
|||
*/
|
||||
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;
|
||||
Con *con;
|
||||
if ((con = con_by_window_id(window)) == NULL || con->window == 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);
|
||||
window_update_class(con->window, prop);
|
||||
|
||||
FREE(client->window_class_instance);
|
||||
FREE(client->window_class_class);
|
||||
|
||||
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);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Expose event means we should redraw our windows (= title bar)
|
||||
*
|
||||
|
|
16
src/manage.c
16
src/manage.c
|
@ -37,7 +37,6 @@ void manage_existing_windows(xcb_window_t root) {
|
|||
for (i = 0; i < len; ++i)
|
||||
manage_window(children[i], cookies[i], true);
|
||||
|
||||
|
||||
free(reply);
|
||||
free(cookies);
|
||||
}
|
||||
|
@ -119,16 +118,18 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
|||
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;
|
||||
|
@ -176,7 +177,6 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
|||
geom->border_width);
|
||||
#endif
|
||||
|
||||
/* Generate callback events for every property we watch */
|
||||
free(geom);
|
||||
out:
|
||||
free(attr);
|
||||
|
|
7
src/nc.c
7
src/nc.c
|
@ -14,6 +14,7 @@ char **start_argv;
|
|||
|
||||
xcb_connection_t *conn;
|
||||
xcb_event_handlers_t evenths;
|
||||
xcb_property_handlers_t prophs;
|
||||
xcb_atom_t atoms[NUM_ATOMS];
|
||||
|
||||
xcb_window_t root;
|
||||
|
@ -295,8 +296,11 @@ int main(int argc, char *argv[]) {
|
|||
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);
|
||||
|
@ -308,6 +312,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
xcb_event_set_expose_handler(&evenths, handle_expose_event, NULL);
|
||||
|
||||
|
||||
/* Setup NetWM atoms */
|
||||
#define GET_ATOM(name) \
|
||||
do { \
|
||||
|
@ -342,6 +347,8 @@ int main(int argc, char *argv[]) {
|
|||
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);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#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);
|
||||
|
||||
|
@ -158,7 +158,6 @@ void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_mes
|
|||
}
|
||||
}
|
||||
|
||||
#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,
|
||||
|
@ -202,6 +201,7 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
|
|||
|
||||
return buffer;
|
||||
}
|
||||
#if 0
|
||||
|
||||
/*
|
||||
* Returns the client which comes next in focus stack (= was selected before) for
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
10
src/x.c
10
src/x.c
|
@ -157,23 +157,23 @@ void x_draw_decoration(Con *con) {
|
|||
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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue