From b9d785aa9c681f0a6c804eec9bc356aaca78f3ee Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 2 Jan 2024 22:07:15 -0600 Subject: initial commit --- acdwm.scm | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 acdwm.scm (limited to 'acdwm.scm') diff --git a/acdwm.scm b/acdwm.scm new file mode 100755 index 0000000..fdd8395 --- /dev/null +++ b/acdwm.scm @@ -0,0 +1,110 @@ +#!/bin/sh +#| -*- scheme -*- +exec csi -ss "$0" "$@" ; acdwm +based on tinywm: https://github.com/mackstann/tinywm/ +|# + +(import (chicken bitwise) + (chicken process-context) + (srfi 1) + matchable + xlib) + +(define TRUE 1) +(define FALSE 0) + +(define dpy (make-parameter #f)) +(define screen (make-parameter #f)) +(define root (make-parameter #f)) + +(define (grab-keys) + (xgrabkey (dpy) + (char->integer (xkeysymtokeycode (dpy) (xstringtokeysym "F1"))) + MOD1MASK + (root) + TRUE + GRABMODEASYNC + GRABMODEASYNC) + (xgrabbutton (dpy) + 1 + MOD1MASK + (root) + TRUE + (bitwise-ior BUTTONPRESSMASK + BUTTONRELEASEMASK + POINTERMOTIONMASK) + GRABMODEASYNC + GRABMODEASYNC + NONE + NONE) + (xgrabbutton (dpy) + 3 + MOD1MASK + (root) + TRUE + (bitwise-ior BUTTONPRESSMASK + BUTTONRELEASEMASK + POINTERMOTIONMASK) + GRABMODEASYNC + GRABMODEASYNC + NONE + NONE)) + +(define (handle-events) + (let ((event (make-xevent)) + (start (make-xbuttonevent)) + (attrs (make-xwindowattributes))) + (set-xbuttonevent-subwindow! start NONE) + (let loop () + (xnextevent (dpy) event) + (cond + ((and (= KEYPRESS (xevent-type event)) + (not (= NONE (xevent-xkey-subwindow event)))) + (xraisewindow (dpy) (xevent-xkey-subwindow event))) + + ((and (= BUTTONPRESS (xevent-type event)) + (not (= NONE (xevent-xbutton-subwindow event)))) + (print "button!") + (xgetwindowattributes (dpy) (xevent-xbutton-subwindow event) attrs) + (set-xbuttonevent-x_root! start (xevent-xbutton-x_root event)) + (set-xbuttonevent-y_root! start (xevent-xbutton-y_root event)) + (set-xbuttonevent-button! start (xevent-xbutton-button event)) + (set-xbuttonevent-subwindow! start (xevent-xbutton-subwindow event))) + + ((and (= MOTIONNOTIFY (xevent-type event)) + (not (= NONE (xbuttonevent-subwindow start)))) + (let ((xdiff (- (xevent-xbutton-x_root event) + (xbuttonevent-x_root start))) + (ydiff (- (xevent-xbutton-y_root event) + (xbuttonevent-y_root start))) + (button (xbuttonevent-button start))) + (xmoveresizewindow (dpy) + (xbuttonevent-subwindow start) + (+ (xwindowattributes-x attrs) + (if (= button 1) xdiff 0)) + (+ (xwindowattributes-y attrs) + (if (= button 1) ydiff 0)) + (max 1 (+ (xwindowattributes-width attrs) + (if (= button 3) xdiff 0))) + (max 1 (+ (xwindowattributes-height attrs) + (if (= button 3) ydiff 0)))))) + + ((= BUTTONRELEASE (xevent-type event)) + (print "buttonrelease!") + (set-xbuttonevent-subwindow! start NONE))) + + ;; Annnd go around again + (loop)))) + +(define (main args) + (parameterize ((dpy (xopendisplay #f))) + (assert (dpy)) + (parameterize ((screen (xdefaultscreen (dpy)))) + (parameterize ((root (xrootwindow (dpy) (screen)))) + (grab-keys) + (handle-events))))) + +(cond-expand + ((or chicken-script compiling) + (main (command-line-arguments))) + (else)) -- cgit 1.4.1-21-gabe81