Define KBDs conditionally based on flag

Create KBDs that work when the Ergodox isn't attached.

There is a little noise in this diff created by running Prettier on the
buffer.
This commit is contained in:
William Carroll 2018-07-06 13:35:22 -04:00
parent bb8cb310fa
commit a9fed7009d

View file

@ -1,110 +1,123 @@
/* globals S,slate,_ */ // Support flag to branch KBDs depending on presence of Ergodox keyboard.
// Bindings for slate.
// Forked from rschmukler/dotfiles
// Hotkeys for quickly opening apps & changing window size
// Since the Ergodox has complicated modifier keys like "hyper" and "meh" key,
// we should prefer to use these when that keyboard is attached because it
// reduces the potential for collisions for Emacs KBDs. This becomes
// problematic, however, when the Ergodox is not attached because these keys are
// unavailable. Slate KBDs. Under these circumstances, potential collisions
// with Emacs KBDs is acceptable.
var modal_key = ":alt;shift;cmd;ctrl"; // hyper key var ergodox_attached = false;
var resize_key = ":alt;shift;ctrl"; // meh key
var HYPER = ":alt;shift;cmd;ctrl";
var MEH = ":alt;shift;ctrl";
var modal_key = ergodox_attached ? HYPER : ":ctrl;shift";
var resize_key = ergodox_attached ? MEH : ":alt;shift";
// Configs // Configs
S.cfga({ S.cfga({
defaultToCurrentScreen: true, defaultToCurrentScreen: true,
secondsBetweenRepeat: 0.1, secondsBetweenRepeat: 0.1,
checkDefaultsOnLoad: true, checkDefaultsOnLoad: true,
focusCheckWidthMax: 3000, focusCheckWidthMax: 3000
}); });
// window resizing bindings // window resizing bindings
var window_resizing_bindings = { var window_resizing_bindings = {
';': { ";": {
x: 'screenSizeX/3*2 + screenOriginX+20', x: "screenSizeX/3*2 + screenOriginX+20",
y: 'screenOriginY+20', y: "screenOriginY+20",
width: 'screenSizeX/3 - 40', width: "screenSizeX/3 - 40",
height: 'screenSizeY-100' height: "screenSizeY-100"
}, },
'g': { g: {
x: 'screenOriginX+20', x: "screenOriginX+20",
y: 'screenOriginY+20', y: "screenOriginY+20",
width: 'screenSizeX/3*2 - 40', width: "screenSizeX/3*2 - 40",
height: 'screenSizeY-100' height: "screenSizeY-100"
}, },
'o': { o: {
x: 'screenSizeX / 2 + screenOriginX + 20', x: "screenSizeX / 2 + screenOriginX + 20",
y: 'screenOriginY + 20', y: "screenOriginY + 20",
width: 'screenSizeX / 2 - 40', width: "screenSizeX / 2 - 40",
height: '(screenSizeY - 120) / 2' height: "(screenSizeY - 120) / 2"
}, },
',': { ",": {
x: 'screenSizeX / 2 + screenOriginX + 20', x: "screenSizeX / 2 + screenOriginX + 20",
y: '(screenSizeY - 120) / 2 + 20 + 20', y: "(screenSizeY - 120) / 2 + 20 + 20",
width: 'screenSizeX / 2 - 40', width: "screenSizeX / 2 - 40",
height: '(screenSizeY - 120) / 2' height: "(screenSizeY - 120) / 2"
}, },
'h': { h: {
x: 'screenOriginX+20', x: "screenOriginX+20",
y: 'screenOriginY+20', y: "screenOriginY+20",
width: 'screenSizeX*0.5 - 40', width: "screenSizeX*0.5 - 40",
height: 'screenSizeY-100' height: "screenSizeY-100"
}, },
'j': { j: {
x: 'screenOriginX+screenSizeX/6', x: "screenOriginX+screenSizeX/6",
y: 'screenOriginY+20', y: "screenOriginY+20",
width: '2*screenSizeX/3', width: "2*screenSizeX/3",
height: 'screenSizeY - 100' height: "screenSizeY - 100"
}, },
'k': { k: {
x: 'screenOriginX+20', x: "screenOriginX+20",
y: 'screenOriginY+20', y: "screenOriginY+20",
width: 'screenSizeX - 40', width: "screenSizeX - 40",
height: 'screenSizeY - 100' height: "screenSizeY - 100"
}, },
'l': { l: {
x: 'screenSizeX/2 + screenOriginX+20', x: "screenSizeX/2 + screenOriginX+20",
y: 'screenOriginY+20', y: "screenOriginY+20",
width: 'screenSizeX*0.5 - 40', width: "screenSizeX*0.5 - 40",
height: 'screenSizeY-100' height: "screenSizeY-100"
}, }
} };
var window_resizing_bindings = Object.keys(window_resizing_bindings).reduce(function(acc, kbd) { var window_resizing_bindings = Object.keys(window_resizing_bindings).reduce(
acc[kbd + resize_key] = S.op('move', window_resizing_bindings[kbd]); function(acc, kbd) {
return acc; acc[kbd + resize_key] = S.op("move", window_resizing_bindings[kbd]);
}, {}); return acc;
},
{}
);
S.bnda(window_resizing_bindings); S.bnda(window_resizing_bindings);
// Moves applications across multiple screens // Moves applications across multiple screens
var throwLeft = slate.operation('throw', {screen: '0', width: 'screenSizeX', height: 'screenSizeY',}); var throwLeft = slate.operation("throw", {
var throwRight = slate.operation('throw', {screen: '1', width: 'screenSizeX', height: 'screenSizeY',}); screen: "0",
width: "screenSizeX",
slate.bind('1:ctrl', throwLeft); height: "screenSizeY"
slate.bind('2:ctrl', throwRight); });
var throwRight = slate.operation("throw", {
screen: "1",
width: "screenSizeX",
height: "screenSizeY"
});
slate.bind("1:ctrl", throwLeft);
slate.bind("2:ctrl", throwRight);
var focus_apps = { var focus_apps = {
1: '1Password', 1: "1Password",
i: 'iTunes', i: "iTunes",
a: 'Atom', a: "Atom",
h: 'Dash', h: "Dash",
e: 'Emacs', e: "Emacs",
t: 'iTerm2', t: "iTerm2",
m: 'Messages', m: "Messages",
s: 'Spotify', s: "Spotify",
c: 'Google Chrome', c: "Google Chrome",
l: 'LimeChat', l: "LimeChat",
k: 'Slack', k: "Slack",
w: 'Wireshark', w: "Wireshark",
p: 'Tomato One', p: "Tomato One",
d: 'Discord', d: "Discord"
}; };
Object.keys(focus_apps).forEach(function(key) { Object.keys(focus_apps).forEach(function(key) {
app = focus_apps[key]; app = focus_apps[key];
S.bind(key + modal_key, S.op("focus", {app: app})); S.bind(key + modal_key, S.op("focus", { app: app }));
}); });