Send IPC window events for focus and title changes

This patch fixes ticket #1168 to extend the window IPC event mechanism
to send IPC events for window focus and title changes. The newly added
window events use the same format as the already established "new"
event.

Specifically this patch:

* Moves the ipc_send_window_event() function from src/manage.c into
  src/ipc.c and adds an argument for the change property of the event
* Updates src/manage.c to use the new function signature. To ensure
  that the "new" event does not send the same event data as the
  "focus" event, setting focus now happens after the "new" event
  has been sent
* Adds IPC focus event notification to src/x.c. To workaround a problem
  during window close when accessing the window name, a function has been
  added to query whether a window is actually attached to its parent. To
  avoid obsolete focus notification, a new field has been added to keep
  track of the focus without any interference by the click handling
* Adds IPC title event notification to src/handlers.c. To avoid
  obsolete title notification, a function has been added to determine
  whether a window title has actually changed
* Updates the IPC documentation to include the new events
* Updates testcases/t/205-ipc-windows.t to include the "focus" event
  in order to ensure the correct event sequence
* Adds two new unit tests, b/testcases/t/219-ipc-window-focus.t and
  b/testcases/t/220-ipc-window-title.t to ensure proper "focus" and
 "title" events
This commit is contained in:
Marco Hunsicker
2014-02-22 11:52:01 +01:00
committed by Michael Stapelberg
parent 07d583d780
commit 00ee86de79
9 changed files with 278 additions and 45 deletions

33
src/x.c
View File

@ -15,6 +15,11 @@
/* Stores the X11 window ID of the currently focused window */
xcb_window_t focused_id = XCB_NONE;
/* Because 'focused_id' might be reset to force input focus (after click to
* raise), we separately keep track of the X11 window ID to be able to always
* tell whether the focused window actually changed. */
static xcb_window_t last_focused = XCB_NONE;
/* The bottom-to-top window stack of all windows which are managed by i3.
* Used for x_get_window_stack(). */
static xcb_window_t *btt_stack;
@ -232,7 +237,7 @@ void x_con_kill(Con *con) {
free(state);
/* Invalidate focused_id to correctly focus new windows with the same ID */
focused_id = XCB_NONE;
focused_id = last_focused = XCB_NONE;
}
/*
@ -848,6 +853,24 @@ static void x_push_node_unmaps(Con *con) {
x_push_node_unmaps(current);
}
/*
* Returns true if the given container is currently attached to its parent.
*
* TODO: Remove once #1185 has been fixed
*/
static bool is_con_attached(Con *con) {
if (con->parent == NULL)
return false;
Con *current;
TAILQ_FOREACH(current, &(con->parent->nodes_head), nodes) {
if (current == con)
return true;
}
return false;
}
/*
* Pushes all changes (state of each node, see x_push_node() and the window
* stack) to X11.
@ -972,6 +995,9 @@ void x_push_changes(Con *con) {
send_take_focus(to_focus);
set_focus = !focused->window->doesnt_accept_focus;
DLOG("set_focus = %d\n", set_focus);
if (!set_focus && to_focus != last_focused && is_con_attached(focused))
ipc_send_window_event("focus", focused);
}
if (set_focus) {
@ -990,9 +1016,12 @@ void x_push_changes(Con *con) {
}
ewmh_update_active_window(to_focus);
if (to_focus != XCB_NONE && to_focus != last_focused && focused->window != NULL && is_con_attached(focused))
ipc_send_window_event("focus", focused);
}
focused_id = to_focus;
focused_id = last_focused = to_focus;
}
}