Created
March 10, 2012 12:17
-
-
Save cesarblum/2011279 to your computer and use it in GitHub Desktop.
TinyWM in Chicken Scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; TinyWM is written by Nick Welch <[email protected]>, 2005. | |
;; Ported to Chicken by César L. B. Silveira <[email protected]>, 2011. | |
;; | |
;; Original TinyWM website: http://incise.org/tinywm.html | |
;; | |
;; This software is in the public domain | |
;; and is provided AS IS, with NO WARRANTY. | |
(require-extension xlib) | |
(let* ((dpy (xopendisplay #f)) | |
(root (xdefaultrootwindow dpy)) | |
(attr (make-xwindowattributes)) | |
(start-button 0) | |
(start-x 0) | |
(start-y 0) | |
(ev (make-xevent))) | |
(xgrabkey dpy | |
(char->integer (xkeysymtokeycode dpy (xstringtokeysym "F1"))) | |
MOD1MASK | |
root | |
1 | |
GRABMODEASYNC | |
GRABMODEASYNC) | |
(xgrabbutton dpy | |
BUTTON1 | |
MOD1MASK | |
root | |
1 | |
BUTTONPRESSMASK | |
GRABMODEASYNC | |
GRABMODEASYNC | |
NONE | |
NONE) | |
(xgrabbutton dpy | |
BUTTON3 | |
MOD1MASK | |
root | |
1 | |
BUTTONPRESSMASK | |
GRABMODEASYNC | |
GRABMODEASYNC | |
NONE | |
NONE) | |
(let loop () | |
(xnextevent dpy ev) | |
(cond ((and (equal? (xevent-type ev) KEYPRESS) | |
(not (equal? (xkeyevent-subwindow ev) NONE))) | |
(xraisewindow dpy (xkeyevent-subwindow ev))) | |
((and (equal? (xevent-type ev) BUTTONPRESS) | |
(not (equal? (xbuttonevent-subwindow ev) NONE))) | |
(xgrabpointer dpy | |
(xbuttonevent-subwindow ev) | |
1 | |
(bitwise-ior POINTERMOTIONMASK BUTTONRELEASEMASK) | |
GRABMODEASYNC | |
GRABMODEASYNC | |
NONE | |
NONE | |
CURRENTTIME) | |
(xgetwindowattributes dpy (xbuttonevent-subwindow ev) attr) | |
(set! start-button (xbuttonevent-button ev)) | |
(set! start-x (xbuttonevent-x_root ev)) | |
(set! start-y (xbuttonevent-y_root ev))) | |
((equal? (xevent-type ev) MOTIONNOTIFY) | |
(let ((xdiff (- (xmotionevent-x_root ev) start-x)) | |
(ydiff (- (xmotionevent-y_root ev) start-y))) | |
(xmoveresizewindow | |
dpy | |
(xmotionevent-window ev) | |
(+ (xwindowattributes-x attr) | |
(if (equal? start-button BUTTON1) xdiff 0)) | |
(+ (xwindowattributes-y attr) | |
(if (equal? start-button BUTTON1) ydiff 0)) | |
(max 1 (+ (xwindowattributes-width attr) | |
(if (equal? start-button BUTTON3) xdiff 0))) | |
(max 1 (+ (xwindowattributes-height attr) | |
(if (equal? start-button BUTTON3) ydiff 0)))))) | |
((equal? (xevent-type ev) BUTTONRELEASE) | |
(xungrabpointer dpy CURRENTTIME))) | |
(loop))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, I was looking for something like this.