diff --git a/CHANGELOG.md b/CHANGELOG.md index 25c2c1e1..619fb17a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Hide power indicator from the status-bar if a battery could not be found [#60](https://github.com/koekeishiya/yabai/issues/60) - Disable focus follows mouse while the *mouse_modifier* key is held down [#62](https://github.com/koekeishiya/yabai/issues/62) - Silence meaningless warning reported by the scripting-bridge framework [#55](https://github.com/koekeishiya/yabai/issues/55) +- Extend definition of *WINDOW_SEL* to include *mouse*, targetting the window below the cursor [#66](https://github.com/koekeishiya/yabai/issues/66) ## [1.0.1] - 2019-06-23 ### Added diff --git a/doc/yabai.1 b/doc/yabai.1 index 325b65bb..3259d9e8 100644 --- a/doc/yabai.1 +++ b/doc/yabai.1 @@ -78,7 +78,7 @@ Loads the scripting\-addition into Dock.app. .nf DIR_SEL := north | east | south | west -WINDOW_SEL := prev | next | last | DIR_SEL +WINDOW_SEL := prev | next | last | mouse | DIR_SEL DISPLAY_SEL := prev | next | last | arrangement index (1\-based) diff --git a/doc/yabai.asciidoc b/doc/yabai.asciidoc index 048f283b..3216e77d 100644 --- a/doc/yabai.asciidoc +++ b/doc/yabai.asciidoc @@ -61,7 +61,7 @@ Definitions ---- DIR_SEL := north | east | south | west -WINDOW_SEL := prev | next | last | DIR_SEL +WINDOW_SEL := prev | next | last | mouse | DIR_SEL DISPLAY_SEL := prev | next | last | arrangement index (1-based) diff --git a/src/message.c b/src/message.c index 08d78058..e558a3f9 100644 --- a/src/message.c +++ b/src/message.c @@ -141,13 +141,14 @@ static const char *bool_str[] = { "off", "on" }; #define COMMAND_WINDOW_DISPLAY "--display" #define COMMAND_WINDOW_SPACE "--space" -#define ARGUMENT_WINDOW_SEL_PREV "prev" -#define ARGUMENT_WINDOW_SEL_NEXT "next" -#define ARGUMENT_WINDOW_SEL_LAST "last" #define ARGUMENT_WINDOW_DIR_NORTH "north" #define ARGUMENT_WINDOW_DIR_EAST "east" #define ARGUMENT_WINDOW_DIR_SOUTH "south" #define ARGUMENT_WINDOW_DIR_WEST "west" +#define ARGUMENT_WINDOW_SEL_MOUSE "mouse" +#define ARGUMENT_WINDOW_SEL_PREV "prev" +#define ARGUMENT_WINDOW_SEL_NEXT "next" +#define ARGUMENT_WINDOW_SEL_LAST "last" #define ARGUMENT_WINDOW_GRID "%d:%d:%d:%d:%d:%d" #define ARGUMENT_WINDOW_MOVE "%255[^:]:%f:%f" #define ARGUMENT_WINDOW_RESIZE "%255[^:]:%f:%f" @@ -946,6 +947,13 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) } else { daemon_fail(rsp, "could not locate the selected window.\n"); } + } else if (token_equals(value, ARGUMENT_WINDOW_SEL_MOUSE)) { + struct ax_window *mouse_window = window_manager_find_window_below_cursor(&g_window_manager); + if (mouse_window) { + window_manager_focus_window_with_raise(mouse_window->id); + } else { + daemon_fail(rsp, "could not locate a window below the cursor.\n"); + } } else if (token_equals(value, ARGUMENT_WINDOW_SEL_PREV)) { if (window) { struct ax_window *prev_window = window_manager_find_prev_managed_window(&g_space_manager, &g_window_manager, window); diff --git a/src/window_manager.c b/src/window_manager.c index cb1efb88..996e76b4 100644 --- a/src/window_manager.c +++ b/src/window_manager.c @@ -501,6 +501,13 @@ struct ax_window *window_manager_find_window_at_point(struct window_manager *wm, return window_manager_find_window(wm, window_id); } +struct ax_window *window_manager_find_window_below_cursor(struct window_manager *wm) +{ + CGPoint cursor; + SLSGetCurrentCursorLocation(g_connection, &cursor); + return window_manager_find_window_at_point(wm, cursor); +} + static struct ax_window *window_manager_find_closest_window_for_direction_in_window_list(struct window_manager *wm, struct ax_window *source, int direction, uint32_t *window_list, int window_count) { CGRect source_frame = window_frame(source); diff --git a/src/window_manager.h b/src/window_manager.h index e931eef1..60dd987d 100644 --- a/src/window_manager.h +++ b/src/window_manager.h @@ -87,6 +87,7 @@ struct ax_window *window_manager_find_window_on_space_by_rank(struct window_mana struct ax_window *window_manager_find_window_on_display_by_rank(struct window_manager *wm, uint32_t did, int rank); struct ax_window *window_manager_find_window_at_point_filtering_window(struct window_manager *wm, CGPoint point, uint32_t filter_wid); struct ax_window *window_manager_find_window_at_point(struct window_manager *wm, CGPoint point); +struct ax_window *window_manager_find_window_below_cursor(struct window_manager *wm); struct ax_window *window_manager_find_closest_managed_window_in_direction(struct window_manager *wm, struct ax_window *window, int direction); struct ax_window *window_manager_find_closest_window_in_direction(struct window_manager *wm, struct ax_window *window, int direction); struct ax_window *window_manager_find_prev_managed_window(struct space_manager *sm, struct window_manager *wm, struct ax_window *window);