add option for moving cursor to the focused window (#89)

This commit is contained in:
Himadri Bhattacharjee
2025-03-26 09:11:12 +05:30
committed by Peter Fajdiga
parent c99cad96c3
commit 6dd356dc53
8 changed files with 39 additions and 0 deletions

View File

@@ -29,6 +29,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_cursorFollowsFocus">
<property name="text">
<string>Cursor follows focus</string>
</property>
<property name="toolTip">
<string>When a window gains focus, move the cursor to it</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_stackColumnsByDefault">
<property name="text">

View File

@@ -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"]
}
}

View File

@@ -4,3 +4,4 @@ declare const Workspace: Workspace;
declare const qmlBase: QmlObject;
declare const notificationInvalidWindowRules: Notification;
declare const notificationInvalidPresetWidths: Notification;
declare const moveCursorToFocus: DBusCall;

View File

@@ -11,6 +11,7 @@ type Config = {
presetWidths: string;
offScreenOpacity: number;
untileOnDrag: boolean;
cursorFollowsFocus: boolean;
stackColumnsByDefault: boolean;
resizeNeighborColumn: boolean;
reMaximize: boolean;

View File

@@ -114,6 +114,11 @@ const configDef = [
type: "Bool",
default: true,
},
{
name: "cursorFollowsFocus",
type: "Bool",
default: false,
},
{
name: "stackColumnsByDefault",
type: "Bool",

3
src/lib/extern/dbuscall.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
type DBusCall = QmlObject & {
call(): void;
};

View File

@@ -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) {

View File

@@ -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;