add action screen-switch (fixes #37)

This commit is contained in:
Peter Fajdiga
2024-07-09 09:13:52 +02:00
parent 914202f091
commit c6066c354d
4 changed files with 29 additions and 5 deletions

View File

@@ -252,6 +252,12 @@ namespace Actions {
});
};
case "screen-switch": return () => {
world.do((clientManager, desktopManager) => {
desktopManager.selectScreen(Workspace.activeScreen);
});
};
default: throw new Error("unknown action: " + name);
}
}

View File

@@ -146,6 +146,11 @@ const keyBindings: KeyBinding[] = [
description: "Scroll to end",
defaultKeySequence: "Meta+Alt+End",
},
{
name: "screen-switch",
description: "Move Karousel grid to the current screen",
defaultKeySequence: "Meta+Ctrl+Return",
}
];
const numKeyBindings: NumKeyBinding[] = [

View File

@@ -11,6 +11,7 @@ class Desktop {
public readonly kwinDesktop: KwinDesktop,
private readonly pinManager: PinManager,
private readonly config: Desktop.Config,
private readonly getScreen: () => Output,
layoutConfig: LayoutConfig,
) {
this.scrollX = 0;
@@ -18,12 +19,12 @@ class Desktop {
this.dirtyScroll = true;
this.dirtyPins = true;
this.grid = new Grid(this, layoutConfig);
this.clientArea = Desktop.getClientArea(kwinDesktop);
this.clientArea = Desktop.getClientArea(this.getScreen(), kwinDesktop);
this.tilingArea = Desktop.getTilingArea(this.clientArea, kwinDesktop, pinManager, config);
}
private updateArea() {
const newClientArea = Desktop.getClientArea(this.kwinDesktop);
const newClientArea = Desktop.getClientArea(this.getScreen(), this.kwinDesktop);
if (newClientArea === this.clientArea && !this.dirtyPins) {
return;
}
@@ -36,8 +37,8 @@ class Desktop {
this.autoAdjustScroll();
}
private static getClientArea(kwinDesktop: KwinDesktop) {
return Workspace.clientArea(ClientAreaOption.PlacementArea, Workspace.activeScreen, kwinDesktop);
private static getClientArea(screen: Output, kwinDesktop: KwinDesktop) {
return Workspace.clientArea(ClientAreaOption.PlacementArea, screen, kwinDesktop);
}
private static getTilingArea(clientArea: QmlRect, kwinDesktop: KwinDesktop, pinManager: PinManager, config: Desktop.Config) {

View File

@@ -3,6 +3,7 @@ class DesktopManager {
private readonly config: Desktop.Config;
public readonly layoutConfig: LayoutConfig;
private readonly desktops: Map<string, Desktop>; // key is activityId|desktopId
private selectedScreen: Output;
private kwinActivities: Set<string>;
private kwinDesktops: Set<KwinDesktop>;
@@ -11,6 +12,7 @@ class DesktopManager {
this.config = config;
this.layoutConfig = layoutConfig;
this.desktops = new Map();
this.selectedScreen = Workspace.activeScreen;
this.kwinActivities = new Set(Workspace.activities);
this.kwinDesktops = new Set(Workspace.desktops);
this.addDesktop(currentActivity, currentDesktop);
@@ -43,7 +45,13 @@ class DesktopManager {
private addDesktop(activity: string, kwinDesktop: KwinDesktop) {
const desktopKey = DesktopManager.getDesktopKey(activity, kwinDesktop);
const desktop = new Desktop(kwinDesktop, this.pinManager, this.config, this.layoutConfig);
const desktop = new Desktop(
kwinDesktop,
this.pinManager,
this.config,
() => this.selectedScreen,
this.layoutConfig,
);
this.desktops.set(desktopKey, desktop);
return desktop;
}
@@ -72,6 +80,10 @@ class DesktopManager {
this.kwinDesktops = newDesktops;
}
public selectScreen(screen: Output) {
this.selectedScreen = screen;
}
private removeActivity(activity: string) {
for (const kwinDesktop of this.kwinDesktops) {
this.destroyDesktop(activity, kwinDesktop);