From a34e63877d68be532498505494cd30a65bd05295 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 20 Dec 2022 10:34:37 +0000 Subject: [PATCH] add buffer --- buffer.fnl | 35 +++++++++++++++++++++++++++++++++++ dunlin.fnl | 8 +++++--- frame.fnl | 30 ++++++++++++++++++++++++------ 3 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 buffer.fnl diff --git a/buffer.fnl b/buffer.fnl new file mode 100644 index 0000000..3e026e4 --- /dev/null +++ b/buffer.fnl @@ -0,0 +1,35 @@ +(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi)) + +(fn new-buffer [name] + (let [props {} + widget (WebKit2.WebView { + ;; :on_decide_policy + ;; (fn [self decision dtype] + ;; (if (and + ;; (WebKit2.ResponsePolicyDecision:is_type_of decision) + ;; (not (decision:is_mime_type_supported))) + ;; (do + ;; (download decision.request.uri decision.response.http_headers) + ;; (decision:ignore) + ;; true) + ;; false)) + :on_notify + (fn [self pspec] + (when (not (= pspec.name :parent)) + (let [val (. self pspec.name)] + (tset props pspec.name val) + ;(listeners:notify pspec.name val) + ))) + })] + {:webview widget + :visit (fn [self u] (print "visit " u) (widget:load_uri u)) + :properties props})) + +(let [buffers {}] + { + :new (fn [name] + (let [b (new-buffer name)] + (tset buffers name b) + b)) + :find (fn [self term] (. buffers term)) + }) diff --git a/dunlin.fnl b/dunlin.fnl index 6be809d..c18ef67 100644 --- a/dunlin.fnl +++ b/dunlin.fnl @@ -2,9 +2,11 @@ (local { : Gtk : Gdk : WebKit2 : cairo } lgi) (local frame (require :frame)) +(local buffer (require :buffer)) +(let [f (frame.new) + b (buffer.new "main")] + (f:show-buffer b) + (b:visit "file:///home/dan/src/dunlin/doc/index.html")) - - -(frame.new) (Gtk.main) diff --git a/frame.fnl b/frame.fnl index 8fc3beb..82b081f 100644 --- a/frame.fnl +++ b/frame.fnl @@ -1,7 +1,9 @@ (local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi)) - +(local { : view } (require :fennel)) (local command (require :command)) +(var frames []) + (fn new-frame [] (let [hpad 2 vpad 2 @@ -24,9 +26,9 @@ :fraction 1.0 :margin 0 }) - contentwidget (Gtk.Button { - :label "paceholder" - }) + contentwidget (Gtk.Box { + :orientation Gtk.Orientation.VERTICAL + }) ] (doto container (: :pack_start commander false false vpad) @@ -34,6 +36,22 @@ (: :pack_start contentwidget true true vpad)) (window:add container) (window:show_all) - window)) + (let [f + { + :window window + :buffer nil + :commander commander + :content contentwidget + :show-buffer (fn [self b] + (each [_ w (pairs (contentwidget:get_children))] + (print "hide " w) + (w:hide)) + (print "show " (view b)) + (contentwidget:pack_start b.webview true true 0) + (b.webview:show)) + }] + (table.insert frames f) + f))) -{ :new new-frame } + +{ :new new-frame :frames frames }