Skip to content

Instantly share code, notes, and snippets.

@baris
Last active December 15, 2015 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baris/5211334 to your computer and use it in GitHub Desktop.
Save baris/5211334 to your computer and use it in GitHub Desktop.
KWin script to automatically move and resize windows to fit left or right half of the screen when switching windows.
var to_the_left = true;
previous_active_client_id = null;
function resize_client(client) {
geo = client.geometry;
geo.width = workspace.workspaceWidth / 2;
geo.height = workspace.workspaceHeight - 30;
client.geometry = geo;
}
function move_client(fun) {
for (var i = 0; i < 10; i++) {
fun();
}
}
workspace.clientActivated.connect(function(client) {
if (client === null) {
return;
} else if (previous_active_client_id === null) {
previous_active_client_id = client.windowId;
} else if (previous_active_client_id === client.windowId) {
return;
}
resize_client(client);
if (to_the_left === true) {
move_client(workspace.slotWindowPackLeft);
to_the_left = false;
} else {
move_client(workspace.slotWindowPackRight);
to_the_left = true;
}
move_client(workspace.slotWindowPackUp);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment