diff --git a/src/switch-wm.scm b/src/switch-wm.scm index dc08cda..050daee 100644 --- a/src/switch-wm.scm +++ b/src/switch-wm.scm @@ -7,6 +7,8 @@ (font font "-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*") (select-next keys "M-k n") (select-previous keys "M-k p") + (swap-next keys "M-k t") + (swap-previous keys "M-k r") ) (define (create-switch-wm out-channel dpy parent options default-options @@ -46,12 +48,11 @@ (data (make-switch-wm-data '() empty-titlebar (cons #f #f)))) (update-titlebars wm data) - (grab-shortcut dpy window - (get-option-value options 'select-next) - 'select-next channel #f) - (grab-shortcut dpy window - (get-option-value options 'select-previous) - 'select-previous channel #f) + (for-each (lambda (id) + (grab-shortcut dpy window + (get-option-value options id) + id channel #f)) + '(select-next select-previous swap-next swap-previous)) (spawn* (list 'switch-wm wm) (lambda (release) @@ -157,6 +158,9 @@ ((select-next) (select-next-client wm (second msg))) ((select-previous) (select-previous-client wm (second msg))) + ((swap-next) (swap-titlebar-with-next wm data (second msg))) + ((swap-previous) (swap-titlebar-with-previous wm data (second msg))) + ((show-clients) (let ((clients (second msg))) ;; it's a list of a client and it's transients. @@ -352,3 +356,42 @@ (define (select-previous-client wm time) (select-next-client* wm (reverse (wm-clients wm)) time)) + +;; *** + +(define (swap-titlebar wm data time next?) + (let* ((cc (wm-current-client wm)) + (titlebars (if next? + (data:titlebars data) + (reverse (data:titlebars data)))) + (before.after + (fold-right (lambda (client.tb result) + (if (eq? (car client.tb) cc) + (cons (cdr result) (cons client.tb (car result))) + (cons (cons client.tb (car result)) (cdr result)))) + (cons '() '()) + titlebars)) + (before (car before.after)) + (after (cdr before.after)) + (ntitlebars (cond + ((null? after) titlebars) ;; cc not in list + ((null? (cdr after)) ;; it's the last one + ;; this is not really a 'swap', but probably + ;; what the user expects + (cons (car after) + before)) + (else + (append before + (cons (cadr after) + (cons (car after) (cddr after)))))))) + (if next? + (set-data:titlebars! data ntitlebars) + (set-data:titlebars! data (reverse ntitlebars))) + (fit-titlebars wm data))) + + +(define (swap-titlebar-with-next wm data time) + (swap-titlebar wm data time #t)) + +(define (swap-titlebar-with-previous wm data time) + (swap-titlebar wm data time #f))