-
Notifications
You must be signed in to change notification settings - Fork 0
/
kde6-workarounds.mjs
executable file
·78 lines (76 loc) · 2.48 KB
/
kde6-workarounds.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env nodejsscript
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */
const pathLastDesktop= ()=> $.xdg.temp`kde6-workarounds-last-desktop.txt`;
const css= echo.css`
.code { color: gray; }
`;
$.api()
.version("2024-02-29")
.describe("Workarounds for KDE6.")
.command("logout")
.action(function(){
$.is_silent= true;
const res= s.run([
"echo ::options::",
"|",
"rofi -dmenu -p 'Logout' -l 4 -theme-str 'window { width: 25ch; }' -normal-window"
].join(" "), {
options: [ "-", "poweroff", "reboot" ].join("\n")
}).trim();
if(res && res!=="-") s.run(res);
$.exit(0);
})
.command("klipper-edit", "Edit last item in klipper.")
.action(async function(){
$.is_silent= true;
const qdbus= "qdbus org.kde.klipper /klipper org.kde.klipper.klipper.";
try{
const candidate= s.run(`${qdbus}getClipboardContents`).trim();
const content= await $.read({ "-p": "Edit", completions: [ candidate ] });
s.run(`${qdbus}setClipboardContents "${content}"`);
$.exit(0);
} catch (_){
$.exit(1);
}
})
.command("desktops-alttab", "Workaround for KDE6 alt-tab between virtual desktops.")
.action(function(){
const path= pathLastDesktop();
// Regarding ★ : this is a workaround for diagonal switching (it duplicates desktop index)
let desktop= s.cat(path).trim() || "1";
if(desktop.length>3){ // ★
const [ _1, _2, ..._3 ]= desktop.slice(-4, desktop.length);
if(_1===_2)
desktop= desktop.slice(0, -4).concat(_1, ..._3);
}
if(desktop.length>2){ // ★
const [ _1, _2 ]= desktop.slice(-2, desktop.length);
if(_1===_2)
desktop= desktop.slice(0, -1);
}
if(desktop.length>2){
desktop= desktop.slice(-2, desktop.length);
s.echo(desktop).to(path);
}
echo(desktop);
s.run`qdbus org.kde.KWin /KWin org.kde.KWin.setCurrentDesktop ${desktop[0]}`;
$.exit(0);
})
.command("desktops-last-dbus")
.action(function(){
echo([
"dbus-monitor",
'"interface=org.kde.KWin.VirtualDesktopManager" "member=currentChanged"',
"|",
'xargs -e -I {} kde6-workarounds.mjs desktops-last-save {}'
].join(" "));
$.exit(0);
})
.command("desktops-last-save <dbus>", "Workaround for KDE6 alt-tab between virtual desktops.")
.action(function(dbus){
if(-1===dbus.indexOf("path=/VirtualDesktopManager; interface=org.kde.KWin.VirtualDesktopManager; member=currentChanged"))
return $.exit(1);
const desktop= s.run`qdbus org.kde.KWin /KWin org.kde.KWin.currentDesktop`.trim();
s.echo(desktop).toEnd(pathLastDesktop());
})
.parse();