From b784659f0f133686d9b6130496cee949e95c01f3 Mon Sep 17 00:00:00 2001 From: John Mercouris Date: Fri, 22 Mar 2024 16:56:35 -0500 Subject: [PATCH 1/6] gitmodules: Update cl-electron. --- _build/cl-electron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_build/cl-electron b/_build/cl-electron index f2245dc1450..e647943dac3 160000 --- a/_build/cl-electron +++ b/_build/cl-electron @@ -1 +1 @@ -Subproject commit f2245dc1450a6ad416984cf932be50e00957390a +Subproject commit e647943dac358f97f3a27ab4a49dad3625c5c471 From 54f5ba01addfa2b1ef4ea23aef31e95bd0caab2c Mon Sep 17 00:00:00 2001 From: John Mercouris Date: Tue, 19 Mar 2024 23:34:22 -0500 Subject: [PATCH 2/6] Refactor input handling. It is now done per buffer, instead of per window. Opens possibilities for further simplifying input handling such as having multiple buffers per window or binding keybindings on panel buffers. Disconnect handlers when hiding a buffer on the WebKitGTK port. Prevents the prompt buffer from having unnecessary handlers bound to it as it disappears and appears. Move command-dispatcher slot from window to browser class. Move key-stack and last-key slots from window to buffer class. Delete input-skip-dispatcher slot. --- source/browser.lisp | 5 +++ source/buffer.lisp | 9 ++++- source/describe.lisp | 12 ++----- source/input.lisp | 27 ++++++++------- source/mode/repeat.lisp | 13 ++------ source/renderer/gtk.lisp | 72 ++++++++++++++-------------------------- source/window.lisp | 19 ----------- 7 files changed, 55 insertions(+), 102 deletions(-) diff --git a/source/browser.lisp b/source/browser.lisp index 0bc09ec8f92..e1b38fca96f 100644 --- a/source/browser.lisp +++ b/source/browser.lisp @@ -107,6 +107,11 @@ Which commands will they invoke next?") nil :type (maybe function) :documentation "The last command invoked by the user.") + (command-dispatcher + #'dispatch-command + :type (or sym:function-symbol function) + :documentation "Function to process the command processed in `dispatch-input-event'. +Takes the function/command as the only argument.") (prompt-buffer-generic-history (make-ring) :documentation "The default history of all prompt buffer entries. diff --git a/source/buffer.lisp b/source/buffer.lisp index 4034e034bfd..f7f0bc6b19a 100644 --- a/source/buffer.lisp +++ b/source/buffer.lisp @@ -36,7 +36,14 @@ inherited from the superclasses.") (new-id) :type unsigned-byte :documentation "Unique identifier for a buffer.") - ;; TODO: Or maybe a dead-buffer should just be a buffer history? + (key-stack + '() + :documentation "A stack of the key chords a user has pressed.") + (last-key + nil + :export nil + :type (or null keymaps:key) + :documentation "Last pressed key. Useful for `self-insert'.") (profile (global-profile) :type nyxt-profile diff --git a/source/describe.lisp b/source/describe.lisp index 8bb42b14918..324d2003659 100644 --- a/source/describe.lisp +++ b/source/describe.lisp @@ -645,19 +645,11 @@ A command is a special kind of function that can be called with :command (typecase command (symbol command) (command (name command)))) - (setf (command-dispatcher (current-window)) #'dispatch-command - (input-skip-dispatcher (current-window)) #'dispatch-input-skip))) - -(defun skip-describe-dispatch (keyspec) - (declare (ignore keyspec)) - (echo "Canceled describe-key.") - (setf (command-dispatcher (current-window)) #'dispatch-command - (input-skip-dispatcher (current-window)) #'dispatch-input-skip)) + (setf (command-dispatcher *browser*) #'dispatch-command))) (define-command describe-key () "Display binding of user-inputted keys." - (setf (command-dispatcher (current-window)) #'describe-key-dispatch - (input-skip-dispatcher (current-window)) #'skip-describe-dispatch) + (setf (command-dispatcher *browser*) #'describe-key-dispatch) (echo "Press a key sequence to describe:")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/source/input.lisp b/source/input.lisp index f66939e133f..6acccf00003 100644 --- a/source/input.lisp +++ b/source/input.lisp @@ -86,7 +86,7 @@ KEYCODE-LESS-DISPLAY (KEYCODE-DISPLAY)." (-> dispatch-command ((or sym:function-symbol function)) *) (export-always 'dispatch-command) (defun dispatch-command (function) - "Default `command-dispatcher'. Runs FUNCTION asynchronously." + "Runs FUNCTION asynchronously." (echo-dismiss) ; Clean up message-view on command. ;; TODO: Instead of hard-coding these ignored-commands, we could add a boolean ;; slot to the `command' class. @@ -113,10 +113,10 @@ KEYCODE-LESS-DISPLAY (KEYCODE-DISPLAY)." (log:debug "Skipping input event key ~s" keyspecs)) (export-always 'dispatch-input-event) -(defun dispatch-input-event (event buffer window) - "Dispatch keys in WINDOW `key-stack'. +(defun dispatch-input-event (event buffer) + "Dispatch keys in BUFFER `key-stack'. Return nil to forward to renderer or non-nil otherwise." - (with-accessors ((key-stack key-stack)) window + (with-accessors ((key-stack key-stack)) buffer (labels ((keyspecs (key &optional translated-key) (if translated-key (let ((specs (keyspecs key)) @@ -129,9 +129,15 @@ Return nil to forward to renderer or non-nil otherwise." (keyspecs-with-optional-keycode key)))) (when (input-buffer-p buffer) (setf (last-event buffer) event)) + (when (prompt-buffer-p buffer) + ;; Prompt buffer updating must happen on a separate thread. + (run-thread "update-prompt-buffer" + (update-prompt-input buffer + (ps-eval :buffer buffer + (ps:chain (nyxt/ps:qs document "#input") value))))) (multiple-value-bind (bound-function matching-keymap translated-key) (the keyscheme:nyxt-keymap-value - (keymaps:lookup-key key-stack (current-keymaps))) + (keymaps:lookup-key key-stack (current-keymaps buffer))) (declare (ignore matching-keymap)) (cond ((keymaps:keymap-p bound-function) @@ -148,9 +154,9 @@ Return nil to forward to renderer or non-nil otherwise." ;; We save the last key separately to keep it available to the ;; command even after key-stack has been reset in the other ;; thread. - (setf (last-key window) (first key-stack)) + (setf (last-key buffer) (first key-stack)) (unwind-protect - (funcall (command-dispatcher window) command) + (funcall (command-dispatcher *browser*) command) ;; We must reset the key-stack on errors or else all subsequent ;; keypresses will keep triggering the same erroring command. (setf key-stack nil)) @@ -162,13 +168,6 @@ Return nil to forward to renderer or non-nil otherwise." (setf key-stack nil) nil) - ((and (input-buffer-p buffer) (not (forward-input-events-p buffer))) - ;; After checking `pointer-event-p', otherwise pointer events - ;; might not be forwarded. - (funcall (input-skip-dispatcher window) (keyspecs key-stack)) - (setf key-stack nil) - t) - (t (log:debug "Fallback forward key ~s" (keyspecs key-stack)) (setf key-stack nil) diff --git a/source/mode/repeat.lisp b/source/mode/repeat.lisp index 405674ebdab..a597470db81 100644 --- a/source/mode/repeat.lisp +++ b/source/mode/repeat.lisp @@ -122,17 +122,9 @@ repeating it like a regular `repeat-mode' does." :function (lambda (mode) (declare (ignore mode)) (nyxt::run command))) - (setf (command-dispatcher (current-window)) #'dispatch-command - (input-skip-dispatcher (current-window)) #'dispatch-input-skip + (setf (command-dispatcher *browser*) #'dispatch-command *repeat-times-stack* 0))))) -(defun skip-repeat-dispatch (keyspec) - "A stub copy of `dispatch-input-skip' customized for `repeat-mode'." - (declare (ignore keyspec)) - (echo "Canceled repeat-key.") - (setf (command-dispatcher (current-window)) #'dispatch-command - (input-skip-dispatcher (current-window)) #'dispatch-input-skip)) - (define-command-global repeat-key (&key (times (let ((nyxt::*interactive-p* t)) (or @@ -147,6 +139,5 @@ repeating it like a regular `repeat-mode' does." :sources 'prompter:raw-source))))))) "Repeat the command bound to the user-pressed keybinding TIMES times." (setf *repeat-times-stack* (+ times (* 10 *repeat-times-stack*)) - (command-dispatcher (current-window)) (make-repeat-command-dispatcher *repeat-times-stack*) - (input-skip-dispatcher (current-window)) #'skip-repeat-dispatch) + (command-dispatcher *browser*) (make-repeat-command-dispatcher *repeat-times-stack*)) (echo "Press a key sequence for command to repeat ~R times:" *repeat-times-stack*)) diff --git a/source/renderer/gtk.lisp b/source/renderer/gtk.lisp index d64bb99776a..c283adb3e02 100644 --- a/source/renderer/gtk.lisp +++ b/source/renderer/gtk.lisp @@ -518,16 +518,14 @@ response. The BODY is wrapped with `with-protect'." (gtk:gtk-container-add gtk-object root-box-layout) - (connect-signal window "key_press_event" nil (widget event) - (declare (ignore widget)) - #+darwin - (push-modifier *browser* event) - (on-signal-key-press-event window event)) - (connect-signal window "key_release_event" nil (widget event) - (declare (ignore widget)) - #+darwin - (pop-modifier *browser* event) - (on-signal-key-release-event window event)) + #+darwin + (progn + (connect-signal window "key_press_event" nil (widget event) + (declare (ignore widget)) + (push-modifier *browser* event)) + (connect-signal window "key_release_event" nil (widget event) + (declare (ignore widget)) + (pop-modifier *browser* event))) (connect-signal window "destroy" nil (widget) (declare (ignore widget)) (on-signal-destroy window)) @@ -705,28 +703,19 @@ See `gtk-browser's `modifier-translator' slot." (character character)) (setf (gtk:gtk-entry-text (key-string-buffer window)) "")))) -(defun update-prompt (buffer) - (run-thread "Prompt updater" - ;; Rebind prompt-buffer to ensure the watcher does not mix up the - ;; different prompt-buffers. - (let ((prompt-buffer buffer)) - (nyxt::update-prompt-input prompt-buffer)))) - -(define-ffi-method on-signal-key-press-event ((sender gtk-window) event) +(define-ffi-method on-signal-key-press-event ((sender gtk-buffer) event) (let* ((keycode (gdk:gdk-event-key-hardware-keycode event)) (keyval (gdk:gdk-event-key-keyval event)) (keyval-name (gdk:gdk-keyval-name keyval)) (character (gdk:gdk-keyval-to-unicode keyval)) - (printable-value (printable-p sender event)) + (printable-value (printable-p (current-window) event)) (key-string (or printable-value (derive-key-string keyval-name character))) (modifiers (funcall (modifier-translator *browser*) (key-event-modifiers event) - event)) - (buffer (or (current-prompt-buffer) - (nyxt::active-buffer sender)))) - (log:debug key-string keycode character keyval-name modifiers) - (when (prompt-buffer-p buffer) (update-prompt buffer)) + event))) + (log:debug sender key-string keycode character keyval-name modifiers) + ;; Do not forward modifier-only presses to the renderer. (if key-string (flet ((key () (keymaps:make-key :code keycode @@ -736,30 +725,15 @@ See `gtk-browser's `modifier-translator' slot." (alex:appendf (key-stack sender) (list (key))) (run-thread "on-signal-key-press" - (on-signal-key-press buffer (key))) - (dispatch-input-event event buffer sender)) - ;; Do not forward modifier-only to renderer. + (on-signal-key-press sender (key))) + (dispatch-input-event event sender)) t))) (defmethod gtk-object ((prompt-buffer prompt-buffer)) (prompt-buffer-view (window prompt-buffer))) -(define-ffi-method on-signal-key-release-event ((sender gtk-window) event) - (declare (ignore sender event)) - ;; REVIEW: Is there any use for handling release events? - nil) - -(defun sender-window (sender) - (or (find sender (window-list) :key #'nyxt::active-prompt-buffers) - (find sender (window-list) :key #'nyxt::active-buffer) - (current-window))) - (define-ffi-method on-signal-button-press-event ((sender gtk-buffer) event) (let* ((button (gdk:gdk-event-button-button event)) - ;; REVIEW: No need to store X and Y? - ;; (x (gdk:gdk-event-button-x event)) - ;; (y (gdk:gdk-event-button-y event)) - (window (sender-window sender)) (key-string (format nil "button~s" button)) (modifiers (funcall (modifier-translator *browser*) (button-event-modifiers event) @@ -775,11 +749,10 @@ See `gtk-browser's `modifier-translator' slot." :status :pressed))) (run-thread "on-signal-button-press" (on-signal-button-press buffer (key))) - (when (prompt-buffer-p buffer) (update-prompt buffer)) (when key-string - (alex:appendf (key-stack window) + (alex:appendf (key-stack buffer) (list (key))) - (dispatch-input-event event sender window))))) + (dispatch-input-event event sender))))) (define-ffi-method on-signal-scroll-event ((sender gtk-buffer) event) (let* ((button (match (gdk:gdk-event-scroll-direction event) @@ -797,17 +770,16 @@ See `gtk-browser's `modifier-translator' slot." 6) ((< 0 (gdk:gdk-event-scroll-delta-x event)) 7))))) - (window (sender-window sender)) (key-string (format nil "button~s" button)) (modifiers (funcall (modifier-translator *browser*) (scroll-event-modifiers event) event))) (when key-string - (alex:appendf (key-stack window) + (alex:appendf (key-stack sender) (list (keymaps:make-key :value key-string :modifiers modifiers :status :pressed))) - (dispatch-input-event event sender window)))) + (dispatch-input-event event sender)))) (define-class gtk-scheme () ((context @@ -1584,6 +1556,9 @@ the `active-buffer'." (connect-signal buffer "button-press-event" nil (web-view event) (declare (ignore web-view)) (on-signal-button-press-event buffer event)) + (connect-signal buffer "key_press_event" nil (widget event) + (declare (ignore widget)) + (on-signal-key-press-event buffer event)) (connect-signal buffer "scroll-event" nil (web-view event) (declare (ignore web-view)) (on-signal-scroll-event buffer event)) @@ -1733,6 +1708,9 @@ the `active-buffer'." (define-ffi-method ffi-buffer-delete ((buffer gtk-buffer)) (cond ((not (slot-value buffer 'gtk-object)) + (mapc (lambda (handler-id) + (gobject:g-signal-handler-disconnect (gtk-object buffer) handler-id)) + (handler-ids buffer)) (nyxt::buffer-hide buffer)) ((webkit:webkit-web-view-is-web-process-responsive (gtk-object buffer)) (webkit:webkit-web-view-try-close (gtk-object buffer))) diff --git a/source/window.lisp b/source/window.lisp index 738294ec5bb..71d09ce9b95 100644 --- a/source/window.lisp +++ b/source/window.lisp @@ -43,14 +43,6 @@ Not to be confused with `current-buffer'.") for the prompt buffer to be available. You should not rely on the value of this channel. The channel is popped when a prompt buffer is hidden.") - (key-stack - '() - :documentation "A stack of the key chords a user has pressed.") - (last-key - nil - :export nil - :type (or null keymaps:key) - :documentation "Last pressed key. Useful for `self-insert'.") (fullscreen-p nil :export nil @@ -74,17 +66,6 @@ the generic functions on `status-buffer'. Finally set the `window' (make-instance 'message-buffer) :type message-buffer :documentation "The `message-buffer' instance for this window.") - (command-dispatcher - #'dispatch-command - :type (or sym:function-symbol function) - :documentation "Function to process the command processed in `dispatch-input-event'. -Takes the function/command as the only argument.") - (input-skip-dispatcher - #'dispatch-input-skip - :type function - :documentation "Function to process the skipped input event. -It runs when the pressed keybinding has no associated command. -The only argument is a string representation of the pressed key.") (window-set-buffer-hook (make-instance 'hook-window-buffer) :type hook-window-buffer From 0332294465ad960daf6d972e321b9f5252d0a85c Mon Sep 17 00:00:00 2001 From: John Mercouris Date: Wed, 20 Mar 2024 23:30:35 -0500 Subject: [PATCH 3/6] Remove darwin support from WebKitGTK port. These are problems that GTK should solve, not us. Additionally GTK does not work well on macOS, particularly WebKitGTK+. See https://github.com/NixOS/nixpkgs/pull/126101. --- source/renderer/gi-gtk.lisp | 10 +---- source/renderer/gtk.lisp | 90 ++----------------------------------- 2 files changed, 4 insertions(+), 96 deletions(-) diff --git a/source/renderer/gi-gtk.lisp b/source/renderer/gi-gtk.lisp index 19dd4c84a65..988b8dbe2f2 100644 --- a/source/renderer/gi-gtk.lisp +++ b/source/renderer/gi-gtk.lisp @@ -35,14 +35,9 @@ For now it is also partly based on `nyxt/renderer/gtk'.")) (defmethod nyxt/renderer/gtk::renderer-thread-p ((renderer gi-gtk-renderer) &optional (thread (bt:current-thread))) (string= (bt:thread-name thread) - #+darwin - "thread" - #-darwin renderer-thread-name)) (defmethod ffi-initialize ((browser gi-gtk-browser) urls startup-timestamp) - "On GNU/Linux we can create a separate thread to launch the GTK -interface. On Darwin, we must run the GTK thread on the main thread." (declare (ignore urls startup-timestamp)) (log:debug "Initializing GI-GTK Interface") (if nyxt/renderer/gtk::gtk-running-p @@ -56,14 +51,11 @@ interface. On Darwin, we must run the GTK thread on the main thread." (gir:invoke ((gir:ffi "Gtk" "3.0") 'main))))) (setf nyxt/renderer/gtk::gtk-running-p t) (call-next-method) - #-darwin (let ((main-thread (bt:make-thread #'main-func :name renderer-thread-name))) (unless nyxt::*run-from-repl-p* (bt:join-thread main-thread) ;; See comment about FreeBSD in gtk.lisp - (uiop:quit (slot-value browser 'nyxt::exit-code) #+freebsd nil))) - #+darwin - (main-func)))) + (uiop:quit (slot-value browser 'nyxt::exit-code) #+freebsd nil)))))) (nyxt/renderer/gtk:define-ffi-method ffi-kill-browser ((browser gi-gtk-browser)) (unless nyxt::*run-from-repl-p* diff --git a/source/renderer/gtk.lisp b/source/renderer/gtk.lisp index c283adb3e02..26515579beb 100644 --- a/source/renderer/gtk.lisp +++ b/source/renderer/gtk.lisp @@ -14,14 +14,7 @@ (:documentation "WebKit renderer class.")) (define-class gtk-browser () - (#+darwin - (modifiers - '() - :documentation "On macOS some modifiers like Super and Meta are seen like -regular keys. -To work around this issue, we store them in this list while they are pressed. -See `push-modifiers', `pop-modifiers' and `key-event-modifiers'.") - (modifier-translator + ((modifier-translator #'translate-modifiers :documentation "Function that returns a list of modifiers understood by `keymaps:make-key'. You can customize this slot if you want to change the @@ -170,9 +163,6 @@ As a workaround, we never leave the GTK main loop when running from a REPL. See https://github.com/atlas-engineer/nyxt/issues/740") (defmethod renderer-thread-p ((renderer gtk-renderer) &optional (thread (bt:current-thread))) - #+darwin - (string= "main thread" (bt:thread-name thread)) - #-darwin (string= "cl-cffi-gtk main thread" (bt:thread-name thread))) (defmacro within-gtk-thread (&body body) @@ -243,18 +233,12 @@ the renderer thread, use `defmethod' instead." (error condition))))))))) (defmethod ffi-initialize ((browser gtk-browser) urls startup-timestamp) - "gtk:within-main-loop handles all the GTK initialization. On - GNU/Linux, Nyxt could hang after 10 minutes if it's not - used. Conversely, on Darwin, if gtk:within-main-loop is used, no - drawing happens. Drawing operations on Darwin MUST originate from - the main thread, which the GTK main loop is not guaranteed to be - on." + "gtk:within-main-loop handles all the GTK initialization." (declare (ignore urls startup-timestamp)) (log:debug "Initializing GTK Interface") (if gtk-running-p (within-gtk-thread (call-next-method)) - #-darwin (progn (setf gtk-running-p t) (glib:g-set-prgname "nyxt") @@ -272,14 +256,7 @@ the renderer thread, use `defmethod' instead." ;; UIOP:QUIT with FINISH-OUTPUT = NIL in the first place. ;; ;; FIXME: This also can be true for other BSD systems. - (uiop:quit (slot-value browser 'nyxt::exit-code) #+freebsd nil))) - #+darwin - (progn - (setf gtk-running-p t) - (glib:g-set-prgname "nyxt") - (gdk:gdk-set-program-class "Nyxt") - (call-next-method) - (gtk:gtk-main)))) + (uiop:quit (slot-value browser 'nyxt::exit-code) #+freebsd nil))))) (define-ffi-method ffi-kill-browser ((browser gtk-browser)) ;; TODO: Terminating the GTK thread from the REPL seems to prevent Nyxt from @@ -518,14 +495,6 @@ response. The BODY is wrapped with `with-protect'." (gtk:gtk-container-add gtk-object root-box-layout) - #+darwin - (progn - (connect-signal window "key_press_event" nil (widget event) - (declare (ignore widget)) - (push-modifier *browser* event)) - (connect-signal window "key_release_event" nil (widget event) - (declare (ignore widget)) - (pop-modifier *browser* event))) (connect-signal window "destroy" nil (widget) (declare (ignore widget)) (on-signal-destroy window)) @@ -598,41 +567,6 @@ Return nil when key must be discarded, e.g. for modifiers." (str:replace-all "_" "" (string-downcase result)) result))) -#+darwin -(defmethod push-modifier ((browser gtk-browser) event) - (let* ((modifier-state (gdk:gdk-event-key-state event)) - (key-value (gdk:gdk-event-key-keyval event)) - (key-value-name (gdk:gdk-keyval-name key-value))) - (when (member :control-mask modifier-state) - (push :control-mask (modifiers browser))) - (when (member :shift-mask modifier-state) - (push :shift-mask (modifiers browser))) - (when (or (string= key-value-name "Arabic_switch") - (string= key-value-name "Alt_L") - (string= key-value-name "Alt_R")) - (push :mod1-mask (modifiers browser))) - (when (and (member :mod2-mask modifier-state) - (member :meta-mask modifier-state)) - (push :super-mask (modifiers browser)))) - (setf (modifiers browser) (delete-duplicates (modifiers browser)))) - -#+darwin -(defmethod pop-modifier ((browser gtk-browser) event) - (let* ((modifier-state (gdk:gdk-event-key-state event)) - (key-value (gdk:gdk-event-key-keyval event)) - (key-value-name (gdk:gdk-keyval-name key-value))) - (when (member :control-mask modifier-state) - (alex:deletef (modifiers browser) :control-mask)) - (when (member :shift-mask modifier-state) - (alex:deletef (modifiers browser) :shift-mask)) - (when (or (string= key-value-name "Arabic_switch") - (string= key-value-name "Alt_L") - (string= key-value-name "Alt_R")) - (alex:deletef (modifiers browser) :mod1-mask)) - (when (and (member :mod2-mask modifier-state) - (member :meta-mask modifier-state)) - (alex:deletef (modifiers browser) :super-mask)))) - (-> translate-modifiers (list &optional gdk:gdk-event) list) (defun translate-modifiers (modifier-state &optional event) "Return list of modifiers fit for `keymaps:make-key'. @@ -648,12 +582,6 @@ See `gtk-browser's `modifier-translator' slot." :lock-mask nil))) (delete nil (mapcar (lambda (mod) (getf plist mod)) modifier-state)))) -#+darwin -(defun key-event-modifiers (key-event) - (declare (ignore key-event)) - (modifiers *browser*)) - -#-darwin (defun key-event-modifiers (key-event) (gdk:gdk-event-key-state key-event)) @@ -668,21 +596,9 @@ See `gtk-browser's `modifier-translator' slot." (setf (cffi:mem-ref modifiers 'gdk:gdk-modifier-type) state) (cffi:mem-ref modifiers 'gdk:gdk-modifier-type))))) -#+darwin -(defun button-event-modifiers (button-event) - (declare (ignore button-event)) - (modifiers *browser*)) - -#-darwin (defun button-event-modifiers (button-event) (gdk-event-button-state button-event)) -#+darwin -(defun scroll-event-modifiers (scroll-event) - (declare (ignore scroll-event)) - (modifiers *browser*)) - -#-darwin (defun scroll-event-modifiers (scroll-event) (gdk:gdk-event-scroll-state scroll-event)) From 6a4332c5e9059d028a66e86185ac761cf9f828d8 Mon Sep 17 00:00:00 2001 From: John Mercouris Date: Thu, 21 Mar 2024 15:37:48 -0500 Subject: [PATCH 4/6] describe: Remove unneeded comments. --- source/describe.lisp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/describe.lisp b/source/describe.lisp index 324d2003659..92eaa4c03b0 100644 --- a/source/describe.lisp +++ b/source/describe.lisp @@ -652,11 +652,8 @@ A command is a special kind of function that can be called with (setf (command-dispatcher *browser*) #'describe-key-dispatch) (echo "Press a key sequence to describe:")) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; TODO: Move rest somewhere else? Maybe too low-level for help.lisp. - (export-always 'system-information) -(defun system-information () ; TODO: Rename report-system-information? +(defun system-information () "Return a system information report as a string." (labels ((->string (obj) (princ-to-string obj)) (asdf-information () From 3c71755296ebd86fbf124709418c829447766e92 Mon Sep 17 00:00:00 2001 From: John Mercouris Date: Fri, 22 Mar 2024 17:05:26 -0500 Subject: [PATCH 5/6] renderer/electron: Use per buffer input handling system. --- source/renderer/electron.lisp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/source/renderer/electron.lisp b/source/renderer/electron.lisp index 8f05c8025c6..f038cb6f55e 100644 --- a/source/renderer/electron.lisp +++ b/source/renderer/electron.lisp @@ -113,6 +113,9 @@ (:documentation "Electron buffer class.")) (defmethod initialize-instance :after ((buffer electron-buffer) &key extra-modes no-hook-p) + (electron:register-before-input-event buffer + (lambda (buffer event) + (on-signal-key-press-event buffer event))) (finalize-buffer buffer :extra-modes extra-modes :no-hook-p no-hook-p)) ;; TODO Needed for resurrect-buffer. @@ -327,12 +330,7 @@ :width-p t) (electron:load-url status-buffer "about:blank") ;; KLUDGE Without it, the window won't intercept input events. - (electron:load-url window "about:blank") - ;; Each window listens to input events. Another approach would be to listen - ;; the each buffer. - (electron:register-before-input-event window - (lambda (win event) - (on-signal-key-press-event win event))))) + (electron:load-url window "about:blank"))) (defmethod add-buffer ((window electron-window) (buffer electron-buffer) &key (x 0) (y 0) (width 1000) (height 1000) @@ -454,17 +452,16 @@ Return nil when key must be discarded, e.g. for modifiers." ("F12" "f12") (_ key-string))) -(defmethod on-signal-key-press-event ((sender electron-window) event) - (let ((key-string (translate-key-string (rest (assoc :key event)))) - (buffer (or (current-prompt-buffer) (nyxt::active-buffer sender)))) +(defmethod on-signal-key-press-event ((sender electron-buffer) event) + (let ((key-string (translate-key-string (rest (assoc :key event))))) (flet ((key () (keymaps:make-key :value key-string :modifiers (translate-modifiers event) :status :pressed))) (when key-string (alex:appendf (key-stack sender) (list (key))) - (run-thread "on-signal-key-press" (on-signal-key-press buffer (key))) - (dispatch-input-event event buffer sender))))) + (run-thread "on-signal-key-press" (on-signal-key-press sender (key))) + (dispatch-input-event event sender))))) (defmethod on-signal-key-release-event ((sender electron-window) event) (declare (ignore sender event))) From 51004e0daf36b074c81f799bdca625bb4710c825 Mon Sep 17 00:00:00 2001 From: John Mercouris Date: Mon, 25 Mar 2024 13:43:06 -0500 Subject: [PATCH 6/6] changelog: Mention input handling refactor. --- source/changelog.lisp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/changelog.lisp b/source/changelog.lisp index 8d8f90a9858..fa705880fbf 100644 --- a/source/changelog.lisp +++ b/source/changelog.lisp @@ -27,6 +27,14 @@ (define-version "4.0.0" (:ul + (:li "Refactor input to be handled on the buffer level rather than the window +level.") + (:li "Deprecate " (:code "input-skip-dispatcher") ".") + (:li "Move slot " (:nxref :slot 'command-dispatcher :class-name 'browser) + " from window to the browser class.") + (:li "Move slots " (:nxref :slot 'last-key :class-name 'buffer) + " and " (:nxref :slot 'key-stack :class-name 'buffer) + " from window to the buffer class.") (:li "Refactor renderer interface input handling.") (:li "Refactor custom schemes URLs API.") (:li "Deprecate slot " (:code "input-dispatcher")