Skip to content

Commit 55f89c2

Browse files
committed
Add changes from StumpWM to event handling.
1 parent 46ff35d commit 55f89c2

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

events.lisp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@
3232
(defvar *current-event-time* nil)
3333

3434
(defmacro define-thesis-event-handler (event keys &body body)
35-
(let ((fn-name (gensym))
36-
(event-slots (gensym)))
35+
(let ((event-slots (gensym)))
3736
(multiple-value-bind (body declarations docstring)
3837
(parse-body body :documentation t)
39-
`(labels ((,fn-name (&rest ,event-slots &key ,@keys &allow-other-keys)
40-
(declare (ignore ,event-slots))
41-
,@(when docstring
42-
(list docstring))
43-
,@declarations
44-
,@body))
45-
(setf (gethash ,event *event-fn-table*) #',fn-name)))))
38+
`(setf (gethash ,event *event-fn-table*)
39+
(lambda (&rest ,event-slots &key ,@keys &allow-other-keys)
40+
(declare (ignore ,event-slots)
41+
,@(cdar declarations))
42+
,@(when docstring
43+
(list docstring))
44+
,@body)))))
4645

4746
;;; Configure request
4847

@@ -390,6 +389,20 @@ converted to an atom is removed."
390389
(define-thesis-event-handler :selection-clear (selection)
391390
(setf (getf *x-selection* selection) nil))
392391

392+
(define-thesis-event-handler :selection-notify (window property selection)
393+
(dformat 2 "selection-notify: ~s ~s ~s~%" window property selection)
394+
(when property
395+
(let* ((selection (or selection :primary))
396+
(sel-string (utf8-to-string
397+
(xlib:get-property window
398+
property
399+
:type :utf8_string
400+
:result-type 'vector
401+
:delete-p t))))
402+
(when (< 0 (length sel-string))
403+
(setf (getf *x-selection* selection) sel-string)
404+
(run-hook-with-args *selection-notify-hook* sel-string)))))
405+
393406
(defun find-message-window-screen (win)
394407
"Return the screen, if any, that message window WIN belongs."
395408
(dolist (screen *screen-list*)
@@ -471,9 +484,8 @@ converted to an atom is removed."
471484
(echo-string (window-screen window) (format nil "'~a' denied map request" (window-name window)))
472485
(echo-string (window-screen window) (format nil "'~a' denied map request in group ~a" (window-name window) (group-name (window-group window))))))
473486
(frame-raise-window (window-group window) (window-frame window) window
474-
(if (eq (window-frame window)
475-
(tile-group-current-frame (window-group window)))
476-
t nil))))
487+
(eq (window-frame window)
488+
(tile-group-current-frame (window-group window))))))
477489

478490
(defun maybe-raise-window (window)
479491
(if (deny-request-p window *deny-raise-request*)
@@ -599,8 +611,9 @@ the window in it's frame."
599611
(defun make-xlib-window (drawable)
600612
"For some reason the CLX xid cache screws up returns pixmaps when
601613
they should be windows. So use this function to make a window out of DRAWABLE."
602-
(xlib::make-window :id (xlib:drawable-id drawable)
603-
:display *display*))
614+
(make-instance 'xlib:window
615+
:id (xlib:drawable-id drawable)
616+
:display *display*))
604617

605618
(defun handle-event (&rest event-slots &key display event-key &allow-other-keys)
606619
(declare (ignore display))

primitives.lisp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
*mode-line-click-hook*
5959
*pre-command-hook*
6060
*post-command-hook*
61+
*selection-notify-hook*
6162
*display*
6263
*shell-program*
6364
*maxsize-border-width*
@@ -323,6 +324,10 @@ the command as a symbol.")
323324
"Called after a command is called. It is called with 1 argument:
324325
the command as a symbol.")
325326

327+
(defvar *selection-notify-hook* '()
328+
"Called after a :selection-notify event is processed. It is called
329+
with 1 argument: the selection as a string.")
330+
326331
;; Data types and globals used by thesiswm
327332

328333
(defvar *display* nil

0 commit comments

Comments
 (0)