From a779b2ee8eb46d4c18fb03b4a5a70aca74057a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=82=E7=84=B6=20=28Sauntor=29?= Date: Mon, 17 Jul 2023 16:40:24 +0800 Subject: [PATCH] Fixed #4 Modified from https://github.com/YidaozhanYa/kwin-maxmize-to-new-desktop/commit/f209b10b5fe1f96075ef6217872cfedc6a622679 , and avoid switching desktop on login and logout --- contents/code/main.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/contents/code/main.js b/contents/code/main.js index 7d9b4c0..c1ac5c2 100644 --- a/contents/code/main.js +++ b/contents/code/main.js @@ -18,6 +18,10 @@ const NewDesktopPositionValue = { NextToCurrent: 1, NextToApp: 2, }; +/** + * Clients that should skipped always + */ +const GlobalSkippedClients = ['ksmserver-logout-greeter', 'plasmashell']; function Config() { } @@ -83,7 +87,11 @@ State.prototype.isKnownClient = function(client) { } State.prototype.isSkippedClient = function (client) { - var idx = this.cachedConfig.blockWMClass.indexOf(client.resourceClass.toString()); + const resourceClass = client.resourceClass.toString(); + if (GlobalSkippedClients.indexOf(resourceClass) != -1) { + return true; + } + var idx = this.cachedConfig.blockWMClass.indexOf(); return idx != -1; } @@ -179,6 +187,35 @@ function Main() { log('handle maximize done'); }, + added: function(client) { + log('handle added'); + var area = workspace.clientArea(KWin.MaximizeArea, client); + + // const clause = { + // resourceClass: client.resourceClass.toString(), + // clientArea: { + // width: client.width, + // height: client.height + // }, + // maximizeArea: { + // width: area.width, + // height: area.height + // } + // }; + // log('clause = ' + JSON.stringify(clause)); + + // There may be a 1-pixel gap on some display/screen + var isMaximized = client.width + 1 >= area.width && client.height + 1 >= area.height; + + if (isMaximized) { + self.handlers.maximize(client, true, true); + // } else { + // log('not maximized, skip'); + } + log('handle added done'); + //if (!(!isMaximized || state.isSkippedClient(client) || state.isSkippedName(client))) {main.moveToNewDesktop(client);}; + }, + closed: function(client) { log('handle remove'); self.state.debugDump(); @@ -367,12 +404,14 @@ Main.prototype.moveBack = function(client, removed) { Main.prototype.install = function() { workspace.clientFullScreenSet.connect(this.handlers.fullscreen); workspace.clientMaximizeSet.connect(this.handlers.maximize); + workspace.clientAdded.connect(this.handlers.added); log("Handler installed"); } Main.prototype.uninstall = function() { workspace.clientFullScreenSet.disconnect(this.handlers.fullscreen); workspace.clientMaximizeSet.disconnect(this.handlers.maximize); + workspace.clientAdded.disconnect(this.handlers.added); log("Handler cleared"); }