Skip to content

Commit 495578c

Browse files
committed
fix: use old mask offset for plasma 6.1.x or lower
1 parent b0008b0 commit 495578c

File tree

2 files changed

+120
-5
lines changed

2 files changed

+120
-5
lines changed

package/contents/ui/code/version.js

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @enum
3+
*/
4+
const VersionDifference = {
5+
Lower: 0,
6+
Greater: 1,
7+
Equal: 2,
8+
};
9+
10+
class Version {
11+
/**
12+
*
13+
* @param {string} version Version string e.g 1.2.3
14+
*/
15+
constructor(version) {
16+
this._version = version;
17+
}
18+
19+
get version() {
20+
return this._version;
21+
}
22+
23+
/**
24+
* Compare two versions
25+
* @param {string} version1 Version 1
26+
* @param {string} version2 Version 2
27+
* @returns {VersionDifference}
28+
*/
29+
compareVersions(version1, version2) {
30+
var v1 = version1.split("-")[0].split(".").map(Number);
31+
var v2 = version2.split("-")[0].split(".").map(Number);
32+
33+
for (var i = 0; i < v1.length; ++i) {
34+
if (v2.length == i) {
35+
return VersionDifference.Greater;
36+
}
37+
if (v1[i] == v2[i]) {
38+
continue;
39+
} else if (v1[i] > v2[i]) {
40+
return VersionDifference.Greater;
41+
} else {
42+
return VersionDifference.Lower;
43+
}
44+
}
45+
46+
if (version1.includes("-") && !version2.includes("-")) {
47+
return VersionDifference.Lower;
48+
} else if (!version1.includes("-") && version2.includes("-")) {
49+
return VersionDifference.Greater;
50+
} else if (version1.includes("-") && version2.includes("-")) {
51+
let suffix1 = version1.split("-")[1];
52+
let suffix2 = version2.split("-")[1];
53+
if (suffix1 > suffix2) {
54+
return VersionDifference.Greater;
55+
} else if (suffix1 < suffix2) {
56+
return VersionDifference.Lower;
57+
}
58+
}
59+
60+
return v1.length != v2.length
61+
? VersionDifference.Lower
62+
: VersionDifference.Equal;
63+
}
64+
65+
/**
66+
* Compare version
67+
* @param {string} version2 Version to compare against
68+
* @returns {VersionDifference} Difference between versions
69+
*/
70+
compare(version2) {
71+
return this.compareVersions(this._version, version2);
72+
}
73+
74+
/**
75+
* Check if is Lower
76+
* @param {string} version2 Version to compare against
77+
* @returns {bool} Whether or not `version2` is Lower
78+
*/
79+
isLowerThan(version2) {
80+
return VersionDifference.Lower === this.compare(version2);
81+
}
82+
83+
/**
84+
* Check if is Greater
85+
* @param {string} version2 Version to compare against
86+
* @returns {bool} Whether or not `version2` is Greater
87+
*/
88+
isGreaterThan(version2) {
89+
return VersionDifference.Greater === this.compare(version2);
90+
}
91+
92+
/**
93+
* Check if is equal
94+
* @param {string} version2 Version to compare against
95+
* @returns {bool} Whether or not `version2` is equal
96+
*/
97+
isEqual(version2) {
98+
return VersionDifference.Equal === this.compare(version2);
99+
}
100+
}
101+
102+
// console.log(new Version("6.3.80").isLowerThan("6.2.0")); // false
103+
// console.log(new Version("6.3.80").isGreaterThan("6.2.0")); // true
104+
// console.log(new Version("6.3.80").isLowerThan("6.2.0")); // false
105+
// console.log(new Version("6.3").isLowerThan("6.2.5")); // false
106+
// console.log(new Version("6.1.5").isLowerThan("6.2.0")); // true

package/contents/ui/main.qml

+14-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import "components" as Components
1919
import "code/utils.js" as Utils
2020
import "code/globals.js" as Globals
2121
import "code/enum.js" as Enum
22+
import "code/version.js" as VersionUtil
2223

2324
PlasmoidItem {
2425
id: main
@@ -147,6 +148,7 @@ PlasmoidItem {
147148
property var panelWidth: panelElement?.width ?? 0
148149
property var panelHeight: panelElement?.height ?? 0
149150
property bool debug: plasmoid.configuration.enableDebug
151+
property var plasmaVersion: new VersionUtil.Version("999.999.999") // to assume latest
150152
signal recolorCountChanged()
151153
signal refreshNeeded()
152154
signal updateUnified()
@@ -1136,12 +1138,14 @@ PlasmoidItem {
11361138

11371139
// TODO find where does 16 and 8 come from instead of blindly hardcoding them
11381140
property real moveX: {
1139-
let m = horizontal ? 0 : (panelElement?.floating && plasmoid.location === PlasmaCore.Types.RightEdge ? 16 : 0)
1141+
const edge = main.plasmaVersion.isLowerThan("6.2.0") ? PlasmaCore.Types.LeftEdge : PlasmaCore.Types.RightEdge
1142+
const m = horizontal ? 0 : (panelElement?.floating && plasmoid.location === edge ? 16 : 0)
11401143
return floatigness > 0 ? 8 : m
11411144
}
11421145

11431146
property real moveY: {
1144-
let m = horizontal ? (panelElement?.floating && plasmoid.location === PlasmaCore.Types.BottomEdge ? 16 : 0) : 0
1147+
const edge = main.plasmaVersion.isLowerThan("6.2.0") ? PlasmaCore.Types.TopEdge : PlasmaCore.Types.BottomEdge
1148+
const m = horizontal ? (panelElement?.floating && plasmoid.location === edge ? 16 : 0) : 0
11451149
return floatigness > 0 ? 8 : m
11461150
}
11471151

@@ -1228,8 +1232,6 @@ PlasmoidItem {
12281232
delayed: true
12291233
}
12301234

1231-
// TODO: should we remove option for blur from per-widget settings?
1232-
// IMO doesn't make much sense to have only some widgets blurred...
12331235
Binding {
12341236
target: panelElement
12351237
property: "panelMask"
@@ -1617,6 +1619,7 @@ PlasmoidItem {
16171619

16181620
Component.onCompleted: {
16191621
bindPlasmoidStatus()
1622+
runCommand.run("plasmashell --version")
16201623
Qt.callLater(function() {
16211624
const config = Utils.mergeConfigs(Globals.defaultConfig, cfg)
16221625
plasmoid.configuration.globalSettings = Utils.stringify(config)
@@ -1646,9 +1649,10 @@ PlasmoidItem {
16461649
console.error(cmd, exitCode, exitStatus, stdout, stderr)
16471650
return
16481651
}
1652+
stdout = stdout.trim()
16491653
if (cmd.startsWith("cat")) {
16501654
try {
1651-
presetContent = JSON.parse(stdout.trim())
1655+
presetContent = JSON.parse(stdout)
16521656
} catch (e) {
16531657
console.error(`Error reading preset (${cmd}): ${e}`)
16541658
return
@@ -1657,6 +1661,11 @@ PlasmoidItem {
16571661
plasmoid.configuration.lastPreset = lastPreset
16581662
plasmoid.configuration.writeConfig();
16591663
}
1664+
if (cmd === "plasmashell --version") {
1665+
const parts = stdout.split(" ")
1666+
if (parts.length < 2) return
1667+
main.plasmaVersion = new VersionUtil.Version(parts[1])
1668+
}
16601669
}
16611670
}
16621671

0 commit comments

Comments
 (0)