Skip to content

Instantly share code, notes, and snippets.

@TeMPOraL
Created September 11, 2017 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeMPOraL/f393753f4c45ac07c17563dce03903cc to your computer and use it in GitHub Desktop.
Save TeMPOraL/f393753f4c45ac07c17563dce03903cc to your computer and use it in GitHub Desktop.
Example of a X window that properly handles closing events from the WM.
(defpackage #:scratch/clx-test
(:use #:cl)
(:export #:run))
(in-package #:scratch/clx-test)
;;; A minimum test case for properly handling window close events from the window manager.
(defun delete-window-event-p (display type data)
(and (eq type :wm_protocols)
(eq (xlib:atom-name display (aref data 0)) :wm_delete_window)))
(defun run (&optional (host ""))
(let* ((display (xlib:open-display host))
(screen (first (xlib:display-roots display)))
(black (xlib:screen-black-pixel screen))
(root-window (xlib:screen-root screen))
(my-window (xlib:create-window :parent root-window
:x 0
:y 0
:width 400
:height 300
:background black
:event-mask (xlib:make-event-mask :exposure
:enter-window))))
(xlib:map-window my-window)
(setf (xlib:wm-protocols my-window) '(:wm_delete_window))
(format t "Protocols: ~S~%" (xlib:wm-protocols my-window))
(xlib:event-case (display :force-output-p t
:discard-p t)
(:exposure () (format t "Exposed~%"))
(:enter-notify () nil)
(:client-message (type format sequence data)
(format t "Got client message!~%~2TType: ~S~%~2TFormat: ~S~%~2TSequence: ~S~%~2TData: ~S~%"
type format sequence data)
(delete-window-event-p display type data)))
(xlib:destroy-window my-window)
(xlib:close-display display)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment