Compare commits
4 Commits
862780878c
...
ad2628ddfc
Author | SHA1 | Date |
---|---|---|
Daniel Barlow | ad2628ddfc | |
Daniel Barlow | a81d9d4d4c | |
Daniel Barlow | 3fac6a2601 | |
Daniel Barlow | 0f9d93630e |
19
command.fnl
19
command.fnl
|
@ -35,7 +35,7 @@
|
|||
"visit-location"
|
||||
[[:buffer
|
||||
Buffer.match
|
||||
#($1.buffer.name)]
|
||||
#$1.buffer.name]
|
||||
[:url #{$1 $1} #($1.buffer:location)]
|
||||
]
|
||||
(fn [{:url url :buffer buffer}]
|
||||
|
@ -139,14 +139,22 @@
|
|||
)))
|
||||
|
||||
|
||||
(fn activate [{: state : entry : prompt}]
|
||||
(fn activate [{: state : entry : prompt &as self}]
|
||||
(tset state :active true)
|
||||
(set entry.sensitive true)
|
||||
(set entry.text "")
|
||||
(set prompt.label (or state.this-param "Command" ""))
|
||||
(update-widget-state
|
||||
self
|
||||
{:active true
|
||||
:prompt (or state.this-param "Command" "")
|
||||
})
|
||||
(entry:grab_focus)
|
||||
state)
|
||||
|
||||
(fn deactivate [{: state : entry : prompt &as self}]
|
||||
(doto state
|
||||
(lume.clear)
|
||||
(tset :active false))
|
||||
(update-widget-state self {:active false}))
|
||||
|
||||
(fn invoke-interactively [self name params]
|
||||
(let [c (find-command name)
|
||||
supplied-params (collect [k v (pairs params)]
|
||||
|
@ -175,6 +183,7 @@
|
|||
self {
|
||||
:state default-state
|
||||
: activate
|
||||
: deactivate
|
||||
:active? (fn [self] self.state.active)
|
||||
: on-input
|
||||
: on-activate
|
||||
|
|
|
@ -45,6 +45,10 @@
|
|||
(match (recogniser:accept-event event)
|
||||
[name params] (commander:invoke-interactively name params)
|
||||
(nil prompt) (print "prompted" prompt)))
|
||||
(when (and (commander:active?)
|
||||
(= keymap.keyval.Escape event.keyval))
|
||||
(commander:deactivate))
|
||||
|
||||
(when (and event.state.MOD1_MASK
|
||||
(= event.keyval (string.byte "x")))
|
||||
(commander:activate))))
|
||||
|
|
41
keymap.fnl
41
keymap.fnl
|
@ -2,19 +2,26 @@
|
|||
(local { : view } (require :fennel))
|
||||
|
||||
(local modifier-keyvals
|
||||
{
|
||||
;; These aren't canonical or official, this is just the
|
||||
;; result of pressing keys on my keyboard. If Gtk/Gdk/GI
|
||||
;; implemented KeyEvent.is_modifier we wouldn't have to
|
||||
;; do this
|
||||
65507 :control_l
|
||||
65505 :shift_l
|
||||
269025067 :fn
|
||||
65515 :windows
|
||||
65513 :alt_l
|
||||
65027 :alt_gr
|
||||
65508 :control_r
|
||||
})
|
||||
;; we need to detect and discard modifier-only key events when
|
||||
;; looking for the next key in a key sequence. Gtk/Gdk
|
||||
;; allegedly has KeyEvent.is_modifier to do this but it's always
|
||||
;; 0 because GI doesn't expose it.
|
||||
(let [names
|
||||
[
|
||||
:Control_L
|
||||
:Control_R
|
||||
:Control
|
||||
:Shift_L
|
||||
:Shift_R
|
||||
:WakeUp ; labelled "Fn"
|
||||
:Super_L ; labelled with Windows logo
|
||||
:Super_R ; menu key? not on my keyboard
|
||||
:Alt_L
|
||||
:Alt_R
|
||||
:ISO_Level3_Shift ; AltGr
|
||||
]]
|
||||
(collect [_ n (ipairs names)]
|
||||
(values (Gdk.keyval_from_name n) n))))
|
||||
|
||||
(fn modifier? [keyval]
|
||||
(. modifier-keyvals keyval))
|
||||
|
@ -77,6 +84,11 @@
|
|||
(do
|
||||
(set m keymap)
|
||||
v)
|
||||
|
||||
(where nil (= c "103:4"))
|
||||
(do
|
||||
(set m keymap)
|
||||
(values nil "cancelled"))
|
||||
_
|
||||
(do
|
||||
(set m keymap)
|
||||
|
@ -85,6 +97,9 @@
|
|||
|
||||
|
||||
{ : recogniser
|
||||
:keyval {
|
||||
:Escape (Gdk.keyval_from_name "Escape")
|
||||
}
|
||||
:_ {
|
||||
;; symbols in _ are exported only for testing
|
||||
: keychord->spec
|
||||
|
|
Loading…
Reference in New Issue