1 ;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Main functions
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
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 ;;; --------------------------------------------------------------------------
28 (defgeneric child-border-size
(child))
30 (defmethod child-border-size ((child frame
))
31 (x-drawable-border-width (frame-window child
)))
33 (defmethod child-border-size ((child xlib
:window
))
34 (x-drawable-border-width child
))
36 (defmethod child-border-size (child)
37 (declare (ignore child
))
40 (defgeneric set-child-border-size
(child value
))
42 (defmethod set-child-border-size ((child frame
) value
)
43 (setf (x-drawable-border-width (frame-window child
)) value
))
45 (defmethod set-child-border-size ((child xlib
:window
) value
)
46 (setf (x-drawable-border-width child
) value
))
48 (defmethod set-child-border-size (child value
)
49 (declare (ignore child value
)))
51 (defsetf child-border-size set-child-border-size
)
55 ;;; Conversion functions
56 ;;; Float -> Pixel conversion
57 (defun x-fl->px
(x parent
)
58 "Convert float X coordinate to pixel"
59 (round (+ (* x
(frame-rw parent
)) (frame-rx parent
))))
61 (defun y-fl->px
(y parent
)
62 "Convert float Y coordinate to pixel"
63 (round (+ (* y
(frame-rh parent
)) (frame-ry parent
))))
65 (defun w-fl->px
(w parent
)
66 "Convert float Width coordinate to pixel"
67 (round (* w
(frame-rw parent
))))
69 (defun h-fl->px
(h parent
)
70 "Convert float Height coordinate to pixel"
71 (round (* h
(frame-rh parent
))))
73 ;;; Pixel -> Float conversion
74 (defun x-px->fl
(x parent
)
75 "Convert pixel X coordinate to float"
76 (/ (- x
(frame-rx parent
) (child-border-size parent
)) (frame-rw parent
)))
78 (defun y-px->fl
(y parent
)
79 "Convert pixel Y coordinate to float"
80 (/ (- y
(frame-ry parent
) (child-border-size parent
)) (frame-rh parent
)))
82 (defun w-px->fl
(w parent
)
83 "Convert pixel Width coordinate to float"
84 (/ w
(frame-rw parent
)))
86 (defun h-px->fl
(h parent
)
87 "Convert pixel Height coordinate to float"
88 (/ h
(frame-rh parent
)))
92 (defun rect-hidden-p (rect1 rect2
)
93 "Return T if child-rect1 hide child-rect2"
94 (and *show-hide-policy
*
95 (funcall *show-hide-policy
* (child-rect-x rect1
) (child-rect-x rect2
))
96 (funcall *show-hide-policy
* (child-rect-y rect1
) (child-rect-y rect2
))
97 (funcall *show-hide-policy
* (+ (child-rect-x rect2
) (child-rect-w rect2
))
98 (+ (child-rect-x rect1
) (child-rect-w rect1
)))
99 (funcall *show-hide-policy
* (+ (child-rect-y rect2
) (child-rect-h rect2
))
100 (+ (child-rect-y rect1
) (child-rect-h rect1
)))))
104 (defgeneric frame-p
(frame))
105 (defmethod frame-p ((frame frame
))
106 (declare (ignore frame
))
108 (defmethod frame-p (frame)
109 (declare (ignore frame
))
114 ;;; in-*: Find if point (x,y) is in frame, window or child
115 (defun in-rect (x y xr yr wr hr
)
116 (and (<= xr x
(+ xr wr
))
117 (<= yr y
(+ yr hr
))))
119 (defun in-frame (frame x y
)
121 (in-rect x y
(frame-rx frame
) (frame-ry frame
) (frame-rw frame
) (frame-rh frame
))))
123 (defun in-window (window x y
)
124 (and (xlib:window-p window
)
126 (x-drawable-x window
) (x-drawable-y window
)
127 (x-drawable-width window
) (x-drawable-height window
))))
129 (defgeneric in-child
(child x y
))
131 (defmethod in-child ((child frame
) x y
)
132 (in-frame child x y
))
133 (defmethod in-child ((child xlib
:window
) x y
)
134 (in-window child x y
))
135 (defmethod in-child (child x y
)
136 (declare (ignore child x y
))
142 (defun frame-selected-child (frame)
143 (when (frame-p frame
)
144 (with-slots (child selected-pos
) frame
145 (let ((len (length child
)))
146 (cond ((minusp selected-pos
) (setf selected-pos
0))
147 ((>= selected-pos len
) (setf selected-pos
(max (1- len
) 0)))))
148 (nth selected-pos child
))))
154 (defgeneric child-equal-p
(child-1 child-2
))
156 (defmethod child-equal-p ((child-1 xlib
:window
) (child-2 xlib
:window
))
157 (xlib:window-equal child-1 child-2
))
159 (defmethod child-equal-p ((child-1 frame
) (child-2 frame
))
160 (equal child-1 child-2
))
162 (defmethod child-equal-p (child-1 child-2
)
163 (declare (ignore child-1 child-2
))
169 (declaim (inline child-member child-remove child-position
))
171 (defun child-member (child list
)
172 (member child list
:test
#'child-equal-p
))
174 (defun child-remove (child list
)
175 (remove child list
:test
#'child-equal-p
))
177 (defun child-position (child list
)
178 (position child list
:test
#'child-equal-p
))
182 ;;; Frame data manipulation functions
183 (defun frame-data-slot (frame slot
)
184 "Return the value associated to data slot"
185 (when (frame-p frame
)
186 (second (assoc slot
(frame-data frame
)))))
188 (defun set-frame-data-slot (frame slot value
)
189 "Set the value associated to data slot"
190 (when (frame-p frame
)
191 (with-slots (data) frame
192 (setf data
(remove (assoc slot data
) data
))
193 (push (list slot value
) data
))
196 (defsetf frame-data-slot set-frame-data-slot
)
199 (defun remove-frame-data-slot (frame slot
)
200 "Remove a slot in frame data slots"
201 (when (frame-p frame
)
202 (with-slots (data) frame
203 (setf data
(remove (assoc slot data
) data
)))))
207 (defun managed-window-p (window frame
)
208 "Return t only if window is managed by frame"
210 (with-slots ((managed forced-managed-window
)
211 (unmanaged forced-unmanaged-window
)) frame
212 (and (xlib:window-p window
)
213 (not (child-member window unmanaged
))
214 (not (member (xlib:wm-name window
) unmanaged
:test
#'string-equal-p
))
215 (or (member :all
(frame-managed-type frame
))
216 (member (window-type window
) (frame-managed-type frame
))
217 (child-member window managed
)
218 (member (xlib:wm-name window
) managed
:test
#'string-equal-p
))))
222 (defun add-in-never-managed-window-list (value)
223 (pushnew value
*never-managed-window-list
* :test
#'equal
))
225 (defun never-managed-window-p (window)
226 (when (xlib:window-p window
)
227 (dolist (type *never-managed-window-list
*)
228 (when (funcall (first type
) window
)
229 (return (values t
(second type
)))))))
233 (defgeneric child-name
(child))
235 (defmethod child-name ((child xlib
:window
))
236 (xlib:wm-name child
))
238 (defmethod child-name ((child frame
))
241 (defmethod child-name (child)
242 (declare (ignore child
))
246 (defgeneric set-child-name
(child name
))
248 (defmethod set-child-name ((child xlib
:window
) name
)
249 (setf (xlib:wm-name child
) name
))
251 (defmethod set-child-name ((child frame
) name
)
252 (setf (frame-name child
) name
))
254 (defmethod set-child-name (child name
)
255 (declare (ignore child name
)))
257 (defsetf child-name set-child-name
)
262 (defgeneric child-fullname
(child))
264 (defmethod child-fullname ((child xlib
:window
))
265 (format nil
"~A (~A)" (or (xlib:wm-name child
) "?") (or (xlib:get-wm-class child
) "?")))
267 (defmethod child-fullname ((child frame
))
268 (aif (frame-name child
)
269 (format nil
"~A (Frame ~A)" it
(frame-number child
))
270 (format nil
"Frame ~A" (frame-number child
))))
272 (defmethod child-fullname (child)
273 (declare (ignore child
))
277 (defgeneric child-transparency
(child))
279 (defmethod child-transparency ((child xlib
:window
))
280 (window-transparency child
))
282 (defmethod child-transparency ((child frame
))
283 (window-transparency (frame-window child
)))
285 (defmethod child-transparency (child)
286 (declare (ignore child
))
289 (defgeneric set-child-transparency
(child value
))
291 (defmethod set-child-transparency ((child xlib
:window
) value
)
292 (setf (window-transparency child
) value
))
294 (defmethod set-child-transparency ((child frame
) value
)
295 (setf (window-transparency (frame-window child
)) value
))
297 (defmethod set-child-transparency (child value
)
298 (declare (ignore child value
)))
300 (defsetf child-transparency set-child-transparency
)
304 (defgeneric child-x
(child))
305 (defmethod child-x ((child xlib
:window
))
306 (x-drawable-x child
))
307 (defmethod child-x ((child frame
))
310 (defgeneric child-y
(child))
311 (defmethod child-y ((child xlib
:window
))
312 (x-drawable-y child
))
313 (defmethod child-y ((child frame
))
316 (defgeneric child-width
(child))
317 (defmethod child-width ((child xlib
:window
))
318 (x-drawable-width child
))
319 (defmethod child-width ((child frame
))
322 (defgeneric child-height
(child))
323 (defmethod child-height ((child xlib
:window
))
324 (x-drawable-height child
))
325 (defmethod child-height ((child frame
))
328 (defgeneric child-x2
(child))
329 (defmethod child-x2 ((child xlib
:window
))
330 (+ (x-drawable-x child
) (x-drawable-width child
)))
331 (defmethod child-x2 ((child frame
))
332 (+ (frame-rx child
) (frame-rw child
)))
334 (defgeneric child-y2
(child))
335 (defmethod child-y2 ((child xlib
:window
))
336 (+ (x-drawable-y child
) (x-drawable-height child
)))
337 (defmethod child-y2 ((child frame
))
338 (+ (frame-ry child
) (frame-rh child
)))
342 (defgeneric child-center
(child))
344 (defmethod child-center ((child xlib
:window
))
345 (values (+ (x-drawable-x child
) (/ (x-drawable-width child
) 2))
346 (+ (x-drawable-y child
) (/ (x-drawable-height child
) 2))))
348 (defmethod child-center ((child frame
))
349 (values (+ (frame-rx child
) (/ (frame-rw child
) 2))
350 (+ (frame-ry child
) (/ (frame-rh child
) 2))))
352 (defun child-distance (child1 child2
)
353 (multiple-value-bind (x1 y1
) (child-center child1
)
354 (multiple-value-bind (x2 y2
) (child-center child2
)
355 (values (+ (abs (- x2 x1
)) (abs (- y2 y1
)))
359 (defun middle-child-x (child)
360 (+ (child-x child
) (/ (child-width child
) 2)))
362 (defun middle-child-y (child)
363 (+ (child-y child
) (/ (child-height child
) 2)))
365 (declaim (inline adj-border-xy adj-border-wh
))
366 (defgeneric adj-border-xy
(value child
))
367 (defgeneric adj-border-wh
(value child
))
369 (defmethod adj-border-xy (v (child xlib
:window
))
370 (+ v
(x-drawable-border-width child
)))
372 (defmethod adj-border-xy (v (child frame
))
373 (+ v
(x-drawable-border-width (frame-window child
))))
375 (defmethod adj-border-wh (v (child xlib
:window
))
376 (- v
(* (x-drawable-border-width child
) 2)))
378 (defmethod adj-border-wh (v (child frame
))
379 (- v
(* (x-drawable-border-width (frame-window child
)) 2)))
382 (declaim (inline anti-adj-border-xy anti-adj-border-wh
))
383 (defgeneric anti-adj-border-xy
(value child
))
384 (defgeneric anti-adj-border-wh
(value child
))
386 (defmethod anti-adj-border-xy (v (child xlib
:window
))
387 (- v
(x-drawable-border-width child
)))
389 (defmethod anti-adj-border-xy (v (child frame
))
390 (- v
(x-drawable-border-width (frame-window child
))))
392 (defmethod anti-adj-border-wh (v (child xlib
:window
))
393 (+ v
(* (x-drawable-border-width child
) 2)))
395 (defmethod anti-adj-border-wh (v (child frame
))
396 (+ v
(* (x-drawable-border-width (frame-window child
)) 2)))
401 (defmacro with-focus-window
((window) &body body
)
402 `(let ((,window
(xlib:input-focus
*display
*)))
403 (when (and ,window
(not (xlib:window-equal
,window
*no-focus-window
*)))
408 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
409 (defmacro with-all-children
((root child
) &body body
)
411 (sub-child (gensym)))
413 (labels ((,rec
(,child
)
415 (when (frame-p ,child
)
416 (dolist (,sub-child
(reverse (frame-child ,child
)))
417 (,rec
,sub-child
)))))
421 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
422 (defmacro with-all-children-reversed
((root child
) &body body
)
424 (sub-child (gensym)))
426 (labels ((,rec
(,child
)
428 (when (frame-p ,child
)
429 (dolist (,sub-child
(frame-child ,child
))
430 (,rec
,sub-child
)))))
437 ;; (with-all-frames (*root-frame* frame) (print (frame-number frame)))
438 (defmacro with-all-frames
((root frame
) &body body
)
442 (labels ((,rec
(,frame
)
443 (when (frame-p ,frame
)
445 (dolist (,child
(reverse (frame-child ,frame
)))
450 ;; (with-all-windows (*root-frame* window) (print window))
451 (defmacro with-all-windows
((root window
) &body body
)
455 (labels ((,rec
(,window
)
456 (when (xlib:window-p
,window
)
458 (when (frame-p ,window
)
459 (dolist (,child
(reverse (frame-child ,window
)))
465 ;; (with-all-frames-windows (*root-frame* child) (print child) (print (frame-number child)))
466 (defmacro with-all-windows-frames
((root child
) body-window body-frame
)
468 (sub-child (gensym)))
470 (labels ((,rec
(,child
)
472 (xlib:window
,body-window
)
474 (dolist (,sub-child
(reverse (frame-child ,child
)))
475 (,rec
,sub-child
))))))
478 (defmacro with-all-windows-frames-and-parent
((root child parent
) body-window body-frame
)
480 (sub-child (gensym)))
482 (labels ((,rec
(,child
,parent
)
484 (xlib:window
,body-window
)
486 (dolist (,sub-child
(reverse (frame-child ,child
)))
487 (,rec
,sub-child
,child
))))))
493 (defun create-frame-window ()
494 (let ((win (xlib:create-window
:parent
*root
*
499 :background
(get-color *frame-background
*)
500 :colormap
(xlib:screen-default-colormap
*screen
*)
501 :border-width
*border-size
*
502 :border
(get-color *color-selected
*)
503 :event-mask
'(:exposure
:button-press
:button-release
:pointer-motion
:enter-window
))))
504 (setf (window-transparency win
) *frame-transparency
*)
507 (defun create-frame-gc (window)
508 (xlib:create-gcontext
:drawable window
509 :foreground
(get-color *frame-foreground
*)
510 :background
(get-color *frame-background
*)
515 (defun destroy-all-frames-window ()
516 (with-all-frames (*root-frame
* frame
)
517 (when (frame-gc frame
)
518 (xlib:free-gcontext
(frame-gc frame
))
519 (setf (frame-gc frame
) nil
))
520 (when (frame-window frame
)
521 (xlib:destroy-window
(frame-window frame
))
522 (setf (frame-window frame
) nil
))))
524 (defun create-all-frames-window ()
525 (with-all-frames (*root-frame
* frame
)
526 (unless (frame-window frame
)
527 (setf (frame-window frame
) (create-frame-window)))
528 (unless (frame-gc frame
)
529 (setf (frame-gc frame
) (create-frame-gc (frame-window frame
)))))
530 (with-all-frames (*root-frame
* frame
)
531 (dolist (child (frame-child frame
))
533 (dbg (child-fullname child
))
535 (setf (frame-child frame
) (remove child
(frame-child frame
) :test
#'child-equal-p
))
541 (defun frame-find-free-number ()
542 (let ((all-numbers nil
))
543 (with-all-frames (*root-frame
* frame
)
544 (pushnew (frame-number frame
) all-numbers
))
545 (find-free-number all-numbers
)))
548 (defun create-frame (&rest args
&key
(number (frame-find-free-number)) &allow-other-keys
)
549 (let* ((window (create-frame-window))
550 (gc (create-frame-gc window
)))
551 (apply #'make-instance
'frame
:number number
:window window
:gc gc args
)))
554 (defun add-frame (frame parent
)
555 (push frame
(frame-child parent
))
559 (defun place-frame (frame parent prx pry prw prh
)
560 "Place a frame from real (pixel) coordinates"
561 (when (and (frame-p frame
) (frame-p parent
))
562 (with-slots (window x y w h
) frame
563 (setf (x-drawable-x window
) prx
564 (x-drawable-y window
) pry
565 (x-drawable-width window
) prw
566 (x-drawable-height window
) prh
567 x
(x-px->fl prx parent
)
568 y
(y-px->fl pry parent
)
569 w
(w-px->fl prw parent
)
570 h
(h-px->fl prh parent
))
571 (xlib:display-finish-output
*display
*))))
575 (defun find-child (to-find root
)
576 "Find to-find in root or in its children"
577 (with-all-children (root child
)
578 (when (child-equal-p child to-find
)
579 (return-from find-child t
))))
583 (defmacro with-find-in-all-frames
(test &optional return-value
)
586 (with-all-frames (root frame
)
589 (return-from return-block
(or ,return-value frame
))
591 (or ,return-value ret
))))
593 (defun find-parent-frame (to-find &optional
(root *root-frame
*) first-foundp
)
594 "Return the parent frame of to-find"
595 (with-find-in-all-frames
596 (child-member to-find
(frame-child frame
))))
598 (defun find-frame-window (window &optional
(root *root-frame
*) first-foundp
)
599 "Return the frame with the window window"
600 (with-find-in-all-frames
601 (xlib:window-equal window
(frame-window frame
))))
603 (defun find-frame-by-name (name &optional
(root *root-frame
*) first-foundp
)
604 "Find a frame from its name"
606 (with-find-in-all-frames
607 (string-equal name
(frame-name frame
)))))
609 (defun find-frame-by-number (number &optional
(root *root-frame
*) first-foundp
)
610 "Find a frame from its number"
611 (when (numberp number
)
612 (with-find-in-all-frames
613 (= number
(frame-number frame
)))))
616 (defun find-child-in-parent (child base
)
617 "Return t if child is in base or in its parents"
619 (when (child-equal-p child base
)
620 (return-from find-child-in-parent t
))
621 (let ((parent (find-parent-frame base
)))
626 ;;; Multiple roots support (replace the old *current-root* variable)
627 (let ((root-list nil
)
629 (defun get-root-list ()
632 (let ((save-root-list nil
))
633 (defun save-root-list ()
634 (setf save-root-list nil
)
635 (dolist (root root-list
)
636 (push (copy-root root
) save-root-list
)))
637 (defun restore-root-list ()
639 (dolist (root save-root-list
)
640 (push (copy-root root
) root-list
))))
642 (defmacro with-saved-root-list
(() &body body
)
646 (restore-root-list)))
648 (defun reset-root-list ()
652 (defun define-as-root (child x y width height
)
653 (push (make-root :child child
:original child
:current-child nil
:x x
:y y
:w width
:h height
) root-list
))
655 (defun find-root-by-coordinates (x y
)
656 (dolist (root root-list
)
657 (when (in-rect x y
(root-x root
) (root-y root
) (root-w root
) (root-h root
))
660 (defun root (x &optional y
)
661 "Return the root at coordinates (x,y) if y is not nil.
662 Otherwise, return the x nth root in root-list"
664 (find-root-by-coordinates x y
)
667 (defun all-root-child ()
668 (loop for root in root-list
669 collect
(root-child root
)))
671 (defmacro with-all-root-child
((root) &body body
)
672 (let ((root-symb (gensym)))
673 `(dolist (,root-symb
(get-root-list))
674 (let ((,root
(root-child ,root-symb
)))
677 (labels ((generic-child-root-p (child function
)
678 (dolist (root root-list
)
679 (when (child-equal-p child
(funcall function root
))
681 (defun child-root-p (child)
682 (generic-child-root-p child
#'root-child
))
684 (defun child-original-root-p (child)
685 (generic-child-root-p child
#'root-original
)))
687 (defun change-root (old-root new-child
)
688 (when (and old-root new-child
)
689 (setf (root-child old-root
) new-child
)))
691 (defun find-root (child)
692 (aif (child-original-root-p child
)
694 (awhen (find-parent-frame child
)
697 (defun find-child-in-all-root (child)
698 (dolist (root root-list
)
699 (when (find-child child
(root-child root
))
700 (return-from find-child-in-all-root root
))))
702 (defun find-current-root ()
703 (root-child (find-root current-child
)))
705 (defun exchange-root-geometry (root-1 root-2
)
706 (when (and root-1 root-2
)
707 (rotatef (root-x root-1
) (root-x root-2
))
708 (rotatef (root-y root-1
) (root-y root-2
))
709 (rotatef (root-w root-1
) (root-w root-2
))
710 (rotatef (root-h root-1
) (root-h root-2
))))
712 (defun rotate-root-geometry ()
713 (let* ((current (first root-list
))
714 (orig-x (root-x current
))
715 (orig-y (root-y current
))
716 (orig-w (root-w current
))
717 (orig-h (root-h current
)))
718 (dolist (elem (rest root-list
))
719 (setf (root-x current
) (root-x elem
)
720 (root-y current
) (root-y elem
)
721 (root-w current
) (root-w elem
)
722 (root-h current
) (root-h elem
)
724 (let ((last (car (last root-list
))))
725 (setf (root-x last
) orig-x
728 (root-h last
) orig-h
))))
730 (defun anti-rotate-root-geometry ()
731 (setf root-list
(nreverse root-list
))
732 (rotate-root-geometry)
733 (setf root-list
(nreverse root-list
)))
735 ;;; Current child functions
736 (defun current-child ()
739 (defun current-child-setter (value)
741 (awhen (find-root value
)
742 (setf (root-current-child it
) value
))
743 (setf current-child value
)))
745 (defmacro with-current-child
((new-child) &body body
)
746 "Temporarly change the current child"
747 (let ((old-child (gensym))
749 `(let ((,old-child
(current-child)))
750 (setf (current-child) ,new-child
)
751 (let ((,ret
(multiple-value-list (progn ,@body
))))
752 (setf (current-child) ,old-child
)
753 (values-list ,ret
)))))
755 (defun child-is-a-current-child-p (child)
756 (find child root-list
:test
#'child-equal-p
:key
#'root-current-child
)))
758 (defsetf current-child current-child-setter
)
760 (defun ensure-at-least-one-root ()
761 (unless (get-root-list)
762 (let ((frame (create-frame)))
763 (add-frame frame
*root-frame
*)
764 (define-as-root frame
0 0 (xlib:screen-width
*screen
*) (xlib:screen-height
*screen
*))
765 (add-frame (create-frame) frame
))))
772 (defun is-in-current-child-p (child)
773 (and (frame-p (current-child))
774 (child-member child
(frame-child (current-child)))))
778 (defun fixe-real-size (frame parent
)
779 "Fixe real (pixel) coordinates in float coordinates"
780 (when (frame-p frame
)
781 (with-slots (x y w h rx ry rw rh
) frame
782 (setf x
(x-px->fl rx parent
)
783 y
(y-px->fl ry parent
)
784 w
(w-px->fl
(anti-adj-border-wh rw parent
) parent
)
785 h
(h-px->fl
(anti-adj-border-wh rh parent
) parent
)))))
787 (defun fixe-real-size-current-child ()
788 "Fixe real (pixel) coordinates in float coordinates for children in the current child"
789 (when (frame-p (current-child))
790 (dolist (child (frame-child (current-child)))
791 (fixe-real-size child
(current-child)))))
795 ;;; Multiple physical screen helper
796 (defun add-placed-frame-tmp (frame n
) ;; For test
797 (add-frame (create-frame :x
0.01 :y
0.01 :w
0.4 :h
0.4) frame
)
798 (add-frame (create-frame :x
0.55 :y
0.01 :w
0.4 :h
0.4) frame
)
799 (add-frame (create-frame :x
0.03 :y
0.5 :w
0.64 :h
0.44) frame
)
801 (add-placed-frame-tmp (first (frame-child frame
)) (1- n
))))
803 (defun parse-xinerama-info (line)
805 (mapcar (lambda (string)
806 (parse-integer string
:junk-allowed t
))
807 (split-string (substitute #\space
#\x
(substitute #\space
#\
, line
))))))
809 (defun get-connected-heads-size (&optional fake
)
810 (labels ((heads-info ()
812 (do-shell "xdpyinfo -ext XINERAMA")
814 (setf *show-root-frame-p
* t
)
815 (do-shell "echo ' available colormap entries: 256 per subfield
816 red, green, blue masks: 0xff0000, 0xff00, 0xff
817 significant bits in color specification: 8 bits
819 XINERAMA version 1.1 opcode: 150
820 head #0: 500x300 @ 10,10
821 head #1: 480x300 @ 520,20
822 head #2: 600x250 @ 310,330'")))))
823 (when (xlib:query-extension
*display
* "XINERAMA")
824 (let ((output (heads-info))
826 (loop for line
= (read-line output nil nil
)
828 do
(when (search " head " line
)
829 (destructuring-bind (w h x y
)
830 (parse-xinerama-info line
)
833 (destructuring-bind (x1 y1 w1 h1
) s
836 (<= (+ x w
) (+ x1 w1
))
837 (<= (+ y h
) (+ y1 h1
)))
840 (push (list x y w h
) sizes
))))))
842 ;;'((10 10 500 300) (550 50 400 400) (100 320 400 270))))))
843 ;;'((10 10 500 580) (540 50 470 500))))))
846 (let ((last-sizes nil
))
847 (defun reset-last-head-size ()
848 (setf last-sizes nil
))
850 (defun place-frames-from-xinerama-infos ()
851 "Place frames according to xdpyinfo/xinerama informations"
852 (let ((sizes (get-connected-heads-size))
853 (width (xlib:screen-width
*screen
*))
854 (height (xlib:screen-height
*screen
*)))
855 (labels ((update-root-geometry ()
856 (loop for size in sizes
857 for root in
(get-root-list)
858 do
(destructuring-bind (x y w h
) size
859 (setf (root-x root
) x
863 (setf last-sizes sizes
)
865 (create-root-geometry ()
867 ;; Add frames in *root-frame* until we get the same number as screen heads
868 (loop while
(< (length (frame-child *root-frame
*)) (length sizes
))
869 do
(let ((frame (create-frame)))
870 (add-frame frame
*root-frame
*)))
871 ;; On the opposite way: remove frames while there is more than screen heads in *root-frame*
872 (when (and sizes
(> (length (frame-child *root-frame
*)) (length sizes
)))
873 (dotimes (i (- (length (frame-child *root-frame
*)) (length sizes
)))
874 (let ((deleted-child (pop (frame-child *root-frame
*))))
875 (typecase deleted-child
876 (xlib:window
(push deleted-child
(frame-child (first (frame-child *root-frame
*)))))
877 (frame (dolist (child (frame-child deleted-child
))
878 (push child
(frame-child (first (frame-child *root-frame
*)))))))
879 (setf (frame-layout (first (frame-child *root-frame
*))) 'tile-space-layout
880 (frame-data-slot (first (frame-child *root-frame
*)) :tile-layout-keep-position
) :yes
))))
881 (loop for size in sizes
882 for frame in
(frame-child *root-frame
*)
883 do
(destructuring-bind (x y w h
) size
884 (setf (frame-x frame
) (float (/ x width
))
885 (frame-y frame
) (float (/ y height
))
886 (frame-w frame
) (float (/ w width
))
887 (frame-h frame
) (float (/ h height
)))
888 ;;(add-placed-frame-tmp frame 2) ;; For tests
889 (unless (frame-child frame
)
890 (add-frame (create-frame) frame
))
891 (define-as-root frame x y w h
)))
892 (setf last-sizes sizes
)
894 (format t
"Screen sizes: ~A~%" sizes
)
895 (if (= (length sizes
) (length last-sizes
))
896 (update-root-geometry)
897 (create-root-geometry))))))
901 (defun finish-configuring-root ()
902 (ensure-at-least-one-root)
903 (setf (current-child) (first (frame-child (first (frame-child *root-frame
*))))))
907 (defun get-all-windows (&optional
(root *root-frame
*))
908 "Return all windows in root and in its children"
910 (with-all-windows (root window
)
914 (defun get-all-frame-windows (&optional
(root *root-frame
*))
915 "Return all frame windows in root and in its children"
917 (with-all-frames (root frame
)
918 (push (frame-window frame
) acc
))
922 (defun get-hidden-windows ()
923 "Return all hiddens windows"
924 (let ((all-windows (get-all-windows))
925 (hidden-windows (remove-if-not #'window-hidden-p
926 (copy-list (xlib:query-tree
*root
*)))))
927 (set-difference hidden-windows all-windows
)))
931 ;;; Current window utilities
932 (defun get-current-window ()
933 (typecase (current-child)
934 (xlib:window
(current-child))
935 (frame (frame-selected-child (current-child)))))
937 (defmacro with-current-window
(&body body
)
938 "Bind 'window' to the current window"
939 `(let ((window (get-current-window)))
940 (when (xlib:window-p window
)
943 (defun get-first-window ()
944 (typecase (current-child)
945 (xlib:window
(current-child))
946 (frame (or (first (frame-child (current-child)))
953 (defun display-frame-info (frame)
954 (when (frame-p frame
)
955 (let ((dy (+ (xlib:max-char-ascent
*default-font
*) (xlib:max-char-descent
*default-font
*))))
956 (with-slots (name number gc window child hidden-children
) frame
957 (setf (xlib:gcontext-background gc
) (get-color *frame-background
*)
958 (xlib:window-background window
) (get-color *frame-background
*))
959 (clear-pixmap-buffer window gc
)
960 (setf (xlib:gcontext-foreground gc
) (get-color (if (and (child-root-p frame
)
961 (child-equal-p frame
(current-child)))
962 *frame-foreground-root
* *frame-foreground
*)))
963 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 dy
964 (format nil
"Frame: ~A~A"
966 (if name
(format nil
" - ~A" name
) "")))
968 (when (child-root-p frame
)
969 (when *child-selection
*
970 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
971 (with-output-to-string (str)
972 (format str
" Selection: ")
973 (dolist (child *child-selection
*)
975 (xlib:window
(format str
" ~A " (xlib:wm-name child
)))
976 (frame (format str
" frame:~A[~A] " (frame-number child
)
977 (aif (frame-name child
) it
"")))))))))
979 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
980 (format nil
" ~A" (ensure-printable (child-fullname ch
))))))
981 (copy-pixmap-buffer window gc
)
985 (defgeneric rename-child
(child name
))
987 (defmethod rename-child ((child frame
) name
)
988 (setf (frame-name child
) name
)
989 (display-frame-info child
))
991 (defmethod rename-child ((child xlib
:window
) name
)
992 (setf (xlib:wm-name child
) name
))
994 (defmethod rename-child (child name
)
995 (declare (ignore child name
)))
998 (defun get-parent-layout (child parent
)
999 (aif (child-root-p child
)
1000 (values (- (root-x it
) (child-border-size child
)) (- (root-y it
) (child-border-size child
))
1001 (root-w it
) (root-h it
))
1002 (if (or (frame-p child
) (managed-window-p child parent
))
1003 (if (frame-p parent
)
1004 (aif (frame-layout parent
)
1005 (funcall it child parent
)
1006 (no-layout child parent
))
1007 (values (- (child-border-size child
)) (- (child-border-size child
))
1008 (xlib:screen-width
*screen
*)
1009 (xlib:screen-height
*screen
*)))
1010 (values (x-drawable-x child
) (x-drawable-y child
)
1011 (x-drawable-width child
) (x-drawable-height child
)))))
1017 (defgeneric adapt-child-to-parent
(child parent
))
1019 (defmethod adapt-child-to-parent ((window xlib
:window
) parent
)
1020 (when (managed-window-p window parent
)
1021 (multiple-value-bind (nx ny nw nh
)
1022 (get-parent-layout window parent
)
1023 (setf nw
(max nw
1) nh
(max nh
1))
1025 (when (or (/= (x-drawable-x window
) nx
)
1026 (/= (x-drawable-y window
) ny
))
1027 (setf change
:moved
))
1028 (when (or (/= (x-drawable-width window
) nw
)
1029 (/= (x-drawable-height window
) nh
))
1030 (setf change
:resized
))
1032 (xlib:with-state
(window)
1033 (setf (x-drawable-x window
) nx
1034 (x-drawable-y window
) ny
1035 (x-drawable-width window
) nw
1036 (x-drawable-height window
) nh
)))
1040 (defmethod adapt-child-to-parent ((frame frame
) parent
)
1041 (declare (ignore parent
))
1042 (with-slots (rx ry rw rh window
) frame
1044 (when (or (/= (x-drawable-x window
) rx
)
1045 (/= (x-drawable-y window
) ry
))
1046 (setf change
:moved
))
1047 (when (or (/= (x-drawable-width window
) rw
)
1048 (/= (x-drawable-height window
) rh
))
1049 (setf change
:resized
))
1051 (xlib:with-state
(window)
1052 (setf (x-drawable-x window
) rx
1053 (x-drawable-y window
) ry
1054 (x-drawable-width window
) rw
1055 (x-drawable-height window
) rh
)))
1058 (defmethod adapt-child-to-parent (child parent
)
1059 (declare (ignore child parent
))
1063 (defgeneric set-child-stack-order
(window child
)
1064 (:documentation
"Raise window if child is NIL else put window just below child"))
1066 (defmethod set-child-stack-order (window (child xlib
:window
))
1067 (lower-window window child
))
1069 (defmethod set-child-stack-order (window (child frame
))
1070 (lower-window window
(frame-window child
)))
1072 (defmethod set-child-stack-order (window child
)
1073 (declare (ignore window child
)))
1077 (defgeneric show-child
(child parent previous
))
1079 (defmethod show-child ((frame frame
) parent previous
)
1080 (declare (ignore parent
))
1081 (with-slots (window show-window-p
) frame
1082 (if (and show-window-p
1083 (or *show-root-frame-p
* (not (child-root-p frame
))))
1086 (set-child-stack-order window previous
)
1087 (display-frame-info frame
))
1088 (hide-window window
))))
1092 (defun hide-unmanaged-window-p (parent)
1093 (let ((action (frame-data-slot parent
:unmanaged-window-action
)))
1097 (t *hide-unmanaged-window
*))))
1100 (defmethod show-child ((window xlib
:window
) parent previous
)
1101 (if (or (managed-window-p window parent
)
1102 (child-equal-p window
(current-child))
1103 (not (hide-unmanaged-window-p parent
))
1104 (child-is-a-current-child-p parent
))
1107 (set-child-stack-order window previous
))
1108 (hide-window window
)))
1110 (defmethod show-child (child parent raise-p
)
1111 (declare (ignore child parent raise-p
))
1115 (defgeneric hide-child
(child))
1117 (defmethod hide-child ((frame frame
))
1118 (with-slots (window) frame
1119 (xlib:unmap-window window
)))
1121 (defmethod hide-child ((window xlib
:window
))
1122 (hide-window window
))
1124 (defmethod hide-child (child)
1125 (declare (ignore child
))
1129 (defgeneric select-child
(child selected
))
1131 (labels ((get-selected-color (child selected-p
)
1132 (get-color (cond ((child-equal-p child
(current-child)) *color-selected
*)
1133 (selected-p *color-maybe-selected
*)
1134 (t *color-unselected
*)))))
1135 (defmethod select-child ((frame frame
) selected-p
)
1136 (when (and (frame-p frame
) (frame-window frame
))
1137 (setf (xlib:window-border
(frame-window frame
))
1138 (get-selected-color frame selected-p
))))
1140 (defmethod select-child ((window xlib
:window
) selected-p
)
1141 (setf (xlib:window-border window
)
1142 (get-selected-color window selected-p
)))
1144 (defmethod select-child (child selected
)
1145 (declare (ignore child selected
))
1148 (defun select-current-frame (selected)
1149 (select-child (current-child) selected
))
1151 (defun unselect-all-frames ()
1152 (with-all-children (*root-frame
* child
)
1153 (select-child child nil
)))
1157 (defun set-focus-to-current-child ()
1158 (labels ((rec (child)
1160 (xlib:window
(focus-window child
))
1161 (frame (rec (frame-selected-child child
))))))
1163 (rec (current-child))))
1168 (defun adapt-frame-to-parent (frame parent
)
1169 (multiple-value-bind (nx ny nw nh
)
1170 (get-parent-layout frame parent
)
1171 (with-slots (rx ry rw rh window
) frame
1177 (defun adapt-child-to-rect (rect)
1178 (let ((window (typecase (child-rect-child rect
)
1179 (xlib:window
(when (managed-window-p (child-rect-child rect
) (child-rect-parent rect
))
1180 (child-rect-child rect
)))
1181 (frame (frame-window (child-rect-child rect
))))))
1183 (let ((change (or (/= (x-drawable-x window
) (child-rect-x rect
))
1184 (/= (x-drawable-y window
) (child-rect-y rect
))
1185 (/= (x-drawable-width window
) (child-rect-w rect
))
1186 (/= (x-drawable-height window
) (child-rect-h rect
)))))
1188 (setf (x-drawable-width window
) (child-rect-w rect
)
1189 (x-drawable-height window
) (child-rect-h rect
)
1190 (x-drawable-x window
) (child-rect-x rect
)
1191 (x-drawable-y window
) (child-rect-y rect
)))
1197 (defun show-all-children (&optional
(from-root-frame nil
))
1198 "Show all children and hide those not in a root frame"
1199 (declare (ignore from-root-frame
))
1200 (let ((geometry-change nil
)
1201 (displayed-child nil
)
1203 (labels ((in-displayed-list (child)
1204 (member child displayed-child
:test
(lambda (c rect
)
1205 (child-equal-p c
(child-rect-child rect
)))))
1207 (add-in-hidden-list (child)
1208 (pushnew child hidden-child
:test
#'child-equal-p
))
1210 (set-geometry (child parent in-current-root child-current-root-p
)
1211 (if (or in-current-root child-current-root-p
)
1212 (when (frame-p child
)
1213 (adapt-frame-to-parent child
(if child-current-root-p nil parent
)))
1214 (add-in-hidden-list child
)))
1216 (recurse-on-frame-child (child in-current-root child-current-root-p selected-p
)
1217 (let ((selected-child (frame-selected-child child
)))
1218 (dolist (sub-child (frame-child child
))
1219 (rec sub-child child
1220 (and selected-p
(child-equal-p sub-child selected-child
))
1221 (or in-current-root child-current-root-p
)))))
1223 (hidden-child-p (rect)
1224 (dolist (r displayed-child
)
1225 (when (and (rect-hidden-p r rect
)
1226 (or (not (xlib:window-p
(child-rect-child r
)))
1227 (eq (window-type (child-rect-child r
)) :normal
)))
1230 (select-and-display (child parent selected-p
)
1231 (multiple-value-bind (nx ny nw nh
)
1232 (get-parent-layout child parent
)
1233 (let ((rect (make-child-rect :child child
:parent parent
1234 :selected-p selected-p
1235 :x nx
:y ny
:w nw
:h nh
)))
1236 (if (and *show-hide-policy
* (hidden-child-p rect
))
1237 (add-in-hidden-list child
)
1238 (push rect displayed-child
)))))
1240 (display-displayed-child ()
1241 (let ((previous nil
))
1242 (dolist (rect (nreverse displayed-child
))
1243 (when (adapt-child-to-rect rect
)
1244 (setf geometry-change t
))
1245 (select-child (child-rect-child rect
) (child-rect-selected-p rect
))
1246 (show-child (child-rect-child rect
)
1247 (child-rect-parent rect
)
1249 (setf previous
(child-rect-child rect
)))))
1251 (rec (child parent selected-p in-current-root
)
1252 (let ((child-current-root-p (child-root-p child
)))
1253 (unless (in-displayed-list child
)
1254 (set-geometry child parent in-current-root child-current-root-p
))
1255 (when (frame-p child
)
1256 (recurse-on-frame-child child in-current-root child-current-root-p selected-p
))
1257 (when (and (or in-current-root child-current-root-p
)
1258 (not (in-displayed-list child
)))
1259 (select-and-display child parent selected-p
)))))
1261 (rec *root-frame
* nil t
(child-root-p *root-frame
*))
1262 (display-displayed-child)
1263 (dolist (child hidden-child
)
1265 (set-focus-to-current-child)
1266 (xlib:display-finish-output
*display
*)
1272 (defun hide-all-children (root &optional except
)
1273 "Hide all root children"
1274 (when (and (frame-p root
) (not (child-equal-p root except
)))
1275 (dolist (child (frame-child root
))
1276 (hide-all child except
))))
1278 (defun hide-all (root &optional except
)
1279 "Hide root and all its children"
1280 (unless (child-equal-p root except
)
1282 (hide-all-children root except
))
1288 (defun focus-child (child parent
)
1289 "Focus child - Return true if something has change"
1290 (when (and (frame-p parent
)
1291 (child-member child
(frame-child parent
)))
1292 (when (not (child-equal-p child
(frame-selected-child parent
)))
1293 (with-slots ((parent-child child
) selected-pos
) parent
1294 (setf parent-child
(nth-insert selected-pos child
(child-remove child parent-child
))))
1297 (defun focus-child-rec (child parent
)
1298 "Focus child and its parents - Return true if something has change"
1300 (labels ((rec (child parent
)
1301 (when (focus-child child parent
)
1304 (rec parent
(find-parent-frame parent
)))))
1309 (defun set-current-child-generic (child)
1310 (unless (child-equal-p (current-child) child
)
1311 (setf (current-child) child
)
1314 (defgeneric set-current-child
(child parent window-parent
))
1316 (defmethod set-current-child ((child xlib
:window
) parent window-parent
)
1317 (set-current-child-generic (if window-parent parent child
)))
1319 (defmethod set-current-child ((child frame
) parent window-parent
)
1320 (declare (ignore parent window-parent
))
1321 (set-current-child-generic child
))
1323 (defmethod set-current-child (child parent window-parent
)
1324 (declare (ignore child parent window-parent
))
1328 (defun set-current-root (child parent window-parent
)
1329 "Set current root if parent is not in current root"
1330 (let ((root (find-root child
)))
1331 (when (and root window-parent
1332 (not (child-root-p child
))
1333 (not (find-child parent
(root-child root
))))
1334 (change-root root parent
)
1337 (defun focus-all-children (child parent
&optional
(window-parent t
))
1338 "Focus child and its parents -
1339 For window: set current child to window or its parent according to window-parent"
1340 (let ((new-focus (focus-child-rec child parent
))
1341 (new-current-child (set-current-child child parent window-parent
))
1342 (new-root (set-current-root child parent window-parent
)))
1343 (or new-focus new-current-child new-root
)))
1348 (defun select-next-level ()
1349 "Select the next level in frame"
1350 (select-current-frame :maybe
)
1351 (when (frame-p (current-child))
1352 (awhen (frame-selected-child (current-child))
1353 (setf (current-child) it
)))
1354 (show-all-children))
1356 (defun select-previous-level ()
1357 "Select the previous level in frame"
1358 (unless (child-root-p (current-child))
1359 (select-current-frame :maybe
)
1360 (awhen (find-parent-frame (current-child))
1361 (setf (current-child) it
))
1362 (show-all-children)))
1365 (defun enter-frame ()
1366 "Enter in the selected frame - ie make it the root frame"
1367 (let ((root (find-root (current-child))))
1368 (when (and root
(not (child-equal-p (root-child root
) (current-child))))
1369 (change-root root
(current-child)))
1370 (show-all-children t
)))
1372 (defun leave-frame ()
1373 "Leave the selected frame - ie make its parent the root frame"
1374 (let ((root (find-root (current-child))))
1375 (unless (or (child-equal-p (root-child root
) *root-frame
*)
1376 (child-original-root-p (root-child root
)))
1377 (awhen (and root
(find-parent-frame (root-child root
)))
1379 (change-root root it
)))
1380 (show-all-children))))
1383 ;;; Other actions (select-next-child, select-next-brother...) are in
1384 ;;; clfswm-circulate-mode.lisp
1388 (defun frame-lower-child ()
1389 "Lower the child in the current frame"
1390 (when (frame-p (current-child))
1391 (with-slots (child selected-pos
) (current-child)
1392 (unless (>= selected-pos
(length child
))
1393 (when (nth (1+ selected-pos
) child
)
1394 (rotatef (nth selected-pos child
)
1395 (nth (1+ selected-pos
) child
)))
1396 (incf selected-pos
)))
1397 (show-all-children)))
1400 (defun frame-raise-child ()
1401 "Raise the child in the current frame"
1402 (when (frame-p (current-child))
1403 (with-slots (child selected-pos
) (current-child)
1404 (unless (< selected-pos
1)
1405 (when (nth (1- selected-pos
) child
)
1406 (rotatef (nth selected-pos child
)
1407 (nth (1- selected-pos
) child
)))
1408 (decf selected-pos
)))
1409 (show-all-children)))
1412 (defun frame-select-next-child ()
1413 "Select the next child in the current frame"
1414 (when (frame-p (current-child))
1415 (with-slots (child selected-pos
) (current-child)
1416 (setf selected-pos
(mod (1+ selected-pos
) (max (length child
) 1))))
1417 (show-all-children)))
1420 (defun frame-select-previous-child ()
1421 "Select the previous child in the current frame"
1422 (when (frame-p (current-child))
1423 (with-slots (child selected-pos
) (current-child)
1424 (setf selected-pos
(mod (1- selected-pos
) (max (length child
) 1))))
1425 (show-all-children)))
1429 (defun switch-to-root-frame (&key
(show-later nil
))
1430 "Switch to the root frame"
1431 (let ((root (find-root (current-child))))
1433 (change-root root
(root-original root
)))
1435 (show-all-children t
))))
1437 (defun switch-and-select-root-frame (&key
(show-later nil
))
1438 "Switch and select the root frame"
1439 (let ((root (find-root (current-child))))
1441 (change-root root
(root-original root
))
1442 (setf (current-child) (root-original root
)))
1444 (show-all-children t
))))
1447 (defun toggle-show-root-frame ()
1448 "Show/Hide the root frame"
1449 (setf *show-root-frame-p
* (not *show-root-frame-p
*))
1450 (show-all-children))
1454 (defun prevent-current-*-equal-child
(child)
1455 " Prevent current-root and current-child equal to child"
1456 (if (child-original-root-p child
)
1459 (awhen (child-root-p child
)
1460 (change-root it
(find-parent-frame child
)))
1461 (when (child-equal-p child
(current-child))
1462 (awhen (find-root child
)
1463 (setf (current-child) (root-child it
))))
1468 (defun remove-child-in-frame (child frame
)
1469 "Remove the child in frame"
1470 (when (frame-p frame
)
1471 (setf (frame-child frame
) (child-remove child
(frame-child frame
)))))
1473 (defun remove-child-in-frames (child root
)
1474 "Remove child in the frame root and in all its children"
1475 (with-all-frames (root frame
)
1476 (remove-child-in-frame child frame
)))
1479 (defun remove-child-in-all-frames (child)
1480 "Remove child in all frames from *root-frame*"
1481 (when (prevent-current-*-equal-child child
)
1482 (remove-child-in-frames child
*root-frame
*)))
1485 (defun delete-child-in-frames (child root
&optional
(close-methode 'delete-window
))
1486 "Delete child in the frame root and in all its children
1487 Warning:frame window and gc are freeed."
1488 (with-all-frames (root frame
)
1489 (remove-child-in-frame child frame
)
1490 (unless (find-frame-window (frame-window frame
))
1491 (awhen (frame-gc frame
) (xlib:free-gcontext it
) (setf it nil
))
1492 (awhen (frame-window frame
) (xlib:destroy-window it
) (setf it nil
))))
1493 (when (xlib:window-p child
)
1494 (funcall close-methode child
)
1495 (netwm-remove-in-client-list child
)))
1499 (defun delete-child-in-all-frames (child &optional
(close-methode 'delete-window
))
1500 "Delete child in all frames from *root-frame*"
1501 (when (prevent-current-*-equal-child child
)
1502 (delete-child-in-frames child
*root-frame
* close-methode
)))
1504 (defun delete-child-and-children-in-frames (child root
&optional
(close-methode 'delete-window
))
1505 "Delete child and its children in the frame root and in all its children
1506 Warning:frame window and gc are freeed."
1507 (when (and (frame-p child
) (frame-child child
))
1508 (dolist (ch (frame-child child
))
1509 (delete-child-and-children-in-frames ch root close-methode
)))
1510 (delete-child-in-frames child root close-methode
))
1512 (defun delete-child-and-children-in-all-frames (child &optional
(close-methode 'delete-window
))
1513 "Delete child and its children in all frames from *root-frame*"
1514 (when (prevent-current-*-equal-child child
)
1515 (when (frame-p child
)
1516 (delete-child-and-children-in-frames child
*root-frame
* close-methode
))
1517 (when (xlib:window-p child
)
1518 (funcall close-methode child
))))
1521 (defun clean-windows-in-all-frames ()
1522 "Remove all xlib:windows present in *root-frame* and not in the xlib tree"
1523 (let ((x-tree (xlib:query-tree
*root
*)))
1524 (with-all-frames (*root-frame
* frame
)
1525 (dolist (child (frame-child frame
))
1526 (when (xlib:window-p child
)
1527 (unless (member child x-tree
:test
#'xlib
:window-equal
)
1528 (when (prevent-current-*-equal-child child
)
1529 (setf (frame-child frame
)
1530 (child-remove child
(frame-child frame
))))))))))
1534 (defun do-all-frames-nw-hook (window)
1535 "Call nw-hook of each frame."
1536 (catch 'nw-hook-loop
1538 (with-all-frames (*root-frame
* frame
)
1539 (awhen (frame-nw-hook frame
)
1540 (setf found
(call-hook it frame window
))))
1545 (defun process-new-window (window)
1546 "When a new window is created (or when we are scanning initial
1547 windows), this function dresses the window up and gets it ready to be
1549 (setf (xlib:window-event-mask window
) *window-events
*)
1550 (set-window-state window
+normal-state
+)
1551 (setf (x-drawable-border-width window
) (case (window-type window
)
1552 (:normal
*border-size
*)
1554 (:transient
*border-size
*)
1555 (:dialog
*border-size
*)
1557 (grab-all-buttons window
)
1558 (unless (never-managed-window-p window
)
1559 (unless (do-all-frames-nw-hook window
)
1560 (call-hook *default-nw-hook
* *root-frame
* window
)))
1561 (netwm-add-in-client-list window
))
1566 (defun with-all-mapped-windows (screen fun
)
1567 (let ((all-windows (get-all-windows)))
1568 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1569 (unless (child-member win all-windows
)
1570 (let ((map-state (xlib:window-map-state win
))
1571 (wm-state (window-state win
)))
1572 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1573 (eql win
*no-focus-window
*)
1574 (is-notify-window-p win
))
1575 (when (or (eql map-state
:viewable
)
1576 (eql wm-state
+iconic-state
+))
1577 (funcall fun win
))))))))
1579 (defun store-root-background ()
1580 (with-all-mapped-windows *screen
* #'hide-window
)
1581 (setf *background-image
* (xlib:create-pixmap
:width
(xlib:screen-width
*screen
*)
1582 :height
(xlib:screen-height
*screen
*)
1583 :depth
(xlib:screen-root-depth
*screen
*)
1585 *background-gc
* (xlib:create-gcontext
:drawable
*background-image
*
1586 :foreground
(get-color *frame-foreground
*)
1587 :background
(get-color *frame-background
*)
1588 :font
*default-font
*
1589 :line-style
:solid
))
1590 (xlib:copy-area
*root
* *background-gc
*
1591 0 0 (xlib:screen-width
*screen
*) (xlib:screen-height
*screen
*)
1592 *background-image
* 0 0)
1593 (with-all-mapped-windows *screen
* #'unhide-window
))
1598 (defun hide-existing-windows (screen)
1599 "Hide all existing windows in screen"
1600 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1605 (defun process-existing-windows (screen)
1606 "Windows present when clfswm starts up must be absorbed by clfswm."
1607 (setf *in-process-existing-windows
* t
)
1609 (all-windows (get-all-windows))
1610 (all-frame-windows (get-all-frame-windows)))
1611 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1612 (unless (or (child-member win all-windows
)
1613 (child-member win all-frame-windows
))
1614 (let ((map-state (xlib:window-map-state win
))
1615 (wm-state (window-state win
)))
1616 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1617 (eql win
*no-focus-window
*)
1618 (is-notify-window-p win
)
1619 (never-managed-window-p win
))
1620 (when (or (eql map-state
:viewable
)
1621 (eql wm-state
+iconic-state
+))
1622 (format t
"Processing ~S: type=~A ~S~%" (xlib:wm-name win
) (window-type win
) win
)
1624 (process-new-window win
)
1627 (pushnew (xlib:window-id win
) id-list
))))))
1628 (netwm-set-client-list id-list
))
1629 (setf *in-process-existing-windows
* nil
))
1632 ;;; Child order manipulation functions
1633 (defun put-child-on-top (child parent
)
1634 "Put the child on top of its parent children"
1635 (when (frame-p parent
)
1636 (setf (frame-child parent
) (cons child
(child-remove child
(frame-child parent
)))
1637 (frame-selected-pos parent
) 0)))
1639 (defun put-child-on-bottom (child parent
)
1640 "Put the child at the bottom of its parent children"
1641 (when (frame-p parent
)
1642 (setf (frame-child parent
) (append (child-remove child
(frame-child parent
)) (list child
))
1643 (frame-selected-pos parent
) 0)))