diff --git a/source/foreign-interface.lisp b/source/foreign-interface.lisp index 7ee020b7a6f4..440e33288939 100644 --- a/source/foreign-interface.lisp +++ b/source/foreign-interface.lisp @@ -26,15 +26,38 @@ If the `:setter-p' option is non-nil, then a dummy setf method is defined." (define-ffi-generic ffi-window-delete (window) (:documentation "Delete WINDOW.")) -(define-ffi-generic ffi-window-fullscreen (window) - (:documentation "Set fullscreen WINDOW state on.")) -(define-ffi-generic ffi-window-unfullscreen (window) - (:documentation "Set fullscreen WINDOW state off.")) - -(define-ffi-generic ffi-window-maximize (window) - (:documentation "Set WINDOW to a maximized state.")) -(define-ffi-generic ffi-window-unmaximize (window) - (:documentation "Set WINDOW to an unmaximized state.")) +(define-ffi-generic ffi-window-fullscreen (window &key &allow-other-keys) + (:method :around ((window window) &key user-event-p &allow-other-keys) + (setf (slot-value window 'fullscreen-p) t) + (if user-event-p + (call-next-method) + ;; Hide the status and message buffers only in this case as to account + ;; for full screening a video stream. + (toggle-toolbars window))) + (:documentation "Set fullscreen WINDOW state on. +USER-EVENT-P helps to distinguish events requested by the user or +renderer (e.g. fullscreen a video stream).")) +(define-ffi-generic ffi-window-unfullscreen (window &key &allow-other-keys) + (:method :around ((window window) &key user-event-p &allow-other-keys) + (setf (slot-value window 'fullscreen-p) nil) + (if user-event-p + (call-next-method) + (toggle-toolbars window))) + (:documentation "Set fullscreen WINDOW state off. +See `ffi-window-fullscreen'.")) + +(define-ffi-generic ffi-window-maximize (window &key &allow-other-keys) + (:method :around ((window window) &key user-event-p &allow-other-keys) + (setf (slot-value window 'maximized-p) t) + (when user-event-p (call-next-method))) + (:documentation "Set WINDOW to a maximized state. +USER-EVENT-P helps to distinguish events requested by the user or renderer.")) +(define-ffi-generic ffi-window-unmaximize (window &key &allow-other-keys) + (:method :around ((window window) &key user-event-p &allow-other-keys) + (setf (slot-value window 'maximized-p) nil) + (when user-event-p (call-next-method))) + (:documentation "Set WINDOW to an unmaximized state. +See `ffi-window-maximize'.")) (define-ffi-generic ffi-buffer-url (buffer) (:documentation "Return the URL associated with BUFFER as a `quri:uri'. diff --git a/source/renderer/gtk.lisp b/source/renderer/gtk.lisp index 379fd29f3905..433265c19320 100644 --- a/source/renderer/gtk.lisp +++ b/source/renderer/gtk.lisp @@ -500,12 +500,10 @@ response. The BODY is wrapped with `with-protect'." (on-signal-destroy window)) (connect-signal window "window-state-event" nil (widget event) (declare (ignore widget)) - (setf (nyxt::fullscreen-p window) - (find :fullscreen - (gdk:gdk-event-window-state-new-window-state event))) - (setf (nyxt::maximized-p window) - (find :maximized - (gdk:gdk-event-window-state-new-window-state event))) + (dolist (state (gdk:gdk-event-window-state-new-window-state event)) + (case state + (:fullscreen t) ; No-op for now. + (:maximized (ffi-window-maximize window :user-event-p nil)))) nil)) (unless nyxt::*headless-p* @@ -523,16 +521,16 @@ response. The BODY is wrapped with `with-protect'." (define-ffi-method ffi-window-delete ((window gtk-window)) (gtk:gtk-widget-destroy (gtk-object window))) -(define-ffi-method ffi-window-fullscreen ((window gtk-window)) +(define-ffi-method ffi-window-fullscreen ((window gtk-window) &key &allow-other-keys) (gtk:gtk-window-fullscreen (gtk-object window))) -(define-ffi-method ffi-window-unfullscreen ((window gtk-window)) +(define-ffi-method ffi-window-unfullscreen ((window gtk-window) &key &allow-other-keys) (gtk:gtk-window-unfullscreen (gtk-object window))) -(define-ffi-method ffi-window-maximize ((window gtk-window)) +(define-ffi-method ffi-window-maximize ((window gtk-window) &key &allow-other-keys) (gtk:gtk-window-maximize (gtk-object window))) -(define-ffi-method ffi-window-unmaximize ((window gtk-window)) +(define-ffi-method ffi-window-unmaximize ((window gtk-window) &key &allow-other-keys) (gtk:gtk-window-unmaximize (gtk-object window))) (defun derive-key-string (keyval character) @@ -1610,13 +1608,11 @@ the `active-buffer'." nil) (connect-signal buffer "enter-fullscreen" nil (web-view) (declare (ignore web-view)) - (setf (nyxt::fullscreen-p (current-window)) t) - (toggle-fullscreen :skip-renderer-resize t) + (ffi-window-fullscreen (current-window) :user-event-p nil) nil) (connect-signal buffer "leave-fullscreen" nil (web-view) (declare (ignore web-view)) - (setf (nyxt::fullscreen-p (current-window)) nil) - (toggle-fullscreen :skip-renderer-resize t) + (ffi-window-unfullscreen (current-window) :user-event-p nil) nil) buffer) diff --git a/source/window.lisp b/source/window.lisp index 82c47e2ce78d..4268a79cc876 100644 --- a/source/window.lisp +++ b/source/window.lisp @@ -178,24 +178,18 @@ not try to quit the browser." (window-set-buffer window buffer) (values window buffer))) -(define-command toggle-fullscreen (&key (window (current-window)) - skip-renderer-resize) - "Fullscreen WINDOW, or the current window, when omitted. -When `skip-renderer-resize' is non-nil, don't ask the renderer to fullscreen the window." - (let ((fullscreen (fullscreen-p window))) - (unless skip-renderer-resize - (if fullscreen - (ffi-window-unfullscreen window) - (ffi-window-fullscreen window))) - (toggle-status-buffer :show-p (not fullscreen)) - (toggle-message-buffer :show-p (not fullscreen)))) - -(define-command toggle-maximize (&key (window (current-window))) - "Maximize WINDOW, or the current window, when omitted." - (let ((maximized (maximized-p window))) - (if maximized - (ffi-window-unmaximize window) - (ffi-window-maximize window)))) +;; can't hide message buffer otherwise info is lost. see how other browsers do it. +(define-command toggle-fullscreen (&optional (window (current-window))) + "Toggle fullscreen state of window." + (if (fullscreen-p window) + (ffi-window-unfullscreen window) + (ffi-window-fullscreen window))) + +(define-command toggle-maximize (&optional (window (current-window))) + "Toggle maximized state of window." + (if (maximized-p window) + (ffi-window-unmaximize window) + (ffi-window-maximize window))) (defun enable-status-buffer (&optional (window (current-window))) (setf (ffi-height (status-buffer window)) (height (status-buffer window)))) @@ -211,33 +205,17 @@ When `skip-renderer-resize' is non-nil, don't ask the renderer to fullscreen the (define-command toggle-toolbars (&optional (window (current-window))) "Toggle the visibility of the message and status buffers." - (toggle-status-buffer :window window) - (toggle-message-buffer :window window)) - -(define-command toggle-status-buffer (&key (window (current-window)) - (show-p nil show-provided-p)) - "Toggle the visibility of the status buffer. - -If SHOW-P is provided: -- If SHOW-P is T, then `status-buffer' is always enabled; -- Otherwise, it is always disabled." - (cond ((and show-provided-p show-p) - (enable-status-buffer window)) - ((and (not show-provided-p) - (zerop (ffi-height (status-buffer window)))) - (enable-status-buffer window)) - (t (disable-status-buffer window)))) - -(define-command toggle-message-buffer (&key (window (current-window)) - (show-p nil show-provided-p)) - "Toggle the visibility of the message buffer. - -If SHOW-P is provided: -- If SHOW-P is T, then `message-buffer' is always enabled; -- Otherwise, it is always disabled." - (cond ((and show-provided-p show-p) - (enable-message-buffer window)) - ((and (not show-provided-p) - (zerop (height (message-buffer window)))) - (enable-message-buffer window)) - (t (disable-message-buffer window)))) + (toggle-status-buffer window) + (toggle-message-buffer window)) + +(define-command toggle-status-buffer (&optional (window (current-window))) + "Toggle the visibility of the status buffer." + (if (zerop (ffi-height (status-buffer window))) + (enable-status-buffer window) + (disable-status-buffer window))) + +(define-command toggle-message-buffer (&optional (window (current-window))) + "Toggle the visibility of the message buffer." + (if (zerop (ffi-height (message-buffer window))) + (enable-message-buffer window) + (disable-message-buffer window)))