fix: add KWin dock force-hide workaround
This commit is contained in:
175
kwin/manjaro_dock_force_hide/contents/code/main.js
Normal file
175
kwin/manjaro_dock_force_hide/contents/code/main.js
Normal file
@@ -0,0 +1,175 @@
|
||||
var delaySeconds = parseInt(readConfig("delaySeconds", 6), 10);
|
||||
if (!(delaySeconds > 0)) {
|
||||
delaySeconds = 6;
|
||||
}
|
||||
|
||||
var debugValue = readConfig("debug", false);
|
||||
var debug = debugValue === true || debugValue === "true" || debugValue === 1 || debugValue === "1";
|
||||
|
||||
var trackedWindows = [];
|
||||
var forceHideTimer = new QTimer();
|
||||
forceHideTimer.singleShot = true;
|
||||
|
||||
function log(message) {
|
||||
if (debug) {
|
||||
print("manjaro_dock_force_hide: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
function rectContains(rect, point) {
|
||||
return point.x >= rect.x &&
|
||||
point.x < rect.x + rect.width &&
|
||||
point.y >= rect.y &&
|
||||
point.y < rect.y + rect.height;
|
||||
}
|
||||
|
||||
function isBottomPlasmaDock(window) {
|
||||
if (!window || !window.dock || window.resourceClass !== "plasmashell" || !window.output) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var frame = window.frameGeometry;
|
||||
var output = window.output.geometry;
|
||||
return (frame.y + frame.height) >= (output.y + output.height - 4);
|
||||
}
|
||||
|
||||
function visibleBottomDocks() {
|
||||
var docks = [];
|
||||
var stack = workspace.stackingOrder;
|
||||
|
||||
for (var i = 0; i < stack.length; ++i) {
|
||||
var window = stack[i];
|
||||
if (isBottomPlasmaDock(window) && !window.hidden) {
|
||||
docks.push(window);
|
||||
}
|
||||
}
|
||||
|
||||
return docks;
|
||||
}
|
||||
|
||||
function cursorInsideVisibleDock() {
|
||||
var cursorPos = workspace.cursorPos;
|
||||
var docks = visibleBottomDocks();
|
||||
|
||||
for (var i = 0; i < docks.length; ++i) {
|
||||
if (rectContains(docks[i].frameGeometry, cursorPos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function restartForceHideTimer(ms) {
|
||||
if (!(ms > 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
forceHideTimer.stop();
|
||||
forceHideTimer.interval = ms;
|
||||
forceHideTimer.start();
|
||||
log("timer armed for " + ms + "ms");
|
||||
}
|
||||
|
||||
function forceHideBottomPanels() {
|
||||
var plasmaScript =
|
||||
"for (var i = 0; i < panelIds.length; ++i) {" +
|
||||
" var panel = panelById(panelIds[i]);" +
|
||||
" if (panel.location == 'bottom' && panel.hiding == 'autohide') {" +
|
||||
" panel.hiding = 'none';" +
|
||||
" panel.hiding = 'autohide';" +
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
callDBus(
|
||||
"org.kde.plasmashell",
|
||||
"/PlasmaShell",
|
||||
"org.kde.PlasmaShell",
|
||||
"evaluateScript",
|
||||
plasmaScript,
|
||||
function () {
|
||||
log("forced bottom dock hide pulse sent");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function onForceHideTimer() {
|
||||
var docks = visibleBottomDocks();
|
||||
if (docks.length === 0) {
|
||||
log("timer fired but no visible bottom docks");
|
||||
return;
|
||||
}
|
||||
|
||||
if (cursorInsideVisibleDock()) {
|
||||
log("cursor is on a dock; delaying force-hide recheck");
|
||||
restartForceHideTimer(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
log("forcing dock hide");
|
||||
forceHideBottomPanels();
|
||||
}
|
||||
|
||||
function onDockVisibilityMaybeChanged(window) {
|
||||
if (!isBottomPlasmaDock(window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!window.hidden) {
|
||||
log("bottom dock shown");
|
||||
restartForceHideTimer(delaySeconds * 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (visibleBottomDocks().length === 0) {
|
||||
log("all bottom docks hidden; stopping timer");
|
||||
forceHideTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
function trackWindow(window) {
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < trackedWindows.length; ++i) {
|
||||
if (trackedWindows[i] === window) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
trackedWindows.push(window);
|
||||
|
||||
window.hiddenChanged.connect(function () {
|
||||
onDockVisibilityMaybeChanged(window);
|
||||
});
|
||||
|
||||
window.outputChanged.connect(function () {
|
||||
onDockVisibilityMaybeChanged(window);
|
||||
});
|
||||
|
||||
if (isBottomPlasmaDock(window) && !window.hidden) {
|
||||
restartForceHideTimer(delaySeconds * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
forceHideTimer.timeout.connect(onForceHideTimer);
|
||||
|
||||
var stack = workspace.stackingOrder;
|
||||
for (var i = 0; i < stack.length; ++i) {
|
||||
trackWindow(stack[i]);
|
||||
}
|
||||
|
||||
workspace.windowAdded.connect(function (window) {
|
||||
trackWindow(window);
|
||||
});
|
||||
|
||||
if (visibleBottomDocks().length > 0) {
|
||||
restartForceHideTimer(delaySeconds * 1000);
|
||||
}
|
||||
|
||||
log("loaded with delaySeconds=" + delaySeconds);
|
||||
}
|
||||
|
||||
init();
|
||||
18
kwin/manjaro_dock_force_hide/contents/config/main.xml
Normal file
18
kwin/manjaro_dock_force_hide/contents/config/main.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
|
||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
|
||||
<kcfgfile name=""/>
|
||||
|
||||
<group name="Script-manjaro_dock_force_hide">
|
||||
<entry name="delaySeconds" type="Int">
|
||||
<label>Seconds to wait before force-hiding a popped-up dock.</label>
|
||||
<default>6</default>
|
||||
</entry>
|
||||
<entry name="debug" type="Bool">
|
||||
<label>Whether to log debug messages to the KWin journal.</label>
|
||||
<default>false</default>
|
||||
</entry>
|
||||
</group>
|
||||
</kcfg>
|
||||
12
kwin/manjaro_dock_force_hide/metadata.json
Normal file
12
kwin/manjaro_dock_force_hide/metadata.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"KPackageStructure": "KWin/Script",
|
||||
"KPlugin": {
|
||||
"Id": "manjaro_dock_force_hide",
|
||||
"Name": "Manjaro Dock Force Hide",
|
||||
"Description": "Force-hide bottom auto-hide Plasma docks a few seconds after they pop up.",
|
||||
"Version": "1.0.0",
|
||||
"License": "MIT"
|
||||
},
|
||||
"X-Plasma-API": "javascript",
|
||||
"X-Plasma-MainScript": "contents/code/main.js"
|
||||
}
|
||||
Reference in New Issue
Block a user