Skip to content

Instantly share code, notes, and snippets.

@dirn
Created October 25, 2013 20:54
Show Gist options
  • Save dirn/7161681 to your computer and use it in GitHub Desktop.
Save dirn/7161681 to your computer and use it in GitHub Desktop.
slate.js
slate.configAll({
'defaultToCurrentScreen': true,
'secondsBetweenRepeat': 0.1,
'checkDefaultsOnLoad': true,
'focusCheckWidthMax': 3000,
'orderScreensLeftToRight': true,
});
// screen references
var leftScreen = '0';
var rightScreen = '1';
// operations
var centeredOnScreen = slate.operation('move', {
'x': '(screenSizeX-windowSizeX)/2',
'y': '(screenSizeY-windowSizeY)/2',
'width': 'windowSizeX',
'height': 'windowSizeY',
});
var leftChat = slate.operation('corner', {
'screen': leftScreen,
'direction': 'top-left',
'width': 'screenSizeX/7',
'height': 'screenSizeY',
});
var rightChat = leftChat.dup({
'screen': rightScreen,
'width': 650,
'height': 550,
});
var leftFullScreen = slate.operation('throw', {
'screen': leftScreen,
'width': 'screenSizeX',
'height': 'screenSizeY',
});
var leftTopRight = slate.operation('corner', {
'screen': leftScreen,
'direction': 'top-right',
'width': 'windowSizeX',
'height': 'windowSizeY',
});
var rightBottomRight = leftTopRight.dup({
'screen': rightScreen,
'direction': 'bottom-left',
});
var rightTopRight = rightBottomRight.dup({
'direction': 'top-right',
});
var nudge5 = slate.operation('nudge', {
'x': '+5%',
'y': '+5%',
});
var nudgeMinus5 = slate.operation('nudge', {
'x': '+500',
'y': '+0',
});
var skype = slate.operation('move', {
'screen': rightScreen,
'x': 'screenSizeX*3/4',
'y': 'screenSizeY*3/4',
'width': 'windowSizeX',
'height': 'windowSizeY',
});
var twoScreens = slate.layout('twoScreens', {
// 'Google Chrome': {
// 'operations': [centeredOnScreen],
// 'ignore-fail': true,
// 'repeat': true,
// },
// 'HipChat': {
// 'operations': [rightTopRight],
// 'ignore-fail': true,
// 'repeat': true,
// },
// 'iTerm': {
// 'operations': [leftFullScreen],
// },
// 'MacVim': {
// 'operations': [centeredOnScreen],
// 'ignore-fail': true,
// 'repeat': true,
// },
'Messages': {
'operations': [function(windowObject) {
var title = windowObject.title();
if (title !== undefined && title.match('Messages')) {
windowObject.doOperation(rightChat);
windowObject.doOperation(nudge5);
} else {
windowObject.doOperation(leftChat);
}
}],
'ignore-fail': true,
'repeat': true,
},
'Skype': {
'operations': [skype],
'ignore-fail': true,
'repeat': true,
},
// 'Twitter': {
// 'operations': [leftTopRight, function(windowObject) {
// windowObject.doOperation(slate.operation('nudge', {
// 'x': '-100',
// 'y': '+50',
// }));
// }],
// 'ignore-fail': true,
// 'repeat': true,
// },
});
slate.default(2, twoScreens);
slate.bindAll({
'1:ctrl': slate.operation('relaunch'),
'esc:cmd': slate.operation('hint'),
'left:ctrl,shift': slate.operation('nudge', {
'x': '-100',
'y': '+0',
}),
});
// helper functions
var valueOr = function(object, default_) {
if (typeof object === 'undefined') {
object = default_;
}
return object;
};
var withDefaults = function(options) {
return _.extend(defaults, options);
};
// config
slate.configAll({
'defaultToCurrentScreen': true,
'secondsBetweenRepeat': 0.1,
'checkDefaultsOnLoad': true,
'focusCheckWidthMax': 3000,
'orderScreensLeftToRight': true,
});
// screen references
var screens = {left: '0', right: '1'};
// convenience functions
var center = function(width, height) {
return move('(screenSizeX-windowSizeX)/2', '(screenSizeY-windowSizeY)/2', width, height);
};
var corner = function(screen, direction, width, height) {
width = valueOr(width, 'windowSizeX');
height = valueOr(height, 'windowSizeY');
return slate.operation('corner', {
screen: screen,
direction: direction,
width: width,
height: height
});
};
var fullscreen = function(screen) {
options = {};
if (typeof screen !== 'undefined') {
options.screen = screen;
}
return slate.operation('corner', _.extend(options, {
direction: 'top-left',
width: 'screenSizeX',
height: 'screenSizeY'
}));
};
var move = function(x, y, width, height) {
width = valueOr(width, 'windowSizeX');
height = valueOr(height, 'windowSizeY');
return slate.operation('move', {
x: x,
y: y,
width: width,
height: height
});
};
var nudge = function(x, y) {
return slate.operation('nudge', {
x: x,
y: y
});
};
var throw_ = function(screen, x, y, width, height) {
x = valueOr(x, 'windowTopLeftX');
y = valueOr(y, 'windowTopLeftY');
width = valueOr(width, 'windowSizeX');
height = valueOr(height, 'windowSizeY');
return slate.operation('throw', {
screen: screen,
x: x,
y: y,
width: width,
height: height
});
};
// operations
var leftChat = corner(screens.left, 'top-left', 'screenSizeX/7', 'screenSizeY');
var rightChat = corner(screens.right, 'top-left', 650, 550);
var leftTopRight = corner(screens.left, 'top-right');
var rightBottomRight = corner(screens.right, 'bottom-right');
var rightTopRight = corner(screens.right, 'top-right');
// layouts
var defaults = {'ignore-fail': true, repeat: true};
var twoScreens = slate.layout('twoScreens', {
'Google Chrome': withDefaults({
operations: [center()]
}),
'HipChat': withDefaults({
operations: [rightTopRight, nudge('-20%', '+10%')]
}),
'iTerm': withDefaults({
operations: [fullscreen(screens.left)]
}),
'MacVim': withDefaults({
operations: [center()]
}),
'Messages': withDefaults({
'operations': [function(windowObject) {
var title = windowObject.title();
if (title !== undefined && title.match('Messages')) {
windowObject.doOperation(rightChat);
windowObject.doOperation(nudge('+5%', '+5%'));
} else {
windowObject.doOperation(leftChat);
}
}]
}),
'Skype': withDefaults({
operations: [rightBottomRight, nudge('-20%', '-20%')]
}),
'Twitter': withDefaults({
operations: [leftTopRight, nudge('-100', '+50')]
}),
});
slate.default(2, twoScreens);
// bindings
slate.bindAll({
'1:ctrl': slate.operation('relaunch'),
'esc:cmd': slate.operation('hint'),
'f:alt,cmd,ctrl': fullscreen(),
'm:alt,cmd,ctrl': center(),
'h:cmd,ctrl,shift': throw_(screens.left),
'l:cmd,ctrl,shift': throw_(screens.right),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment