1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Main functions
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2011 Philippe Brochard <hocwp@free.fr>
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ;;; --------------------------------------------------------------------------
30 ;;; Conversion functions
31 ;;; Float -> Pixel conversion
32 (defun x-fl->px
(x parent
)
33 "Convert float X coordinate to pixel"
34 (round (+ (* x
(frame-rw parent
)) (frame-rx parent
))))
36 (defun y-fl->px
(y parent
)
37 "Convert float Y coordinate to pixel"
38 (round (+ (* y
(frame-rh parent
)) (frame-ry parent
))))
40 (defun w-fl->px
(w parent
)
41 "Convert float Width coordinate to pixel"
42 (round (* w
(frame-rw parent
))))
44 (defun h-fl->px
(h parent
)
45 "Convert float Height coordinate to pixel"
46 (round (* h
(frame-rh parent
))))
48 ;;; Pixel -> Float conversion
49 (defun x-px->fl
(x parent
)
50 "Convert pixel X coordinate to float"
51 (/ (- x
(frame-rx parent
) *border-size
*) (frame-rw parent
)))
53 (defun y-px->fl
(y parent
)
54 "Convert pixel Y coordinate to float"
55 (/ (- y
(frame-ry parent
) *border-size
*) (frame-rh parent
)))
57 (defun w-px->fl
(w parent
)
58 "Convert pixel Width coordinate to float"
59 (/ w
(frame-rw parent
)))
61 (defun h-px->fl
(h parent
)
62 "Convert pixel Height coordinate to float"
63 (/ h
(frame-rh parent
)))
67 (defgeneric frame-p
(frame))
68 (defmethod frame-p ((frame frame
))
69 (declare (ignore frame
))
71 (defmethod frame-p (frame)
72 (declare (ignore frame
))
77 ;;; in-*: Find if point (x,y) is in frame, window or child
78 (defun in-frame (frame x y
)
80 (<= (frame-rx frame
) x
(+ (frame-rx frame
) (frame-rw frame
)))
81 (<= (frame-ry frame
) y
(+ (frame-ry frame
) (frame-rh frame
)))))
83 (defun in-window (window x y
)
84 (and (xlib:window-p window
)
85 (<= (xlib:drawable-x window
) x
(+ (xlib:drawable-x window
) (xlib:drawable-width window
)))
86 (<= (xlib:drawable-y window
) y
(+ (xlib:drawable-y window
) (xlib:drawable-height window
)))))
88 (defgeneric in-child
(child x y
))
90 (defmethod in-child ((child frame
) x y
)
92 (defmethod in-child ((child xlib
:window
) x y
)
93 (in-window child x y
))
94 (defmethod in-child (child x y
)
95 (declare (ignore child x y
))
101 (defun frame-selected-child (frame)
102 (when (frame-p frame
)
103 (with-slots (child selected-pos
) frame
104 (let ((len (length child
)))
105 (cond ((minusp selected-pos
) (setf selected-pos
0))
106 ((>= selected-pos len
) (setf selected-pos
(max (1- len
) 0)))))
107 (nth selected-pos child
))))
113 (defgeneric child-equal-p
(child-1 child-2
))
115 (defmethod child-equal-p ((child-1 xlib
:window
) (child-2 xlib
:window
))
116 (xlib:window-equal child-1 child-2
))
118 (defmethod child-equal-p ((child-1 frame
) (child-2 frame
))
119 (equal child-1 child-2
))
121 (defmethod child-equal-p (child-1 child-2
)
122 (declare (ignore child-1 child-2
))
126 (declaim (inline child-member child-remove child-position
))
128 (defun child-member (child list
)
129 (member child list
:test
#'child-equal-p
))
131 (defun child-remove (child list
)
132 (remove child list
:test
#'child-equal-p
))
134 (defun child-position (child list
)
135 (position child list
:test
#'child-equal-p
))
139 ;;; Frame data manipulation functions
140 (defun frame-data-slot (frame slot
)
141 "Return the value associated to data slot"
142 (when (frame-p frame
)
143 (second (assoc slot
(frame-data frame
)))))
145 (defun set-frame-data-slot (frame slot value
)
146 "Set the value associated to data slot"
147 (when (frame-p frame
)
148 (with-slots (data) frame
149 (setf data
(remove (assoc slot data
) data
))
150 (push (list slot value
) data
))
153 (defsetf frame-data-slot set-frame-data-slot
)
156 (defun remove-frame-data-slot (frame slot
)
157 "Remove a slot in frame data slots"
158 (when (frame-p frame
)
159 (with-slots (data) frame
160 (setf data
(remove (assoc slot data
) data
)))))
164 (defun managed-window-p (window frame
)
165 "Return t only if window is managed by frame"
167 (with-slots ((managed forced-managed-window
)
168 (unmanaged forced-unmanaged-window
)) frame
169 (and (xlib:window-p window
)
170 (not (child-member window unmanaged
))
171 (not (member (xlib:wm-name window
) unmanaged
:test
#'string-equal-p
))
172 (or (member :all
(frame-managed-type frame
))
173 (member (window-type window
) (frame-managed-type frame
))
174 (child-member window managed
)
175 (member (xlib:wm-name window
) managed
:test
#'string-equal-p
))))
179 (defun never-managed-window-p (window)
180 (when (xlib:window-p window
)
181 (dolist (type *never-managed-window-list
*)
182 (when (funcall (first type
) window
)
183 (return (values t
(second type
)))))))
187 (defgeneric child-name
(child))
189 (defmethod child-name ((child xlib
:window
))
190 (xlib:wm-name child
))
192 (defmethod child-name ((child frame
))
195 (defmethod child-name (child)
196 (declare (ignore child
))
200 (defgeneric set-child-name
(child name
))
202 (defmethod set-child-name ((child xlib
:window
) name
)
203 (setf (xlib:wm-name child
) name
))
205 (defmethod set-child-name ((child frame
) name
)
206 (setf (frame-name child
) name
))
208 (defmethod set-child-name (child name
)
209 (declare (ignore child name
)))
211 (defsetf child-name set-child-name
)
216 (defgeneric child-fullname
(child))
218 (defmethod child-fullname ((child xlib
:window
))
219 (format nil
"~A (~A)" (or (xlib:wm-name child
) "?") (or (xlib:get-wm-class child
) "?")))
221 (defmethod child-fullname ((child frame
))
222 (aif (frame-name child
)
223 (format nil
"~A (Frame ~A)" it
(frame-number child
))
224 (format nil
"Frame ~A" (frame-number child
))))
226 (defmethod child-fullname (child)
227 (declare (ignore child
))
231 (defgeneric child-x
(child))
232 (defmethod child-x ((child xlib
:window
))
233 (xlib:drawable-x child
))
234 (defmethod child-x ((child frame
))
237 (defgeneric child-y
(child))
238 (defmethod child-y ((child xlib
:window
))
239 (xlib:drawable-y child
))
240 (defmethod child-y ((child frame
))
243 (defgeneric child-width
(child))
244 (defmethod child-width ((child xlib
:window
))
245 (xlib:drawable-width child
))
246 (defmethod child-width ((child frame
))
249 (defgeneric child-height
(child))
250 (defmethod child-height ((child xlib
:window
))
251 (xlib:drawable-height child
))
252 (defmethod child-height ((child frame
))
259 (defgeneric rename-child
(child name
))
261 (defmethod rename-child ((child frame
) name
)
262 (setf (frame-name child
) name
)
263 (display-frame-info child
))
265 (defmethod rename-child ((child xlib
:window
) name
)
266 (setf (xlib:wm-name child
) name
))
268 (defmethod rename-child (child name
)
269 (declare (ignore child name
)))
272 (defun is-in-current-child-p (child)
273 (and (frame-p *current-child
*)
274 (child-member child
(frame-child *current-child
*))))
278 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
279 (defmacro with-all-children
((root child
) &body body
)
281 (sub-child (gensym)))
283 (labels ((,rec
(,child
)
285 (when (frame-p ,child
)
286 (dolist (,sub-child
(reverse (frame-child ,child
)))
287 (,rec
,sub-child
)))))
291 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
292 (defmacro with-all-children-reversed
((root child
) &body body
)
294 (sub-child (gensym)))
296 (labels ((,rec
(,child
)
298 (when (frame-p ,child
)
299 (dolist (,sub-child
(frame-child ,child
))
300 (,rec
,sub-child
)))))
304 ;; (with-all-frames (*root-frame* frame) (print (frame-number frame)))
305 (defmacro with-all-frames
((root frame
) &body body
)
309 (labels ((,rec
(,frame
)
310 (when (frame-p ,frame
)
312 (dolist (,child
(reverse (frame-child ,frame
)))
317 ;; (with-all-windows (*root-frame* window) (print window))
318 (defmacro with-all-windows
((root window
) &body body
)
322 (labels ((,rec
(,window
)
323 (when (xlib:window-p
,window
)
325 (when (frame-p ,window
)
326 (dolist (,child
(reverse (frame-child ,window
)))
332 ;; (with-all-frames-windows (*root-frame* child) (print child) (print (frame-number child)))
333 (defmacro with-all-windows-frames
((root child
) body-window body-frame
)
335 (sub-child (gensym)))
337 (labels ((,rec
(,child
)
339 (xlib:window
,body-window
)
341 (dolist (,sub-child
(reverse (frame-child ,child
)))
342 (,rec
,sub-child
))))))
345 (defmacro with-all-windows-frames-and-parent
((root child parent
) body-window body-frame
)
347 (sub-child (gensym)))
349 (labels ((,rec
(,child
,parent
)
351 (xlib:window
,body-window
)
353 (dolist (,sub-child
(reverse (frame-child ,child
)))
354 (,rec
,sub-child
,child
))))))
359 (defun frame-find-free-number ()
360 (let ((all-numbers nil
))
361 (with-all-frames (*root-frame
* frame
)
362 (pushnew (frame-number frame
) all-numbers
))
363 (find-free-number all-numbers
)))
366 (defun create-frame (&rest args
&key
(number (frame-find-free-number)) &allow-other-keys
)
367 (let* ((window (xlib:create-window
:parent
*root
*
372 :background
(get-color *frame-background
*)
373 :colormap
(xlib:screen-default-colormap
*screen
*)
374 :border-width
*border-size
*
375 :border
(get-color *color-selected
*)
376 :event-mask
'(:exposure
:button-press
:button-release
:pointer-motion
:enter-window
)))
377 (gc (xlib:create-gcontext
:drawable window
378 :foreground
(get-color *frame-foreground
*)
379 :background
(get-color *frame-background
*)
381 :line-style
:solid
)))
382 (apply #'make-instance
'frame
:number number
:window window
:gc gc args
)))
388 (defun add-frame (frame parent
)
389 (push frame
(frame-child parent
))
393 (defun place-frame (frame parent prx pry prw prh
)
394 "Place a frame from real (pixel) coordinates"
395 (when (and (frame-p frame
) (frame-p parent
))
396 (with-slots (window x y w h
) frame
397 (setf (xlib:drawable-x window
) prx
398 (xlib:drawable-y window
) pry
399 (xlib:drawable-width window
) prw
400 (xlib:drawable-height window
) prh
401 x
(x-px->fl prx parent
)
402 y
(y-px->fl pry parent
)
403 w
(w-px->fl prw parent
)
404 h
(h-px->fl prh parent
))
405 (xlib:display-finish-output
*display
*))))
407 (defun fixe-real-size (frame parent
)
408 "Fixe real (pixel) coordinates in float coordinates"
409 (when (frame-p frame
)
410 (with-slots (x y w h rx ry rw rh
) frame
411 (setf x
(x-px->fl rx parent
)
412 y
(y-px->fl ry parent
)
413 w
(w-px->fl rw parent
)
414 h
(h-px->fl rh parent
)))))
416 (defun fixe-real-size-current-child ()
417 "Fixe real (pixel) coordinates in float coordinates for children in the current child"
418 (when (frame-p *current-child
*)
419 (dolist (child (frame-child *current-child
*))
420 (fixe-real-size child
*current-child
*))))
425 (defun find-child (to-find root
)
426 "Find to-find in root or in its children"
427 (with-all-children (root child
)
428 (when (child-equal-p child to-find
)
429 (return-from find-child t
))))
433 (defmacro with-find-in-all-frames
(test &optional return-value
)
436 (with-all-frames (root frame
)
439 (return-from return-block
(or ,return-value frame
))
441 (or ,return-value ret
))))
443 (defun find-parent-frame (to-find &optional
(root *root-frame
*) first-foundp
)
444 "Return the parent frame of to-find"
445 (with-find-in-all-frames
446 (child-member to-find
(frame-child frame
))))
448 (defun find-frame-window (window &optional
(root *root-frame
*) first-foundp
)
449 "Return the frame with the window window"
450 (with-find-in-all-frames
451 (xlib:window-equal window
(frame-window frame
))))
453 (defun find-frame-by-name (name &optional
(root *root-frame
*) first-foundp
)
454 "Find a frame from its name"
456 (with-find-in-all-frames
457 (string-equal name
(frame-name frame
)))))
459 (defun find-frame-by-number (number &optional
(root *root-frame
*) first-foundp
)
460 "Find a frame from its number"
461 (when (numberp number
)
462 (with-find-in-all-frames
463 (= number
(frame-number frame
)))))
466 (defun find-child-in-parent (child base
)
467 "Return t if child is in base or in its parents"
469 (when (child-equal-p child base
)
470 (return-from find-child-in-parent t
))
471 (let ((parent (find-parent-frame base
)))
479 (defun get-all-windows (&optional
(root *root-frame
*))
480 "Return all windows in root and in its children"
482 (with-all-windows (root window
)
487 (defun get-hidden-windows ()
488 "Return all hiddens windows"
489 (let ((all-windows (get-all-windows))
490 (hidden-windows (remove-if-not #'window-hidden-p
491 (copy-list (xlib:query-tree
*root
*)))))
492 (set-difference hidden-windows all-windows
)))
496 ;;; Current window utilities
497 (defun get-current-window ()
498 (typecase *current-child
*
499 (xlib:window
*current-child
*)
500 (frame (frame-selected-child *current-child
*))))
502 (defmacro with-current-window
(&body body
)
503 "Bind 'window' to the current window"
504 `(let ((window (get-current-window)))
505 (when (xlib:window-p window
)
508 (defun get-first-window ()
509 (typecase *current-child
*
510 (xlib:window
*current-child
*)
511 (frame (or (first (frame-child *current-child
*))
518 (defun display-frame-info (frame)
519 (let ((dy (+ (xlib:max-char-ascent
*default-font
*) (xlib:max-char-descent
*default-font
*))))
520 (with-slots (name number gc window child hidden-children
) frame
521 (setf (xlib:gcontext-background gc
) (get-color *frame-background
*)
522 (xlib:window-background window
) (get-color *frame-background
*))
523 (clear-pixmap-buffer window gc
)
524 (setf (xlib:gcontext-foreground gc
) (get-color (if (and (child-equal-p frame
*current-root
*)
525 (child-equal-p frame
*current-child
*))
526 *frame-foreground-root
* *frame-foreground
*)))
527 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 dy
528 (format nil
"Frame: ~A~A"
530 (if name
(format nil
" - ~A" name
) "")))
532 (when (child-equal-p frame
*current-root
*)
533 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
534 (format nil
" ~A hidden windows" (length (get-hidden-windows))))
535 (when *child-selection
*
536 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
537 (with-output-to-string (str)
538 (format str
" Selection: ")
539 (dolist (child *child-selection
*)
541 (xlib:window
(format str
" ~A " (xlib:wm-name child
)))
542 (frame (format str
" frame:~A[~A] " (frame-number child
)
543 (aif (frame-name child
) it
"")))))))))
545 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
546 (format nil
" ~A" (ensure-printable (child-fullname ch
)))))
547 (setf (xlib:gcontext-foreground gc
) (get-color *frame-foreground-hidden
*))
548 (dolist (ch hidden-children
)
549 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
550 (format nil
" ~A - hidden" (ensure-printable (child-fullname ch
))))))
551 (copy-pixmap-buffer window gc
)
555 (defun display-all-frame-info (&optional
(root *current-root
*))
556 (with-all-frames (root frame
)
557 (display-frame-info frame
)))
563 (defun get-parent-layout (child parent
)
565 (aif (frame-layout parent
)
566 (funcall it child parent
)
567 (no-layout child parent
))
568 (get-fullscreen-size)))
572 (defgeneric adapt-child-to-parent
(child parent
))
574 (defmethod adapt-child-to-parent ((window xlib
:window
) parent
)
575 (when (managed-window-p window parent
)
576 (multiple-value-bind (nx ny nw nh
)
577 (get-parent-layout window parent
)
578 (setf nw
(max nw
1) nh
(max nh
1))
579 (let ((change (or (/= (xlib:drawable-x window
) nx
)
580 (/= (xlib:drawable-y window
) ny
)
581 (/= (xlib:drawable-width window
) nw
)
582 (/= (xlib:drawable-height window
) nh
))))
584 (setf (xlib:drawable-x window
) nx
585 (xlib:drawable-y window
) ny
586 (xlib:drawable-width window
) nw
587 (xlib:drawable-height window
) nh
)
588 (xlib:display-finish-output
*display
*))
592 (defmethod adapt-child-to-parent ((frame frame
) parent
)
593 (multiple-value-bind (nx ny nw nh
)
594 (get-parent-layout frame parent
)
595 (with-slots (rx ry rw rh window
) frame
599 (let ((change (or (/= (xlib:drawable-x window
) rx
)
600 (/= (xlib:drawable-y window
) ry
)
601 (/= (xlib:drawable-width window
) rw
)
602 (/= (xlib:drawable-height window
) rh
))))
604 (setf (xlib:drawable-x window
) rx
605 (xlib:drawable-y window
) ry
606 (xlib:drawable-width window
) rw
607 (xlib:drawable-height window
) rh
)
608 (xlib:display-finish-output
*display
*))
611 (defmethod adapt-child-to-parent (child parent
)
612 (declare (ignore child parent
))
616 (defgeneric set-child-stack-order
(window child
)
617 (:documentation
"Raise window if child is NIL else put window just below child"))
619 (defmethod set-child-stack-order (window (child xlib
:window
))
620 (lower-window window child
))
622 (defmethod set-child-stack-order (window (child frame
))
623 (lower-window window
(frame-window child
)))
625 (defmethod set-child-stack-order (window child
)
626 (declare (ignore child
))
627 (raise-window window
)
628 (xlib:display-finish-output
*display
*))
632 (defgeneric show-child
(child parent previous
))
634 (defmethod show-child ((frame frame
) parent previous
)
635 (declare (ignore parent
))
636 (with-slots (window show-window-p
) frame
637 (if (and show-window-p
638 (or *show-root-frame-p
* (not (child-equal-p frame
*current-root
*))))
641 (set-child-stack-order window previous
)
642 (display-frame-info frame
))
643 (hide-window window
))))
647 (defun hide-unmanaged-window-p (parent)
648 (let ((action (frame-data-slot parent
:unmanaged-window-action
)))
652 (t *hide-unmanaged-window
*))))
655 (defmethod show-child ((window xlib
:window
) parent previous
)
656 (if (or (managed-window-p window parent
)
657 (child-equal-p window
*current-child
*)
658 (not (hide-unmanaged-window-p parent
))
659 (child-equal-p parent
*current-child
*))
662 (set-child-stack-order window previous
))
663 (hide-window window
)))
665 (defmethod show-child (child parent raise-p
)
666 (declare (ignore child parent raise-p
))
670 (defgeneric hide-child
(child))
672 (defmethod hide-child ((frame frame
))
673 (with-slots (window) frame
674 (xlib:unmap-window window
)))
676 (defmethod hide-child ((window xlib
:window
))
677 (hide-window window
))
679 (defmethod hide-child (child)
680 (declare (ignore child
))
686 (defgeneric child-coordinates
(child))
688 (defmethod child-coordinates ((frame frame
))
689 (values (frame-rx frame
)
691 (+ (frame-rx frame
) (frame-rw frame
))
692 (+ (frame-ry frame
) (frame-rh frame
))))
694 (defmethod child-coordinates ((window xlib
:window
))
695 (values (xlib:drawable-x window
)
696 (xlib:drawable-y window
)
697 (+ (xlib:drawable-x window
) (xlib:drawable-width window
))
698 (+ (xlib:drawable-y window
) (xlib:drawable-height window
))))
700 (defmethod child-coordinates (child)
701 (declare (ignore child
))
706 (defgeneric select-child
(child selected
))
708 (labels ((get-selected-color (child selected-p
)
709 (get-color (cond ((child-equal-p child
*current-child
*) *color-selected
*)
710 (selected-p *color-maybe-selected
*)
711 (t *color-unselected
*)))))
712 (defmethod select-child ((frame frame
) selected-p
)
713 (when (and (frame-p frame
) (frame-window frame
))
714 (setf (xlib:window-border
(frame-window frame
))
715 (get-selected-color frame selected-p
))))
717 (defmethod select-child ((window xlib
:window
) selected-p
)
718 (setf (xlib:window-border window
)
719 (get-selected-color window selected-p
)))
721 (defmethod select-child (child selected
)
722 (declare (ignore child selected
))
725 (defun select-current-frame (selected)
726 (select-child *current-child
* selected
))
728 (defun unselect-all-frames ()
729 (with-all-children (*current-root
* child
)
730 (select-child child nil
)))
734 (defun set-focus-to-current-child ()
735 (labels ((rec (child)
737 (xlib:window
(focus-window child
))
738 (frame (rec (frame-selected-child child
))))))
740 (rec *current-child
*)))
744 (defun show-all-children (&optional
(from-root-from nil
))
745 "Show all children from *current-root*. When from-root-from is true
746 Display all children from root frame and hide those not in *current-root*"
747 (let ((geometry-change nil
)
749 (displayed-child nil
))
750 (labels ((in-displayed-list (child)
751 (member child displayed-child
:test
#'child-equal-p
))
753 (set-geometry (child parent in-current-root child-current-root-p
)
754 (if (or in-current-root child-current-root-p
)
755 (when (adapt-child-to-parent child
(if child-current-root-p nil parent
))
756 (setf geometry-change t
))
759 (recurse-on-frame-child (child in-current-root child-current-root-p selected-p
)
760 (let ((selected-child (frame-selected-child child
)))
761 (dolist (sub-child (frame-child child
))
763 (and selected-p
(child-equal-p sub-child selected-child
))
764 (or in-current-root child-current-root-p
)))))
766 (select-and-display (child parent selected-p
)
767 (push child displayed-child
)
768 (select-child child selected-p
)
769 (show-child child parent previous
)
770 (setf previous child
))
772 (rec (child parent selected-p in-current-root
)
773 (let ((child-current-root-p (child-equal-p child
*current-root
*)))
774 (unless (in-displayed-list child
)
775 (set-geometry child parent in-current-root child-current-root-p
))
776 (when (frame-p child
)
777 (recurse-on-frame-child child in-current-root child-current-root-p selected-p
))
778 (when (and (or in-current-root child-current-root-p
)
779 (not (in-displayed-list child
)))
780 (select-and-display child parent selected-p
)))))
782 (rec (if from-root-from
*root-frame
* *current-root
*)
783 nil t
(child-equal-p *current-root
* *root-frame
*))
784 (set-focus-to-current-child)
792 (defun hide-all-children (root &optional except
)
793 "Hide all root children"
794 (when (and (frame-p root
) (not (child-equal-p root except
)))
795 (dolist (child (frame-child root
))
796 (hide-all child except
))))
798 (defun hide-all (root &optional except
)
799 "Hide root and all its children"
800 (unless (child-equal-p root except
)
802 (hide-all-children root except
))
808 (defun focus-child (child parent
)
809 "Focus child - Return true if something has change"
810 (when (and (frame-p parent
)
811 (child-member child
(frame-child parent
)))
812 (when (not (child-equal-p child
(frame-selected-child parent
)))
813 (with-slots ((parent-child child
) selected-pos
) parent
814 (setf parent-child
(nth-insert selected-pos child
(child-remove child parent-child
))))
817 (defun focus-child-rec (child parent
)
818 "Focus child and its parents - Return true if something has change"
820 (labels ((rec (child parent
)
821 (when (focus-child child parent
)
824 (rec parent
(find-parent-frame parent
)))))
829 (defun set-current-child-generic (child)
830 (unless (child-equal-p *current-child
* child
)
831 (setf *current-child
* child
)
834 (defgeneric set-current-child
(child parent window-parent
))
836 (defmethod set-current-child ((child xlib
:window
) parent window-parent
)
837 (set-current-child-generic (if window-parent parent child
)))
839 (defmethod set-current-child ((child frame
) parent window-parent
)
840 (declare (ignore parent window-parent
))
841 (set-current-child-generic child
))
843 (defmethod set-current-child (child parent window-parent
)
844 (declare (ignore child parent window-parent
))
848 (defun set-current-root (parent window-parent
)
849 "Set current root if parent is not in current root"
850 (when (and window-parent
(not (find-child parent
*current-root
*)))
851 (setf *current-root
* parent
)))
854 (defun focus-all-children (child parent
&optional
(window-parent t
))
855 "Focus child and its parents -
856 For window: set current child to window or its parent according to window-parent"
857 (let ((new-focus (focus-child-rec child parent
))
858 (new-current-child (set-current-child child parent window-parent
))
859 (new-root (set-current-root parent window-parent
)))
860 (or new-focus new-current-child new-root
)))
865 (defun select-next-level ()
866 "Select the next level in frame"
867 (select-current-frame :maybe
)
868 (when (frame-p *current-child
*)
869 (awhen (frame-selected-child *current-child
*)
870 (setf *current-child
* it
)))
873 (defun select-previous-level ()
874 "Select the previous level in frame"
875 (unless (child-equal-p *current-child
* *current-root
*)
876 (select-current-frame :maybe
)
877 (awhen (find-parent-frame *current-child
*)
878 (setf *current-child
* it
))
879 (show-all-children)))
883 (defun enter-frame ()
884 "Enter in the selected frame - ie make it the root frame"
885 (setf *current-root
* *current-child
*)
886 (show-all-children t
))
888 (defun leave-frame ()
889 "Leave the selected frame - ie make its parent the root frame"
890 (unless (child-equal-p *current-root
* *root-frame
*)
891 (hide-all *current-root
* (get-first-window))
892 (awhen (find-parent-frame *current-root
*)
894 (setf *current-root
* it
)))
895 (show-all-children)))
898 ;;; Other actions (select-next-child, select-next-brother...) are in
899 ;;; clfswm-circulate-mode.lisp
903 (defun frame-lower-child ()
904 "Lower the child in the current frame"
905 (when (frame-p *current-child
*)
906 (with-slots (child selected-pos
) *current-child
*
907 (unless (>= selected-pos
(length child
))
908 (when (nth (1+ selected-pos
) child
)
909 (rotatef (nth selected-pos child
)
910 (nth (1+ selected-pos
) child
)))
911 (incf selected-pos
)))
912 (show-all-children)))
915 (defun frame-raise-child ()
916 "Raise the child in the current frame"
917 (when (frame-p *current-child
*)
918 (with-slots (child selected-pos
) *current-child
*
919 (unless (< selected-pos
1)
920 (when (nth (1- selected-pos
) child
)
921 (rotatef (nth selected-pos child
)
922 (nth (1- selected-pos
) child
)))
923 (decf selected-pos
)))
924 (show-all-children)))
927 (defun frame-select-next-child ()
928 "Select the next child in the current frame"
929 (when (frame-p *current-child
*)
930 (with-slots (child selected-pos
) *current-child
*
931 (unless (>= selected-pos
(length child
))
932 (incf selected-pos
)))
933 (show-all-children)))
936 (defun frame-select-previous-child ()
937 "Select the previous child in the current frame"
938 (when (frame-p *current-child
*)
939 (with-slots (child selected-pos
) *current-child
*
940 (unless (< selected-pos
1)
941 (decf selected-pos
)))
942 (show-all-children)))
946 (defun switch-to-root-frame (&key
(show-later nil
))
947 "Switch to the root frame"
948 (setf *current-root
* *root-frame
*)
950 (show-all-children t
)))
952 (defun switch-and-select-root-frame (&key
(show-later nil
))
953 "Switch and select the root frame"
954 (setf *current-root
* *root-frame
*)
955 (setf *current-child
* *current-root
*)
957 (show-all-children t
)))
960 (defun toggle-show-root-frame ()
961 "Show/Hide the root frame"
962 (setf *show-root-frame-p
* (not *show-root-frame-p
*))
966 (defun remove-child-in-frame (child frame
)
967 "Remove the child in frame"
968 (when (frame-p frame
)
969 (setf (frame-child frame
) (child-remove child
(frame-child frame
)))))
971 (defun remove-child-in-frames (child root
)
972 "Remove child in the frame root and in all its children"
973 (with-all-frames (root frame
)
974 (remove-child-in-frame child frame
)))
977 (defun remove-child-in-all-frames (child)
978 "Remove child in all frames from *root-frame*"
979 (when (child-equal-p child
*current-root
*)
980 (setf *current-root
* (find-parent-frame child
)))
981 (when (child-equal-p child
*current-child
*)
982 (setf *current-child
* *current-root
*))
983 (remove-child-in-frames child
*root-frame
*))
986 (defun delete-child-in-frames (child root
)
987 "Delete child in the frame root and in all its children
988 Warning:frame window and gc are freeed."
989 (with-all-frames (root frame
)
990 (remove-child-in-frame child frame
)
991 (unless (find-frame-window (frame-window frame
))
992 (awhen (frame-gc frame
) (xlib:free-gcontext it
) (setf it nil
))
993 (awhen (frame-window frame
) (xlib:destroy-window it
) (setf it nil
))))
994 (when (xlib:window-p child
)
995 (netwm-remove-in-client-list child
)))
998 (defun delete-child-in-all-frames (child)
999 "Delete child in all frames from *root-frame*"
1000 (when (child-equal-p child
*current-root
*)
1001 (setf *current-root
* (find-parent-frame child
)))
1002 (when (child-equal-p child
*current-child
*)
1003 (setf *current-child
* *current-root
*))
1004 (delete-child-in-frames child
*root-frame
*))
1007 (defun delete-child-and-children-in-frames (child root
&optional
(close-methode 'delete-window
))
1008 "Delete child and its children in the frame root and in all its children
1009 Warning:frame window and gc are freeed."
1010 (when (and (frame-p child
) (frame-child child
))
1011 (dolist (ch (frame-child child
))
1012 (delete-child-and-children-in-frames ch root close-methode
)))
1013 (delete-child-in-frames child root
)
1014 (when (xlib:window-p child
)
1015 (funcall close-methode child
)))
1017 (defun delete-child-and-children-in-all-frames (child &optional
(close-methode 'delete-window
))
1018 "Delete child and its children in all frames from *root-frame*"
1019 (when (child-equal-p child
*current-root
*)
1020 (setf *current-root
* (find-parent-frame child
)))
1021 (when (child-equal-p child
*current-child
*)
1022 (setf *current-child
* *current-root
*))
1023 (delete-child-and-children-in-frames child
*root-frame
* close-methode
))
1027 (defun place-window-from-hints (window)
1028 "Place a window from its hints"
1029 (let* ((hints (xlib:wm-normal-hints window
))
1030 (min-width (or (and hints
(xlib:wm-size-hints-min-width hints
)) 0))
1031 (min-height (or (and hints
(xlib:wm-size-hints-min-height hints
)) 0))
1032 (max-width (or (and hints
(xlib:wm-size-hints-max-width hints
)) (xlib:drawable-width
*root
*)))
1033 (max-height (or (and hints
(xlib:wm-size-hints-max-height hints
)) (xlib:drawable-height
*root
*)))
1034 (rwidth (or (and hints
(or (xlib:wm-size-hints-width hints
) (xlib:wm-size-hints-base-width hints
)))
1035 (xlib:drawable-width window
)))
1036 (rheight (or (and hints
(or (xlib:wm-size-hints-height hints
) (xlib:wm-size-hints-base-height hints
)))
1037 (xlib:drawable-height window
))))
1038 (setf (xlib:drawable-width window
) (min (max min-width rwidth
*default-window-width
*) max-width
)
1039 (xlib:drawable-height window
) (min (max min-height rheight
*default-window-height
*) max-height
))
1040 (setf (xlib:drawable-x window
) (truncate (/ (- (xlib:screen-width
*screen
*) (+ (xlib:drawable-width window
) 2)) 2))
1041 (xlib:drawable-y window
) (truncate (/ (- (xlib:screen-height
*screen
*) (+ (xlib:drawable-height window
) 2)) 2)))
1042 (xlib:display-finish-output
*display
*)))
1046 (defun do-all-frames-nw-hook (window)
1047 "Call nw-hook of each frame."
1048 (catch 'nw-hook-loop
1050 (with-all-frames (*root-frame
* frame
)
1051 (awhen (frame-nw-hook frame
)
1052 (setf found
(call-hook it
(list frame window
)))))
1057 (defun process-new-window (window)
1058 "When a new window is created (or when we are scanning initial
1059 windows), this function dresses the window up and gets it ready to be
1061 (setf (xlib:window-event-mask window
) *window-events
*)
1062 (set-window-state window
+normal-state
+)
1063 (setf (xlib:drawable-border-width window
) (case (window-type window
)
1064 (:normal
*border-size
*)
1065 (:maxsize
*border-size
*)
1066 (:transient
*border-size
*)
1068 (grab-all-buttons window
)
1069 (unless (never-managed-window-p window
)
1070 (unless (do-all-frames-nw-hook window
)
1071 (call-hook *default-nw-hook
* (list *root-frame
* window
))))
1072 (netwm-add-in-client-list window
))
1077 (defun hide-existing-windows (screen)
1078 "Hide all existing windows in screen"
1079 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1082 (defun process-existing-windows (screen)
1083 "Windows present when clfswm starts up must be absorbed by clfswm."
1084 (setf *in-process-existing-windows
* t
)
1086 (all-windows (get-all-windows)))
1087 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1088 (unless (child-member win all-windows
)
1089 (let ((map-state (xlib:window-map-state win
))
1090 (wm-state (window-state win
)))
1091 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1092 (eql win
*no-focus-window
*))
1093 (when (or (eql map-state
:viewable
)
1094 (eql wm-state
+iconic-state
+))
1095 (format t
"Processing ~S: type=~A ~S~%" (xlib:wm-name win
) (window-type win
) win
)
1097 (process-new-window win
)
1100 (pushnew (xlib:window-id win
) id-list
))))))
1101 (netwm-set-client-list id-list
))
1102 (setf *in-process-existing-windows
* nil
))
1105 ;;; Child order manipulation functions
1106 (defun put-child-on-top (child parent
)
1107 "Put the child on top of its parent children"
1108 (when (frame-p parent
)
1109 (setf (frame-child parent
) (cons child
(child-remove child
(frame-child parent
)))
1110 (frame-selected-pos parent
) 0)))
1112 (defun put-child-on-bottom (child parent
)
1113 "Put the child at the bottom of its parent children"
1114 (when (frame-p parent
)
1115 (setf (frame-child parent
) (append (child-remove child
(frame-child parent
)) (list child
))
1116 (frame-selected-pos parent
) 0)))