<commit_before>;;; renderer-qt.lisp --- functions for creating Qt interface onscreen

(in-package :next)
(annot:enable-annot-syntax)

@export
@export-accessors
(defclass qt-browser (browser)
  ((application :accessor application)))

(define-class-type browser)
(declaim (type (browser-type) *browser-class*))
@export
(defparameter *browser-class* 'qt-browser)

(defmethod initialize ((browser qt-browser) urls startup-timestamp)
  (log:debug "Initializing Qt Interface")
  (setf (application browser)
        (qt:new-q-application 1 (cffi:foreign-alloc :string
                                                    :initial-contents (list "Next")
                                                    :null-terminated-p t)))
  (finalize browser urls startup-timestamp)
  (qt:application-exec (application browser)))

(defmethod kill-interface ((browser qt-browser))
  (qt:application-quit (application browser)))

@export
@export-accessors
(defclass qt-window (window)
  ((qt-object :accessor qt-object)
   (box-layout :accessor box-layout)
   (minibuffer-view :accessor minibuffer-view)))

(define-class-type window)
(declaim (type (window-type) *window-class*))
@export
(defparameter *window-class* 'qt-window)

@export
@export-accessors
(defclass qt-buffer (buffer)
  ((qt-object :accessor qt-object)))

(define-class-type buffer)
(declaim (type (buffer-type) *buffer-class*))
@export
(defparameter *buffer-class* 'qt-buffer)

(defmethod initialize-instance :after ((window qt-window) &key)
  (with-slots (id qt-object box-layout active-buffer minibuffer-view) window
    (setf id (get-unique-window-identifier *browser*))
    (setf qt-object (qt:new-q-widget))
    (setf box-layout (qt:new-qv-box-layout))
    (setf active-buffer (make-instance *buffer-class*))
    (setf minibuffer-view (qt:new-q-web-engine-view))
    ;; Add views to window, configure window widget
    (qt:widget-set-layout qt-object box-layout)
    (qt:layout-add-widget box-layout (qt-object active-buffer))
    (qt:layout-add-widget box-layout minibuffer-view)
    (qt:layout-set-contents-margins box-layout 0 0 0 0)
    (qt:layout-set-spacing box-layout 0)
    (ipc-window-set-minibuffer-height window (status-buffer-height window))
    ;; load about:blank to permit JS evaluation
    (qt:web-engine-view-load minibuffer-view "about:blank")
    (qt:widget-show qt-object)))

(defmethod process-destroy ((window qt-window))
  (window-delete window))

@export
(defmethod ipc-window-delete ((window qt-window))
  "Delete a window object and remove it from the hash of windows.")

(defmethod ipc-window-fullscreen ((window qt-window)))

(defmethod ipc-window-unfullscreen ((window qt-window)))

(defmethod initialize-instance :after ((buffer qt-buffer) &key)
  (next-hooks:run-hook (buffer-before-make-hook *browser*) buffer)
  (setf (id buffer) (get-unique-buffer-identifier *browser*))
  (setf (qt-object buffer) (qt:new-q-web-engine-view))
  ;; load about:blank to permit JS evaluation
  (qt:web-engine-view-load (qt-object buffer) "about:blank"))

@export
(defmethod ipc-window-make ((browser qt-browser))
  "Make a window."
  (make-instance *window-class*))

@export
(defmethod ipc-window-to-foreground ((window qt-window))
  "Show window in foreground.")

@export
(defmethod ipc-window-set-title ((window qt-window) title)<commit_msg>renderer-qt.lisp: implement window full screen/unfullscreen<commit_after>;;; renderer-qt.lisp --- functions for creating Qt interface onscreen

(in-package :next)
(annot:enable-annot-syntax)

@export
@export-accessors
(defclass qt-browser (browser)
  ((application :accessor application)))

(define-class-type browser)
(declaim (type (browser-type) *browser-class*))
@export
(defparameter *browser-class* 'qt-browser)

(defmethod initialize ((browser qt-browser) urls startup-timestamp)
  (log:debug "Initializing Qt Interface")
  (setf (application browser)
        (qt:new-q-application 1 (cffi:foreign-alloc :string
                                                    :initial-contents (list "Next")
                                                    :null-terminated-p t)))
  (finalize browser urls startup-timestamp)
  (qt:application-exec (application browser)))

(defmethod kill-interface ((browser qt-browser))
  (qt:application-quit (application browser)))

@export
@export-accessors
(defclass qt-window (window)
  ((qt-object :accessor qt-object)
   (box-layout :accessor box-layout)
   (minibuffer-view :accessor minibuffer-view)))

(define-class-type window)
(declaim (type (window-type) *window-class*))
@export
(defparameter *window-class* 'qt-window)

@export
@export-accessors
(defclass qt-buffer (buffer)
  ((qt-object :accessor qt-object)))

(define-class-type buffer)
(declaim (type (buffer-type) *buffer-class*))
@export
(defparameter *buffer-class* 'qt-buffer)

(defmethod initialize-instance :after ((window qt-window) &key)
  (with-slots (id qt-object box-layout active-buffer minibuffer-view) window
    (setf id (get-unique-window-identifier *browser*))
    (setf qt-object (qt:new-q-widget))
    (setf box-layout (qt:new-qv-box-layout))
    (setf active-buffer (make-instance *buffer-class*))
    (setf minibuffer-view (qt:new-q-web-engine-view))
    ;; Add views to window, configure window widget
    (qt:widget-set-layout qt-object box-layout)
    (qt:layout-add-widget box-layout (qt-object active-buffer))
    (qt:layout-add-widget box-layout minibuffer-view)
    (qt:layout-set-contents-margins box-layout 0 0 0 0)
    (qt:layout-set-spacing box-layout 0)
    (ipc-window-set-minibuffer-height window (status-buffer-height window))
    ;; load about:blank to permit JS evaluation
    (qt:web-engine-view-load minibuffer-view "about:blank")
    (qt:widget-show qt-object)))

(defmethod process-destroy ((window qt-window))
  (window-delete window))

@export
(defmethod ipc-window-delete ((window qt-window))
  "Delete a window object and remove it from the hash of windows.")

(defmethod ipc-window-fullscreen ((window qt-window))
  (qt:window-show-full-screen (qt-object window)))

(defmethod ipc-window-unfullscreen ((window qt-window))
  (qt:window-show-normal (qt-object window)))

(defmethod initialize-instance :after ((buffer qt-buffer) &key)
  (next-hooks:run-hook (buffer-before-make-hook *browser*) buffer)
  (setf (id buffer) (get-unique-buffer-identifier *browser*))
  (setf (qt-object buffer) (qt:new-q-web-engine-view))
  ;; load about:blank to permit JS evaluation
  (qt:web-engine-view-load (qt-object buffer) "about:blank"))

@export
(defmethod ipc-window-make ((browser qt-browser))
  "Make a window."
  (make-instance *window-class*))

@export
(defmethod ipc-window-to-foreground ((window qt-window))
  "Show window in foreground.")

@export
(defmethod ipc-window-set-title ((window qt-window) title)
{'fraction_non_alphanumeric': 0.1436178080165656, 'fraction_numerical': 0.0017748853719863926, 'mean_word_length': 4.050037341299477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2814815', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2200, 'n_words': 535}