From 6dd356dc53d581aeb75588a1faf39aabd2578873 Mon Sep 17 00:00:00 2001
From: Himadri Bhattacharjee <107522312+lavafroth@users.noreply.github.com>
Date: Wed, 26 Mar 2025 09:11:12 +0530
Subject: [PATCH] add option for moving cursor to the focused window (#89)
---
package/contents/ui/config.ui | 10 ++++++++++
package/contents/ui/main.qml | 9 +++++++++
src/extern/global.d.ts | 1 +
src/lib/config/config.ts | 1 +
src/lib/config/definition.ts | 5 +++++
src/lib/extern/dbuscall.ts | 3 +++
src/lib/world/World.ts | 9 +++++++++
src/tests/utils/global.ts | 1 +
8 files changed, 39 insertions(+)
create mode 100644 src/lib/extern/dbuscall.ts
diff --git a/package/contents/ui/config.ui b/package/contents/ui/config.ui
index 6ac6e65..f0f9edc 100644
--- a/package/contents/ui/config.ui
+++ b/package/contents/ui/config.ui
@@ -29,6 +29,16 @@
+ -
+
+
+ Cursor follows focus
+
+
+ When a window gains focus, move the cursor to it
+
+
+
-
diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml
index d4cd1a2..2e0cdbd 100644
--- a/package/contents/ui/main.qml
+++ b/package/contents/ui/main.qml
@@ -51,4 +51,13 @@ Item {
onCancelled: qmlBase.karouselInstance.gestureScrollFinish()
onProgressChanged: qmlBase.karouselInstance.gestureScroll(progress)
}
+
+ DBusCall {
+ id: moveCursorToFocus
+
+ service: "org.kde.kglobalaccel"
+ path: "/component/kwin"
+ method: "invokeShortcut"
+ arguments: ["MoveMouseToFocus"]
+ }
}
diff --git a/src/extern/global.d.ts b/src/extern/global.d.ts
index 14c21af..247bb7b 100644
--- a/src/extern/global.d.ts
+++ b/src/extern/global.d.ts
@@ -4,3 +4,4 @@ declare const Workspace: Workspace;
declare const qmlBase: QmlObject;
declare const notificationInvalidWindowRules: Notification;
declare const notificationInvalidPresetWidths: Notification;
+declare const moveCursorToFocus: DBusCall;
diff --git a/src/lib/config/config.ts b/src/lib/config/config.ts
index f6a63e0..2d717c1 100644
--- a/src/lib/config/config.ts
+++ b/src/lib/config/config.ts
@@ -11,6 +11,7 @@ type Config = {
presetWidths: string;
offScreenOpacity: number;
untileOnDrag: boolean;
+ cursorFollowsFocus: boolean;
stackColumnsByDefault: boolean;
resizeNeighborColumn: boolean;
reMaximize: boolean;
diff --git a/src/lib/config/definition.ts b/src/lib/config/definition.ts
index 15c2a8a..62d6b50 100644
--- a/src/lib/config/definition.ts
+++ b/src/lib/config/definition.ts
@@ -114,6 +114,11 @@ const configDef = [
type: "Bool",
default: true,
},
+ {
+ name: "cursorFollowsFocus",
+ type: "Bool",
+ default: false,
+ },
{
name: "stackColumnsByDefault",
type: "Bool",
diff --git a/src/lib/extern/dbuscall.ts b/src/lib/extern/dbuscall.ts
new file mode 100644
index 0000000..f0bc73c
--- /dev/null
+++ b/src/lib/extern/dbuscall.ts
@@ -0,0 +1,3 @@
+type DBusCall = QmlObject & {
+ call(): void;
+};
diff --git a/src/lib/world/World.ts b/src/lib/world/World.ts
index 2db41cf..c76a47a 100644
--- a/src/lib/world/World.ts
+++ b/src/lib/world/World.ts
@@ -5,9 +5,11 @@ class World {
private readonly workspaceSignalManager: SignalManager;
private readonly shortcutActions: ShortcutAction[];
private readonly screenResizedDelayer: Delayer;
+ private readonly cursorFollowsFocus: boolean;
constructor(config: Config) {
this.workspaceSignalManager = initWorkspaceSignalHandlers(this);
+ this.cursorFollowsFocus = config.cursorFollowsFocus;
let presetWidths = {
next: (currentWidth: number, minWidth: number, maxWidth: number) => currentWidth,
@@ -97,6 +99,13 @@ class World {
private update() {
this.desktopManager.getCurrentDesktop().arrange();
+ this.moveCursorToFocus();
+ }
+
+ private moveCursorToFocus() {
+ if (this.cursorFollowsFocus && moveCursorToFocus !== undefined) {
+ moveCursorToFocus.call();
+ }
}
public do(f: (clientManager: ClientManager, desktopManager: DesktopManager) => void) {
diff --git a/src/tests/utils/global.ts b/src/tests/utils/global.ts
index 2daa880..a4d4039 100644
--- a/src/tests/utils/global.ts
+++ b/src/tests/utils/global.ts
@@ -4,6 +4,7 @@ let Workspace: Workspace;
let qmlBase: QmlObject;
let notificationInvalidWindowRules: Notification;
let notificationInvalidPresetWidths: Notification;
+let moveCursorToFocus: DBusCall;
let screen: MockQmlRect;
let tilingArea: MockQmlRect;