Created
November 19, 2021 17:43
-
-
Save residentsummer/e61bdfa663a5763cceab8b104c412281 to your computer and use it in GitHub Desktop.
More mouse_follows_focus for yabai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/message.c b/src/message.c | |
index 4927814..ce446dc 100644 | |
--- a/src/message.c | |
+++ b/src/message.c | |
@@ -1628,15 +1628,17 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) | |
{ | |
struct token command; | |
struct window *acting_window; | |
- struct selector selector = parse_window_selector(NULL, &message, window_manager_focused_window(&g_window_manager)); | |
+ struct window *focused_window = window_manager_focused_window(&g_window_manager); | |
+ struct selector selector = parse_window_selector(NULL, &message, focused_window); | |
if (selector.did_parse) { | |
acting_window = selector.window; | |
command = get_token(&message); | |
} else { | |
- acting_window = window_manager_focused_window(&g_window_manager); | |
+ acting_window = focused_window; | |
command = selector.token; | |
} | |
+ warn("=== ACTING WINDOW: %s %d\n", window_title(acting_window), acting_window->id); | |
if (!acting_window && !token_equals(command, COMMAND_WINDOW_FOCUS)) { | |
daemon_fail(rsp, "could not locate the window to act on!\n"); | |
@@ -1647,12 +1649,40 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) | |
struct selector selector = parse_window_selector(rsp, &message, acting_window); | |
if (selector.did_parse && selector.window) { | |
window_manager_focus_window_with_raise(&selector.window->application->psn, selector.window->id, selector.window->ref); | |
+ window_manager_center_mouse(&g_window_manager, selector.window); | |
} | |
} else if (token_equals(command, COMMAND_WINDOW_SWAP)) { | |
struct selector selector = parse_window_selector(rsp, &message, acting_window); | |
if (selector.did_parse && selector.window) { | |
+ warn("=== TARGET WINDOW: %s %d\n", window_title(selector.window), selector.window->id); | |
+ const char* action = "SWAP"; | |
+ CGRect ax_frame = window_ax_frame(acting_window); | |
+ CGRect frame = window_frame(acting_window); | |
+ warn("=== BEFORE %s: ax_frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ ax_frame.origin.x, ax_frame.origin.y, | |
+ ax_frame.origin.x + ax_frame.size.width, | |
+ ax_frame.origin.y + ax_frame.size.height); | |
+ warn("=== BEFORE %s: frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ frame.origin.x, frame.origin.y, | |
+ frame.origin.x + frame.size.width, | |
+ frame.origin.y + frame.size.height); | |
+ | |
enum window_op_error result = window_manager_swap_window(&g_space_manager, &g_window_manager, acting_window, selector.window); | |
- if (result == WINDOW_OP_ERROR_INVALID_SRC_VIEW) { | |
+ if (result == WINDOW_OP_ERROR_SUCCESS) { | |
+ ax_frame = window_ax_frame(acting_window); | |
+ frame = window_frame(acting_window); | |
+ warn("=== AFTER %s: ax_frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ ax_frame.origin.x, ax_frame.origin.y, | |
+ ax_frame.origin.x + ax_frame.size.width, | |
+ ax_frame.origin.y + ax_frame.size.height); | |
+ warn("=== AFTER %s: frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ frame.origin.x, frame.origin.y, | |
+ frame.origin.x + frame.size.width, | |
+ frame.origin.y + frame.size.height); | |
+ | |
+ warn("=== REFOCUS WINDOW: %s %d\n", window_title(focused_window), focused_window->id); | |
+ window_manager_center_mouse(&g_window_manager, focused_window); | |
+ } else if (result == WINDOW_OP_ERROR_INVALID_SRC_VIEW) { | |
daemon_fail(rsp, "the acting window is not within a bsp space.\n"); | |
} else if (result == WINDOW_OP_ERROR_INVALID_DST_VIEW) { | |
daemon_fail(rsp, "the selected window is not within a bsp space.\n"); | |
@@ -1669,8 +1699,35 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) | |
} else if (token_equals(command, COMMAND_WINDOW_WARP)) { | |
struct selector selector = parse_window_selector(rsp, &message, acting_window); | |
if (selector.did_parse && selector.window) { | |
+ warn("=== TARGET WINDOW: %s %d\n", window_title(selector.window), selector.window->id); | |
+ const char* action = "WARP"; | |
+ CGRect ax_frame = window_ax_frame(acting_window); | |
+ CGRect frame = window_frame(acting_window); | |
+ warn("=== BEFORE %s: ax_frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ ax_frame.origin.x, ax_frame.origin.y, | |
+ ax_frame.origin.x + ax_frame.size.width, | |
+ ax_frame.origin.y + ax_frame.size.height); | |
+ warn("=== BEFORE %s: frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ frame.origin.x, frame.origin.y, | |
+ frame.origin.x + frame.size.width, | |
+ frame.origin.y + frame.size.height); | |
+ | |
enum window_op_error result = window_manager_warp_window(&g_space_manager, &g_window_manager, acting_window, selector.window); | |
- if (result == WINDOW_OP_ERROR_INVALID_SRC_VIEW) { | |
+ if (result == WINDOW_OP_ERROR_SUCCESS) { | |
+ ax_frame = window_ax_frame(acting_window); | |
+ frame = window_frame(acting_window); | |
+ warn("=== AFTER %s: ax_frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ ax_frame.origin.x, ax_frame.origin.y, | |
+ ax_frame.origin.x + ax_frame.size.width, | |
+ ax_frame.origin.y + ax_frame.size.height); | |
+ warn("=== AFTER %s: frame is (%4.0f, %4.0f) <-> (%4.0f, %4.0f)\n", action, | |
+ frame.origin.x, frame.origin.y, | |
+ frame.origin.x + frame.size.width, | |
+ frame.origin.y + frame.size.height); | |
+ | |
+ warn("=== REFOCUS WINDOW: %s %d\n", window_title(focused_window), focused_window->id); | |
+ window_manager_center_mouse(&g_window_manager, focused_window); | |
+ } else if (result == WINDOW_OP_ERROR_INVALID_SRC_VIEW) { | |
daemon_fail(rsp, "the acting window is not within a bsp space.\n"); | |
} else if (result == WINDOW_OP_ERROR_INVALID_DST_VIEW) { | |
daemon_fail(rsp, "the selected window is not within a bsp space.\n"); | |
diff --git a/src/window_manager.c b/src/window_manager.c | |
index cdb9436..01bd058 100644 | |
--- a/src/window_manager.c | |
+++ b/src/window_manager.c | |
@@ -269,7 +269,7 @@ void window_manager_center_mouse(struct window_manager *wm, struct window *windo | |
CGPoint cursor; | |
SLSGetCurrentCursorLocation(g_connection, &cursor); | |
- CGRect frame = window_frame(window); | |
+ CGRect frame = window_ax_frame(window); | |
if (CGRectContainsPoint(frame, cursor)) return; | |
uint32_t did = window_display_id(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment