dunlin/frame.fnl

107 lines
3.9 KiB
Plaintext
Raw Permalink 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))
2022-12-27 12:23:24 +00:00
(local lume (require :lume))
(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-23 15:21:06 +00:00
(fn new-frame [global-keymap]
2022-12-19 18:19:13 +00:00
(let [hpad 2
vpad 2
self {}
2022-12-23 15:21:06 +00:00
recogniser (keymap.recogniser global-keymap)
2023-01-01 16:49:15 +00:00
bottom-line (Gtk.Stack {
:transition_type Gtk.StackTransitionType.SLIDE_UP_DOWN
:transition_duration 100
})
commander (Command.commander self)
echo-area (Gtk.Label {
:xalign 0
:margin_start 10
})
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
})
2023-01-02 22:03:03 +00:00
update-prop (fn [props name value]
(match name
:estimated-load-progress
(tset progress-bar :fraction value)
:uri
2023-01-02 22:03:03 +00:00
(do (tset echo-area :label value)
(_G.history:visit value (os.time)))
:title
(_G.history:title self.buffer.properties.uri value)
n
(comment (print "prop change" n value))))]
2023-01-01 16:49:15 +00:00
(doto bottom-line
(: :add_named echo-area "echo-area")
(: :add_named commander.widget "commander")
(: :set_visible_child_name "commander"))
(doto container
(: :pack_start progress-bar false false vpad)
(: :pack_start contentwidget true true vpad)
(: :pack_end bottom-line false false vpad))
(tset window :on_key_release_event
(fn [window event]
(when (not (commander:active?))
2022-12-23 14:43:29 +00:00
(match (recogniser:accept-event event)
[name params] (commander:invoke-interactively name params)
(nil prompt) (tset echo-area :label prompt)))
2023-01-01 11:10:14 +00:00
(when (and (commander:active?)
2023-01-01 11:27:33 +00:00
(= keymap.keyval.Escape event.keyval))
2023-01-01 11:10:14 +00:00
(commander:deactivate))
(when (and event.state.MOD1_MASK
(= event.keyval (string.byte "x")))
(commander:activate))))
2023-01-01 16:49:15 +00:00
(echo-area:show) (commander.widget:show)
2022-12-19 18:19:13 +00:00
(window:add container)
(window:show_all)
2022-12-20 10:34:37 +00:00
(let [f
{
:window window
:buffer nil
:content contentwidget
:message (fn [self message]
(tset echo-area :label message))
2022-12-20 10:34:37 +00:00
:show-buffer (fn [self b]
(each [_ w (pairs (contentwidget:get_children))]
(w:hide))
(tset self :buffer b)
2022-12-20 10:34:37 +00:00
(contentwidget:pack_start b.webview true true 0)
(b:subscribe-property-changes
(fn [name val]
(if (= b self.buffer)
2023-01-02 22:03:03 +00:00
(update-prop self name val)
(print "ignore props from background" b))))
2022-12-20 10:34:37 +00:00
(b.webview:show))
}]
(lume.extend self f)
(table.insert frames self)
self)))
2022-12-20 10:34:37 +00:00
2022-12-19 18:19:13 +00:00
2022-12-20 10:34:37 +00:00
{ :new new-frame :frames frames }