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

Help with a kwin script

Tags: None
(comma "," separated)
gh403
Registered Member
Posts
1
Karma
0

Help with a kwin script

Tue Feb 12, 2013 11:58 pm
So here's my script for kwin. The goal is to be able to have a keyboard shortcut that will expand the active window to its neighbors' edges.

Code: Select all
function GrowWindow()
{
  var client = workspace.activeClient;
  var clients = workspace.clientList();
  var bounds = client.geometry;
  var newBounds = bounds;  // I can't figure out how to make a new QRect.

  newBounds.x = 0;
  newBounds.y = 0;
  newBounds.width = workspace.workspaceWidth / workspace.desktopGridWidth;
  newBounds.height = workspace.workspaceHeight / workspace.desktopGridHeight;

  for(var i = 0; i < clients.length; i++) {
    if(clients[i].caption == client.caption) {
      continue;
    }
    if(clients[i].desktop != workspace.currentDesktop) {
      continue;
    }

    var clientBounds = clients[i].geometry;

    if(clientBounds.x + clientBounds.width < bounds.x && clientBounds.x + clientBounds.width > newBounds.x) {
      newBounds.x = clientBounds.x + clientBounds.width;
    }
    else if(clientBounds.x < bounds.x + bounds.width && clientBounds.x > newBounds.x + newBounds.width) {
      newBounds.width = clientBounds.x - bounds.width;
    }

    if(clientBounds.y + clientBounds.height < bounds.y && clientBounds.y + clientBounds.height > newBounds.y) {
      newBounds.y = clientBounds.y + clientBounds.height;
    }
    else if(clientBounds.y < bounds.y + bounds.height && clientBounds.y > newBounds.y + newBounds.height) {
      newBounds.height = clientBounds.y - bounds.height;
    }
  }

  // Now assign the new geometry
  client.geometry = newBounds;
}

registerShortcut("grow", "Grow Window to Available Space", "", GrowWindow);


The problem is that the window always fills the entire screen. What am I doing wrong?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Help with a kwin script

Wed Feb 13, 2013 5:11 am
Moved to the KWin forum.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
mgraesslin
KDE Developer
Posts
572
Karma
7
OS

Re: Help with a kwin script

Wed Feb 13, 2013 7:28 am
you are using "workspace.workspaceWidth / workspace.desktopGridWidth;" which is unsuited for this task. What you want to use is workspace.clientArea() with the ClientAreaOption best suited for your task.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient