This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Window geometry depending on which display is connected

Tags: None
(comma "," separated)
pilat
Registered Member
Posts
27
Karma
0
OS
Here's what I'm trying to achieve:

1. If i'm working on the notebook's screen(LVDS 1366x768) -- Google Chrome should start maximized;

2. If I'm working on the external display (VGA 1920x1080) -- Google Chrome should have specified geometry (size and position);

Does KWin allow something like this?


pilat, proud to be a member of KDE forums since 2008-Oct.
luebking
Karma
0
pilat
Registered Member
Posts
27
Karma
0
OS
Scripting is going to work. But I can't get through the documentation..

In particular, how to make client maximized.


pilat, proud to be a member of KDE forums since 2008-Oct.
mgraesslin
KDE Developer
Posts
572
Karma
7
OS
pilat wrote:Scripting is going to work. But I can't get through the documentation..

In particular, how to make client maximized.


workspace.slotWindowMaximize() - but it looks like only active client can get maximized that way. The property on Client is either not supported or the documentation is outdated.
luebking
Karma
0
Nope, maximizeMode is not exported :-(
For the moment, you'll have to
Code: Select all
var aClient = workspace.activeClient;
workspace.activeClient = clientToMaximize;
workspace.slotWindowMaximize();
workspace.activeClient = aClient;
pilat
Registered Member
Posts
27
Karma
0
OS
Thank you! What about restoring to normal (from maximized)?

It looks that applying custom geomtry does not work if the window is started maximized... Here's my curent code:

Code: Select all
workspace.clientAdded.connect(function(client) {

  // Only move a finger if this is Google Chrome window
  if (client.resourceClass == "google-chrome-stable") {

    print("Got one on", workspace.displayWidth, " wide screen");
    print("Caption:", client.caption);

    if (workspace.displayWidth > 1412) { // that is draft, so magic numbers are allowed!

      print("Display is wide enough: apply custom geometry");
      var rect = client.geometry;
      rect.x = 0; rect.y = 0;
      rect.width = 1412;
      rect.height = workspace.displayHeight;
      client.geometry = rect;
    }
  }
});


Seems to only work if the window is started non-maximized.


pilat, proud to be a member of KDE forums since 2008-Oct.
pilat
Registered Member
Posts
27
Karma
0
OS
luebking wrote:Nope, maximizeMode is not exported :-(
For the moment, you'll have to
Code: Select all
var aClient = workspace.activeClient;
workspace.activeClient = clientToMaximize;
workspace.slotWindowMaximize();
workspace.activeClient = aClient;


Does not work.. The window is activated, but not maximized.

I've even tried the following "direct" (without signals) code in the wm console:
Code: Select all
workspace.activeClient=clients[6];
workspace.slotWindowMaximize();


It activates the window I need to maximize (brings it to forward, puts focus into it), but it is "WM Console" window itself that gets maximized.. Tried with Google Chrome an Okular. With pause between those two lines and without.


pilat, proud to be a member of KDE forums since 2008-Oct.
luebking
Karma
0
a bit more tricky since the client is not actually mapped when the added signal fires.
this should work:

Code: Select all
/********************************************************************
 KWin - the KDE window manager
 This file is not part of the KDE project.

Copyright (C) 2014 Thomas Lübking <thomas.luebking@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/

var RELEVANT = Array("chromium", "chrome");
var lastAdded;

var fixGgeometry = function() {
    var area = workspace.clientArea(KWin.PlacementArea, workspace.activeScreen, workspace.currentDesktop);
    if (area.width < 1025) { // "small screen"
        var activeClient = workspace.activeClient;
        if (activeClient != lastAdded)
            workspace.activeClient = lastAdded;
        var geo = lastAdded.geometry;
        geo.x = area.x;
        geo.y = area.y;
        lastAdded.geometry = geo;
        workspace.slotWindowMaximize();
        if (activeClient != lastAdded)
            workspace.activeClient = activeClient;
    } else { // big screen -> nice golden mean ratio of placement area
        var geo = lastAdded.geometry;
        geo.width = 10*area.width/16;
        geo.height = 10*area.height/16;
        // center - it's likely 0x0 otherwise
        geo.x = area.x + (area.width - geo.width) / 2;
        geo.y = area.y + (area.height - geo.height) / 2;
        lastAdded.geometry = geo;
    }
};

var geometryFix = new QTimer;
geometryFix.singleShot = true;
geometryFix.timeout.connect(fixGgeometry);
workspace.clientAdded.connect(
    function(client) {
        if (RELEVANT.indexOf(client.resourceClass.toString()) > -1) {
            lastAdded = client;
            var geo = client.geometry;
            geo.width = 600; // explicit width -> ensure the client isn't maximized
            client.geometry = geo;
            geometryFix.start(1); // wait until the client is actually mapped and activ(atabl)e
        }
    }
);
pilat
Registered Member
Posts
27
Karma
0
OS
luebking wrote:a bit more tricky since the client is not actually mapped when the added signal fires.


Thank you for this example. I'd like to confirm one thing:

There's a block:
Code: Select all
        var activeClient = workspace.activeClient;
        if (activeClient != lastAdded)
            workspace.activeClient = lastAdded;


Why it is expected to be executed in "Small area" case only? Shouldn't it be before `if (area.width < 1025)` line?


pilat, proud to be a member of KDE forums since 2008-Oct.
luebking
Karma
0
changing the active client is only required to maximize it.
you don't want it maximized on the big screen, right?
pilat
Registered Member
Posts
27
Karma
0
OS
Thank you. Here's my version of the script:
https://github.com/mityukov/kwinscripts ... de/main.js

There is strange behavior, however: first time a new Google Chrome window is opened maximized. If I closeit and then re-open -- it becomes of expected size.


pilat, proud to be a member of KDE forums since 2008-Oct.
luebking
Karma
0
Yupp see this (when creating new windows with the chromium shortcut at least)
-> can you please bump this thread next week (so i won't forget it ;-)


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora, watchstar