Handle legacy window titles by rendering them not unicode-compatible.
This commit is contained in:
parent
17bcdd8b0f
commit
cc2c63b860
|
@ -223,6 +223,10 @@ struct Client {
|
|||
|
||||
/* Name (= window title) */
|
||||
char *name;
|
||||
/* name_len stores the real string length (glyphs) of the window title if the client uses
|
||||
_NET_WM_NAME. Otherwise, it is set to -1 to indicate that name should be just passed
|
||||
to X as 8-bit string and therefore will not be rendered correctly. This behaviour is
|
||||
to support legacy applications which do not set _NET_WM_NAME */
|
||||
int name_len;
|
||||
|
||||
/* fullscreen is pretty obvious */
|
||||
|
|
|
@ -21,6 +21,8 @@ int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure
|
|||
int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_notify_event_t *event);
|
||||
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);
|
||||
int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t state,
|
||||
xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop);
|
||||
int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *event);
|
||||
int handle_client_message(void *data, xcb_connection_t *conn, xcb_client_message_event_t *event);
|
||||
int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
|
||||
|
|
|
@ -584,8 +584,8 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti
|
|||
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) {
|
||||
LOG("window's name changed.\n");
|
||||
if (prop == NULL) {
|
||||
LOG("prop == NULL\n");
|
||||
if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
|
||||
LOG("_NET_WM_NAME not specified, not changing\n");
|
||||
return 1;
|
||||
}
|
||||
Client *client = table_get(byChild, window);
|
||||
|
@ -632,6 +632,66 @@ int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
* incorrectly. In order to correctly render unicode window titles in i3, an application
|
||||
* has to set _NET_WM_NAME, which is in UTF-8 encoding.
|
||||
*
|
||||
* On every update, a message is put out to the user, so he may improve the situation and
|
||||
* update applications which display filenames in their title to correctly use
|
||||
* _NET_WM_NAME and therefore support unicode.
|
||||
*
|
||||
*/
|
||||
int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t state,
|
||||
xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
|
||||
LOG("window's name changed (legacy).\n");
|
||||
if (prop == NULL) {
|
||||
LOG("prop == NULL\n");
|
||||
return 1;
|
||||
}
|
||||
Client *client = table_get(byChild, 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 */
|
||||
LOG("Name should change to \"%s\"\n", new_name);
|
||||
|
||||
/* Check if they are the same and don’t update if so. */
|
||||
if (client->name != NULL &&
|
||||
strlen(new_name) == strlen(client->name) &&
|
||||
strcmp(client->name, new_name) == 0) {
|
||||
LOG("Name did not change, not updating\n");
|
||||
free(new_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
LOG("Using legacy window title. Note that in order to get Unicode window titles in i3,"
|
||||
"the application has to set _NET_WM_NAME which is in UTF-8 encoding.\n");
|
||||
|
||||
char *old_name = client->name;
|
||||
client->name = new_name;
|
||||
client->name_len = -1;
|
||||
|
||||
if (old_name != NULL)
|
||||
free(old_name);
|
||||
|
||||
/* If the client is a dock window, we don’t need to render anything */
|
||||
if (client->dock)
|
||||
return 1;
|
||||
|
||||
if (client->container->mode == MODE_STACK)
|
||||
render_container(conn, client->container);
|
||||
else decorate_window(conn, client, client->frame, client->titlegc, 0);
|
||||
xcb_flush(conn);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expose event means we should redraw our windows (= title bar)
|
||||
*
|
||||
|
|
|
@ -169,6 +169,13 @@ void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t draw
|
|||
uint32_t values[] = { text_color, background_color, font->id };
|
||||
xcb_change_gc(conn, gc, mask, values);
|
||||
|
||||
/* name_len == -1 means this is a legacy application which does not specify _NET_WM_NAME,
|
||||
and we don’t handle the old window name (COMPOUND_TEXT) but only _NET_WM_NAME, which
|
||||
is UTF-8 */
|
||||
if (client->name_len == -1)
|
||||
xcb_image_text_8(conn, strlen(client->name), drawable, gc, 3 /* X */,
|
||||
offset + font->height /* Y = baseline of font */, client->name);
|
||||
else
|
||||
xcb_image_text_16(conn, client->name_len, drawable, gc, 3 /* X */,
|
||||
offset + font->height /* Y = baseline of font */, (xcb_char2b_t*)client->name);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *conn, xcb_
|
|||
if (attr && geom) {
|
||||
reparent_window(conn, window, attr->visual, geom->root, geom->depth,
|
||||
geom->x, geom->y, geom->width, geom->height);
|
||||
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NAME);
|
||||
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, atoms[_NET_WM_NAME]);
|
||||
}
|
||||
|
||||
|
@ -467,6 +468,9 @@ int main(int argc, char *argv[], char *env[]) {
|
|||
/* Watch _NET_WM_NAME (= title of the window in UTF-8) property */
|
||||
xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL);
|
||||
|
||||
/* Watch WM_NAME (= title of the window in compound text) property for legacy applications */
|
||||
xcb_watch_wm_name(&prophs, 128, handle_windowname_change_legacy, NULL);
|
||||
|
||||
/* Set up the atoms we support */
|
||||
check_error(conn, xcb_change_property_checked(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTED],
|
||||
ATOM, 32, 7, atoms), "Could not set _NET_SUPPORTED");
|
||||
|
|
Loading…
Reference in New Issue