diff --git a/event.c b/event.c index 9d730ddc8..ddda3a6d4 100644 --- a/event.c +++ b/event.c @@ -586,24 +586,38 @@ event_handle_leavenotify(xcb_leave_notify_event_t *ev) * Ignore events with non-normal modes. Those are because a grab * activated/deactivated. Everything will be "back to normal" after the * grab. - * - * Also ignore events with detail "inferior". This means that the window was - * left for a child window, i.e. the pointer is basically still inside of - * our window. */ - if(ev->mode != XCB_NOTIFY_MODE_NORMAL || ev->detail == XCB_NOTIFY_DETAIL_INFERIOR) + if(ev->mode != XCB_NOTIFY_MODE_NORMAL) return; if((c = client_getbyframewin(ev->event))) { - luaA_object_push(L, c); - luaA_object_emit_signal(L, -1, "mouse::leave", 0); + /* The window was left in some way, so definitely no titlebar has the + * mouse cursor. + */ + lua_pushnil(L); + event_drawable_under_mouse(L, -1); + lua_pop(L, 1); + + /* If detail is inferior, it means that the cursor is now in some child + * window of our window. Thus, the titlebar was left, but now the cursor + * is in the actual child window. Thus, ignore detail=Inferior for + * leaving client windows. + */ + if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR) { + luaA_object_push(L, c); + luaA_object_emit_signal(L, -1, "mouse::leave", 0); + lua_pop(L, 1); + } + } else if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR) { + /* Some window was left. This must be a drawin. Ignore detail=Inferior, + * because this means that some child window now contains the mouse + * cursor, i.e. a systray window. Everything else is a real 'leave'. + */ + lua_pushnil(L); + event_drawable_under_mouse(L, -1); lua_pop(L, 1); } - - lua_pushnil(L); - event_drawable_under_mouse(L, -1); - lua_pop(L, 1); } /** The enter notify event handler. @@ -622,15 +636,20 @@ event_handle_enternotify(xcb_enter_notify_event_t *ev) * Ignore events with non-normal modes. Those are because a grab * activated/deactivated. Everything will be "back to normal" after the * grab. - * - * Also ignore events with detail "inferior". This means that the cursor was - * previously inside of a child window and now left that child window. For - * our purposes, the cursor was already inside our window before. */ - if(ev->mode != XCB_NOTIFY_MODE_NORMAL || ev->detail == XCB_NOTIFY_DETAIL_INFERIOR) + if(ev->mode != XCB_NOTIFY_MODE_NORMAL) return; - if((drawin = drawin_getbywin(ev->event))) + /* + * We ignore events with detail "inferior". This detail means that the + * cursor was previously inside of a child window and now left that child + * window. For our purposes, the cursor was already inside our window + * before. + * One exception are titlebars: They are not their own window, but are + * "outside of the actual client window". + */ + + if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR && (drawin = drawin_getbywin(ev->event))) { luaA_object_push(L, drawin); luaA_object_push_item(L, -1, drawin->drawable); @@ -641,18 +660,25 @@ event_handle_enternotify(xcb_enter_notify_event_t *ev) if((c = client_getbyframewin(ev->event))) { luaA_object_push(L, c); - luaA_object_emit_signal(L, -1, "mouse::enter", 0); + /* Detail=Inferior means that a child of the frame window now contains + * the mouse cursor, i.e. the actual client now has the cursor. All + * other details mean that the client itself was really left. + */ + if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR) { + luaA_object_emit_signal(L, -1, "mouse::enter", 0); + } drawable_t *d = client_get_drawable(c, ev->event_x, ev->event_y); if (d) { luaA_object_push_item(L, -1, d); - event_drawable_under_mouse(L, -1); - lua_pop(L, 1); + } else { + lua_pushnil(L); } - lua_pop(L, 1); + event_drawable_under_mouse(L, -1); + lua_pop(L, 2); } - else if (ev->event == globalconf.screen->root) { + else if (ev->detail != XCB_NOTIFY_DETAIL_INFERIOR && ev->event == globalconf.screen->root) { /* When there are multiple X screens with awesome running separate * instances, reset focus. */