Skip to content

Instantly share code, notes, and snippets.

@Zren
Created August 19, 2016 18:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zren/6e36a7652237a6fa415f90abc7ab85f6 to your computer and use it in GitHub Desktop.
Save Zren/6e36a7652237a6fa415f90abc7ab85f6 to your computer and use it in GitHub Desktop.
function isGoogleChrome(client) {
var suffix = ' - Google Chrome';
return client.caption.indexOf(suffix) >= 0;
}
function applyGridCheck(client) {
var rect = client.geometry;
//print(rect.x, rect.y, rect.width, rect.height, client.caption);
var halfX = 960;
var halfY = 523;
if ((rect.x == 0 || rect.x == halfX) && rect.width == halfX && rect.y == 0 && rect.height == halfY) {
// (0 0 960 523) => (-5 -77 970 620)
// (960 0 960 523) => (955 -77 970 620)
rect.y = -77;
rect.width = halfX + 5 + 5;
rect.height = halfY + 77 + 5 + 15; // 620
if (rect.x == 0) {
rect.x = -5;
} else if (rect.x == halfX) {
rect.x = halfX-5;
}
client.geometry = rect;
}
}
function onClientFinishUserMovedResized(client) {
applyGridCheck(client);
}
function onClientAdded(client) {
if (isGoogleChrome(client)) {
client.clientFinishUserMovedResized.connect(onClientFinishUserMovedResized);
}
}
workspace.clientAdded.connect(onClientAdded);
var clients = workspace.clientList();
for (var i = 0; i < clients.length; i++) {
var client = clients[i];
onClientAdded(client);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment