Skip to content

Commit

Permalink
Improve preset auto-loading
Browse files Browse the repository at this point in the history
- Allow loading a preset when a window is touching the panel #44
- Now is possible to have assign a preset for all states and they are loaded with the following priority:

1. Normal
2. Floating
3. Touching
4. Maximized
  • Loading branch information
luisbocanegra committed May 15, 2024
1 parent dffb8de commit b44ff93
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
5 changes: 5 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@
type="String">
<default></default>
</entry>
<entry
name="touchingWindowPreset"
type="String">
<default></default>
</entry>
<entry
name="maximizedPreset"
type="String">
Expand Down
27 changes: 25 additions & 2 deletions package/contents/ui/configPresetAutoload.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ KCM.SimpleKCM {

property string cfg_normalPreset
property string cfg_floatingPreset
property string cfg_touchingWindowPreset
property string cfg_maximizedPreset

ListModel {
Expand Down Expand Up @@ -114,6 +115,19 @@ KCM.SimpleKCM {
}

ColumnLayout {
Label {
text: i18n("Here you can switch between different panel presets based on the Panel and window states below.")
Layout.maximumWidth: root.width - (Kirigami.Units.gridUnit * 2)
wrapMode: Text.Wrap
Layout.alignment: Qt.AlignHCenter
}

Label {
text: i18n("Priorities go from lowest to highest. E.g. if both <b>Maximized window is shown</b> and <b>Panel touching window</b> have a preset selected, and there is a maximized window on the screen, the <b>Maximized</b> preset will be applied.")
Layout.maximumWidth: root.width - (Kirigami.Units.gridUnit * 2)
wrapMode: Text.Wrap
Layout.alignment: Qt.AlignHCenter
}
Kirigami.FormLayout {

ComboBox {
Expand All @@ -136,7 +150,17 @@ KCM.SimpleKCM {
cfg_floatingPreset = model.get(currentIndex)["value"]
}
currentIndex: getIndex(model, cfg_floatingPreset)
enabled: cfg_maximizedPreset === ""
}

ComboBox {
id: touchingWindowPreset
model: presetsModel
textRole: "name"
Kirigami.FormData.label: i18n("Window touching panel:")
onCurrentIndexChanged: {
cfg_touchingWindowPreset = model.get(currentIndex)["value"]
}
currentIndex: getIndex(model, cfg_touchingWindowPreset)
}

ComboBox {
Expand All @@ -148,7 +172,6 @@ KCM.SimpleKCM {
cfg_maximizedPreset = model.get(currentIndex)["value"]
}
currentIndex: getIndex(model, cfg_maximizedPreset)
enabled: cfg_floatingPreset === ""
}
}
}
Expand Down
37 changes: 24 additions & 13 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ PlasmoidItem {
}) : null
}
property bool isFloating: !panelElement ? false : Boolean(panelElement.floatingness)
property bool isTouchingWindow: !panelElement ? false : Boolean(panelElement.touchingWindow)

property ContainmentItem containmentItem: null
readonly property int depth : 14
Expand All @@ -252,10 +253,12 @@ PlasmoidItem {
"objectName",
"lastPreset",
"floatingPreset",
"touchingWindowPreset",
"normalPreset",
"maximizedPreset"
]
property string floatingPreset: plasmoid.configuration.floatingPreset
property string touchingWindowPreset: plasmoid.configuration.touchingWindowPreset
property string normalPreset: plasmoid.configuration.normalPreset
property string maximizedPreset: plasmoid.configuration.maximizedPreset
property string lastPreset
Expand Down Expand Up @@ -362,24 +365,32 @@ PlasmoidItem {
plasmoid.configuration.writeConfig();
}

onIsFloatingChanged: {
if (floatingPreset === "") return
console.log("FLOATING:", isFloating);
if (isFloating) {
function switchPreset() {
if (maximizedWindowExists && maximizedPreset !== "") {
applyPreset(maximizedPreset)
return
}
if (isTouchingWindow && touchingWindowPreset !== "") {
applyPreset(touchingWindowPreset)
return
}
if (isFloating && floatingPreset !== "") {
applyPreset(floatingPreset)
} else {
applyPreset(normalPreset)
return
}
applyPreset(normalPreset)
}

onIsFloatingChanged: {
switchPreset()
}

onIsTouchingWindowChanged: {
switchPreset()
}

onMaximizedWindowExistsChanged: {
if (maximizedPreset === "") return
console.log("MAXIMIZED:", maximizedWindowExists);
if (maximizedWindowExists) {
applyPreset(maximizedPreset)
} else {
applyPreset(normalPreset)
}
switchPreset()
}

function hexToRgb(hex) {
Expand Down

0 comments on commit b44ff93

Please sign in to comment.