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 (defun rect-hidden-p (rect1 rect2
)
68 "Return T if child-rect1 hide child-rect2"
69 (and (<= (child-rect-x rect1
) (child-rect-x rect2
))
70 (<= (child-rect-y rect1
) (child-rect-y rect2
))
71 (>= (+ (child-rect-x rect1
) (child-rect-w rect1
)) (+ (child-rect-x rect2
) (child-rect-w rect2
)))
72 (>= (+ (child-rect-y rect1
) (child-rect-h rect1
)) (+ (child-rect-y rect2
) (child-rect-h rect2
)))))
76 (defgeneric frame-p
(frame))
77 (defmethod frame-p ((frame frame
))
78 (declare (ignore frame
))
80 (defmethod frame-p (frame)
81 (declare (ignore frame
))
86 ;;; in-*: Find if point (x,y) is in frame, window or child
87 (defun in-frame (frame x y
)
89 (<= (frame-rx frame
) x
(+ (frame-rx frame
) (frame-rw frame
)))
90 (<= (frame-ry frame
) y
(+ (frame-ry frame
) (frame-rh frame
)))))
92 (defun in-window (window x y
)
93 (and (xlib:window-p window
)
94 (<= (xlib:drawable-x window
) x
(+ (xlib:drawable-x window
) (xlib:drawable-width window
)))
95 (<= (xlib:drawable-y window
) y
(+ (xlib:drawable-y window
) (xlib:drawable-height window
)))))
97 (defgeneric in-child
(child x y
))
99 (defmethod in-child ((child frame
) x y
)
100 (in-frame child x y
))
101 (defmethod in-child ((child xlib
:window
) x y
)
102 (in-window child x y
))
103 (defmethod in-child (child x y
)
104 (declare (ignore child x y
))
110 (defun frame-selected-child (frame)
111 (when (frame-p frame
)
112 (with-slots (child selected-pos
) frame
113 (let ((len (length child
)))
114 (cond ((minusp selected-pos
) (setf selected-pos
0))
115 ((>= selected-pos len
) (setf selected-pos
(max (1- len
) 0)))))
116 (nth selected-pos child
))))
122 (defgeneric child-equal-p
(child-1 child-2
))
124 (defmethod child-equal-p ((child-1 xlib
:window
) (child-2 xlib
:window
))
125 (xlib:window-equal child-1 child-2
))
127 (defmethod child-equal-p ((child-1 frame
) (child-2 frame
))
128 (equal child-1 child-2
))
130 (defmethod child-equal-p (child-1 child-2
)
131 (declare (ignore child-1 child-2
))
135 (declaim (inline child-member child-remove child-position
))
137 (defun child-member (child list
)
138 (member child list
:test
#'child-equal-p
))
140 (defun child-remove (child list
)
141 (remove child list
:test
#'child-equal-p
))
143 (defun child-position (child list
)
144 (position child list
:test
#'child-equal-p
))
148 ;;; Frame data manipulation functions
149 (defun frame-data-slot (frame slot
)
150 "Return the value associated to data slot"
151 (when (frame-p frame
)
152 (second (assoc slot
(frame-data frame
)))))
154 (defun set-frame-data-slot (frame slot value
)
155 "Set the value associated to data slot"
156 (when (frame-p frame
)
157 (with-slots (data) frame
158 (setf data
(remove (assoc slot data
) data
))
159 (push (list slot value
) data
))
162 (defsetf frame-data-slot set-frame-data-slot
)
165 (defun remove-frame-data-slot (frame slot
)
166 "Remove a slot in frame data slots"
167 (when (frame-p frame
)
168 (with-slots (data) frame
169 (setf data
(remove (assoc slot data
) data
)))))
173 (defun managed-window-p (window frame
)
174 "Return t only if window is managed by frame"
176 (with-slots ((managed forced-managed-window
)
177 (unmanaged forced-unmanaged-window
)) frame
178 (and (xlib:window-p window
)
179 (not (child-member window unmanaged
))
180 (not (member (xlib:wm-name window
) unmanaged
:test
#'string-equal-p
))
181 (or (member :all
(frame-managed-type frame
))
182 (member (window-type window
) (frame-managed-type frame
))
183 (child-member window managed
)
184 (member (xlib:wm-name window
) managed
:test
#'string-equal-p
))))
188 (defun never-managed-window-p (window)
189 (when (xlib:window-p window
)
190 (dolist (type *never-managed-window-list
*)
191 (when (funcall (first type
) window
)
192 (return (values t
(second type
)))))))
196 (defgeneric child-name
(child))
198 (defmethod child-name ((child xlib
:window
))
199 (xlib:wm-name child
))
201 (defmethod child-name ((child frame
))
204 (defmethod child-name (child)
205 (declare (ignore child
))
209 (defgeneric set-child-name
(child name
))
211 (defmethod set-child-name ((child xlib
:window
) name
)
212 (setf (xlib:wm-name child
) name
))
214 (defmethod set-child-name ((child frame
) name
)
215 (setf (frame-name child
) name
))
217 (defmethod set-child-name (child name
)
218 (declare (ignore child name
)))
220 (defsetf child-name set-child-name
)
225 (defgeneric child-fullname
(child))
227 (defmethod child-fullname ((child xlib
:window
))
228 (format nil
"~A (~A)" (or (xlib:wm-name child
) "?") (or (xlib:get-wm-class child
) "?")))
230 (defmethod child-fullname ((child frame
))
231 (aif (frame-name child
)
232 (format nil
"~A (Frame ~A)" it
(frame-number child
))
233 (format nil
"Frame ~A" (frame-number child
))))
235 (defmethod child-fullname (child)
236 (declare (ignore child
))
240 (defgeneric child-x
(child))
241 (defmethod child-x ((child xlib
:window
))
242 (xlib:drawable-x child
))
243 (defmethod child-x ((child frame
))
246 (defgeneric child-y
(child))
247 (defmethod child-y ((child xlib
:window
))
248 (xlib:drawable-y child
))
249 (defmethod child-y ((child frame
))
252 (defgeneric child-width
(child))
253 (defmethod child-width ((child xlib
:window
))
254 (xlib:drawable-width child
))
255 (defmethod child-width ((child frame
))
258 (defgeneric child-height
(child))
259 (defmethod child-height ((child xlib
:window
))
260 (xlib:drawable-height child
))
261 (defmethod child-height ((child frame
))
264 (defgeneric child-x2
(child))
265 (defmethod child-x2 ((child xlib
:window
))
266 (+ (xlib:drawable-x child
) (xlib:drawable-width child
)))
267 (defmethod child-x2 ((child frame
))
268 (+ (frame-rx child
) (frame-rw child
)))
270 (defgeneric child-y2
(child))
271 (defmethod child-y2 ((child xlib
:window
))
272 (+ (xlib:drawable-y child
) (xlib:drawable-height child
)))
273 (defmethod child-y2 ((child frame
))
274 (+ (frame-ry child
) (frame-rh child
)))
278 (defgeneric child-center
(child))
280 (defmethod child-center ((child xlib
:window
))
281 (values (+ (xlib:drawable-x child
) (/ (xlib:drawable-width child
) 2))
282 (+ (xlib:drawable-y child
) (/ (xlib:drawable-height child
) 2))))
284 (defmethod child-center ((child frame
))
285 (values (+ (frame-rx child
) (/ (frame-rw child
) 2))
286 (+ (frame-ry child
) (/ (frame-rh child
) 2))))
288 (defun child-distance (child1 child2
)
289 (multiple-value-bind (x1 y1
) (child-center child1
)
290 (multiple-value-bind (x2 y2
) (child-center child2
)
291 (values (+ (abs (- x2 x1
)) (abs (- y2 y1
)))
295 (defun middle-child-x (child)
296 (+ (child-x child
) (/ (child-width child
) 2)))
298 (defun middle-child-y (child)
299 (+ (child-y child
) (/ (child-height child
) 2)))
301 (declaim (inline adj-border-xy adj-border-wh
))
302 (defgeneric adj-border-xy
(value child
))
303 (defgeneric adj-border-wh
(value child
))
305 (defmethod adj-border-xy (v (child xlib
:window
))
306 (+ v
(xlib:drawable-border-width child
)))
308 (defmethod adj-border-xy (v (child frame
))
309 (+ v
(xlib:drawable-border-width
(frame-window child
))))
311 (defmethod adj-border-wh (v (child xlib
:window
))
312 (- v
(* (xlib:drawable-border-width child
) 2)))
314 (defmethod adj-border-wh (v (child frame
))
315 (- v
(* (xlib:drawable-border-width
(frame-window child
)) 2)))
318 (declaim (inline anti-adj-border-xy anti-adj-border-wh
))
319 (defgeneric anti-adj-border-xy
(value child
))
320 (defgeneric anti-adj-border-wh
(value child
))
322 (defmethod anti-adj-border-xy (v (child xlib
:window
))
323 (- v
(xlib:drawable-border-width child
)))
325 (defmethod anti-adj-border-xy (v (child frame
))
326 (- v
(xlib:drawable-border-width
(frame-window child
))))
328 (defmethod anti-adj-border-wh (v (child xlib
:window
))
329 (+ v
(* (xlib:drawable-border-width child
) 2)))
331 (defmethod anti-adj-border-wh (v (child frame
))
332 (+ v
(* (xlib:drawable-border-width
(frame-window child
)) 2)))
337 (defmacro with-focus-window
((window) &body body
)
338 `(let ((,window
(xlib:input-focus
*display
*)))
339 (when (and ,window
(not (xlib:window-equal
,window
*no-focus-window
*)))
343 (defgeneric rename-child
(child name
))
345 (defmethod rename-child ((child frame
) name
)
346 (setf (frame-name child
) name
)
347 (display-frame-info child
))
349 (defmethod rename-child ((child xlib
:window
) name
)
350 (setf (xlib:wm-name child
) name
))
352 (defmethod rename-child (child name
)
353 (declare (ignore child name
)))
356 (defun is-in-current-child-p (child)
357 (and (frame-p *current-child
*)
358 (child-member child
(frame-child *current-child
*))))
362 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
363 (defmacro with-all-children
((root child
) &body body
)
365 (sub-child (gensym)))
367 (labels ((,rec
(,child
)
369 (when (frame-p ,child
)
370 (dolist (,sub-child
(reverse (frame-child ,child
)))
371 (,rec
,sub-child
)))))
375 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
376 (defmacro with-all-children-reversed
((root child
) &body body
)
378 (sub-child (gensym)))
380 (labels ((,rec
(,child
)
382 (when (frame-p ,child
)
383 (dolist (,sub-child
(frame-child ,child
))
384 (,rec
,sub-child
)))))
388 ;; (with-all-frames (*root-frame* frame) (print (frame-number frame)))
389 (defmacro with-all-frames
((root frame
) &body body
)
393 (labels ((,rec
(,frame
)
394 (when (frame-p ,frame
)
396 (dolist (,child
(reverse (frame-child ,frame
)))
401 ;; (with-all-windows (*root-frame* window) (print window))
402 (defmacro with-all-windows
((root window
) &body body
)
406 (labels ((,rec
(,window
)
407 (when (xlib:window-p
,window
)
409 (when (frame-p ,window
)
410 (dolist (,child
(reverse (frame-child ,window
)))
416 ;; (with-all-frames-windows (*root-frame* child) (print child) (print (frame-number child)))
417 (defmacro with-all-windows-frames
((root child
) body-window body-frame
)
419 (sub-child (gensym)))
421 (labels ((,rec
(,child
)
423 (xlib:window
,body-window
)
425 (dolist (,sub-child
(reverse (frame-child ,child
)))
426 (,rec
,sub-child
))))))
429 (defmacro with-all-windows-frames-and-parent
((root child parent
) body-window body-frame
)
431 (sub-child (gensym)))
433 (labels ((,rec
(,child
,parent
)
435 (xlib:window
,body-window
)
437 (dolist (,sub-child
(reverse (frame-child ,child
)))
438 (,rec
,sub-child
,child
))))))
443 (defun frame-find-free-number ()
444 (let ((all-numbers nil
))
445 (with-all-frames (*root-frame
* frame
)
446 (pushnew (frame-number frame
) all-numbers
))
447 (find-free-number all-numbers
)))
450 (defun create-frame (&rest args
&key
(number (frame-find-free-number)) &allow-other-keys
)
451 (let* ((window (xlib:create-window
:parent
*root
*
456 :background
(get-color *frame-background
*)
457 :colormap
(xlib:screen-default-colormap
*screen
*)
458 :border-width
*border-size
*
459 :border
(get-color *color-selected
*)
460 :event-mask
'(:exposure
:button-press
:button-release
:pointer-motion
:enter-window
)))
461 (gc (xlib:create-gcontext
:drawable window
462 :foreground
(get-color *frame-foreground
*)
463 :background
(get-color *frame-background
*)
465 :line-style
:solid
)))
466 (apply #'make-instance
'frame
:number number
:window window
:gc gc args
)))
472 (defun add-frame (frame parent
)
473 (push frame
(frame-child parent
))
477 (defun place-frame (frame parent prx pry prw prh
)
478 "Place a frame from real (pixel) coordinates"
479 (when (and (frame-p frame
) (frame-p parent
))
480 (with-slots (window x y w h
) frame
481 (setf (xlib:drawable-x window
) prx
482 (xlib:drawable-y window
) pry
483 (xlib:drawable-width window
) prw
484 (xlib:drawable-height window
) prh
485 x
(x-px->fl prx parent
)
486 y
(y-px->fl pry parent
)
487 w
(w-px->fl prw parent
)
488 h
(h-px->fl prh parent
))
489 (xlib:display-finish-output
*display
*))))
491 (defun fixe-real-size (frame parent
)
492 "Fixe real (pixel) coordinates in float coordinates"
493 (when (frame-p frame
)
494 (with-slots (x y w h rx ry rw rh
) frame
495 (setf x
(x-px->fl rx parent
)
496 y
(y-px->fl ry parent
)
497 w
(w-px->fl
(anti-adj-border-wh rw parent
) parent
)
498 h
(h-px->fl
(anti-adj-border-wh rh parent
) parent
)))))
500 (defun fixe-real-size-current-child ()
501 "Fixe real (pixel) coordinates in float coordinates for children in the current child"
502 (when (frame-p *current-child
*)
503 (dolist (child (frame-child *current-child
*))
504 (fixe-real-size child
*current-child
*))))
509 (defun find-child (to-find root
)
510 "Find to-find in root or in its children"
511 (with-all-children (root child
)
512 (when (child-equal-p child to-find
)
513 (return-from find-child t
))))
517 (defmacro with-find-in-all-frames
(test &optional return-value
)
520 (with-all-frames (root frame
)
523 (return-from return-block
(or ,return-value frame
))
525 (or ,return-value ret
))))
527 (defun find-parent-frame (to-find &optional
(root *root-frame
*) first-foundp
)
528 "Return the parent frame of to-find"
529 (with-find-in-all-frames
530 (child-member to-find
(frame-child frame
))))
532 (defun find-frame-window (window &optional
(root *root-frame
*) first-foundp
)
533 "Return the frame with the window window"
534 (with-find-in-all-frames
535 (xlib:window-equal window
(frame-window frame
))))
537 (defun find-frame-by-name (name &optional
(root *root-frame
*) first-foundp
)
538 "Find a frame from its name"
540 (with-find-in-all-frames
541 (string-equal name
(frame-name frame
)))))
543 (defun find-frame-by-number (number &optional
(root *root-frame
*) first-foundp
)
544 "Find a frame from its number"
545 (when (numberp number
)
546 (with-find-in-all-frames
547 (= number
(frame-number frame
)))))
550 (defun find-child-in-parent (child base
)
551 "Return t if child is in base or in its parents"
553 (when (child-equal-p child base
)
554 (return-from find-child-in-parent t
))
555 (let ((parent (find-parent-frame base
)))
563 (defun get-all-windows (&optional
(root *root-frame
*))
564 "Return all windows in root and in its children"
566 (with-all-windows (root window
)
571 (defun get-hidden-windows ()
572 "Return all hiddens windows"
573 (let ((all-windows (get-all-windows))
574 (hidden-windows (remove-if-not #'window-hidden-p
575 (copy-list (xlib:query-tree
*root
*)))))
576 (set-difference hidden-windows all-windows
)))
580 ;;; Current window utilities
581 (defun get-current-window ()
582 (typecase *current-child
*
583 (xlib:window
*current-child
*)
584 (frame (frame-selected-child *current-child
*))))
586 (defmacro with-current-window
(&body body
)
587 "Bind 'window' to the current window"
588 `(let ((window (get-current-window)))
589 (when (xlib:window-p window
)
592 (defun get-first-window ()
593 (typecase *current-child
*
594 (xlib:window
*current-child
*)
595 (frame (or (first (frame-child *current-child
*))
602 (defun display-frame-info (frame)
603 (when (frame-p frame
)
604 (let ((dy (+ (xlib:max-char-ascent
*default-font
*) (xlib:max-char-descent
*default-font
*))))
605 (with-slots (name number gc window child hidden-children
) frame
606 (setf (xlib:gcontext-background gc
) (get-color *frame-background
*)
607 (xlib:window-background window
) (get-color *frame-background
*))
608 (clear-pixmap-buffer window gc
)
609 (setf (xlib:gcontext-foreground gc
) (get-color (if (and (child-equal-p frame
*current-root
*)
610 (child-equal-p frame
*current-child
*))
611 *frame-foreground-root
* *frame-foreground
*)))
612 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 dy
613 (format nil
"Frame: ~A~A"
615 (if name
(format nil
" - ~A" name
) "")))
617 (when (child-equal-p frame
*current-root
*)
618 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
619 (format nil
" ~A hidden windows" (length (get-hidden-windows))))
620 (when *child-selection
*
621 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
622 (with-output-to-string (str)
623 (format str
" Selection: ")
624 (dolist (child *child-selection
*)
626 (xlib:window
(format str
" ~A " (xlib:wm-name child
)))
627 (frame (format str
" frame:~A[~A] " (frame-number child
)
628 (aif (frame-name child
) it
"")))))))))
630 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
631 (format nil
" ~A" (ensure-printable (child-fullname ch
)))))
632 (setf (xlib:gcontext-foreground gc
) (get-color *frame-foreground-hidden
*))
633 (dolist (ch hidden-children
)
634 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
635 (format nil
" ~A - hidden" (ensure-printable (child-fullname ch
))))))
636 (copy-pixmap-buffer window gc
)
640 (defun display-all-frame-info (&optional
(root *current-root
*))
641 (with-all-frames (root frame
)
642 (display-frame-info frame
)))
648 (defun get-parent-layout (child parent
)
649 (if (or (frame-p child
) (managed-window-p child parent
))
651 (aif (frame-layout parent
)
652 (funcall it child parent
)
653 (no-layout child parent
))
654 (get-fullscreen-size))
655 (values -
1 -
1 -
1 -
1)))
659 (defgeneric adapt-child-to-parent
(child parent
))
661 (defmethod adapt-child-to-parent ((window xlib
:window
) parent
)
662 (when (managed-window-p window parent
)
663 (multiple-value-bind (nx ny nw nh
)
664 (get-parent-layout window parent
)
665 (setf nw
(max nw
1) nh
(max nh
1))
666 (let ((change (or (/= (xlib:drawable-x window
) nx
)
667 (/= (xlib:drawable-y window
) ny
)
668 (/= (xlib:drawable-width window
) nw
)
669 (/= (xlib:drawable-height window
) nh
))))
671 (setf (xlib:drawable-x window
) nx
672 (xlib:drawable-y window
) ny
673 (xlib:drawable-width window
) nw
674 (xlib:drawable-height window
) nh
))
678 (defmethod adapt-child-to-parent ((frame frame
) parent
)
679 (declare (ignore parent
))
680 (with-slots (rx ry rw rh window
) frame
681 (let ((change (or (/= (xlib:drawable-x window
) rx
)
682 (/= (xlib:drawable-y window
) ry
)
683 (/= (xlib:drawable-width window
) rw
)
684 (/= (xlib:drawable-height window
) rh
))))
686 (setf (xlib:drawable-x window
) rx
687 (xlib:drawable-y window
) ry
688 (xlib:drawable-width window
) rw
689 (xlib:drawable-height window
) rh
))
692 (defmethod adapt-child-to-parent (child parent
)
693 (declare (ignore child parent
))
697 (defgeneric set-child-stack-order
(window child
)
698 (:documentation
"Raise window if child is NIL else put window just below child"))
700 (defmethod set-child-stack-order (window (child xlib
:window
))
701 (lower-window window child
))
703 (defmethod set-child-stack-order (window (child frame
))
704 (lower-window window
(frame-window child
)))
706 (defmethod set-child-stack-order (window child
)
707 (declare (ignore child
))
708 (raise-window window
))
712 (defgeneric show-child
(child parent previous
))
714 (defmethod show-child ((frame frame
) parent previous
)
715 (declare (ignore parent
))
716 (with-slots (window show-window-p
) frame
717 (if (and show-window-p
718 (or *show-root-frame-p
* (not (child-equal-p frame
*current-root
*))))
721 (set-child-stack-order window previous
)
722 (display-frame-info frame
))
723 (hide-window window
))))
727 (defun hide-unmanaged-window-p (parent)
728 (let ((action (frame-data-slot parent
:unmanaged-window-action
)))
732 (t *hide-unmanaged-window
*))))
735 (defmethod show-child ((window xlib
:window
) parent previous
)
736 (if (or (managed-window-p window parent
)
737 (child-equal-p window
*current-child
*)
738 (not (hide-unmanaged-window-p parent
))
739 (child-equal-p parent
*current-child
*))
742 (set-child-stack-order window previous
))
743 (hide-window window
)))
745 (defmethod show-child (child parent raise-p
)
746 (declare (ignore child parent raise-p
))
750 (defgeneric hide-child
(child))
752 (defmethod hide-child ((frame frame
))
753 (with-slots (window) frame
754 (xlib:unmap-window window
)))
756 (defmethod hide-child ((window xlib
:window
))
757 (hide-window window
))
759 (defmethod hide-child (child)
760 (declare (ignore child
))
764 (defgeneric select-child
(child selected
))
766 (labels ((get-selected-color (child selected-p
)
767 (get-color (cond ((child-equal-p child
*current-child
*) *color-selected
*)
768 (selected-p *color-maybe-selected
*)
769 (t *color-unselected
*)))))
770 (defmethod select-child ((frame frame
) selected-p
)
771 (when (and (frame-p frame
) (frame-window frame
))
772 (setf (xlib:window-border
(frame-window frame
))
773 (get-selected-color frame selected-p
))))
775 (defmethod select-child ((window xlib
:window
) selected-p
)
776 (setf (xlib:window-border window
)
777 (get-selected-color window selected-p
)))
779 (defmethod select-child (child selected
)
780 (declare (ignore child selected
))
783 (defun select-current-frame (selected)
784 (select-child *current-child
* selected
))
786 (defun unselect-all-frames ()
787 (with-all-children (*current-root
* child
)
788 (select-child child nil
)))
792 (defun set-focus-to-current-child ()
793 (labels ((rec (child)
795 (xlib:window
(focus-window child
))
796 (frame (rec (frame-selected-child child
))))))
798 (rec *current-child
*)))
803 (defun adapt-frame-to-parent (frame parent
)
804 (multiple-value-bind (nx ny nw nh
)
805 (get-parent-layout frame parent
)
806 (with-slots (rx ry rw rh window
) frame
812 (defun adapt-child-to-rect (rect)
813 (let ((window (typecase (child-rect-child rect
)
814 (xlib:window
(when (managed-window-p (child-rect-child rect
) (child-rect-parent rect
))
815 (child-rect-child rect
)))
816 (frame (frame-window (child-rect-child rect
))))))
818 (let ((change (or (/= (xlib:drawable-x window
) (child-rect-x rect
))
819 (/= (xlib:drawable-y window
) (child-rect-y rect
))
820 (/= (xlib:drawable-width window
) (child-rect-w rect
))
821 (/= (xlib:drawable-height window
) (child-rect-h rect
)))))
823 (setf (xlib:drawable-x window
) (child-rect-x rect
)
824 (xlib:drawable-y window
) (child-rect-y rect
)
825 (xlib:drawable-width window
) (child-rect-w rect
)
826 (xlib:drawable-height window
) (child-rect-h rect
)))
832 (defun show-all-children (&optional
(from-root-frame nil
))
833 "Show all children from *current-root*. When from-root-frame is true
834 Display all children from root frame and hide those not in *current-root*"
835 (let ((geometry-change nil
)
836 (displayed-child nil
)
838 (labels ((in-displayed-list (child)
839 (member child displayed-child
:test
(lambda (c rect
)
840 (child-equal-p c
(child-rect-child rect
)))))
842 (add-in-hidden-list (child)
843 (pushnew child hidden-child
:test
#'child-equal-p
))
845 (set-geometry (child parent in-current-root child-current-root-p
)
846 (if (or in-current-root child-current-root-p
)
847 (when (frame-p child
)
848 (adapt-frame-to-parent child
(if child-current-root-p nil parent
)))
849 (add-in-hidden-list child
)))
852 (recurse-on-frame-child (child in-current-root child-current-root-p selected-p
)
853 (let ((selected-child (frame-selected-child child
)))
854 (dolist (sub-child (frame-child child
))
856 (and selected-p
(child-equal-p sub-child selected-child
))
857 (or in-current-root child-current-root-p
)))))
859 (hidden-child-p (rect)
860 (dolist (r displayed-child
)
861 (when (rect-hidden-p r rect
)
864 (select-and-display (child parent selected-p
)
865 (multiple-value-bind (nx ny nw nh
)
866 (get-parent-layout child parent
)
867 (let ((rect (make-child-rect :child child
:parent parent
868 :selected-p selected-p
869 :x nx
:y ny
:w nw
:h nh
)))
870 (if (hidden-child-p rect
)
871 (add-in-hidden-list child
)
872 (push rect displayed-child
)))))
874 (display-displayed-child ()
875 (let ((previous nil
))
876 (dolist (rect (nreverse displayed-child
))
877 (when (adapt-child-to-rect rect
)
878 (setf geometry-change t
))
879 (select-child (child-rect-child rect
) (child-rect-selected-p rect
))
880 (show-child (child-rect-child rect
)
881 (child-rect-parent rect
)
883 (setf previous
(child-rect-child rect
)))))
885 (rec (child parent selected-p in-current-root
)
886 (let ((child-current-root-p (child-equal-p child
*current-root
*)))
887 (unless (in-displayed-list child
)
888 (set-geometry child parent in-current-root child-current-root-p
))
889 (when (frame-p child
)
890 (recurse-on-frame-child child in-current-root child-current-root-p selected-p
))
891 (when (and (or in-current-root child-current-root-p
)
892 (not (in-displayed-list child
)))
893 (select-and-display child parent selected-p
)))))
895 (rec (if from-root-frame
*root-frame
* *current-root
*)
896 nil t
(child-equal-p *current-root
* *root-frame
*))
897 (display-displayed-child)
898 (dolist (child hidden-child
)
900 (set-focus-to-current-child)
901 (xlib:display-finish-output
*display
*)
909 (defun hide-all-children (root &optional except
)
910 "Hide all root children"
911 (when (and (frame-p root
) (not (child-equal-p root except
)))
912 (dolist (child (frame-child root
))
913 (hide-all child except
))))
915 (defun hide-all (root &optional except
)
916 "Hide root and all its children"
917 (unless (child-equal-p root except
)
919 (hide-all-children root except
))
925 (defun focus-child (child parent
)
926 "Focus child - Return true if something has change"
927 (when (and (frame-p parent
)
928 (child-member child
(frame-child parent
)))
929 (when (not (child-equal-p child
(frame-selected-child parent
)))
930 (with-slots ((parent-child child
) selected-pos
) parent
931 (setf parent-child
(nth-insert selected-pos child
(child-remove child parent-child
))))
934 (defun focus-child-rec (child parent
)
935 "Focus child and its parents - Return true if something has change"
937 (labels ((rec (child parent
)
938 (when (focus-child child parent
)
941 (rec parent
(find-parent-frame parent
)))))
946 (defun set-current-child-generic (child)
947 (unless (child-equal-p *current-child
* child
)
948 (setf *current-child
* child
)
951 (defgeneric set-current-child
(child parent window-parent
))
953 (defmethod set-current-child ((child xlib
:window
) parent window-parent
)
954 (set-current-child-generic (if window-parent parent child
)))
956 (defmethod set-current-child ((child frame
) parent window-parent
)
957 (declare (ignore parent window-parent
))
958 (set-current-child-generic child
))
960 (defmethod set-current-child (child parent window-parent
)
961 (declare (ignore child parent window-parent
))
965 (defun set-current-root (parent window-parent
)
966 "Set current root if parent is not in current root"
967 (when (and window-parent
(not (find-child parent
*current-root
*)))
968 (setf *current-root
* parent
)))
971 (defun focus-all-children (child parent
&optional
(window-parent t
))
972 "Focus child and its parents -
973 For window: set current child to window or its parent according to window-parent"
974 (let ((new-focus (focus-child-rec child parent
))
975 (new-current-child (set-current-child child parent window-parent
))
976 (new-root (set-current-root parent window-parent
)))
977 (or new-focus new-current-child new-root
)))
982 (defun select-next-level ()
983 "Select the next level in frame"
984 (select-current-frame :maybe
)
985 (when (frame-p *current-child
*)
986 (awhen (frame-selected-child *current-child
*)
987 (setf *current-child
* it
)))
990 (defun select-previous-level ()
991 "Select the previous level in frame"
992 (unless (child-equal-p *current-child
* *current-root
*)
993 (select-current-frame :maybe
)
994 (awhen (find-parent-frame *current-child
*)
995 (setf *current-child
* it
))
996 (show-all-children)))
1000 (defun enter-frame ()
1001 "Enter in the selected frame - ie make it the root frame"
1002 (setf *current-root
* *current-child
*)
1003 (show-all-children t
))
1005 (defun leave-frame ()
1006 "Leave the selected frame - ie make its parent the root frame"
1007 (unless (child-equal-p *current-root
* *root-frame
*)
1008 (hide-all *current-root
* (get-first-window))
1009 (awhen (find-parent-frame *current-root
*)
1011 (setf *current-root
* it
)))
1012 (show-all-children)))
1015 ;;; Other actions (select-next-child, select-next-brother...) are in
1016 ;;; clfswm-circulate-mode.lisp
1020 (defun frame-lower-child ()
1021 "Lower the child in the current frame"
1022 (when (frame-p *current-child
*)
1023 (with-slots (child selected-pos
) *current-child
*
1024 (unless (>= selected-pos
(length child
))
1025 (when (nth (1+ selected-pos
) child
)
1026 (rotatef (nth selected-pos child
)
1027 (nth (1+ selected-pos
) child
)))
1028 (incf selected-pos
)))
1029 (show-all-children)))
1032 (defun frame-raise-child ()
1033 "Raise the child in the current frame"
1034 (when (frame-p *current-child
*)
1035 (with-slots (child selected-pos
) *current-child
*
1036 (unless (< selected-pos
1)
1037 (when (nth (1- selected-pos
) child
)
1038 (rotatef (nth selected-pos child
)
1039 (nth (1- selected-pos
) child
)))
1040 (decf selected-pos
)))
1041 (show-all-children)))
1044 (defun frame-select-next-child ()
1045 "Select the next child in the current frame"
1046 (when (frame-p *current-child
*)
1047 (with-slots (child selected-pos
) *current-child
*
1048 (unless (>= selected-pos
(length child
))
1049 (incf selected-pos
)))
1050 (show-all-children)))
1053 (defun frame-select-previous-child ()
1054 "Select the previous child in the current frame"
1055 (when (frame-p *current-child
*)
1056 (with-slots (child selected-pos
) *current-child
*
1057 (unless (< selected-pos
1)
1058 (decf selected-pos
)))
1059 (show-all-children)))
1063 (defun switch-to-root-frame (&key
(show-later nil
))
1064 "Switch to the root frame"
1065 (setf *current-root
* *root-frame
*)
1067 (show-all-children t
)))
1069 (defun switch-and-select-root-frame (&key
(show-later nil
))
1070 "Switch and select the root frame"
1071 (setf *current-root
* *root-frame
*)
1072 (setf *current-child
* *current-root
*)
1074 (show-all-children t
)))
1077 (defun toggle-show-root-frame ()
1078 "Show/Hide the root frame"
1079 (setf *show-root-frame-p
* (not *show-root-frame-p
*))
1080 (show-all-children))
1083 (defun remove-child-in-frame (child frame
)
1084 "Remove the child in frame"
1085 (when (frame-p frame
)
1086 (setf (frame-child frame
) (child-remove child
(frame-child frame
)))))
1088 (defun remove-child-in-frames (child root
)
1089 "Remove child in the frame root and in all its children"
1090 (with-all-frames (root frame
)
1091 (remove-child-in-frame child frame
)))
1094 (defun remove-child-in-all-frames (child)
1095 "Remove child in all frames from *root-frame*"
1096 (when (child-equal-p child
*current-root
*)
1097 (setf *current-root
* (find-parent-frame child
)))
1098 (when (child-equal-p child
*current-child
*)
1099 (setf *current-child
* *current-root
*))
1100 (remove-child-in-frames child
*root-frame
*))
1103 (defun delete-child-in-frames (child root
)
1104 "Delete child in the frame root and in all its children
1105 Warning:frame window and gc are freeed."
1106 (with-all-frames (root frame
)
1107 (remove-child-in-frame child frame
)
1108 (unless (find-frame-window (frame-window frame
))
1109 (awhen (frame-gc frame
) (xlib:free-gcontext it
) (setf it nil
))
1110 (awhen (frame-window frame
) (xlib:destroy-window it
) (setf it nil
))))
1111 (when (xlib:window-p child
)
1112 (netwm-remove-in-client-list child
)))
1115 (defun delete-child-in-all-frames (child)
1116 "Delete child in all frames from *root-frame*"
1117 (when (child-equal-p child
*current-root
*)
1118 (setf *current-root
* (find-parent-frame child
)))
1119 (when (child-equal-p child
*current-child
*)
1120 (setf *current-child
* *current-root
*))
1121 (delete-child-in-frames child
*root-frame
*))
1124 (defun delete-child-and-children-in-frames (child root
&optional
(close-methode 'delete-window
))
1125 "Delete child and its children in the frame root and in all its children
1126 Warning:frame window and gc are freeed."
1127 (when (and (frame-p child
) (frame-child child
))
1128 (dolist (ch (frame-child child
))
1129 (delete-child-and-children-in-frames ch root close-methode
)))
1130 (delete-child-in-frames child root
)
1131 (when (xlib:window-p child
)
1132 (funcall close-methode child
)))
1134 (defun delete-child-and-children-in-all-frames (child &optional
(close-methode 'delete-window
))
1135 "Delete child and its children in all frames from *root-frame*"
1136 (when (child-equal-p child
*current-root
*)
1137 (setf *current-root
* (find-parent-frame child
)))
1138 (when (child-equal-p child
*current-child
*)
1139 (setf *current-child
* *current-root
*))
1140 (delete-child-and-children-in-frames child
*root-frame
* close-methode
))
1144 (defun place-window-from-hints (window)
1145 "Place a window from its hints"
1146 (let* ((hints (xlib:wm-normal-hints window
))
1147 (min-width (or (and hints
(xlib:wm-size-hints-min-width hints
)) 0))
1148 (min-height (or (and hints
(xlib:wm-size-hints-min-height hints
)) 0))
1149 (max-width (or (and hints
(xlib:wm-size-hints-max-width hints
)) (xlib:drawable-width
*root
*)))
1150 (max-height (or (and hints
(xlib:wm-size-hints-max-height hints
)) (xlib:drawable-height
*root
*)))
1151 (rwidth (or (and hints
(or (xlib:wm-size-hints-width hints
) (xlib:wm-size-hints-base-width hints
)))
1152 (xlib:drawable-width window
)))
1153 (rheight (or (and hints
(or (xlib:wm-size-hints-height hints
) (xlib:wm-size-hints-base-height hints
)))
1154 (xlib:drawable-height window
))))
1155 (setf (xlib:drawable-width window
) (min (max min-width rwidth
*default-window-width
*) max-width
)
1156 (xlib:drawable-height window
) (min (max min-height rheight
*default-window-height
*) max-height
))
1157 (setf (xlib:drawable-x window
) (truncate (/ (- (xlib:screen-width
*screen
*) (+ (xlib:drawable-width window
) 2)) 2))
1158 (xlib:drawable-y window
) (truncate (/ (- (xlib:screen-height
*screen
*) (+ (xlib:drawable-height window
) 2)) 2)))
1159 (xlib:display-finish-output
*display
*)))
1163 (defun do-all-frames-nw-hook (window)
1164 "Call nw-hook of each frame."
1165 (catch 'nw-hook-loop
1167 (with-all-frames (*root-frame
* frame
)
1168 (awhen (frame-nw-hook frame
)
1169 (setf found
(call-hook it
(list frame window
)))))
1174 (defun process-new-window (window)
1175 "When a new window is created (or when we are scanning initial
1176 windows), this function dresses the window up and gets it ready to be
1178 (setf (xlib:window-event-mask window
) *window-events
*)
1179 (set-window-state window
+normal-state
+)
1180 (setf (xlib:drawable-border-width window
) (case (window-type window
)
1181 (:normal
*border-size
*)
1182 (:maxsize
*border-size
*)
1183 (:transient
*border-size
*)
1185 (grab-all-buttons window
)
1186 (unless (never-managed-window-p window
)
1187 (unless (do-all-frames-nw-hook window
)
1188 (call-hook *default-nw-hook
* (list *root-frame
* window
))))
1189 (netwm-add-in-client-list window
))
1194 (defun hide-existing-windows (screen)
1195 "Hide all existing windows in screen"
1196 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1199 (defun process-existing-windows (screen)
1200 "Windows present when clfswm starts up must be absorbed by clfswm."
1201 (setf *in-process-existing-windows
* t
)
1203 (all-windows (get-all-windows)))
1204 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1205 (unless (child-member win all-windows
)
1206 (let ((map-state (xlib:window-map-state win
))
1207 (wm-state (window-state win
)))
1208 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1209 (eql win
*no-focus-window
*))
1210 (when (or (eql map-state
:viewable
)
1211 (eql wm-state
+iconic-state
+))
1212 (format t
"Processing ~S: type=~A ~S~%" (xlib:wm-name win
) (window-type win
) win
)
1214 (process-new-window win
)
1217 (pushnew (xlib:window-id win
) id-list
))))))
1218 (netwm-set-client-list id-list
))
1219 (setf *in-process-existing-windows
* nil
))
1222 ;;; Child order manipulation functions
1223 (defun put-child-on-top (child parent
)
1224 "Put the child on top of its parent children"
1225 (when (frame-p parent
)
1226 (setf (frame-child parent
) (cons child
(child-remove child
(frame-child parent
)))
1227 (frame-selected-pos parent
) 0)))
1229 (defun put-child-on-bottom (child parent
)
1230 "Put the child at the bottom of its parent children"
1231 (when (frame-p parent
)
1232 (setf (frame-child parent
) (append (child-remove child
(frame-child parent
)) (list child
))
1233 (frame-selected-pos parent
) 0)))