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

minimized windows to the current VD when VD is changed

Tags: None
(comma "," separated)
sir_herrbatka
Registered Member
Posts
212
Karma
0
hello, I want to write simple kwin script but I have no idea how to do it.

I want to make all windows being moved to the current desktop when unmminimized. How difficult is to get this behavior?

Last edited by sir_herrbatka on Sun Oct 28, 2012 2:56 pm, edited 1 time in total.
luebking
Karma
0
Sth. like this (just written down, not tested. will contain typos.)

workspace.clientMinimized.connect(function(client) {
client.setDesktop(workspace.currentDesktop);
});

For more info see here:
http://techbase.kde.org/Development/Tut ... /Scripting
and here
http://techbase.kde.org/Development/Tut ... ipting/API
mgraesslin
KDE Developer
Posts
572
Karma
7
OS
instead of client.setDestkop() just use:
client.desktop = workspace.currentDesktop

Don't forget to share your script on kde-look.org ;-)
sir_herrbatka
Registered Member
Posts
212
Karma
0
hmmm, for some reason this script has no effect. I restore minized window and I'm getting moved to the desktop where the window is instead of moving window to the current desktop.

edit,
ok, actually it WORKS

workspace.clientUnminimized.connect(function(client) {
client.desktop = workspace.currentDesktop;
});

but the problem is that clicking on the icon in the icon tasks moves to the desktop containing the window first, and then restores the window. Right clicking and using minimize box bring the effect, but well… that's suboptimal for me.

It feels sad.
luebking
Karma
0
The problem is that the taskbar does not unminize the window but activates it.
you're implictily kicked to the "proper" desktop and the window is automatically unminimized by this.

What you actually want to do is to on every VD change move all minimized clients to that VD (otherwise you'd have to pre-act on the taskbar, not act on window state changes - that's too late.)
sir_herrbatka
Registered Member
Posts
212
Karma
0
uh, I see. I'm not quite sure If I am able to do this. I'm not a programmer at all. I see that there is client.isMinimized() but i have no idea how to use it :/
luebking
Karma
0
I bet you can.

You already managed to bind a function to an event - now you only need to pick the proper event, use the proper parameter in the function - "(client)" does not match that event - and then find a way to do sth. with all clients [1] which are not ("!") minimized and assign their desktop variable the known way.

Try. Then try hader. And if you've remaining questions, just call back =)

[1] hint: see here http://techbase.kde.org/Development/Tut ... ng#Clients
sir_herrbatka
Registered Member
Posts
212
Karma
0
Should I create a new array? But how do I add new elements to array?
mgraesslin
KDE Developer
Posts
572
Karma
7
OS
http://www.w3schools.com/jsref/jsref_obj_array.asp

Code: Select all
var myArray = [];
// one way
myArray.push(myElement);
// other way
myArray[myArray.length] = myElement;
sir_herrbatka
Registered Member
Posts
212
Karma
0
var MinClients = new Array();

workspace.clientMinimized.connect(function(client) {
MinClients.push(client);
});

will push client after being minimized to the MinClients array?

Edit
My plan is to push every window after being minimized to the array and then move every element of the array to the current VD after VD being changed. Will it work this way?
mgraesslin
KDE Developer
Posts
572
Karma
7
OS
would work, but solution is not optimal as you would need to track windows unminimizing and closing. I would just go through all windows when changing the desktop.

Something like:
Code: Select all
workspace.currentDesktopChanged.connect(function () {
    var clients = workspace.clientList();
    for (var i = 0; i < clients.length; i += 1) {
        if (clients[i].minimized) {
            clients[i].desktop = workspace.currentDesktop;
        }
    }
});


code is not tested :-)
sir_herrbatka
Registered Member
Posts
212
Karma
0
It is tested now. :-)

It WORKS! wow, it's a major improvement for me. Thank you mgraesslin, you rock.
sir_herrbatka
Registered Member
Posts
212
Karma
0
I want to only add that i posted the script on the KDE-look.org.
sir_herrbatka
Registered Member
Posts
212
Karma
0
Hi again!

I wanted to add extra check if window is not on all desktops. I figured out that i need:

if (clients[i].desktop != -1) {
}

But it does not work for some reason. I feel a little retarded, it's so simple and I can't make it work.
mgraesslin
KDE Developer
Posts
572
Karma
7
OS
The client has a property onAllDesktops, so just do:
Code: Select all
if (client.onAllDesktops) {
     // do extra handling
}


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft