You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
6.7 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. 'use strict';
  2. var keys = [];
  3. var controlShift = ['ctrl', 'shift'];
  4. var controlAltShift = ['ctrl', 'alt', 'shift'];
  5. var controlCommandShift = ['ctrl', 'cmd', 'shift'];
  6. var margin = 0;
  7. var increment = 0.05;
  8. /* Position */
  9. var Position = {
  10. central: function(frame, window) {
  11. return {
  12. x: frame.x + ((frame.width - window.width) / 2),
  13. y: frame.y + ((frame.height - window.height) / 2)
  14. };
  15. },
  16. top: function(frame, window) {
  17. return {
  18. x: window.x,
  19. y: frame.y
  20. };
  21. },
  22. bottom: function(frame, window) {
  23. return {
  24. x: window.x,
  25. y: (frame.y + frame.height) - window.height
  26. };
  27. },
  28. left: function(frame, window) {
  29. return {
  30. x: frame.x,
  31. y: window.y
  32. };
  33. },
  34. right: function(frame, window) {
  35. return {
  36. x: (frame.x + frame.width) - window.width,
  37. y: window.y
  38. };
  39. },
  40. topLeft: function(frame, window, margin) {
  41. return {
  42. x: Position.left(frame, window).x + margin,
  43. y: Position.top(frame, window).y + margin
  44. };
  45. },
  46. topRight: function(frame, window, margin) {
  47. return {
  48. x: Position.right(frame, window).x - margin,
  49. y: Position.top(frame, window).y + margin
  50. };
  51. },
  52. bottomLeft: function(frame, window, margin) {
  53. return {
  54. x: Position.left(frame, window).x + margin,
  55. y: Position.bottom(frame, window).y - margin
  56. };
  57. },
  58. bottomRight: function(frame, window, margin) {
  59. return {
  60. x: Position.right(frame, window).x - margin,
  61. y: Position.bottom(frame, window).y - margin
  62. };
  63. }
  64. };
  65. /* Grid */
  66. var Frame = {
  67. width: 1,
  68. height: 1,
  69. half: {
  70. width: 0.5,
  71. height: 0.5
  72. }
  73. };
  74. /* Window Functions */
  75. Window.prototype.to = function(position) {
  76. this.setTopLeft(position(this.screen().visibleFrameInRectangle(), this.frame(), margin));
  77. }
  78. Window.prototype.grid = function(x, y, reverse) {
  79. var frame = this.screen().visibleFrameInRectangle();
  80. var newWindowFrame = _(this.frame()).extend({
  81. width: (frame.width * x) - (2 * margin),
  82. height: (frame.height * y) - (2 * margin)
  83. });
  84. var position = reverse ? Position.topRight(frame, newWindowFrame, margin) :
  85. Position.topLeft(frame, newWindowFrame, margin);
  86. this.setFrame(_(newWindowFrame).extend(position));
  87. }
  88. Window.prototype.snapSize = function(axis) {
  89. Phoenix.log(axis);
  90. var modalmessage = new Modal();
  91. modalmessage.message = 'test';
  92. modal.duration = 2;
  93. modal.show();
  94. var frame = this.screen().visibleFrameInRectangle();
  95. if (axis === 'x') {
  96. var newWindowFrame = _(this.frame()).extend({
  97. width: (frame.width)
  98. });
  99. } else {
  100. var newWindowFrame = _(this.frame()).extend({
  101. height: (frame.height)
  102. });
  103. }
  104. var position = reverse ? Position.topRight(frame, newWindowFrame, margin) :
  105. Position.topLeft(frame, newWindowFrame, margin);
  106. this.setFrame(_(newWindowFrame).extend(position));
  107. }
  108. Window.prototype.reverseGrid = function(x, y) {
  109. this.grid(x, y, true);
  110. }
  111. Window.prototype.resize = function(multiplier) {
  112. var frame = this.screen().visibleFrameInRectangle();
  113. var newSize = this.size();
  114. if (multiplier.x) {
  115. newSize.width += frame.width * multiplier.x;
  116. }
  117. if (multiplier.y) {
  118. newSize.height += frame.height * multiplier.y;
  119. }
  120. this.setSize(newSize);
  121. }
  122. Window.prototype.increaseWidth = function() {
  123. this.resize({
  124. x: increment
  125. });
  126. }
  127. Window.prototype.decreaseWidth = function() {
  128. this.resize({
  129. x: -increment
  130. });
  131. }
  132. Window.prototype.increaseHeight = function() {
  133. this.resize({
  134. y: increment
  135. });
  136. }
  137. Window.prototype.decreaseHeight = function() {
  138. this.resize({
  139. y: -increment
  140. });
  141. }
  142. /* Position Bindings */
  143. keys.push(new Key('q', controlShift, function() {
  144. Window.focused() && Window.focused().to(Position.topLeft);
  145. }));
  146. keys.push(new Key('w', controlShift, function() {
  147. Window.focused() && Window.focused().to(Position.topRight);
  148. }));
  149. keys.push(new Key('a', controlShift, function() {
  150. Window.focused() && Window.focused().to(Position.bottomLeft);
  151. }));
  152. keys.push(new Key('s', controlShift, function() {
  153. Window.focused() && Window.focused().to(Position.bottomRight);
  154. }));
  155. keys.push(new Key('z', controlShift, function() {
  156. Window.focused() && Window.focused().to(Position.central);
  157. }));
  158. /* Grid Bindings */
  159. keys.push(new Key('p', controlShift, function() {
  160. Window.focused() && Window.focused().grid(Frame.half.width, Frame.half.height);
  161. }));
  162. keys.push(new Key('o', controlShift, function() {
  163. Window.focused() && Window.focused().grid(Frame.width, Frame.half.height);
  164. }));
  165. keys.push(new Key('k', controlShift, function() {
  166. Window.focused() && Window.focused().grid(Frame.half.width, Frame.height);
  167. }));
  168. keys.push(new Key('l', controlShift, function() {
  169. Window.focused() && Window.focused().grid(Frame.width, Frame.height);
  170. }));
  171. /* Reverse Grid Bindings */
  172. keys.push(new Key('å', controlAltShift, function() {
  173. Window.focused() && Window.focused().reverseGrid(Frame.half.width, Frame.half.height);
  174. }));
  175. keys.push(new Key('p', controlAltShift, function() {
  176. Window.focused() && Window.focused().reverseGrid(Frame.width, Frame.half.height);
  177. }));
  178. keys.push(new Key('ä', controlAltShift, function() {
  179. Window.focused() && Window.focused().reverseGrid(Frame.half.width, Frame.height);
  180. }));
  181. keys.push(new Key('ö', controlAltShift, function() {
  182. Window.focused() && Window.focused().reverseGrid(Frame.width, Frame.height);
  183. }));
  184. /* Resize Bindings */
  185. keys.push(new Key(',', controlShift, function() {
  186. Window.focused() && Window.focused().increaseWidth();
  187. }));
  188. keys.push(new Key('.', controlShift, function() {
  189. Window.focused() && Window.focused().increaseHeight();
  190. }));
  191. keys.push(new Key(',', controlAltShift, function() {
  192. Window.focused() && Window.focused().decreaseWidth();
  193. }));
  194. keys.push(new Key('.', controlAltShift, function() {
  195. Window.focused() && Window.focused().decreaseHeight();
  196. }));
  197. // make full width but same height
  198. keys.push(new Key('z', controlCommandShift, function() {
  199. var modalmessage = new Modal();
  200. modalmessage.message = 'test';
  201. modal.duration = 2;
  202. modal.show();
  203. Window.focused() && Window.focused().snapSize('x');
  204. }));
  205. function focusApp(name) {
  206. Phoenix.log('About to focus ' + name);
  207. App.runningApps().forEach(function(app) {
  208. if (app.name() === name) {
  209. Phoenix.log('Found and focusing ' + name);
  210. Phoenix.log(app.focus());
  211. Phoenix.log('Done focusing ' + name);
  212. }
  213. });
  214. }
  215. keys.push(new Key('g', controlCommandShift, function () {
  216. focusApp('Google Chrome');
  217. }));
  218. keys.push(new Key('a', controlCommandShift, function () {
  219. focusApp('Atom');
  220. }));
  221. keys.push(new Key('s', controlCommandShift, function () {
  222. focusApp('Slack');
  223. }));
  224. keys.push(new Key('t', controlCommandShift, function () {
  225. focusApp('iTerm');
  226. }));
  227. keys.push(new Key('m', controlCommandShift, function () {
  228. focusApp('Messages');
  229. }));