Last active
December 22, 2024 08:52
-
-
Save pepe/160ae0998bebd8d27694c59789f5ea1a to your computer and use it in GitHub Desktop.
jwno config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import jwno/auto-layout) | |
(import jwno/indicator) | |
(import jwno/util) | |
(import jwno/log) | |
(def dir-keys | |
"Direction keys for all the other mappings" | |
{:left "u" | |
:down "j" | |
:up "k" | |
:right "i"}) | |
(def {:key-manager key-man | |
:command-manager command-man | |
:window-manager window-man | |
:ui-manager ui-man | |
:hook-manager hook-man | |
:repl-manager repl-man} | |
"Define all the managers." | |
jwno/context) | |
(def repl-server | |
"Define repl server" | |
(or (:get-default-server repl-man) | |
(:start-server repl-man))) | |
(util/export-to-repl repl-server window-man) | |
(defn move-window-after-split | |
``` | |
Move the activated window into the new empty frame, | |
and activate (move focus to) that frame. | |
``` | |
[frame] | |
(def all-sub-frames (in frame :children)) | |
(def all-wins (in (first all-sub-frames) :children)) | |
(def move-to-frame (in all-sub-frames 1)) | |
(when (>= (length all-wins) 2) | |
(:add-child move-to-frame (:get-current-window frame))) | |
(:activate move-to-frame)) | |
(defn match-exe-name | |
"Matches the windows exe to `exe-name`." | |
[exe-name] | |
(fn [win] | |
(def win-exe (:get-exe-path win)) | |
(string/has-suffix? (string "\\" exe-name) win-exe))) | |
(defmacro defkeymap | |
``` | |
Convenience macro for defining multiple keys in keymap. | |
If `transient` is true, `:pop-keymap` is added for enter and esc. | |
``` | |
[key-man keypairs &opt transient] | |
(with-syms [keymap key-seq cmd docs] | |
~(let [,keymap (:new-keymap ,key-man)] | |
(loop [[,key-seq ,cmd ,docs] :in ,keypairs] | |
(:define-key ,keymap ,key-seq ,cmd ,docs)) | |
,(when transient | |
~(do | |
(:define-key ,keymap "enter" :pop-keymap "Cancel") | |
(:define-key ,keymap "esc" :pop-keymap "Cancel"))) | |
,keymap))) | |
(def resize-mode-keymap | |
"A transient key map for resizing frames." | |
(defkeymap key-man | |
[[(in dir-keys :down) [:resize-frame 0 -100] "Make window lower"] | |
[(in dir-keys :up) [:resize-frame 0 100] "Make window taller"] | |
[(in dir-keys :left) [:resize-frame -100 0] "Make window narrower"] | |
[(in dir-keys :right) [:resize-frame 100 0] "Make window wider"] | |
["=" :balance-frames "Balance windows"] | |
[";" [:zoom-in 0.7] "Zoom in"] | |
["shift + ;" [:zoom-in 0.3]] "Zoom out"] | |
true)) | |
(def yank-mode-keymap | |
"A transient key map for moving windows around." | |
(defkeymap key-man | |
(seq [[cmd key] :pairs dir-keys] | |
[key [:move-window cmd] (string "Move window " cmd)]) | |
true)) | |
(def adjacent-move-arr | |
"A keys for moving windows around and moving in frames." | |
(let [res (array/new 8)] | |
(loop [[cmd key] :pairs dir-keys] | |
(array/push res | |
[(string "win + ctrl + " key) [:adjacent-frame cmd] | |
(string "Move to " cmd " frame")] | |
[(string "win + shift + " key) [:move-window cmd] | |
(string "Move window " cmd)])) | |
res)) | |
(def window-mode-keymap | |
"Transient keymap for window manipulation" | |
(defkeymap key-man | |
[["d" :describe-window "Describe window"] | |
["m" :manage-window "Manage window"] | |
["i" :ignore-window "Ignore window"]] | |
true)) | |
(def root-keymap | |
"Complete keymap with all the parts" | |
(defkeymap key-man | |
[["win + shift + /" :show-root-keymap "Show root keymap"] | |
["win + shift + q" :quit "Quit"] | |
["win + enter" [:exec true "wt.exe"] "Run terminal"] | |
["win + shift + enter" [:exec true "firefox-nightly.exe"] "Run firefox"] | |
["win + shift + r" [:repl true "127.0.0.1" 9999] "Connect repl"] | |
["win + r" :retile "Retile"] | |
["win + shift + c" :close-window-or-frame "Close window or frame"] | |
["win + ctrl + f" :flatten-parent "Flatten parent"] | |
["win + ," [:split-frame :horizontal 2 [0.5] move-window-after-split] | |
"Horizontal split"] | |
["win + ." [:split-frame :vertical 2 [0.5] move-window-after-split] | |
"Vertical split"] | |
["win + =" :balance-frames "Balance frames"] | |
["win + ;" [:zoom-in 0.7] "Zoom in"] | |
["win + shift + ;" [:zoom-in 0.3] "Zoom out"] | |
["win + f" :fill-monitor "File monitor"] | |
["win + p" :cascade-windows-in-frame "Cascade windows in frame"] | |
[(string "win + " (in dir-keys :down)) [:enum-frame :prev] "Previous frame"] | |
[(string "win + " (in dir-keys :up)) [:enum-frame :next] "Next frame"] | |
[(string "win + " (in dir-keys :left)) [:enum-window-in-frame :prev] "Previous window in frame"] | |
[(string "win + " (in dir-keys :right)) [:enum-window-in-frame :next] "Next window in frame"] | |
;adjacent-move-arr | |
["win + w" [:push-keymap window-mode-keymap] "Window transient"] | |
["win + s" [:push-keymap resize-mode-keymap] "Resize transient"] | |
["win + shift + s" :frame-to-window-size "Frame to window size"] | |
["win + y" [:push-keymap yank-mode-keymap] "Yank transient"]])) | |
(:set-keymap key-man root-keymap) | |
(def auto-close-empty-frame | |
"Check for empty frames and close them, when a window is removed." | |
(auto-layout/close-empty-frame jwno/context)) | |
(:enable auto-close-empty-frame) | |
(def current-frame-area | |
"Highlights an empty active frame by drawing a rectangle in it. " | |
(indicator/current-frame-area jwno/context)) | |
(put current-frame-area :margin 1) | |
(:enable current-frame-area) | |
(def current-frame-tooltip | |
"Use the current-frame-tooltip object" | |
(indicator/current-frame-tooltip jwno/context)) | |
(:enable current-frame-tooltip) | |
(:add-hook hook-man :window-created | |
(fn [win uia-win _exe-path _desktop-info] | |
(put (in win :tags) :anchor :center) | |
(put (in win :tags) :margin 1) | |
(def class-name (:get_CachedClassName uia-win)) | |
(if (= "#32770" class-name) # Dialog window class | |
(put (in win :tags) :no-expand true)))) | |
(:add-hook hook-man :monitor-updated | |
(fn [frame] | |
(put (in frame :tags) :padding 1))) | |
(:add-command command-man :fill-monitor | |
(fn [] | |
(def cur-win (:get-current-window (in window-man :root))) | |
(when cur-win | |
(def cur-frame (in cur-win :parent)) | |
(def mon-frame (:get-top-frame cur-frame)) | |
(def rect (:get-padded-rect mon-frame)) | |
(:transform cur-win rect))) | |
``` | |
(:fill-monitor) | |
Resizes the focused window, so that it fills the whole work | |
area of the current monitor. | |
```) | |
(:add-command command-man :show-root-keymap | |
(fn [] | |
(:show-tooltip | |
ui-man | |
:show-root-keymap | |
(:format root-keymap) | |
nil | |
nil | |
10000 | |
:center)) | |
``` | |
(:show-root-keymap) | |
Shows the root keymap defined in the config file. | |
```) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment