shift-shell/kwin/scripts/convergentwindows/contents/ui/main.qml
Devin Lin c45f9ed446 envmanager: Handle SSD toggling with kwin rules
Replace the convergentwindows KWin script SSD toggling with KWin rules to ensure
windows are maximized and have no window border (and toggle off for
docked mode). KWin rules work immediately at window creation, which is
more efficient than listening to window creation events and manually
changing properties on them.

Currently, window rules setting maximization don't seem to address all cases where a window gets unmaximized, so for the time being we will still need the logic in convergentwindows to handle any sidecases.
2025-03-21 16:00:12 +00:00

124 lines
3.9 KiB
QML

// SPDX-FileCopyrightText: 2023 Plata Hill <plata.hill@kdemail.net>
// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later
import QtQuick
import org.kde.kwin as KWinComponents
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
// This script ensures that windows stay maximized in the shell.
//
// We eventually want to replace this with the window rules implementation,
// but it seems that window maximize rules still don't work for all cases just yet
// (ex. unmaximizing fullscreen window)
Loader {
id: root
property var currentWindow
function run(window) {
// HACK: don't maximize xwaylandvideobridge
// see: https://invent.kde.org/plasma/plasma-mobile/-/issues/324
if (window.resourceClass === 'xwaylandvideobridge') {
return;
}
if (!window.normalWindow) {
return;
}
if (ShellSettings.Settings.convergenceModeEnabled) {
return;
}
if (!window.fullScreen) {
const output = window.output;
const desktop = window.desktops[0]; // assume it's the first desktop that the window is on
if (desktop === undefined) {
return;
}
const maximizeRect = KWinComponents.Workspace.clientArea(KWinComponents.Workspace.MaximizeArea, output, desktop);
// set the window to the maximized size and position instantly, avoiding race condition
// between maximizing and window decorations being turned off (changing window height)
// see: https://invent.kde.org/teams/plasma-mobile/issues/-/issues/256
window.frameGeometry = maximizeRect;
}
if (!window.fullScreen) {
// run maximize after to ensure the state is maximized
window.setMaximize(true, true);
}
}
Connections {
target: currentWindow
function onFullScreenChanged() {
currentWindow.interactiveMoveResizeFinished.connect((currentWindow) => {
root.run(currentWindow);
});
root.run(currentWindow);
}
function onMaximizedChanged() {
if (!currentWindow.maximizable) {
return;
}
currentWindow.interactiveMoveResizeFinished.connect((currentWindow) => {
root.run(currentWindow);
});
root.run(currentWindow);
}
}
Connections {
target: ShellSettings.Settings
function onConvergenceModeEnabledChanged() {
const windows = KWinComponents.Workspace.windows;
for (let i = 0; i < windows.length; i++) {
if (windows[i].normalWindow) {
root.run(windows[i]);
}
}
}
}
Connections {
target: KWinComponents.Workspace
function onWindowAdded(window) {
if (window.normalWindow) {
window.interactiveMoveResizeFinished.connect((window) => {
root.run(window);
});
root.run(window);
}
}
function onWindowActivated(window) {
if (window.normalWindow) {
currentWindow = window;
window.interactiveMoveResizeFinished.connect((window) => {
root.run(window);
});
root.run(window);
}
}
function onScreensChanged() {
// Windows are moved from the external screen
// to the internal screen if the external screen
// is disconnected.
const windows = KWinComponents.Workspace.windows;
for (var i = 0; i < windows.length; i++) {
if (windows[i].normalWindow) {
root.run(windows[i]);
}
}
}
}
}