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
))))
130 (defgeneric in-child
(child x y
))
132 (defmethod in-child ((child frame
) x y
)
133 (in-frame child x y
))
134 (defmethod in-child ((child xlib
:window
) x y
)
135 (in-window child x y
))
136 (defmethod in-child (child x y
)
137 (declare (ignore child x y
))
143 (defun frame-selected-child (frame)
144 (when (frame-p frame
)
145 (with-slots (child selected-pos
) frame
146 (let ((len (length child
)))
147 (cond ((minusp selected-pos
) (setf selected-pos
0))
148 ((>= selected-pos len
) (setf selected-pos
(max (1- len
) 0)))))
149 (nth selected-pos child
))))
155 (defgeneric child-equal-p
(child-1 child-2
))
157 (defmethod child-equal-p ((child-1 xlib
:window
) (child-2 xlib
:window
))
158 (xlib:window-equal child-1 child-2
))
160 (defmethod child-equal-p ((child-1 frame
) (child-2 frame
))
161 (equal child-1 child-2
))
163 (defmethod child-equal-p (child-1 child-2
)
164 (declare (ignore child-1 child-2
))
170 (declaim (inline child-member child-remove child-position
))
172 (defun child-member (child list
)
173 (member child list
:test
#'child-equal-p
))
175 (defun child-remove (child list
)
176 (remove child list
:test
#'child-equal-p
))
178 (defun child-position (child list
)
179 (position child list
:test
#'child-equal-p
))
183 ;;; Frame data manipulation functions
184 (defun frame-data-slot (frame slot
)
185 "Return the value associated to data slot"
186 (when (frame-p frame
)
187 (second (assoc slot
(frame-data frame
)))))
189 (defun set-frame-data-slot (frame slot value
)
190 "Set the value associated to data slot"
191 (when (frame-p frame
)
192 (with-slots (data) frame
193 (setf data
(remove (assoc slot data
) data
))
194 (push (list slot value
) data
))
197 (defsetf frame-data-slot set-frame-data-slot
)
200 (defun remove-frame-data-slot (frame slot
)
201 "Remove a slot in frame data slots"
202 (when (frame-p frame
)
203 (with-slots (data) frame
204 (setf data
(remove (assoc slot data
) data
)))))
208 (defun managed-window-p (window frame
)
209 "Return t only if window is managed by frame"
211 (with-slots ((managed forced-managed-window
)
212 (unmanaged forced-unmanaged-window
)) frame
213 (and (xlib:window-p window
)
214 (not (child-member window unmanaged
))
215 (not (member (xlib:wm-name window
) unmanaged
:test
#'string-equal-p
))
216 (or (member :all
(frame-managed-type frame
))
217 (member (window-type window
) (frame-managed-type frame
))
218 (child-member window managed
)
219 (member (xlib:wm-name window
) managed
:test
#'string-equal-p
))))
223 (defun add-in-never-managed-window-list (value)
224 (pushnew value
*never-managed-window-list
* :test
#'equal
))
226 (defun never-managed-window-p (window)
227 (when (xlib:window-p window
)
228 (dolist (type *never-managed-window-list
*)
229 (when (funcall (first type
) window
)
230 (return (values t
(second type
)))))))
234 (defgeneric child-name
(child))
236 (defmethod child-name ((child xlib
:window
))
237 (xlib:wm-name child
))
239 (defmethod child-name ((child frame
))
242 (defmethod child-name (child)
243 (declare (ignore child
))
247 (defgeneric set-child-name
(child name
))
249 (defmethod set-child-name ((child xlib
:window
) name
)
250 (setf (xlib:wm-name child
) name
))
252 (defmethod set-child-name ((child frame
) name
)
253 (setf (frame-name child
) name
))
255 (defmethod set-child-name (child name
)
256 (declare (ignore child name
)))
258 (defsetf child-name set-child-name
)
263 (defgeneric child-fullname
(child))
265 (defmethod child-fullname ((child xlib
:window
))
266 (format nil
"~A (~A)" (or (xlib:wm-name child
) "?") (or (xlib:get-wm-class child
) "?")))
268 (defmethod child-fullname ((child frame
))
269 (aif (frame-name child
)
270 (format nil
"~A (Frame ~A)" it
(frame-number child
))
271 (format nil
"Frame ~A" (frame-number child
))))
273 (defmethod child-fullname (child)
274 (declare (ignore child
))
278 (defgeneric child-transparency
(child))
280 (defmethod child-transparency ((child xlib
:window
))
281 (window-transparency child
))
283 (defmethod child-transparency ((child frame
))
284 (window-transparency (frame-window child
)))
286 (defmethod child-transparency (child)
287 (declare (ignore child
))
290 (defgeneric set-child-transparency
(child value
))
292 (defmethod set-child-transparency ((child xlib
:window
) value
)
293 (setf (window-transparency child
) value
))
295 (defmethod set-child-transparency ((child frame
) value
)
296 (setf (window-transparency (frame-window child
)) value
))
298 (defmethod set-child-transparency (child value
)
299 (declare (ignore child value
)))
301 (defsetf child-transparency set-child-transparency
)
305 (defgeneric child-x
(child))
306 (defmethod child-x ((child xlib
:window
))
307 (x-drawable-x child
))
308 (defmethod child-x ((child frame
))
311 (defgeneric child-y
(child))
312 (defmethod child-y ((child xlib
:window
))
313 (x-drawable-y child
))
314 (defmethod child-y ((child frame
))
317 (defgeneric child-width
(child))
318 (defmethod child-width ((child xlib
:window
))
319 (x-drawable-width child
))
320 (defmethod child-width ((child frame
))
323 (defgeneric child-height
(child))
324 (defmethod child-height ((child xlib
:window
))
325 (x-drawable-height child
))
326 (defmethod child-height ((child frame
))
329 (defgeneric child-x2
(child))
330 (defmethod child-x2 ((child xlib
:window
))
331 (+ (x-drawable-x child
) (x-drawable-width child
)))
332 (defmethod child-x2 ((child frame
))
333 (+ (frame-rx child
) (frame-rw child
)))
335 (defgeneric child-y2
(child))
336 (defmethod child-y2 ((child xlib
:window
))
337 (+ (x-drawable-y child
) (x-drawable-height child
)))
338 (defmethod child-y2 ((child frame
))
339 (+ (frame-ry child
) (frame-rh child
)))
343 (defgeneric child-center
(child))
345 (defmethod child-center ((child xlib
:window
))
346 (values (+ (x-drawable-x child
) (/ (x-drawable-width child
) 2))
347 (+ (x-drawable-y child
) (/ (x-drawable-height child
) 2))))
349 (defmethod child-center ((child frame
))
350 (values (+ (frame-rx child
) (/ (frame-rw child
) 2))
351 (+ (frame-ry child
) (/ (frame-rh child
) 2))))
353 (defun child-distance (child1 child2
)
354 (multiple-value-bind (x1 y1
) (child-center child1
)
355 (multiple-value-bind (x2 y2
) (child-center child2
)
356 (values (+ (abs (- x2 x1
)) (abs (- y2 y1
)))
360 (defun middle-child-x (child)
361 (+ (child-x child
) (/ (child-width child
) 2)))
363 (defun middle-child-y (child)
364 (+ (child-y child
) (/ (child-height child
) 2)))
366 (declaim (inline adj-border-xy adj-border-wh
))
367 (defgeneric adj-border-xy
(value child
))
368 (defgeneric adj-border-wh
(value child
))
370 (defmethod adj-border-xy (v (child xlib
:window
))
371 (+ v
(x-drawable-border-width child
)))
373 (defmethod adj-border-xy (v (child frame
))
374 (+ v
(x-drawable-border-width (frame-window child
))))
376 (defmethod adj-border-wh (v (child xlib
:window
))
377 (- v
(* (x-drawable-border-width child
) 2)))
379 (defmethod adj-border-wh (v (child frame
))
380 (- v
(* (x-drawable-border-width (frame-window child
)) 2)))
383 (declaim (inline anti-adj-border-xy anti-adj-border-wh
))
384 (defgeneric anti-adj-border-xy
(value child
))
385 (defgeneric anti-adj-border-wh
(value child
))
387 (defmethod anti-adj-border-xy (v (child xlib
:window
))
388 (- v
(x-drawable-border-width child
)))
390 (defmethod anti-adj-border-xy (v (child frame
))
391 (- v
(x-drawable-border-width (frame-window child
))))
393 (defmethod anti-adj-border-wh (v (child xlib
:window
))
394 (+ v
(* (x-drawable-border-width child
) 2)))
396 (defmethod anti-adj-border-wh (v (child frame
))
397 (+ v
(* (x-drawable-border-width (frame-window child
)) 2)))
402 (defmacro with-focus-window
((window) &body body
)
403 `(let ((,window
(xlib:input-focus
*display
*)))
404 (when (and ,window
(not (xlib:window-equal
,window
*no-focus-window
*)))
409 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
410 (defmacro with-all-children
((root child
) &body body
)
412 (sub-child (gensym)))
414 (labels ((,rec
(,child
)
416 (when (frame-p ,child
)
417 (dolist (,sub-child
(reverse (frame-child ,child
)))
418 (,rec
,sub-child
)))))
422 ;; (with-all-children (*root-frame* child) (typecase child (xlib:window (print child)) (frame (print (frame-number child)))))
423 (defmacro with-all-children-reversed
((root child
) &body body
)
425 (sub-child (gensym)))
427 (labels ((,rec
(,child
)
429 (when (frame-p ,child
)
430 (dolist (,sub-child
(frame-child ,child
))
431 (,rec
,sub-child
)))))
438 ;; (with-all-frames (*root-frame* frame) (print (frame-number frame)))
439 (defmacro with-all-frames
((root frame
) &body body
)
443 (labels ((,rec
(,frame
)
444 (when (frame-p ,frame
)
446 (dolist (,child
(reverse (frame-child ,frame
)))
451 ;; (with-all-windows (*root-frame* window) (print window))
452 (defmacro with-all-windows
((root window
) &body body
)
456 (labels ((,rec
(,window
)
457 (when (xlib:window-p
,window
)
459 (when (frame-p ,window
)
460 (dolist (,child
(reverse (frame-child ,window
)))
466 ;; (with-all-frames-windows (*root-frame* child) (print child) (print (frame-number child)))
467 (defmacro with-all-windows-frames
((root child
) body-window body-frame
)
469 (sub-child (gensym)))
471 (labels ((,rec
(,child
)
473 (xlib:window
,body-window
)
475 (dolist (,sub-child
(reverse (frame-child ,child
)))
476 (,rec
,sub-child
))))))
479 (defmacro with-all-windows-frames-and-parent
((root child parent
) body-window body-frame
)
481 (sub-child (gensym)))
483 (labels ((,rec
(,child
,parent
)
485 (xlib:window
,body-window
)
487 (dolist (,sub-child
(reverse (frame-child ,child
)))
488 (,rec
,sub-child
,child
))))))
494 (defun create-frame-window ()
495 (let ((win (xlib:create-window
:parent
*root
*
500 :background
(get-color *frame-background
*)
501 :colormap
(xlib:screen-default-colormap
*screen
*)
502 :border-width
*border-size
*
503 :border
(get-color *color-selected
*)
504 :event-mask
'(:exposure
:button-press
:button-release
:pointer-motion
:enter-window
))))
505 (setf (window-transparency win
) *frame-transparency
*)
508 (defun create-frame-gc (window)
509 (xlib:create-gcontext
:drawable window
510 :foreground
(get-color *frame-foreground
*)
511 :background
(get-color *frame-background
*)
516 (defun destroy-all-frames-window ()
517 (with-all-frames (*root-frame
* frame
)
518 (when (frame-gc frame
)
519 (xlib:free-gcontext
(frame-gc frame
))
520 (setf (frame-gc frame
) nil
))
521 (when (frame-window frame
)
522 (xlib:destroy-window
(frame-window frame
))
523 (setf (frame-window frame
) nil
))))
525 (defun create-all-frames-window ()
526 (with-all-frames (*root-frame
* frame
)
527 (unless (frame-window frame
)
528 (setf (frame-window frame
) (create-frame-window)))
529 (unless (frame-gc frame
)
530 (setf (frame-gc frame
) (create-frame-gc (frame-window frame
)))))
531 (with-all-frames (*root-frame
* frame
)
532 (dolist (child (frame-child frame
))
534 (dbg (child-fullname child
))
536 (setf (frame-child frame
) (remove child
(frame-child frame
) :test
#'child-equal-p
))
542 (defun frame-find-free-number ()
543 (let ((all-numbers nil
))
544 (with-all-frames (*root-frame
* frame
)
545 (pushnew (frame-number frame
) all-numbers
))
546 (find-free-number all-numbers
)))
549 (defun create-frame (&rest args
&key
(number (frame-find-free-number)) &allow-other-keys
)
550 (let* ((window (create-frame-window))
551 (gc (create-frame-gc window
)))
552 (apply #'make-instance
'frame
:number number
:window window
:gc gc args
)))
555 (defun add-frame (frame parent
)
556 (push frame
(frame-child parent
))
560 (defun place-frame (frame parent prx pry prw prh
)
561 "Place a frame from real (pixel) coordinates"
562 (when (and (frame-p frame
) (frame-p parent
))
563 (with-slots (window x y w h
) frame
564 (setf (x-drawable-x window
) prx
565 (x-drawable-y window
) pry
566 (x-drawable-width window
) prw
567 (x-drawable-height window
) prh
568 x
(x-px->fl prx parent
)
569 y
(y-px->fl pry parent
)
570 w
(w-px->fl prw parent
)
571 h
(h-px->fl prh parent
))
572 (xlib:display-finish-output
*display
*))))
576 (defun find-child (to-find root
)
577 "Find to-find in root or in its children"
578 (with-all-children (root child
)
579 (when (child-equal-p child to-find
)
580 (return-from find-child t
))))
584 (defmacro with-find-in-all-frames
(test &optional return-value
)
587 (with-all-frames (root frame
)
590 (return-from return-block
(or ,return-value frame
))
592 (or ,return-value ret
))))
594 (defun find-parent-frame (to-find &optional
(root *root-frame
*) first-foundp
)
595 "Return the parent frame of to-find"
596 (with-find-in-all-frames
597 (child-member to-find
(frame-child frame
))))
599 (defun find-frame-window (window &optional
(root *root-frame
*) first-foundp
)
600 "Return the frame with the window window"
601 (with-find-in-all-frames
602 (xlib:window-equal window
(frame-window frame
))))
604 (defun find-frame-by-name (name &optional
(root *root-frame
*) first-foundp
)
605 "Find a frame from its name"
607 (with-find-in-all-frames
608 (string-equal name
(frame-name frame
)))))
610 (defun find-frame-by-number (number &optional
(root *root-frame
*) first-foundp
)
611 "Find a frame from its number"
612 (when (numberp number
)
613 (with-find-in-all-frames
614 (= number
(frame-number frame
)))))
617 (defun find-child-in-parent (child base
)
618 "Return t if child is in base or in its parents"
620 (when (child-equal-p child base
)
621 (return-from find-child-in-parent t
))
622 (let ((parent (find-parent-frame base
)))
627 ;;; Multiple roots support (replace the old *current-root* variable)
628 (let ((root-list nil
)
630 (defun get-root-list ()
633 (let ((save-root-list nil
))
634 (defun save-root-list ()
635 (setf save-root-list nil
)
636 (dolist (root root-list
)
637 (push (copy-root root
) save-root-list
)))
638 (defun restore-root-list ()
640 (dolist (root save-root-list
)
641 (push (copy-root root
) root-list
))))
643 (defmacro with-saved-root-list
(() &body body
)
647 (restore-root-list)))
649 (defun reset-root-list ()
653 (defun define-as-root (child x y width height
)
654 (push (make-root :child child
:original child
:current-child nil
:x x
:y y
:w width
:h height
) root-list
))
656 (defun find-root-by-coordinates (x y
)
657 (dolist (root root-list
)
658 (when (in-rect x y
(root-x root
) (root-y root
) (root-w root
) (root-h root
))
661 (defun root (x &optional y
)
662 "Return the root at coordinates (x,y) if y is not nil.
663 Otherwise, return the x nth root in root-list"
665 (find-root-by-coordinates x y
)
668 (defun all-root-child ()
669 (loop for root in root-list
670 collect
(root-child root
)))
672 (defmacro with-all-root-child
((root) &body body
)
673 (let ((root-symb (gensym)))
674 `(dolist (,root-symb
(get-root-list))
675 (let ((,root
(root-child ,root-symb
)))
678 (labels ((generic-child-root-p (child function
)
679 (dolist (root root-list
)
680 (when (child-equal-p child
(funcall function root
))
682 (defun child-root-p (child)
683 (generic-child-root-p child
#'root-child
))
685 (defun child-original-root-p (child)
686 (generic-child-root-p child
#'root-original
)))
688 (defun change-root (old-root new-child
)
689 (when (and old-root new-child
)
690 (setf (root-child old-root
) new-child
)))
692 (defun find-root (child)
693 (aif (child-original-root-p child
)
695 (awhen (find-parent-frame child
)
698 (defun find-child-in-all-root (child)
699 (dolist (root root-list
)
700 (when (find-child child
(root-child root
))
701 (return-from find-child-in-all-root root
))))
703 (defun find-current-root ()
704 (root-child (find-root current-child
)))
706 (defun exchange-root-geometry (root-1 root-2
)
707 (when (and root-1 root-2
)
708 (rotatef (root-x root-1
) (root-x root-2
))
709 (rotatef (root-y root-1
) (root-y root-2
))
710 (rotatef (root-w root-1
) (root-w root-2
))
711 (rotatef (root-h root-1
) (root-h root-2
))))
713 (defun rotate-root-geometry ()
714 (let* ((current (first root-list
))
715 (orig-x (root-x current
))
716 (orig-y (root-y current
))
717 (orig-w (root-w current
))
718 (orig-h (root-h current
)))
719 (dolist (elem (rest root-list
))
720 (setf (root-x current
) (root-x elem
)
721 (root-y current
) (root-y elem
)
722 (root-w current
) (root-w elem
)
723 (root-h current
) (root-h elem
)
725 (let ((last (car (last root-list
))))
726 (setf (root-x last
) orig-x
729 (root-h last
) orig-h
))))
731 (defun anti-rotate-root-geometry ()
732 (setf root-list
(nreverse root-list
))
733 (rotate-root-geometry)
734 (setf root-list
(nreverse root-list
)))
736 ;;; Current child functions
737 (defun current-child ()
740 (defun current-child-setter (value)
742 (awhen (find-root value
)
743 (setf (root-current-child it
) value
))
744 (setf current-child value
)))
746 (defmacro with-current-child
((new-child) &body body
)
747 "Temporarly change the current child"
748 (let ((old-child (gensym))
750 `(let ((,old-child
(current-child)))
751 (setf (current-child) ,new-child
)
752 (let ((,ret
(multiple-value-list (progn ,@body
))))
753 (setf (current-child) ,old-child
)
754 (values-list ,ret
)))))
756 (defun child-is-a-current-child-p (child)
757 (find child root-list
:test
#'child-equal-p
:key
#'root-current-child
)))
759 (defsetf current-child current-child-setter
)
761 (defun ensure-at-least-one-root ()
762 (unless (get-root-list)
763 (let ((frame (create-frame)))
764 (add-frame frame
*root-frame
*)
765 (define-as-root frame
0 0 (xlib:screen-width
*screen
*) (xlib:screen-height
*screen
*))
766 (add-frame (create-frame) frame
))))
773 (defun is-in-current-child-p (child)
774 (and (frame-p (current-child))
775 (child-member child
(frame-child (current-child)))))
779 (defun fixe-real-size (frame parent
)
780 "Fixe real (pixel) coordinates in float coordinates"
781 (when (frame-p frame
)
782 (with-slots (x y w h rx ry rw rh
) frame
783 (setf x
(x-px->fl rx parent
)
784 y
(y-px->fl ry parent
)
785 w
(w-px->fl
(anti-adj-border-wh rw parent
) parent
)
786 h
(h-px->fl
(anti-adj-border-wh rh parent
) parent
)))))
788 (defun fixe-real-size-current-child ()
789 "Fixe real (pixel) coordinates in float coordinates for children in the current child"
790 (when (frame-p (current-child))
791 (dolist (child (frame-child (current-child)))
792 (fixe-real-size child
(current-child)))))
796 ;;; Multiple physical screen helper
797 (defun add-placed-frame-tmp (frame n
) ;; For test
798 (add-frame (create-frame :x
0.01 :y
0.01 :w
0.4 :h
0.4) frame
)
799 (add-frame (create-frame :x
0.55 :y
0.01 :w
0.4 :h
0.4) frame
)
800 (add-frame (create-frame :x
0.03 :y
0.5 :w
0.64 :h
0.44) frame
)
802 (add-placed-frame-tmp (first (frame-child frame
)) (1- n
))))
804 (defun parse-xinerama-info (line)
806 (mapcar (lambda (string)
807 (parse-integer string
:junk-allowed t
))
808 (split-string (substitute #\space
#\x
(substitute #\space
#\
, line
))))))
810 (defun get-connected-heads-size (&optional fake
)
811 (labels ((heads-info ()
813 (do-shell "xdpyinfo -ext XINERAMA")
815 (setf *show-root-frame-p
* t
)
816 (do-shell "echo ' available colormap entries: 256 per subfield
817 red, green, blue masks: 0xff0000, 0xff00, 0xff
818 significant bits in color specification: 8 bits
820 XINERAMA version 1.1 opcode: 150
821 head #0: 500x300 @ 10,10
822 head #1: 480x300 @ 520,20
823 head #2: 600x250 @ 310,330'")))))
824 (when (xlib:query-extension
*display
* "XINERAMA")
825 (let ((output (heads-info))
827 (loop for line
= (read-line output nil nil
)
829 do
(when (search " head " line
)
830 (destructuring-bind (w h x y
)
831 (parse-xinerama-info line
)
834 (destructuring-bind (x1 y1 w1 h1
) s
837 (<= (+ x w
) (+ x1 w1
))
838 (<= (+ y h
) (+ y1 h1
)))
841 (push (list x y w h
) sizes
))))))
843 ;;'((10 10 500 300) (550 50 400 400) (100 320 400 270))))))
844 ;;'((10 10 500 580) (540 50 470 500))))))
847 (let ((last-sizes nil
))
848 (defun reset-last-head-size ()
849 (setf last-sizes nil
))
851 (defun place-frames-from-xinerama-infos ()
852 "Place frames according to xdpyinfo/xinerama informations"
853 (let ((sizes (get-connected-heads-size))
854 (width (xlib:screen-width
*screen
*))
855 (height (xlib:screen-height
*screen
*)))
856 (labels ((update-root-geometry ()
857 (loop for size in sizes
858 for root in
(get-root-list)
859 do
(destructuring-bind (x y w h
) size
860 (setf (root-x root
) x
864 (setf last-sizes sizes
)
866 (create-root-geometry ()
868 ;; Add frames in *root-frame* until we get the same number as screen heads
869 (loop while
(< (length (frame-child *root-frame
*)) (length sizes
))
870 do
(let ((frame (create-frame)))
871 (add-frame frame
*root-frame
*)))
872 ;; On the opposite way: remove frames while there is more than screen heads in *root-frame*
873 (when (and sizes
(> (length (frame-child *root-frame
*)) (length sizes
)))
874 (dotimes (i (- (length (frame-child *root-frame
*)) (length sizes
)))
875 (let ((deleted-child (pop (frame-child *root-frame
*))))
876 (typecase deleted-child
877 (xlib:window
(push deleted-child
(frame-child (first (frame-child *root-frame
*)))))
878 (frame (dolist (child (frame-child deleted-child
))
879 (push child
(frame-child (first (frame-child *root-frame
*)))))))
880 (setf (frame-layout (first (frame-child *root-frame
*))) 'tile-space-layout
881 (frame-data-slot (first (frame-child *root-frame
*)) :tile-layout-keep-position
) :yes
))))
882 (loop for size in sizes
883 for frame in
(frame-child *root-frame
*)
884 do
(destructuring-bind (x y w h
) size
885 (setf (frame-x frame
) (float (/ x width
))
886 (frame-y frame
) (float (/ y height
))
887 (frame-w frame
) (float (/ w width
))
888 (frame-h frame
) (float (/ h height
)))
889 ;;(add-placed-frame-tmp frame 2) ;; For tests
890 (unless (frame-child frame
)
891 (add-frame (create-frame) frame
))
892 (define-as-root frame x y w h
)))
893 (setf last-sizes sizes
)
895 (format t
"Screen sizes: ~A~%" sizes
)
896 (if (= (length sizes
) (length last-sizes
))
897 (update-root-geometry)
898 (create-root-geometry))))))
902 (defun finish-configuring-root ()
903 (ensure-at-least-one-root)
904 (setf (current-child) (first (frame-child (first (frame-child *root-frame
*))))))
908 (defun get-all-windows (&optional
(root *root-frame
*))
909 "Return all windows in root and in its children"
911 (with-all-windows (root window
)
915 (defun get-all-frame-windows (&optional
(root *root-frame
*))
916 "Return all frame windows in root and in its children"
918 (with-all-frames (root frame
)
919 (push (frame-window frame
) acc
))
923 (defun get-hidden-windows ()
924 "Return all hiddens windows"
925 (let ((all-windows (get-all-windows))
926 (hidden-windows (remove-if-not #'window-hidden-p
927 (copy-list (xlib:query-tree
*root
*)))))
928 (set-difference hidden-windows all-windows
)))
932 ;;; Current window utilities
933 (defun get-current-window ()
934 (typecase (current-child)
935 (xlib:window
(current-child))
936 (frame (frame-selected-child (current-child)))))
938 (defmacro with-current-window
(&body body
)
939 "Bind 'window' to the current window"
940 `(let ((window (get-current-window)))
941 (when (xlib:window-p window
)
944 (defun get-first-window ()
945 (typecase (current-child)
946 (xlib:window
(current-child))
947 (frame (or (first (frame-child (current-child)))
954 (defun display-frame-info (frame)
955 (when (frame-p frame
)
956 (let ((dy (+ (xlib:max-char-ascent
*default-font
*) (xlib:max-char-descent
*default-font
*))))
957 (with-slots (name number gc window child hidden-children
) frame
958 (setf (xlib:gcontext-background gc
) (get-color *frame-background
*)
959 (xlib:window-background window
) (get-color *frame-background
*))
960 (clear-pixmap-buffer window gc
)
961 (setf (xlib:gcontext-foreground gc
) (get-color (if (and (child-root-p frame
)
962 (child-equal-p frame
(current-child)))
963 *frame-foreground-root
* *frame-foreground
*)))
964 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 dy
965 (format nil
"Frame: ~A~A"
967 (if name
(format nil
" - ~A" name
) "")))
969 (when (child-root-p frame
)
970 (when *child-selection
*
971 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
972 (with-output-to-string (str)
973 (format str
" Selection: ")
974 (dolist (child *child-selection
*)
976 (xlib:window
(format str
" ~A " (xlib:wm-name child
)))
977 (frame (format str
" frame:~A[~A] " (frame-number child
)
978 (aif (frame-name child
) it
"")))))))))
980 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
981 (format nil
" ~A" (ensure-printable (child-fullname ch
))))))
982 (copy-pixmap-buffer window gc
)
986 (defgeneric rename-child
(child name
))
988 (defmethod rename-child ((child frame
) name
)
989 (setf (frame-name child
) name
)
990 (display-frame-info child
))
992 (defmethod rename-child ((child xlib
:window
) name
)
993 (setf (xlib:wm-name child
) name
))
995 (defmethod rename-child (child name
)
996 (declare (ignore child name
)))
999 (defun get-parent-layout (child parent
)
1000 (aif (child-root-p child
)
1001 (values (- (root-x it
) (child-border-size child
)) (- (root-y it
) (child-border-size child
))
1002 (root-w it
) (root-h it
))
1003 (if (or (frame-p child
) (managed-window-p child parent
))
1004 (if (frame-p parent
)
1005 (aif (frame-layout parent
)
1006 (funcall it child parent
)
1007 (no-layout child parent
))
1008 (values (- (child-border-size child
)) (- (child-border-size child
))
1009 (xlib:screen-width
*screen
*)
1010 (xlib:screen-height
*screen
*)))
1011 (values (x-drawable-x child
) (x-drawable-y child
)
1012 (x-drawable-width child
) (x-drawable-height child
)))))
1018 (defgeneric adapt-child-to-parent
(child parent
))
1020 (defmethod adapt-child-to-parent ((window xlib
:window
) parent
)
1021 (when (managed-window-p window parent
)
1022 (multiple-value-bind (nx ny nw nh
)
1023 (get-parent-layout window parent
)
1024 (setf nw
(max nw
1) nh
(max nh
1))
1026 (when (or (/= (x-drawable-x window
) nx
)
1027 (/= (x-drawable-y window
) ny
))
1028 (setf change
:moved
))
1029 (when (or (/= (x-drawable-width window
) nw
)
1030 (/= (x-drawable-height window
) nh
))
1031 (setf change
:resized
))
1033 (xlib:with-state
(window)
1034 (setf (x-drawable-x window
) nx
1035 (x-drawable-y window
) ny
1036 (x-drawable-width window
) nw
1037 (x-drawable-height window
) nh
)))
1041 (defmethod adapt-child-to-parent ((frame frame
) parent
)
1042 (declare (ignore parent
))
1043 (with-slots (rx ry rw rh window
) frame
1045 (when (or (/= (x-drawable-x window
) rx
)
1046 (/= (x-drawable-y window
) ry
))
1047 (setf change
:moved
))
1048 (when (or (/= (x-drawable-width window
) rw
)
1049 (/= (x-drawable-height window
) rh
))
1050 (setf change
:resized
))
1052 (xlib:with-state
(window)
1053 (setf (x-drawable-x window
) rx
1054 (x-drawable-y window
) ry
1055 (x-drawable-width window
) rw
1056 (x-drawable-height window
) rh
)))
1059 (defmethod adapt-child-to-parent (child parent
)
1060 (declare (ignore child parent
))
1064 (defgeneric set-child-stack-order
(window child
)
1065 (:documentation
"Put window just below child"))
1067 (defmethod set-child-stack-order (window (child xlib
:window
))
1068 (lower-window window child
))
1070 (defmethod set-child-stack-order (window (child frame
))
1071 (lower-window window
(frame-window child
)))
1073 (defmethod set-child-stack-order (window child
)
1074 (declare (ignore child
))
1075 (unless (maxmin-size-equal-window-in-tree)
1076 (raise-window window
)))
1080 (defgeneric show-child
(child parent previous
))
1082 (defmethod show-child ((frame frame
) parent previous
)
1083 (declare (ignore parent
))
1084 (with-slots (window show-window-p
) frame
1085 (if (and show-window-p
1086 (or *show-root-frame-p
* (not (child-root-p frame
))))
1089 (set-child-stack-order window previous
)
1090 (display-frame-info frame
))
1091 (hide-window window
))))
1095 (defun hide-unmanaged-window-p (parent)
1096 (let ((action (frame-data-slot parent
:unmanaged-window-action
)))
1100 (t *hide-unmanaged-window
*))))
1103 (defmethod show-child ((window xlib
:window
) parent previous
)
1104 (if (or (managed-window-p window parent
)
1105 (child-equal-p window
(current-child))
1106 (not (hide-unmanaged-window-p parent
))
1107 (child-is-a-current-child-p parent
))
1110 (set-child-stack-order window previous
))
1111 (hide-window window
)))
1113 (defmethod show-child (child parent raise-p
)
1114 (declare (ignore child parent raise-p
))
1118 (defgeneric hide-child
(child))
1120 (defmethod hide-child ((frame frame
))
1121 (with-slots (window) frame
1122 (xlib:unmap-window window
)))
1124 (defmethod hide-child ((window xlib
:window
))
1125 (hide-window window
))
1127 (defmethod hide-child (child)
1128 (declare (ignore child
))
1132 (defgeneric select-child
(child selected
))
1134 (labels ((get-selected-color (child selected-p
)
1135 (get-color (cond ((child-equal-p child
(current-child)) *color-selected
*)
1136 (selected-p *color-maybe-selected
*)
1137 (t *color-unselected
*)))))
1138 (defmethod select-child ((frame frame
) selected-p
)
1139 (when (and (frame-p frame
) (frame-window frame
))
1140 (setf (xlib:window-border
(frame-window frame
))
1141 (get-selected-color frame selected-p
))))
1143 (defmethod select-child ((window xlib
:window
) selected-p
)
1144 (setf (xlib:window-border window
)
1145 (get-selected-color window selected-p
)))
1147 (defmethod select-child (child selected
)
1148 (declare (ignore child selected
))
1151 (defun select-current-frame (selected)
1152 (select-child (current-child) selected
))
1154 (defun unselect-all-frames ()
1155 (with-all-children (*root-frame
* child
)
1156 (select-child child nil
)))
1160 (defun set-focus-to-current-child ()
1161 (labels ((rec (child)
1163 (xlib:window
(focus-window child
))
1164 (frame (rec (frame-selected-child child
))))))
1166 (rec (current-child))))
1171 (defun adapt-frame-to-parent (frame parent
)
1172 (multiple-value-bind (nx ny nw nh
)
1173 (get-parent-layout frame parent
)
1174 (with-slots (rx ry rw rh window
) frame
1180 (defun adapt-child-to-rect (rect)
1181 (let ((window (typecase (child-rect-child rect
)
1182 (xlib:window
(when (managed-window-p (child-rect-child rect
) (child-rect-parent rect
))
1183 (child-rect-child rect
)))
1184 (frame (frame-window (child-rect-child rect
))))))
1186 (let ((change (or (/= (x-drawable-x window
) (child-rect-x rect
))
1187 (/= (x-drawable-y window
) (child-rect-y rect
))
1188 (/= (x-drawable-width window
) (child-rect-w rect
))
1189 (/= (x-drawable-height window
) (child-rect-h rect
)))))
1191 (setf (x-drawable-width window
) (child-rect-w rect
)
1192 (x-drawable-height window
) (child-rect-h rect
)
1193 (x-drawable-x window
) (child-rect-x rect
)
1194 (x-drawable-y window
) (child-rect-y rect
)))
1199 (let ((displayed-child nil
))
1200 (defun get-displayed-child ()
1203 (defun show-all-children (&optional
(from-root-frame nil
))
1204 "Show all children and hide those not in a root frame"
1205 (declare (ignore from-root-frame
))
1206 (let ((geometry-change nil
)
1208 (has-no-leader-list nil
))
1209 (labels ((set-has-no-leader-list ()
1210 (let ((window-list nil
)
1212 (with-all-windows (*root-frame
* win
)
1213 (let ((leader (window-leader win
)))
1215 (when (member leader window-list
:test
(lambda (x y
) (eql x
(first y
))))
1216 (pushnew leader leader-list
))
1217 (push (list leader win
) window-list
))))
1218 (dolist (leader-win window-list
)
1219 (unless (member leader-win leader-list
:test
(lambda (x y
) (eql (first x
) y
)))
1220 (push (second leader-win
) has-no-leader-list
)))))
1222 (in-displayed-list (child)
1223 (member child displayed-child
:test
(lambda (c rect
)
1224 (child-equal-p c
(child-rect-child rect
)))))
1226 (add-in-hidden-list (child)
1227 (pushnew child hidden-child
:test
#'child-equal-p
))
1229 (set-geometry (child parent in-current-root child-current-root-p
)
1230 (if (or in-current-root child-current-root-p
)
1231 (when (frame-p child
)
1232 (adapt-frame-to-parent child
(if child-current-root-p nil parent
)))
1233 (add-in-hidden-list child
)))
1235 (recurse-on-frame-child (child in-current-root child-current-root-p selected-p
)
1236 (let ((selected-child (frame-selected-child child
)))
1237 (dolist (sub-child (frame-child child
))
1238 (rec sub-child child
1239 (and selected-p
(child-equal-p sub-child selected-child
))
1240 (or in-current-root child-current-root-p
)))))
1242 (hidden-child-p (rect)
1243 (when (or (frame-p (child-rect-child rect
))
1244 (member (window-type (child-rect-child rect
)) *show-hide-policy-type
*))
1245 (dolist (r displayed-child
)
1246 (when (and (rect-hidden-p r rect
)
1247 (or (not (xlib:window-p
(child-rect-child r
)))
1248 (eq (window-type (child-rect-child r
)) :normal
)))
1251 (select-and-display (child parent selected-p
)
1252 (multiple-value-bind (nx ny nw nh
)
1253 (get-parent-layout child parent
)
1254 (let ((rect (make-child-rect :child child
:parent parent
1255 :selected-p selected-p
1256 :x nx
:y ny
:w nw
:h nh
)))
1257 (if (and *show-hide-policy
* (hidden-child-p rect
)
1258 (member child has-no-leader-list
:test
#'child-equal-p
))
1259 (add-in-hidden-list child
)
1260 (push rect displayed-child
)))))
1262 (display-displayed-child ()
1263 (let ((previous nil
))
1264 (setf displayed-child
(nreverse displayed-child
))
1265 (dolist (rect displayed-child
)
1266 (when (adapt-child-to-rect rect
)
1267 (setf geometry-change t
))
1268 (select-child (child-rect-child rect
) (child-rect-selected-p rect
))
1269 (show-child (child-rect-child rect
)
1270 (child-rect-parent rect
)
1272 (setf previous
(child-rect-child rect
)))))
1274 (rec (child parent selected-p in-current-root
)
1275 (let ((child-current-root-p (child-root-p child
)))
1276 (unless (in-displayed-list child
)
1277 (set-geometry child parent in-current-root child-current-root-p
))
1278 (when (frame-p child
)
1279 (recurse-on-frame-child child in-current-root child-current-root-p selected-p
))
1280 (when (and (or in-current-root child-current-root-p
)
1281 (not (in-displayed-list child
)))
1282 (select-and-display child parent selected-p
)))))
1284 (setf displayed-child nil
)
1285 (set-has-no-leader-list)
1286 (rec *root-frame
* nil t
(child-root-p *root-frame
*))
1287 (display-displayed-child)
1288 (dolist (child hidden-child
)
1290 (set-focus-to-current-child)
1291 (xlib:display-finish-output
*display
*)
1297 (defun hide-all-children (root &optional except
)
1298 "Hide all root children"
1299 (when (and (frame-p root
) (not (child-equal-p root except
)))
1300 (dolist (child (frame-child root
))
1301 (hide-all child except
))))
1303 (defun hide-all (root &optional except
)
1304 "Hide root and all its children"
1305 (unless (child-equal-p root except
)
1307 (hide-all-children root except
))
1313 (defun focus-child (child parent
)
1314 "Focus child - Return true if something has change"
1315 (when (and (frame-p parent
)
1316 (child-member child
(frame-child parent
)))
1317 (when (not (child-equal-p child
(frame-selected-child parent
)))
1318 (with-slots ((parent-child child
) selected-pos
) parent
1319 (setf parent-child
(nth-insert selected-pos child
(child-remove child parent-child
))))
1322 (defun focus-child-rec (child parent
)
1323 "Focus child and its parents - Return true if something has change"
1325 (labels ((rec (child parent
)
1326 (when (focus-child child parent
)
1329 (rec parent
(find-parent-frame parent
)))))
1334 (defun set-current-child-generic (child)
1335 (unless (child-equal-p (current-child) child
)
1336 (setf (current-child) child
)
1339 (defgeneric set-current-child
(child parent window-parent
))
1341 (defmethod set-current-child ((child xlib
:window
) parent window-parent
)
1342 (set-current-child-generic (if window-parent parent child
)))
1344 (defmethod set-current-child ((child frame
) parent window-parent
)
1345 (declare (ignore parent window-parent
))
1346 (set-current-child-generic child
))
1348 (defmethod set-current-child (child parent window-parent
)
1349 (declare (ignore child parent window-parent
))
1353 (defun set-current-root (child parent window-parent
)
1354 "Set current root if parent is not in current root"
1355 (let ((root (find-root child
)))
1356 (when (and root window-parent
1357 (not (child-root-p child
))
1358 (not (find-child parent
(root-child root
))))
1359 (change-root root parent
)
1362 (defun focus-all-children (child parent
&optional
(window-parent t
))
1363 "Focus child and its parents -
1364 For window: set current child to window or its parent according to window-parent"
1365 (let ((new-focus (focus-child-rec child parent
))
1366 (new-current-child (set-current-child child parent window-parent
))
1367 (new-root (set-current-root child parent window-parent
)))
1368 (or new-focus new-current-child new-root
)))
1373 (defun select-next-level ()
1374 "Select the next level in frame"
1375 (select-current-frame :maybe
)
1376 (when (frame-p (current-child))
1377 (awhen (frame-selected-child (current-child))
1378 (setf (current-child) it
)))
1379 (show-all-children))
1381 (defun select-previous-level ()
1382 "Select the previous level in frame"
1383 (unless (child-root-p (current-child))
1384 (select-current-frame :maybe
)
1385 (awhen (find-parent-frame (current-child))
1386 (setf (current-child) it
))
1387 (show-all-children)))
1390 (defun enter-frame ()
1391 "Enter in the selected frame - ie make it the root frame"
1392 (let ((root (find-root (current-child))))
1393 (when (and root
(not (child-equal-p (root-child root
) (current-child))))
1394 (change-root root
(current-child)))
1395 (show-all-children t
)))
1397 (defun leave-frame ()
1398 "Leave the selected frame - ie make its parent the root frame"
1399 (let ((root (find-root (current-child))))
1400 (unless (or (child-equal-p (root-child root
) *root-frame
*)
1401 (child-original-root-p (root-child root
)))
1402 (awhen (and root
(find-parent-frame (root-child root
)))
1404 (change-root root it
)))
1405 (show-all-children))))
1408 ;;; Other actions (select-next-child, select-next-brother...) are in
1409 ;;; clfswm-circulate-mode.lisp
1413 (defun frame-lower-child ()
1414 "Lower the child in the current frame"
1415 (when (frame-p (current-child))
1416 (with-slots (child selected-pos
) (current-child)
1417 (unless (>= selected-pos
(length child
))
1418 (when (nth (1+ selected-pos
) child
)
1419 (rotatef (nth selected-pos child
)
1420 (nth (1+ selected-pos
) child
)))
1421 (incf selected-pos
)))
1422 (show-all-children)))
1425 (defun frame-raise-child ()
1426 "Raise the child in the current frame"
1427 (when (frame-p (current-child))
1428 (with-slots (child selected-pos
) (current-child)
1429 (unless (< selected-pos
1)
1430 (when (nth (1- selected-pos
) child
)
1431 (rotatef (nth selected-pos child
)
1432 (nth (1- selected-pos
) child
)))
1433 (decf selected-pos
)))
1434 (show-all-children)))
1437 (defun frame-select-next-child ()
1438 "Select the next child in the current frame"
1439 (when (frame-p (current-child))
1440 (with-slots (child selected-pos
) (current-child)
1441 (setf selected-pos
(mod (1+ selected-pos
) (max (length child
) 1))))
1442 (show-all-children)))
1445 (defun frame-select-previous-child ()
1446 "Select the previous child in the current frame"
1447 (when (frame-p (current-child))
1448 (with-slots (child selected-pos
) (current-child)
1449 (setf selected-pos
(mod (1- selected-pos
) (max (length child
) 1))))
1450 (show-all-children)))
1454 (defun switch-to-root-frame (&key
(show-later nil
))
1455 "Switch to the root frame"
1456 (let ((root (find-root (current-child))))
1458 (change-root root
(root-original root
)))
1460 (show-all-children t
))))
1462 (defun switch-and-select-root-frame (&key
(show-later nil
))
1463 "Switch and select the root frame"
1464 (let ((root (find-root (current-child))))
1466 (change-root root
(root-original root
))
1467 (setf (current-child) (root-original root
)))
1469 (show-all-children t
))))
1472 (defun toggle-show-root-frame ()
1473 "Show/Hide the root frame"
1474 (setf *show-root-frame-p
* (not *show-root-frame-p
*))
1475 (show-all-children))
1479 (defun prevent-current-*-equal-child
(child)
1480 " Prevent current-root and current-child equal to child"
1481 (if (child-original-root-p child
)
1484 (awhen (child-root-p child
)
1485 (change-root it
(find-parent-frame child
)))
1486 (when (child-equal-p child
(current-child))
1487 (awhen (find-root child
)
1488 (setf (current-child) (root-child it
))))
1493 (defun remove-child-in-frame (child frame
)
1494 "Remove the child in frame"
1495 (when (frame-p frame
)
1496 (setf (frame-child frame
) (child-remove child
(frame-child frame
)))))
1498 (defun remove-child-in-frames (child root
)
1499 "Remove child in the frame root and in all its children"
1500 (with-all-frames (root frame
)
1501 (remove-child-in-frame child frame
)))
1504 (defun remove-child-in-all-frames (child)
1505 "Remove child in all frames from *root-frame*"
1506 (when (prevent-current-*-equal-child child
)
1507 (remove-child-in-frames child
*root-frame
*)))
1510 (defun delete-child-in-frames (child root
&optional
(close-methode 'delete-window
))
1511 "Delete child in the frame root and in all its children
1512 Warning:frame window and gc are freeed."
1513 (with-all-frames (root frame
)
1514 (remove-child-in-frame child frame
)
1515 (unless (find-frame-window (frame-window frame
))
1516 (awhen (frame-gc frame
) (xlib:free-gcontext it
) (setf it nil
))
1517 (awhen (frame-window frame
) (xlib:destroy-window it
) (setf it nil
))))
1518 (when (xlib:window-p child
)
1519 (funcall close-methode child
)
1520 (netwm-remove-in-client-list child
)))
1524 (defun delete-child-in-all-frames (child &optional
(close-methode 'delete-window
))
1525 "Delete child in all frames from *root-frame*"
1526 (when (prevent-current-*-equal-child child
)
1527 (delete-child-in-frames child
*root-frame
* close-methode
)))
1529 (defun delete-child-and-children-in-frames (child root
&optional
(close-methode 'delete-window
))
1530 "Delete child and its children in the frame root and in all its children
1531 Warning:frame window and gc are freeed."
1532 (when (and (frame-p child
) (frame-child child
))
1533 (dolist (ch (frame-child child
))
1534 (delete-child-and-children-in-frames ch root close-methode
)))
1535 (delete-child-in-frames child root close-methode
))
1537 (defun delete-child-and-children-in-all-frames (child &optional
(close-methode 'delete-window
))
1538 "Delete child and its children in all frames from *root-frame*"
1539 (when (prevent-current-*-equal-child child
)
1540 (when (frame-p child
)
1541 (delete-child-and-children-in-frames child
*root-frame
* close-methode
))
1542 (when (xlib:window-p child
)
1543 (funcall close-methode child
))))
1546 (defun clean-windows-in-all-frames ()
1547 "Remove all xlib:windows present in *root-frame* and not in the xlib tree"
1548 (let ((x-tree (xlib:query-tree
*root
*)))
1549 (with-all-frames (*root-frame
* frame
)
1550 (dolist (child (frame-child frame
))
1551 (when (xlib:window-p child
)
1552 (unless (member child x-tree
:test
#'xlib
:window-equal
)
1553 (when (prevent-current-*-equal-child child
)
1554 (setf (frame-child frame
)
1555 (child-remove child
(frame-child frame
))))))))))
1559 (defun do-all-frames-nw-hook (window)
1560 "Call nw-hook of each frame."
1561 (catch 'nw-hook-loop
1563 (with-all-frames (*root-frame
* frame
)
1564 (awhen (frame-nw-hook frame
)
1565 (setf found
(call-hook it frame window
))))
1570 (defun process-new-window (window)
1571 "When a new window is created (or when we are scanning initial
1572 windows), this function dresses the window up and gets it ready to be
1574 (setf (xlib:window-event-mask window
) *window-events
*)
1575 (set-window-state window
+normal-state
+)
1576 (setf (x-drawable-border-width window
) (case (window-type window
)
1577 (:normal
*border-size
*)
1579 (:transient
*border-size
*)
1580 (:dialog
*border-size
*)
1582 (grab-all-buttons window
)
1583 (unless (never-managed-window-p window
)
1584 (unless (do-all-frames-nw-hook window
)
1585 (call-hook *default-nw-hook
* *root-frame
* window
)))
1586 (netwm-add-in-client-list window
))
1591 (defun with-all-mapped-windows (screen fun
)
1592 (let ((all-windows (get-all-windows)))
1593 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1594 (unless (child-member win all-windows
)
1595 (let ((map-state (xlib:window-map-state win
))
1596 (wm-state (window-state win
)))
1597 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1598 (eql win
*no-focus-window
*)
1599 (is-notify-window-p win
))
1600 (when (or (eql map-state
:viewable
)
1601 (eql wm-state
+iconic-state
+))
1602 (funcall fun win
))))))))
1604 (defun store-root-background ()
1605 (with-all-mapped-windows *screen
* #'hide-window
)
1606 (setf *background-image
* (xlib:create-pixmap
:width
(xlib:screen-width
*screen
*)
1607 :height
(xlib:screen-height
*screen
*)
1608 :depth
(xlib:screen-root-depth
*screen
*)
1610 *background-gc
* (xlib:create-gcontext
:drawable
*background-image
*
1611 :foreground
(get-color *frame-foreground
*)
1612 :background
(get-color *frame-background
*)
1613 :font
*default-font
*
1614 :line-style
:solid
))
1615 (xlib:copy-area
*root
* *background-gc
*
1616 0 0 (xlib:screen-width
*screen
*) (xlib:screen-height
*screen
*)
1617 *background-image
* 0 0)
1618 (with-all-mapped-windows *screen
* #'unhide-window
))
1623 (defun hide-existing-windows (screen)
1624 "Hide all existing windows in screen"
1625 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1630 (defun process-existing-windows (screen)
1631 "Windows present when clfswm starts up must be absorbed by clfswm."
1632 (setf *in-process-existing-windows
* t
)
1634 (all-windows (get-all-windows))
1635 (all-frame-windows (get-all-frame-windows)))
1636 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1637 (unless (or (child-member win all-windows
)
1638 (child-member win all-frame-windows
))
1639 (let ((map-state (xlib:window-map-state win
))
1640 (wm-state (window-state win
)))
1641 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1642 (eql win
*no-focus-window
*)
1643 (is-notify-window-p win
)
1644 (never-managed-window-p win
))
1645 (when (or (eql map-state
:viewable
)
1646 (eql wm-state
+iconic-state
+))
1647 (format t
"Processing ~S: type=~A ~S~%" (xlib:wm-name win
) (window-type win
) win
)
1649 (process-new-window win
)
1652 (pushnew (xlib:window-id win
) id-list
))))))
1653 (netwm-set-client-list id-list
))
1654 (setf *in-process-existing-windows
* nil
))
1657 ;;; Child order manipulation functions
1658 (defun put-child-on-top (child parent
)
1659 "Put the child on top of its parent children"
1660 (when (frame-p parent
)
1661 (setf (frame-child parent
) (cons child
(child-remove child
(frame-child parent
)))
1662 (frame-selected-pos parent
) 0)))
1664 (defun put-child-on-bottom (child parent
)
1665 "Put the child at the bottom of its parent children"
1666 (when (frame-p parent
)
1667 (setf (frame-child parent
) (append (child-remove child
(frame-child parent
)) (list child
))
1668 (frame-selected-pos parent
) 0)))