X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fhandlers.c;h=1daefbc912de21b21f93aeb9c33c6d3d6165e01f;hb=bf3cd41b5ddf1e757515ab5fbf811be56e5f69cc;hp=7a6ab8dbc620d4e997c2fccd4e35a7540bd5d8fa;hpb=fa3396b6ea1f456687791ab8bfaf211dba3bd4d7;p=i3%2Fi3 diff --git a/src/handlers.c b/src/handlers.c index 7a6ab8db..1daefbc9 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -4,7 +4,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * * handlers.c: Small handlers for various events (keypresses, focus changes, * …). @@ -16,7 +16,6 @@ #include #include #include -#include #define SN_API_NOT_YET_FROZEN 1 #include @@ -106,7 +105,7 @@ static void check_crossing_screen_boundary(uint32_t x, uint32_t y) { return; } - /* Focus the output on which the user moved his cursor */ + /* Focus the output on which the user moved their cursor */ Con *old_focused = focused; Con *next = con_descend_focused(output_get_content(output->con)); /* Since we are switching outputs, this *must* be a different workspace, so @@ -149,7 +148,7 @@ static void handle_enter_notify(xcb_enter_notify_event_t *event) { enter_child = true; } - /* If not, then the user moved his cursor to the root window. In that case, we adjust c_ws */ + /* If not, then the user moved their cursor to the root window. In that case, we adjust c_ws */ if (con == NULL) { DLOG("Getting screen at %d x %d\n", event->root_x, event->root_y); check_crossing_screen_boundary(event->root_x, event->root_y); @@ -215,7 +214,7 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) { /* Skip events where the pointer was over a child window, we are only * interested in events on the root window. */ - if (event->child != 0) + if (event->child != XCB_NONE) return; Con *con; @@ -228,7 +227,7 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) { if (config.disable_focus_follows_mouse) return; - if (con->layout != L_DEFAULT) + if (con->layout != L_DEFAULT && con->layout != L_SPLITV && con->layout != L_SPLITH) return; /* see over which rect the user is */ @@ -245,8 +244,6 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) { x_push_changes(croot); return; } - - return; } /* @@ -266,7 +263,7 @@ static void handle_mapping_notify(xcb_mapping_notify_event_t *event) { ungrab_all_keys(conn); translate_keysyms(); - grab_all_keys(conn, false); + grab_all_keys(conn); return; } @@ -651,18 +648,18 @@ static void handle_expose_event(xcb_expose_event_t *event) { return; } -#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 -#define _NET_WM_MOVERESIZE_SIZE_TOP 1 -#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2 -#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3 -#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4 -#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5 -#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6 -#define _NET_WM_MOVERESIZE_SIZE_LEFT 7 -#define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */ -#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */ -#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */ -#define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */ +#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 +#define _NET_WM_MOVERESIZE_SIZE_TOP 1 +#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2 +#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3 +#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4 +#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5 +#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6 +#define _NET_WM_MOVERESIZE_SIZE_LEFT 7 +#define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */ +#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */ +#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */ +#define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */ /* * Handle client messages (EWMH) @@ -743,16 +740,17 @@ static void handle_client_message(xcb_client_message_event_t *event) { workspace_show(ws); con_focus(con); } else { - /* If the request is from an application, only focus if the - * workspace is visible. Otherwise set the urgency hint. */ - if (workspace_is_visible(ws)) { - DLOG("Request to focus con on a visible workspace. Focusing con = %p\n", con); + /* Request is from an application. */ + + if (config.focus_on_window_activation == FOWA_FOCUS || (config.focus_on_window_activation == FOWA_SMART && workspace_is_visible(ws))) { + DLOG("Focusing con = %p\n", con); workspace_show(ws); con_focus(con); - } else { - DLOG("Request to focus con on a hidden workspace. Setting urgent con = %p\n", con); + } else if (config.focus_on_window_activation == FOWA_URGENT || (config.focus_on_window_activation == FOWA_SMART && !workspace_is_visible(ws))) { + DLOG("Marking con = %p urgent\n", con); con_set_urgency(con, true); - } + } else + DLOG("Ignoring request for con = %p.\n", con); } tree_render(); @@ -761,7 +759,7 @@ static void handle_client_message(xcb_client_message_event_t *event) { uint32_t rnd = event->data.data32[1]; DLOG("[i3 sync protocol] Sending random value %d back to X11 window 0x%08x\n", rnd, window); - void *reply = scalloc(32); + void *reply = scalloc(32, 1); xcb_client_message_event_t *ev = reply; ev->response_type = XCB_CLIENT_MESSAGE; @@ -874,12 +872,16 @@ static void handle_client_message(xcb_client_message_event_t *event) { .root_y = y_root, .event_x = x_root - (con->rect.x), .event_y = y_root - (con->rect.y)}; - if (direction == _NET_WM_MOVERESIZE_MOVE) { - floating_drag_window(con->parent, &fake); - } else if (direction >= _NET_WM_MOVERESIZE_SIZE_TOPLEFT && direction <= _NET_WM_MOVERESIZE_SIZE_LEFT) { - floating_resize_window(con->parent, FALSE, &fake); - } else { - DLOG("_NET_WM_MOVERESIZE direction %d not implemented\n", direction); + switch (direction) { + case _NET_WM_MOVERESIZE_MOVE: + floating_drag_window(con->parent, &fake); + break; + case _NET_WM_MOVERESIZE_SIZE_TOPLEFT... _NET_WM_MOVERESIZE_SIZE_LEFT: + floating_resize_window(con->parent, false, &fake); + break; + default: + DLOG("_NET_WM_MOVERESIZE direction %d not implemented\n", direction); + break; } } else { DLOG("unhandled clientmessage\n"); @@ -887,15 +889,15 @@ static void handle_client_message(xcb_client_message_event_t *event) { } } -#if 0 -int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, - xcb_atom_t atom, xcb_get_property_reply_t *property) { - /* TODO: Implement this one. To do this, implement a little test program which sleep(1)s - before changing this property. */ - ELOG("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n"); - return 0; +bool handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, + xcb_atom_t atom, xcb_get_property_reply_t *reply) { + Con *con; + if ((con = con_by_window_id(window)) == NULL || con->window == NULL) + return false; + + window_update_type(con->window, reply); + return true; } -#endif /* * Handles the size hints set by a window, but currently only the part necessary for displaying @@ -1159,6 +1161,87 @@ static bool handle_class_change(void *data, xcb_connection_t *conn, uint8_t stat return true; } +/* + * Handles the _NET_WM_STRUT_PARTIAL property for allocating space for dock clients. + * + */ +static bool handle_strut_partial_change(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, + xcb_atom_t name, xcb_get_property_reply_t *prop) { + DLOG("strut partial change for window 0x%08x\n", window); + + Con *con; + if ((con = con_by_window_id(window)) == NULL || con->window == NULL) { + return false; + } + + if (prop == NULL) { + xcb_generic_error_t *err = NULL; + xcb_get_property_cookie_t strut_cookie = xcb_get_property(conn, false, window, A__NET_WM_STRUT_PARTIAL, + XCB_GET_PROPERTY_TYPE_ANY, 0, UINT32_MAX); + prop = xcb_get_property_reply(conn, strut_cookie, &err); + + if (err != NULL) { + DLOG("got error when getting strut partial property: %d\n", err->error_code); + free(err); + return false; + } + + if (prop == NULL) { + return false; + } + } + + DLOG("That is con %p / %s\n", con, con->name); + + window_update_strut_partial(con->window, prop); + + /* we only handle this change for dock clients */ + if (con->parent == NULL || con->parent->type != CT_DOCKAREA) { + return true; + } + + Con *search_at = croot; + Con *output = con_get_output(con); + if (output != NULL) { + DLOG("Starting search at output %s\n", output->name); + search_at = output; + } + + /* find out the desired position of this dock window */ + if (con->window->reserved.top > 0 && con->window->reserved.bottom == 0) { + DLOG("Top dock client\n"); + con->window->dock = W_DOCK_TOP; + } else if (con->window->reserved.top == 0 && con->window->reserved.bottom > 0) { + DLOG("Bottom dock client\n"); + con->window->dock = W_DOCK_BOTTOM; + } else { + DLOG("Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n"); + if (con->geometry.y < (search_at->rect.height / 2)) { + DLOG("geom->y = %d < rect.height / 2 = %d, it is a top dock client\n", + con->geometry.y, (search_at->rect.height / 2)); + con->window->dock = W_DOCK_TOP; + } else { + DLOG("geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n", + con->geometry.y, (search_at->rect.height / 2)); + con->window->dock = W_DOCK_BOTTOM; + } + } + + /* find the dockarea */ + Con *dockarea = con_for_window(search_at, con->window, NULL); + assert(dockarea != NULL); + + /* attach the dock to the dock area */ + con_detach(con); + con->parent = dockarea; + TAILQ_INSERT_HEAD(&(dockarea->focus_head), con, focused); + TAILQ_INSERT_HEAD(&(dockarea->nodes_head), con, nodes); + + tree_render(); + + return true; +} + /* Returns false if the event could not be processed (e.g. the window could not * be found), true otherwise */ typedef bool (*cb_property_handler_t)(void *data, xcb_connection_t *c, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *property); @@ -1177,7 +1260,9 @@ static struct property_handler_t property_handlers[] = { {0, UINT_MAX, handle_clientleader_change}, {0, UINT_MAX, handle_transient_for}, {0, 128, handle_windowrole_change}, - {0, 128, handle_class_change}}; + {0, 128, handle_class_change}, + {0, UINT_MAX, handle_strut_partial_change}, + {0, UINT_MAX, handle_window_type}}; #define NUM_HANDLERS (sizeof(property_handlers) / sizeof(struct property_handler_t)) /* @@ -1196,6 +1281,8 @@ void property_handlers_init(void) { property_handlers[5].atom = XCB_ATOM_WM_TRANSIENT_FOR; property_handlers[6].atom = A_WM_WINDOW_ROLE; property_handlers[7].atom = XCB_ATOM_WM_CLASS; + property_handlers[8].atom = A__NET_WM_STRUT_PARTIAL; + property_handlers[9].atom = A__NET_WM_WINDOW_TYPE; } static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom) { @@ -1231,7 +1318,9 @@ static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom) * */ void handle_event(int type, xcb_generic_event_t *event) { - DLOG("event type %d, xkb_base %d\n", type, xkb_base); + if (type != XCB_MOTION_NOTIFY) + DLOG("event type %d, xkb_base %d\n", type, xkb_base); + if (randr_base > -1 && type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY) { handle_screen_change(event); @@ -1248,7 +1337,9 @@ void handle_event(int type, xcb_generic_event_t *event) { keysyms = xcb_key_symbols_alloc(conn); ungrab_all_keys(conn); translate_keysyms(); - grab_all_keys(conn, false); + grab_all_keys(conn); + if (((xcb_xkb_new_keyboard_notify_event_t *)event)->changed & XCB_XKB_NKN_DETAIL_KEYCODES) + (void)load_keymap(); } else if (state->xkbType == XCB_XKB_MAP_NOTIFY) { if (event_is_ignored(event->sequence, type)) { DLOG("Ignoring map notify event for sequence %d.\n", state->sequence); @@ -1259,26 +1350,16 @@ void handle_event(int type, xcb_generic_event_t *event) { keysyms = xcb_key_symbols_alloc(conn); ungrab_all_keys(conn); translate_keysyms(); - grab_all_keys(conn, false); + grab_all_keys(conn); + (void)load_keymap(); } } else if (state->xkbType == XCB_XKB_STATE_NOTIFY) { DLOG("xkb state group = %d\n", state->group); - - /* See The XKB Extension: Library Specification, section 14.1 */ - /* We check if the current group (each group contains - * two levels) has been changed. Mode_switch activates - * group XCB_XKB_GROUP_2 */ if (xkb_current_group == state->group) return; xkb_current_group = state->group; - if (state->group == XCB_XKB_GROUP_1) { - DLOG("Mode_switch disabled\n"); - ungrab_all_keys(conn); - grab_all_keys(conn, false); - } else { - DLOG("Mode_switch enabled\n"); - grab_all_keys(conn, true); - } + ungrab_all_keys(conn); + grab_all_keys(conn); } return; @@ -1315,7 +1396,7 @@ void handle_event(int type, xcb_generic_event_t *event) { handle_motion_notify((xcb_motion_notify_event_t *)event); break; - /* Enter window = user moved his mouse over the window */ + /* Enter window = user moved their mouse over the window */ case XCB_ENTER_NOTIFY: handle_enter_notify((xcb_enter_notify_event_t *)event); break;