Skip to content

Commit

Permalink
Add option to warp cursor to the center of the focused window
Browse files Browse the repository at this point in the history
  • Loading branch information
anaximeno committed Jul 19, 2024
1 parent 206e8e8 commit 5561ac3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class AdjacentWindows {
if (direction === Direction.Back) {
let newWindow = this.popStack(focusedWindow);
if (newWindow) {
Main.activateWindow(newWindow);
this.activateWindow(newWindow);
}
return;
}
Expand All @@ -188,7 +188,7 @@ class AdjacentWindows {
newWindow = this.getClosestWindow(focusedWindow, focusedMonitor, focusedRec, windows, direction);
}
if (newWindow) {
Main.activateWindow(newWindow);
this.activateWindow(newWindow);
if (this.peekStack() != focusedWindow)
this.pushStack(focusedWindow);
this.pushStack(newWindow);
Expand All @@ -197,6 +197,18 @@ class AdjacentWindows {
return;
}

activateWindow(window) {
let warpPointer = this.settings.getValue("warp-cursor-pointer");

Main.activateWindow(window);
if (window.has_focus() && warpPointer) {
let rec = window.get_frame_rect();
let x = rec.x + rec.width / 2;
let y = rec.y + rec.height / 2;
global.set_pointer(x, y);
}
}

// Find the window that is closes to the focused window in the direction requested
// Does not take into account window visibility
getClosestWindow(focusedWindow, focusedMonitor, focusedRec, windowList, direction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,10 @@
"type": "switch",
"default": false,
"description": "Allow switching to windows on other monitors"
},
"warp-cursor-pointer": {
"type": "switch",
"default": false,
"description": "Warp the cursor to the center of the focused window"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"uuid": "adjacent-windows@klangman",
"name": "Adjacent Windows",
"version": "1.1.0",
"version": "1.2.0",
"description": "Use hotkeys to switch to adjacent windows",
"url": "https://github.com/klangman/Adjacent-Windows",
"website": "https://github.com/klangman/Adjacent-Windows",
Expand Down

0 comments on commit 5561ac3

Please sign in to comment.