Skip to content

Instantly share code, notes, and snippets.

@anekos
Last active January 21, 2025 13:33
Show Gist options
  • Save anekos/56ebc74a566ac190207d51eccde50e55 to your computer and use it in GitHub Desktop.
Save anekos/56ebc74a566ac190207d51eccde50e55 to your computer and use it in GitHub Desktop.
iron-maiden-cl で hyprland 対応
; For https://bitbucket.org/anekos/iron-maiden-cl
; Hyprland {{{
(defvar *hyprland-mutex* (sb-thread:make-mutex :name "hyprland-mutex"))
(defvar *hyprland-active-window-class* nil)
(defun extract-hyprland-active-window (line)
(let ((prefix "activewindow>>"))
(when (and (stringp line)
(>= (length line) (length prefix))
(string= (subseq line 0 (length prefix)) prefix))
(let* ((remaining (subseq line (length prefix)))
(comma-pos (position #\, remaining)))
(if comma-pos
(subseq remaining 0 comma-pos)
remaining)))))
(defun get-hyprland-active-window-class ()
(sb-thread:with-mutex (*hyprland-mutex*)
*hyprland-active-window-class*))
(defun handle-hyprland-socket-line (line)
(when-let (klass (extract-hyprland-active-window line))
(format t "hyprland active window class: ~A~%" klass)
(sb-thread:with-mutex (*hyprland-mutex*)
(setf *hyprland-active-window-class* klass))))
(defun socket-listener ()
(let* ((runtime-dir (uiop:getenv "XDG_RUNTIME_DIR"))
(instance-sig (uiop:getenv "HYPRLAND_INSTANCE_SIGNATURE"))
(socket-path (format nil "~A/hypr/~A/.socket2.sock" runtime-dir instance-sig))
(socket (make-instance 'sb-bsd-sockets:local-socket :type :stream)))
(format t "hyprland socket: ~A~%" socket-path)
(unwind-protect
(progn
(format t "waiting for hyprland socket~%")
(loop until (probe-file socket-path)
do (sleep 0.5))
(format t "hyprland socket found~%")
(sb-bsd-sockets:socket-connect socket socket-path)
(let ((stream (sb-bsd-sockets:socket-make-stream
socket
:input t
:output t
:buffering :full)))
(loop
for line = (read-line stream)
do (if (null line)
(return nil)
(handle-hyprland-socket-line line)))))
(sb-bsd-sockets:socket-close socket))))
(defun start-socket-thread ()
(sb-thread:make-thread #'socket-listener :name "socket-listener-thread"))
(when *use-hyprland*
(start-socket-thread))
; }}}
(define-processor
(for-device ("IST PRO")
; right side button
(change 279 key-leftmeta)
(if (equal "firefox" (get-hyprland-active-window-class))
(progn
; left side 1
(key-map-to-action "<#276>" (press-key im "<C-A-t>")))
(progn
nil))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment