Skip to content

Commit

Permalink
feat(kwinscript): add several modes for placing new spawned windows
Browse files Browse the repository at this point in the history
  • Loading branch information
benemorius committed Jun 18, 2022
1 parent 19f882b commit 96d69c2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/config/bismuth_config.kcfg
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@
<default>1.6</default>
</entry>

<entry name="newWindowAsMaster" type="Bool">
<label>Put new window as master</label>
<default>false</default>
<entry name="newWindowSpawnLocation" type="String">
<label>Where to spawn new windows</label>
<default>end</default>
</entry>

<entry name="experimentalBackend" type="Bool">
Expand Down
2 changes: 1 addition & 1 deletion src/core/ts-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ QJSValue TSProxy::jsConfig()
setProp("screenGapTop", m_config.screenGapTop());
setProp("tileLayoutGap", m_config.tileLayoutGap());

setProp("newWindowAsMaster", m_config.newWindowAsMaster());
setProp("newWindowSpawnLocation", m_config.newWindowSpawnLocation());
setProp("layoutPerActivity", m_config.layoutPerActivity());
setProp("layoutPerDesktop", m_config.layoutPerDesktop());

Expand Down
52 changes: 43 additions & 9 deletions src/kcm/package/contents/ui/Behaviour.qml
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,64 @@ Kirigami.FormLayout {
}

QQC2.RadioButton {
Kirigami.FormData.label: i18n("Spawn windows at:")
text: i18n("Master area")
Kirigami.FormData.label: i18n("New windows spawn:")
text: i18n("At the master area")
QQC2.ButtonGroup.group: windowSpawnPositionGroup
checked: kcm.config.newWindowAsMaster
onClicked: kcm.config.newWindowAsMaster = checked
checked: kcm.config.newWindowSpawnLocation == "master"
onClicked: kcm.config.newWindowSpawnLocation = "master"

KCM.SettingStateBinding {
configObject: kcm.config
settingName: "newWindowAsMaster"
settingName: "newWindowSpawnLocation"
}
}

QQC2.RadioButton {
text: i18n("At the active window")
QQC2.ButtonGroup.group: windowSpawnPositionGroup
checked: kcm.config.newWindowSpawnLocation == "beforeFocused"
onClicked: kcm.config.newWindowSpawnLocation = "beforeFocused"

KCM.SettingStateBinding {
configObject: kcm.config
settingName: "newWindowSpawnLocation"
}
}

QQC2.RadioButton {
text: i18n("After the active window")
QQC2.ButtonGroup.group: windowSpawnPositionGroup
checked: kcm.config.newWindowSpawnLocation == "afterFocused"
onClicked: kcm.config.newWindowSpawnLocation = "afterFocused"

KCM.SettingStateBinding {
configObject: kcm.config
settingName: "newWindowSpawnLocation"
}
}

QQC2.RadioButton {
text: i18n("The layout's end")
text: i18n("At the layout's end")
QQC2.ButtonGroup.group: windowSpawnPositionGroup
checked: !kcm.config.newWindowAsMaster
onClicked: kcm.config.newWindowAsMaster = !checked
checked: kcm.config.newWindowSpawnLocation == "end"
onClicked: kcm.config.newWindowSpawnLocation = "end"

KCM.SettingStateBinding {
configObject: kcm.config
settingName: "newWindowAsMaster"
settingName: "newWindowSpawnLocation"
}
}

QQC2.RadioButton {
text: i18n("Floating")
QQC2.ButtonGroup.group: windowSpawnPositionGroup
checked: kcm.config.newWindowSpawnLocation == "floating"
onClicked: kcm.config.newWindowSpawnLocation = "floating"

KCM.SettingStateBinding {
configObject: kcm.config
settingName: "newWindowSpawnLocation"
}
}

QQC2.Button {
Expand Down
2 changes: 1 addition & 1 deletion src/kwinscript/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Config {
//#endregion

//#region Behavior
newWindowAsMaster: boolean;
newWindowSpawnLocation: string;
//#endregion

//#region KWin-specific
Expand Down
1 change: 1 addition & 0 deletions src/kwinscript/driver/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class DriverWindowImpl implements DriverWindow {
return (
this.client.modal ||
!this.client.resizeable ||
this.config.newWindowSpawnLocation === "floating" ||
(this.config.floatUtility &&
(this.client.dialog ||
this.client.splash ||
Expand Down
15 changes: 14 additions & 1 deletion src/kwinscript/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,22 @@ export class EngineImpl implements Engine {
if (!window.shouldIgnore) {
/* engine#arrange will update the state when required. */
window.state = WindowState.Undecided;
if (this.config.newWindowAsMaster) {
if (this.config.newWindowSpawnLocation == "master") {
this.windows.unshift(window);
} else if (
this.controller.currentWindow &&
this.config.newWindowSpawnLocation == "beforeFocused"
) {
this.windows.push(window);
this.windows.move(window, this.controller.currentWindow);
} else if (
this.controller.currentWindow &&
this.config.newWindowSpawnLocation == "afterFocused"
) {
this.windows.push(window);
this.windows.move(window, this.controller.currentWindow, true);
} else {
/* newWindowSpawnLocation == "end" or "floating" */
this.windows.push(window);
}
}
Expand Down

0 comments on commit 96d69c2

Please sign in to comment.