dunlin/frame.fnl

86 lines
3.0 KiB
Plaintext
Raw Normal View History

2022-12-19 18:19:13 +00:00
(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi))
2022-12-20 10:34:37 +00:00
(local { : view } (require :fennel))
(local Command (require :command))
2022-12-22 22:42:45 +00:00
(local keymap (require :keymap))
2022-12-19 20:57:23 +00:00
2022-12-20 10:34:37 +00:00
(var frames [])
2022-12-19 18:48:51 +00:00
(fn new-frame []
2022-12-19 18:19:13 +00:00
(let [hpad 2
vpad 2
2022-12-22 22:42:45 +00:00
recogniser (keymap.recogniser
{
"g" #(Command.invoke-interactively
"visit-location"
{:buffer "main"})
2022-12-23 14:43:29 +00:00
"M-q" #(Command.invoke-interactively
2022-12-22 22:42:45 +00:00
"quit-browser"
{})
"c" {
"x"
#(Command.invoke-interactively
"quit-browser"
{})
}
})
2022-12-19 18:19:13 +00:00
window (Gtk.Window {
:title "Dunlin"
:default_width 800
:default_height 720
:on_destroy Gtk.main_quit
})
container (Gtk.Box {
:orientation Gtk.Orientation.VERTICAL
})
progress-bar (Gtk.ProgressBar {
:orientation Gtk.Orientation.HORIZONTAL
:fraction 1.0
:margin 0
})
2022-12-20 10:34:37 +00:00
contentwidget (Gtk.Box {
:orientation Gtk.Orientation.VERTICAL
})
2022-12-19 18:19:13 +00:00
]
(tset Command.widget :on_activate
(fn [event]
(let [result (Command.on-input event.text)]
(set Command.widget.placeholder_text
(or result.prompt ""))
(set Command.widget.sensitive result.active)
(set Command.widget.text
(or result.default result.error "")))))
(tset window :on_key_release_event
(fn [window event]
2022-12-22 22:42:45 +00:00
(when (not (Command.active?))
2022-12-23 14:43:29 +00:00
(match (recogniser:accept-event event)
2022-12-22 22:42:45 +00:00
c (c)
(nil prompt) (print "prompted" prompt)))
(when (and event.state.MOD1_MASK
(= event.keyval (string.byte "x")))
(Command.activate))))
2022-12-19 18:19:13 +00:00
(doto container
(: :pack_start Command.widget false false vpad)
2022-12-19 18:19:13 +00:00
(: :pack_start progress-bar false false vpad)
(: :pack_start contentwidget true true vpad))
(window:add container)
(window:show_all)
2022-12-20 10:34:37 +00:00
(let [f
{
:window window
:buffer nil
:content contentwidget
:show-buffer (fn [self b]
(each [_ w (pairs (contentwidget:get_children))]
(w:hide))
(contentwidget:pack_start b.webview true true 0)
(b.webview:show))
}]
(table.insert frames f)
f)))
2022-12-19 18:19:13 +00:00
2022-12-20 10:34:37 +00:00
{ :new new-frame :frames frames }