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
))))
554 (defun display-all-frame-info (&optional
(root *current-root
*))
555 (with-all-frames (root frame
)
556 (display-frame-info frame
)))
562 (defun get-parent-layout (child parent
)
564 (aif (frame-layout parent
)
565 (funcall it child parent
)
566 (no-layout child parent
))
567 (get-fullscreen-size)))
571 (defgeneric adapt-child-to-parent
(child parent
))
573 (defmethod adapt-child-to-parent ((window xlib
:window
) parent
)
574 (when (managed-window-p window parent
)
575 (multiple-value-bind (nx ny nw nh
)
576 (get-parent-layout window parent
)
577 (setf nw
(max nw
1) nh
(max nh
1))
578 (let ((change (or (/= (xlib:drawable-x window
) nx
)
579 (/= (xlib:drawable-y window
) ny
)
580 (/= (xlib:drawable-width window
) nw
)
581 (/= (xlib:drawable-height window
) nh
))))
583 (setf (xlib:drawable-x window
) nx
584 (xlib:drawable-y window
) ny
585 (xlib:drawable-width window
) nw
586 (xlib:drawable-height window
) nh
)
587 (xlib:display-finish-output
*display
*))
591 (defmethod adapt-child-to-parent ((frame frame
) parent
)
592 (multiple-value-bind (nx ny nw nh
)
593 (get-parent-layout frame parent
)
594 (with-slots (rx ry rw rh window
) frame
598 (let ((change (or (/= (xlib:drawable-x window
) rx
)
599 (/= (xlib:drawable-y window
) ry
)
600 (/= (xlib:drawable-width window
) rw
)
601 (/= (xlib:drawable-height window
) rh
))))
603 (setf (xlib:drawable-x window
) rx
604 (xlib:drawable-y window
) ry
605 (xlib:drawable-width window
) rw
606 (xlib:drawable-height window
) rh
)
607 (xlib:display-finish-output
*display
*))
610 (defmethod adapt-child-to-parent (child parent
)
611 (declare (ignore child parent
))
615 (defgeneric set-child-stack-order
(window child
)
616 (:documentation
"Raise window if child is NIL else put window just below child"))
618 (defmethod set-child-stack-order (window (child xlib
:window
))
619 (lower-window window child
))
621 (defmethod set-child-stack-order (window (child frame
))
622 (lower-window window
(frame-window child
)))
624 (defmethod set-child-stack-order (window child
)
625 (declare (ignore child
))
626 (raise-window window
)
627 (xlib:display-finish-output
*display
*))
631 (defgeneric show-child
(child parent previous
))
633 (defmethod show-child ((frame frame
) parent previous
)
634 (declare (ignore parent
))
635 (with-slots (window show-window-p
) frame
636 (if (and show-window-p
637 (or *show-root-frame-p
* (not (child-equal-p frame
*current-root
*))))
640 (set-child-stack-order window previous
)
641 (display-frame-info frame
))
642 (hide-window window
))))
646 (defun hide-unmanaged-window-p (parent)
647 (let ((action (frame-data-slot parent
:unmanaged-window-action
)))
651 (t *hide-unmanaged-window
*))))
654 (defmethod show-child ((window xlib
:window
) parent previous
)
655 (if (or (managed-window-p window parent
)
656 (child-equal-p window
*current-child
*)
657 (not (hide-unmanaged-window-p parent
))
658 (child-equal-p parent
*current-child
*))
661 (set-child-stack-order window previous
))
662 (hide-window window
)))
664 (defmethod show-child (child parent raise-p
)
665 (declare (ignore child parent raise-p
))
669 (defgeneric hide-child
(child))
671 (defmethod hide-child ((frame frame
))
672 (with-slots (window) frame
673 (xlib:unmap-window window
)))
675 (defmethod hide-child ((window xlib
:window
))
676 (hide-window window
))
678 (defmethod hide-child (child)
679 (declare (ignore child
))
685 (defgeneric child-coordinates
(child))
687 (defmethod child-coordinates ((frame frame
))
688 (values (frame-rx frame
)
690 (+ (frame-rx frame
) (frame-rw frame
))
691 (+ (frame-ry frame
) (frame-rh frame
))))
693 (defmethod child-coordinates ((window xlib
:window
))
694 (values (xlib:drawable-x window
)
695 (xlib:drawable-y window
)
696 (+ (xlib:drawable-x window
) (xlib:drawable-width window
))
697 (+ (xlib:drawable-y window
) (xlib:drawable-height window
))))
699 (defmethod child-coordinates (child)
700 (declare (ignore child
))
705 (defgeneric select-child
(child selected
))
707 (labels ((get-selected-color (child selected-p
)
708 (get-color (cond ((child-equal-p child
*current-child
*) *color-selected
*)
709 (selected-p *color-maybe-selected
*)
710 (t *color-unselected
*)))))
711 (defmethod select-child ((frame frame
) selected-p
)
712 (when (and (frame-p frame
) (frame-window frame
))
713 (setf (xlib:window-border
(frame-window frame
))
714 (get-selected-color frame selected-p
))))
716 (defmethod select-child ((window xlib
:window
) selected-p
)
717 (setf (xlib:window-border window
)
718 (get-selected-color window selected-p
)))
720 (defmethod select-child (child selected
)
721 (declare (ignore child selected
))
724 (defun select-current-frame (selected)
725 (select-child *current-child
* selected
))
727 (defun unselect-all-frames ()
728 (with-all-children (*current-root
* child
)
729 (select-child child nil
)))
733 (defun set-focus-to-current-child ()
734 (labels ((rec (child)
736 (xlib:window
(focus-window child
))
737 (frame (rec (frame-selected-child child
))))))
739 (rec *current-child
*)))
743 (defun show-all-children (&optional
(from-root-from nil
))
744 "Show all children from *current-root*. When from-root-from is true
745 Display all children from root frame and hide those not in *current-root*"
746 (let ((geometry-change nil
)
748 (displayed-child nil
))
749 (labels ((in-displayed-list (child)
750 (member child displayed-child
:test
#'child-equal-p
))
752 (set-geometry (child parent in-current-root child-current-root-p
)
753 (if (or in-current-root child-current-root-p
)
754 (when (adapt-child-to-parent child
(if child-current-root-p nil parent
))
755 (setf geometry-change t
))
758 (recurse-on-frame-child (child in-current-root child-current-root-p selected-p
)
759 (let ((selected-child (frame-selected-child child
)))
760 (dolist (sub-child (frame-child child
))
762 (and selected-p
(child-equal-p sub-child selected-child
))
763 (or in-current-root child-current-root-p
)))))
765 (select-and-display (child parent selected-p
)
766 (push child displayed-child
)
767 (select-child child selected-p
)
768 (show-child child parent previous
)
769 (setf previous child
))
771 (rec (child parent selected-p in-current-root
)
772 (let ((child-current-root-p (child-equal-p child
*current-root
*)))
773 (unless (in-displayed-list child
)
774 (set-geometry child parent in-current-root child-current-root-p
))
775 (when (frame-p child
)
776 (recurse-on-frame-child child in-current-root child-current-root-p selected-p
))
777 (when (and (or in-current-root child-current-root-p
)
778 (not (in-displayed-list child
)))
779 (select-and-display child parent selected-p
)))))
781 (rec (if from-root-from
*root-frame
* *current-root
*)
782 nil t
(child-equal-p *current-root
* *root-frame
*))
783 (set-focus-to-current-child)
791 (defun hide-all-children (root &optional except
)
792 "Hide all root children"
793 (when (and (frame-p root
) (not (child-equal-p root except
)))
794 (dolist (child (frame-child root
))
795 (hide-all child except
))))
797 (defun hide-all (root &optional except
)
798 "Hide root and all its children"
799 (unless (child-equal-p root except
)
801 (hide-all-children root except
))
807 (defun focus-child (child parent
)
808 "Focus child - Return true if something has change"
809 (when (and (frame-p parent
)
810 (child-member child
(frame-child parent
)))
811 (when (not (child-equal-p child
(frame-selected-child parent
)))
812 (with-slots ((parent-child child
) selected-pos
) parent
813 (setf parent-child
(nth-insert selected-pos child
(child-remove child parent-child
))))
816 (defun focus-child-rec (child parent
)
817 "Focus child and its parents - Return true if something has change"
819 (labels ((rec (child parent
)
820 (when (focus-child child parent
)
823 (rec parent
(find-parent-frame parent
)))))
828 (defun set-current-child-generic (child)
829 (unless (child-equal-p *current-child
* child
)
830 (setf *current-child
* child
)
833 (defgeneric set-current-child
(child parent window-parent
))
835 (defmethod set-current-child ((child xlib
:window
) parent window-parent
)
836 (set-current-child-generic (if window-parent parent child
)))
838 (defmethod set-current-child ((child frame
) parent window-parent
)
839 (declare (ignore parent window-parent
))
840 (set-current-child-generic child
))
842 (defmethod set-current-child (child parent window-parent
)
843 (declare (ignore child parent window-parent
))
847 (defun set-current-root (parent window-parent
)
848 "Set current root if parent is not in current root"
849 (when (and window-parent
(not (find-child parent
*current-root
*)))
850 (setf *current-root
* parent
)))
853 (defun focus-all-children (child parent
&optional
(window-parent t
))
854 "Focus child and its parents -
855 For window: set current child to window or its parent according to window-parent"
856 (let ((new-focus (focus-child-rec child parent
))
857 (new-current-child (set-current-child child parent window-parent
))
858 (new-root (set-current-root parent window-parent
)))
859 (or new-focus new-current-child new-root
)))
864 (defun select-next-level ()
865 "Select the next level in frame"
866 (select-current-frame :maybe
)
867 (when (frame-p *current-child
*)
868 (awhen (frame-selected-child *current-child
*)
869 (setf *current-child
* it
)))
872 (defun select-previous-level ()
873 "Select the previous level in frame"
874 (unless (child-equal-p *current-child
* *current-root
*)
875 (select-current-frame :maybe
)
876 (awhen (find-parent-frame *current-child
*)
877 (setf *current-child
* it
))
878 (show-all-children)))
882 (defun enter-frame ()
883 "Enter in the selected frame - ie make it the root frame"
884 (setf *current-root
* *current-child
*)
885 (show-all-children t
))
887 (defun leave-frame ()
888 "Leave the selected frame - ie make its parent the root frame"
889 (unless (child-equal-p *current-root
* *root-frame
*)
890 (hide-all *current-root
* (get-first-window))
891 (awhen (find-parent-frame *current-root
*)
893 (setf *current-root
* it
)))
894 (show-all-children)))
897 ;;; Other actions (select-next-child, select-next-brother...) are in
898 ;;; clfswm-circulate-mode.lisp
902 (defun frame-lower-child ()
903 "Lower the child in the current frame"
904 (when (frame-p *current-child
*)
905 (with-slots (child selected-pos
) *current-child
*
906 (unless (>= selected-pos
(length child
))
907 (when (nth (1+ selected-pos
) child
)
908 (rotatef (nth selected-pos child
)
909 (nth (1+ selected-pos
) child
)))
910 (incf selected-pos
)))
911 (show-all-children)))
914 (defun frame-raise-child ()
915 "Raise the child in the current frame"
916 (when (frame-p *current-child
*)
917 (with-slots (child selected-pos
) *current-child
*
918 (unless (< selected-pos
1)
919 (when (nth (1- selected-pos
) child
)
920 (rotatef (nth selected-pos child
)
921 (nth (1- selected-pos
) child
)))
922 (decf selected-pos
)))
923 (show-all-children)))
926 (defun frame-select-next-child ()
927 "Select the next child in the current frame"
928 (when (frame-p *current-child
*)
929 (with-slots (child selected-pos
) *current-child
*
930 (unless (>= selected-pos
(length child
))
931 (incf selected-pos
)))
932 (show-all-children)))
935 (defun frame-select-previous-child ()
936 "Select the previous child in the current frame"
937 (when (frame-p *current-child
*)
938 (with-slots (child selected-pos
) *current-child
*
939 (unless (< selected-pos
1)
940 (decf selected-pos
)))
941 (show-all-children)))
945 (defun switch-to-root-frame (&key
(show-later nil
))
946 "Switch to the root frame"
947 (setf *current-root
* *root-frame
*)
949 (show-all-children t
)))
951 (defun switch-and-select-root-frame (&key
(show-later nil
))
952 "Switch and select the root frame"
953 (setf *current-root
* *root-frame
*)
954 (setf *current-child
* *current-root
*)
956 (show-all-children t
)))
959 (defun toggle-show-root-frame ()
960 "Show/Hide the root frame"
961 (setf *show-root-frame-p
* (not *show-root-frame-p
*))
965 (defun remove-child-in-frame (child frame
)
966 "Remove the child in frame"
967 (when (frame-p frame
)
968 (setf (frame-child frame
) (child-remove child
(frame-child frame
)))))
970 (defun remove-child-in-frames (child root
)
971 "Remove child in the frame root and in all its children"
972 (with-all-frames (root frame
)
973 (remove-child-in-frame child frame
)))
976 (defun remove-child-in-all-frames (child)
977 "Remove child in all frames from *root-frame*"
978 (when (child-equal-p child
*current-root
*)
979 (setf *current-root
* (find-parent-frame child
)))
980 (when (child-equal-p child
*current-child
*)
981 (setf *current-child
* *current-root
*))
982 (remove-child-in-frames child
*root-frame
*))
985 (defun delete-child-in-frames (child root
)
986 "Delete child in the frame root and in all its children
987 Warning:frame window and gc are freeed."
988 (with-all-frames (root frame
)
989 (remove-child-in-frame child frame
)
990 (unless (find-frame-window (frame-window frame
))
991 (awhen (frame-gc frame
) (xlib:free-gcontext it
) (setf it nil
))
992 (awhen (frame-window frame
) (xlib:destroy-window it
) (setf it nil
))))
993 (when (xlib:window-p child
)
994 (netwm-remove-in-client-list child
)))
997 (defun delete-child-in-all-frames (child)
998 "Delete child in all frames from *root-frame*"
999 (when (child-equal-p child
*current-root
*)
1000 (setf *current-root
* (find-parent-frame child
)))
1001 (when (child-equal-p child
*current-child
*)
1002 (setf *current-child
* *current-root
*))
1003 (delete-child-in-frames child
*root-frame
*))
1006 (defun delete-child-and-children-in-frames (child root
&optional
(close-methode 'delete-window
))
1007 "Delete child and its children in the frame root and in all its children
1008 Warning:frame window and gc are freeed."
1009 (when (and (frame-p child
) (frame-child child
))
1010 (dolist (ch (frame-child child
))
1011 (delete-child-and-children-in-frames ch root close-methode
)))
1012 (delete-child-in-frames child root
)
1013 (when (xlib:window-p child
)
1014 (funcall close-methode child
)))
1016 (defun delete-child-and-children-in-all-frames (child &optional
(close-methode 'delete-window
))
1017 "Delete child and its children in all frames from *root-frame*"
1018 (when (child-equal-p child
*current-root
*)
1019 (setf *current-root
* (find-parent-frame child
)))
1020 (when (child-equal-p child
*current-child
*)
1021 (setf *current-child
* *current-root
*))
1022 (delete-child-and-children-in-frames child
*root-frame
* close-methode
))
1026 (defun place-window-from-hints (window)
1027 "Place a window from its hints"
1028 (let* ((hints (xlib:wm-normal-hints window
))
1029 (min-width (or (and hints
(xlib:wm-size-hints-min-width hints
)) 0))
1030 (min-height (or (and hints
(xlib:wm-size-hints-min-height hints
)) 0))
1031 (max-width (or (and hints
(xlib:wm-size-hints-max-width hints
)) (xlib:drawable-width
*root
*)))
1032 (max-height (or (and hints
(xlib:wm-size-hints-max-height hints
)) (xlib:drawable-height
*root
*)))
1033 (rwidth (or (and hints
(or (xlib:wm-size-hints-width hints
) (xlib:wm-size-hints-base-width hints
)))
1034 (xlib:drawable-width window
)))
1035 (rheight (or (and hints
(or (xlib:wm-size-hints-height hints
) (xlib:wm-size-hints-base-height hints
)))
1036 (xlib:drawable-height window
))))
1037 (setf (xlib:drawable-width window
) (min (max min-width rwidth
*default-window-width
*) max-width
)
1038 (xlib:drawable-height window
) (min (max min-height rheight
*default-window-height
*) max-height
))
1039 (setf (xlib:drawable-x window
) (truncate (/ (- (xlib:screen-width
*screen
*) (+ (xlib:drawable-width window
) 2)) 2))
1040 (xlib:drawable-y window
) (truncate (/ (- (xlib:screen-height
*screen
*) (+ (xlib:drawable-height window
) 2)) 2)))
1041 (xlib:display-finish-output
*display
*)))
1045 (defun do-all-frames-nw-hook (window)
1046 "Call nw-hook of each frame."
1047 (catch 'nw-hook-loop
1049 (with-all-frames (*root-frame
* frame
)
1050 (awhen (frame-nw-hook frame
)
1051 (setf found
(call-hook it
(list frame window
)))))
1056 (defun process-new-window (window)
1057 "When a new window is created (or when we are scanning initial
1058 windows), this function dresses the window up and gets it ready to be
1060 (setf (xlib:window-event-mask window
) *window-events
*)
1061 (set-window-state window
+normal-state
+)
1062 (setf (xlib:drawable-border-width window
) (case (window-type window
)
1063 (:normal
*border-size
*)
1064 (:maxsize
*border-size
*)
1065 (:transient
*border-size
*)
1067 (grab-all-buttons window
)
1068 (unless (never-managed-window-p window
)
1069 (unless (do-all-frames-nw-hook window
)
1070 (call-hook *default-nw-hook
* (list *root-frame
* window
))))
1071 (netwm-add-in-client-list window
))
1076 (defun hide-existing-windows (screen)
1077 "Hide all existing windows in screen"
1078 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1081 (defun process-existing-windows (screen)
1082 "Windows present when clfswm starts up must be absorbed by clfswm."
1083 (setf *in-process-existing-windows
* t
)
1085 (all-windows (get-all-windows)))
1086 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1087 (unless (child-member win all-windows
)
1088 (let ((map-state (xlib:window-map-state win
))
1089 (wm-state (window-state win
)))
1090 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1091 (eql win
*no-focus-window
*))
1092 (when (or (eql map-state
:viewable
)
1093 (eql wm-state
+iconic-state
+))
1094 (format t
"Processing ~S: type=~A ~S~%" (xlib:wm-name win
) (window-type win
) win
)
1096 (process-new-window win
)
1099 (pushnew (xlib:window-id win
) id-list
))))))
1100 (netwm-set-client-list id-list
))
1101 (setf *in-process-existing-windows
* nil
))
1104 ;;; Child order manipulation functions
1105 (defun put-child-on-top (child parent
)
1106 "Put the child on top of its parent children"
1107 (when (frame-p parent
)
1108 (setf (frame-child parent
) (cons child
(child-remove child
(frame-child parent
)))
1109 (frame-selected-pos parent
) 0)))
1111 (defun put-child-on-bottom (child parent
)
1112 "Put the child at the bottom of its parent children"
1113 (when (frame-p parent
)
1114 (setf (frame-child parent
) (append (child-remove child
(frame-child parent
)) (list child
))
1115 (frame-selected-pos parent
) 0)))