Skip to content

Instantly share code, notes, and snippets.

@mathias
Last active August 29, 2015 14:05
Show Gist options
  • Save mathias/5b7fdd29bee84c464414 to your computer and use it in GitHub Desktop.
Save mathias/5b7fdd29bee84c464414 to your computer and use it in GitHub Desktop.
(ns phoenix-config.core)
;; ## Phoenix Globals
(def Window js/Window)
(def api js/api)
(def focusedWindow #(.focusedWindow Window))
;; ## Math helpers
(defn round [num] (.round js/Math num))
(defn half [num] (/ num 2))
;; ## Grid functions
(defn calculate-grid
([coords]
(calculate-grid (focusedWindow) coords))
([win {:keys [x y width height]}]
(let [screen (.. win screen frameWithoutDockOrMenu)]
(clj->js {:x (round (+ (* x (.-width screen)) (.-x screen)))
:y (round (+ (* y (.-height screen)) (.-y screen)))
:width (round (* width (.-width screen)))
:height (round (* height (.-height screen)))}))))
(defn size-to-grid [coords]
(let [win (focusedWindow)]
(.setFrame win (calculate-grid win coords))))
;; ## Movement functions
(defn push-left []
(size-to-grid {:x 0
:y 0
:width 0.5
:height 1}))
(defn push-right []
(size-to-grid {:x 0.5
:y 0
:width 0.5
:height 1}))
(defn center-window []
(size-to-grid {:x 0.25
:y 0
:width 0.5
:height 1}))
(defn to-full-screen []
(size-to-grid {:x 0
:y 0
:width 1
:height 1}))
(def mash (js/Array. "ctrl" "alt" "cmd"))
(.bind api "left" mash push-left)
(.bind api "right" mash push-right)
(.bind api "c" mash center-window)
(.bind api "m" mash to-full-screen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment