1 ;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Main functions
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2005-2013 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
))
922 (defun get-all-frames (&optional
(root *root-frame
*))
923 "Return all frame in root and in its children"
925 (with-all-frames (root frame
)
929 (defun get-all-children (&optional
(root *root-frame
*))
930 "Return a list of all children in root"
932 (with-all-children (root child
)
937 (defun get-hidden-windows ()
938 "Return all hiddens windows"
939 (let ((all-windows (get-all-windows))
940 (hidden-windows (remove-if-not #'window-hidden-p
941 (copy-list (xlib:query-tree
*root
*)))))
942 (set-difference hidden-windows all-windows
)))
946 ;;; Current window utilities
947 (defun get-current-window ()
948 (typecase (current-child)
949 (xlib:window
(current-child))
950 (frame (frame-selected-child (current-child)))))
952 (defmacro with-current-window
(&body body
)
953 "Bind 'window' to the current window"
954 `(let ((window (get-current-window)))
955 (when (xlib:window-p window
)
958 (defun get-first-window ()
959 (typecase (current-child)
960 (xlib:window
(current-child))
961 (frame (or (first (frame-child (current-child)))
968 (defun display-frame-info (frame)
969 (when (frame-p frame
)
970 (let ((dy (+ (xlib:max-char-ascent
*default-font
*) (xlib:max-char-descent
*default-font
*))))
971 (with-slots (name number gc window child hidden-children
) frame
972 (setf (xlib:gcontext-background gc
) (get-color *frame-background
*)
973 (xlib:window-background window
) (get-color *frame-background
*))
974 (clear-pixmap-buffer window gc
)
975 (setf (xlib:gcontext-foreground gc
) (get-color (if (and (child-root-p frame
)
976 (child-equal-p frame
(current-child)))
977 *frame-foreground-root
* *frame-foreground
*)))
978 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 dy
979 (format nil
"Frame: ~A~A"
981 (if name
(format nil
" - ~A" name
) "")))
983 (when (child-root-p frame
)
984 (when *child-selection
*
985 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
986 (with-output-to-string (str)
987 (format str
" Selection: ")
988 (dolist (child *child-selection
*)
990 (xlib:window
(format str
" ~A " (xlib:wm-name child
)))
991 (frame (format str
" frame:~A[~A] " (frame-number child
)
992 (aif (frame-name child
) it
"")))))))))
994 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (incf pos dy
)
995 (format nil
" ~A" (ensure-printable (child-fullname ch
))))))
996 (copy-pixmap-buffer window gc
)
1000 (defgeneric rename-child
(child name
))
1002 (defmethod rename-child ((child frame
) name
)
1003 (setf (frame-name child
) name
)
1004 (display-frame-info child
))
1006 (defmethod rename-child ((child xlib
:window
) name
)
1007 (setf (xlib:wm-name child
) name
))
1009 (defmethod rename-child (child name
)
1010 (declare (ignore child name
)))
1013 (defun get-parent-layout (child parent
)
1014 (aif (child-root-p child
)
1015 (values (- (root-x it
) (child-border-size child
)) (- (root-y it
) (child-border-size child
))
1016 (root-w it
) (root-h it
))
1017 (if (or (frame-p child
) (managed-window-p child parent
))
1018 (if (frame-p parent
)
1019 (aif (frame-layout parent
)
1020 (funcall it child parent
)
1021 (no-layout child parent
))
1022 (values (- (child-border-size child
)) (- (child-border-size child
))
1023 (xlib:screen-width
*screen
*)
1024 (xlib:screen-height
*screen
*)))
1025 (values (x-drawable-x child
) (x-drawable-y child
)
1026 (x-drawable-width child
) (x-drawable-height child
)))))
1032 (defgeneric adapt-child-to-parent
(child parent
))
1034 (defmethod adapt-child-to-parent ((window xlib
:window
) parent
)
1035 (when (managed-window-p window parent
)
1036 (multiple-value-bind (nx ny nw nh
)
1037 (get-parent-layout window parent
)
1038 (setf nw
(max nw
1) nh
(max nh
1))
1040 (when (or (/= (x-drawable-x window
) nx
)
1041 (/= (x-drawable-y window
) ny
))
1042 (setf change
:moved
))
1043 (when (or (/= (x-drawable-width window
) nw
)
1044 (/= (x-drawable-height window
) nh
))
1045 (setf change
:resized
))
1047 (xlib:with-state
(window)
1048 (setf (x-drawable-x window
) nx
1049 (x-drawable-y window
) ny
1050 (x-drawable-width window
) nw
1051 (x-drawable-height window
) nh
)))
1055 (defmethod adapt-child-to-parent ((frame frame
) parent
)
1056 (declare (ignore parent
))
1057 (with-slots (rx ry rw rh window
) frame
1059 (when (or (/= (x-drawable-x window
) rx
)
1060 (/= (x-drawable-y window
) ry
))
1061 (setf change
:moved
))
1062 (when (or (/= (x-drawable-width window
) rw
)
1063 (/= (x-drawable-height window
) rh
))
1064 (setf change
:resized
))
1066 (xlib:with-state
(window)
1067 (setf (x-drawable-x window
) rx
1068 (x-drawable-y window
) ry
1069 (x-drawable-width window
) rw
1070 (x-drawable-height window
) rh
)))
1073 (defmethod adapt-child-to-parent (child parent
)
1074 (declare (ignore child parent
))
1078 (defgeneric set-child-stack-order
(window child
)
1079 (:documentation
"Put window just below child"))
1081 (defmethod set-child-stack-order (window (child xlib
:window
))
1082 (lower-window window child
))
1084 (defmethod set-child-stack-order (window (child frame
))
1085 (lower-window window
(frame-window child
)))
1087 (defmethod set-child-stack-order (window child
)
1088 (declare (ignore child
))
1089 (unless (maxmin-size-equal-window-in-tree)
1090 (raise-window window
)))
1094 (defgeneric show-child
(child parent previous
))
1096 (defmethod show-child ((frame frame
) parent previous
)
1097 (declare (ignore parent
))
1098 (with-slots (window show-window-p
) frame
1099 (if (and show-window-p
1100 (or *show-root-frame-p
* (not (child-root-p frame
))))
1103 (set-child-stack-order window previous
)
1104 (display-frame-info frame
))
1105 (hide-window window
))))
1109 (defun hide-unmanaged-window-p (parent)
1110 (let ((action (frame-data-slot parent
:unmanaged-window-action
)))
1114 (t *hide-unmanaged-window
*))))
1117 (defmethod show-child ((window xlib
:window
) parent previous
)
1118 (if (or (managed-window-p window parent
)
1119 (child-equal-p window
(current-child))
1120 (not (hide-unmanaged-window-p parent
))
1121 (child-is-a-current-child-p parent
))
1124 (set-child-stack-order window previous
))
1125 (hide-window window
)))
1127 (defmethod show-child (child parent raise-p
)
1128 (declare (ignore child parent raise-p
))
1132 (defgeneric hide-child
(child))
1134 (defmethod hide-child ((frame frame
))
1135 (with-slots (window) frame
1136 (xlib:unmap-window window
)))
1138 (defmethod hide-child ((window xlib
:window
))
1139 (hide-window window
))
1141 (defmethod hide-child (child)
1142 (declare (ignore child
))
1146 (defgeneric select-child
(child selected
))
1148 (labels ((get-selected-color (child selected-p
)
1149 (get-color (cond ((child-equal-p child
(current-child)) *color-selected
*)
1150 (selected-p *color-maybe-selected
*)
1151 (t *color-unselected
*)))))
1152 (defmethod select-child ((frame frame
) selected-p
)
1153 (when (and (frame-p frame
) (frame-window frame
))
1154 (setf (xlib:window-border
(frame-window frame
))
1155 (get-selected-color frame selected-p
))))
1157 (defmethod select-child ((window xlib
:window
) selected-p
)
1158 (setf (xlib:window-border window
)
1159 (get-selected-color window selected-p
)))
1161 (defmethod select-child (child selected
)
1162 (declare (ignore child selected
))
1165 (defun select-current-frame (selected)
1166 (select-child (current-child) selected
))
1168 (defun unselect-all-frames ()
1169 (with-all-children (*root-frame
* child
)
1170 (select-child child nil
)))
1174 (defun set-focus-to-current-child ()
1175 (labels ((rec (child)
1177 (xlib:window
(focus-window child
))
1178 (frame (rec (frame-selected-child child
))))))
1180 (rec (current-child))))
1185 (defun adapt-frame-to-parent (frame parent
)
1186 (multiple-value-bind (nx ny nw nh
)
1187 (get-parent-layout frame parent
)
1188 (with-slots (rx ry rw rh window
) frame
1194 (defun adapt-child-to-rect (rect)
1195 (let ((window (typecase (child-rect-child rect
)
1196 (xlib:window
(when (managed-window-p (child-rect-child rect
) (child-rect-parent rect
))
1197 (child-rect-child rect
)))
1198 (frame (frame-window (child-rect-child rect
))))))
1200 (let ((change (or (/= (x-drawable-x window
) (child-rect-x rect
))
1201 (/= (x-drawable-y window
) (child-rect-y rect
))
1202 (/= (x-drawable-width window
) (child-rect-w rect
))
1203 (/= (x-drawable-height window
) (child-rect-h rect
)))))
1205 (setf (x-drawable-width window
) (child-rect-w rect
)
1206 (x-drawable-height window
) (child-rect-h rect
)
1207 (x-drawable-x window
) (child-rect-x rect
)
1208 (x-drawable-y window
) (child-rect-y rect
)))
1213 (let ((displayed-child nil
))
1214 (defun get-displayed-child ()
1217 (defun show-all-children (&optional
(from-root-frame nil
))
1218 "Show all children and hide those not in a root frame"
1219 (declare (ignore from-root-frame
))
1220 (let ((geometry-change nil
)
1222 (has-no-leader-list nil
))
1223 (labels ((set-has-no-leader-list ()
1224 (let ((window-list nil
)
1226 (with-all-windows (*root-frame
* win
)
1227 (let ((leader (window-leader win
)))
1229 (when (member leader window-list
:test
(lambda (x y
) (eql x
(first y
))))
1230 (pushnew leader leader-list
))
1231 (push (list leader win
) window-list
))))
1232 (dolist (leader-win window-list
)
1233 (unless (member leader-win leader-list
:test
(lambda (x y
) (eql (first x
) y
)))
1234 (push (second leader-win
) has-no-leader-list
)))))
1236 (in-displayed-list (child)
1237 (member child displayed-child
:test
(lambda (c rect
)
1238 (child-equal-p c
(child-rect-child rect
)))))
1240 (add-in-hidden-list (child)
1241 (pushnew child hidden-child
:test
#'child-equal-p
))
1243 (set-geometry (child parent in-current-root child-current-root-p
)
1244 (if (or in-current-root child-current-root-p
)
1245 (when (frame-p child
)
1246 (adapt-frame-to-parent child
(if child-current-root-p nil parent
)))
1247 (add-in-hidden-list child
)))
1249 (recurse-on-frame-child (child in-current-root child-current-root-p selected-p
)
1250 (let ((selected-child (frame-selected-child child
)))
1251 (dolist (sub-child (frame-child child
))
1252 (rec sub-child child
1253 (and selected-p
(child-equal-p sub-child selected-child
))
1254 (or in-current-root child-current-root-p
)))))
1256 (hidden-child-p (rect)
1257 (when (or (frame-p (child-rect-child rect
))
1258 (member (window-type (child-rect-child rect
)) *show-hide-policy-type
*))
1259 (dolist (r displayed-child
)
1260 (when (and (rect-hidden-p r rect
)
1261 (or (not (xlib:window-p
(child-rect-child r
)))
1262 (eq (window-type (child-rect-child r
)) :normal
)))
1265 (select-and-display (child parent selected-p
)
1266 (multiple-value-bind (nx ny nw nh
)
1267 (get-parent-layout child parent
)
1268 (let ((rect (make-child-rect :child child
:parent parent
1269 :selected-p selected-p
1270 :x nx
:y ny
:w nw
:h nh
)))
1271 (if (and *show-hide-policy
* (hidden-child-p rect
)
1272 (member child has-no-leader-list
:test
#'child-equal-p
))
1273 (add-in-hidden-list child
)
1274 (push rect displayed-child
)))))
1276 (display-displayed-child ()
1277 (let ((previous nil
))
1278 (setf displayed-child
(nreverse displayed-child
))
1279 (dolist (rect displayed-child
)
1280 (when (adapt-child-to-rect rect
)
1281 (setf geometry-change t
))
1282 (select-child (child-rect-child rect
) (child-rect-selected-p rect
))
1283 (show-child (child-rect-child rect
)
1284 (child-rect-parent rect
)
1286 (setf previous
(child-rect-child rect
)))))
1288 (rec (child parent selected-p in-current-root
)
1289 (let ((child-current-root-p (child-root-p child
)))
1290 (unless (in-displayed-list child
)
1291 (set-geometry child parent in-current-root child-current-root-p
))
1292 (when (frame-p child
)
1293 (recurse-on-frame-child child in-current-root child-current-root-p selected-p
))
1294 (when (and (or in-current-root child-current-root-p
)
1295 (not (in-displayed-list child
)))
1296 (select-and-display child parent selected-p
)))))
1298 (setf displayed-child nil
)
1299 (set-has-no-leader-list)
1300 (rec *root-frame
* nil t
(child-root-p *root-frame
*))
1301 (display-displayed-child)
1302 (dolist (child hidden-child
)
1304 (set-focus-to-current-child)
1305 (xlib:display-finish-output
*display
*)
1311 (defun hide-all-children (root &optional except
)
1312 "Hide all root children"
1313 (when (and (frame-p root
) (not (child-equal-p root except
)))
1314 (dolist (child (frame-child root
))
1315 (hide-all child except
))))
1317 (defun hide-all (root &optional except
)
1318 "Hide root and all its children"
1319 (unless (child-equal-p root except
)
1321 (hide-all-children root except
))
1327 (defun focus-child (child parent
)
1328 "Focus child - Return true if something has change"
1329 (when (and (frame-p parent
)
1330 (child-member child
(frame-child parent
)))
1331 (when (not (child-equal-p child
(frame-selected-child parent
)))
1332 (with-slots ((parent-child child
) selected-pos
) parent
1333 (setf parent-child
(nth-insert selected-pos child
(child-remove child parent-child
))))
1336 (defun focus-child-rec (child parent
)
1337 "Focus child and its parents - Return true if something has change"
1339 (labels ((rec (child parent
)
1340 (when (focus-child child parent
)
1343 (rec parent
(find-parent-frame parent
)))))
1348 (defun set-current-child-generic (child)
1349 (unless (child-equal-p (current-child) child
)
1350 (setf (current-child) child
)
1353 (defgeneric set-current-child
(child parent window-parent
))
1355 (defmethod set-current-child ((child xlib
:window
) parent window-parent
)
1356 (set-current-child-generic (if window-parent parent child
)))
1358 (defmethod set-current-child ((child frame
) parent window-parent
)
1359 (declare (ignore parent window-parent
))
1360 (set-current-child-generic child
))
1362 (defmethod set-current-child (child parent window-parent
)
1363 (declare (ignore child parent window-parent
))
1367 (defun set-current-root (child parent window-parent
)
1368 "Set current root if parent is not in current root"
1369 (let ((root (find-root child
)))
1370 (when (and root window-parent
1371 (not (child-root-p child
))
1372 (not (find-child parent
(root-child root
))))
1373 (change-root root parent
)
1376 (defun focus-all-children (child parent
&optional
(window-parent t
))
1377 "Focus child and its parents -
1378 For window: set current child to window or its parent according to window-parent"
1379 (let ((new-focus (focus-child-rec child parent
))
1380 (new-current-child (set-current-child child parent window-parent
))
1381 (new-root (set-current-root child parent window-parent
)))
1382 (or new-focus new-current-child new-root
)))
1387 (defun select-next-level ()
1388 "Select the next level in frame"
1389 (select-current-frame :maybe
)
1390 (when (frame-p (current-child))
1391 (awhen (frame-selected-child (current-child))
1392 (setf (current-child) it
)))
1393 (show-all-children))
1395 (defun select-previous-level ()
1396 "Select the previous level in frame"
1397 (unless (child-root-p (current-child))
1398 (select-current-frame :maybe
)
1399 (awhen (find-parent-frame (current-child))
1400 (setf (current-child) it
))
1401 (show-all-children)))
1404 (defun enter-frame ()
1405 "Enter in the selected frame - ie make it the root frame"
1406 (let ((root (find-root (current-child))))
1407 (when (and root
(not (child-equal-p (root-child root
) (current-child))))
1408 (change-root root
(current-child)))
1409 (show-all-children t
)))
1411 (defun leave-frame ()
1412 "Leave the selected frame - ie make its parent the root frame"
1413 (let ((root (find-root (current-child))))
1414 (unless (or (child-equal-p (root-child root
) *root-frame
*)
1415 (child-original-root-p (root-child root
)))
1416 (awhen (and root
(find-parent-frame (root-child root
)))
1418 (change-root root it
)))
1419 (show-all-children))))
1422 ;;; Other actions (select-next-child, select-next-brother...) are in
1423 ;;; clfswm-circulate-mode.lisp
1427 (defun frame-lower-child ()
1428 "Lower the child in the current frame"
1429 (when (frame-p (current-child))
1430 (with-slots (child selected-pos
) (current-child)
1431 (unless (>= selected-pos
(length child
))
1432 (when (nth (1+ selected-pos
) child
)
1433 (rotatef (nth selected-pos child
)
1434 (nth (1+ selected-pos
) child
)))
1435 (incf selected-pos
)))
1436 (show-all-children)))
1439 (defun frame-raise-child ()
1440 "Raise the child in the current frame"
1441 (when (frame-p (current-child))
1442 (with-slots (child selected-pos
) (current-child)
1443 (unless (< selected-pos
1)
1444 (when (nth (1- selected-pos
) child
)
1445 (rotatef (nth selected-pos child
)
1446 (nth (1- selected-pos
) child
)))
1447 (decf selected-pos
)))
1448 (show-all-children)))
1451 (defun frame-select-next-child ()
1452 "Select the next child in the current frame"
1453 (when (frame-p (current-child))
1454 (with-slots (child selected-pos
) (current-child)
1455 (setf selected-pos
(mod (1+ selected-pos
) (max (length child
) 1))))
1456 (show-all-children)))
1459 (defun frame-select-previous-child ()
1460 "Select the previous child in the current frame"
1461 (when (frame-p (current-child))
1462 (with-slots (child selected-pos
) (current-child)
1463 (setf selected-pos
(mod (1- selected-pos
) (max (length child
) 1))))
1464 (show-all-children)))
1468 (defun switch-to-root-frame (&key
(show-later nil
))
1469 "Switch to the root frame"
1470 (let ((root (find-root (current-child))))
1472 (change-root root
(root-original root
)))
1474 (show-all-children t
))))
1476 (defun switch-and-select-root-frame (&key
(show-later nil
))
1477 "Switch and select the root frame"
1478 (let ((root (find-root (current-child))))
1480 (change-root root
(root-original root
))
1481 (setf (current-child) (root-original root
)))
1483 (show-all-children t
))))
1486 (defun toggle-show-root-frame ()
1487 "Show/Hide the root frame"
1488 (setf *show-root-frame-p
* (not *show-root-frame-p
*))
1489 (show-all-children))
1493 (defun move-child-to (child frame-dest
)
1494 (when (and child
(frame-p frame-dest
))
1495 (remove-child-in-frame child
(find-parent-frame child
))
1496 (pushnew child
(frame-child frame-dest
) :test
#'child-equal-p
)
1497 (focus-all-children child frame-dest
)
1498 (show-all-children t
)))
1501 (defun prevent-current-*-equal-child
(child)
1502 " Prevent current-root and current-child equal to child"
1503 (if (child-original-root-p child
)
1506 (awhen (child-root-p child
)
1507 (change-root it
(find-parent-frame child
)))
1508 (when (child-equal-p child
(current-child))
1509 (awhen (find-root child
)
1510 (setf (current-child) (root-child it
))))
1515 (defun remove-child-in-frame (child frame
)
1516 "Remove the child in frame"
1517 (when (frame-p frame
)
1518 (setf (frame-child frame
) (child-remove child
(frame-child frame
)))))
1520 (defun remove-child-in-frames (child root
)
1521 "Remove child in the frame root and in all its children"
1522 (with-all-frames (root frame
)
1523 (remove-child-in-frame child frame
)))
1526 (defun remove-child-in-all-frames (child)
1527 "Remove child in all frames from *root-frame*"
1528 (when (prevent-current-*-equal-child child
)
1529 (remove-child-in-frames child
*root-frame
*)))
1532 (defun delete-child-in-frames (child root
&optional
(close-methode 'delete-window
))
1533 "Delete child in the frame root and in all its children
1534 Warning:frame window and gc are freeed."
1535 (with-all-frames (root frame
)
1536 (remove-child-in-frame child frame
)
1537 (unless (find-frame-window (frame-window frame
))
1538 (awhen (frame-gc frame
) (xlib:free-gcontext it
) (setf it nil
))
1539 (awhen (frame-window frame
) (xlib:destroy-window it
) (setf it nil
))))
1540 (when (xlib:window-p child
)
1541 (funcall close-methode child
)
1542 (netwm-remove-in-client-list child
)))
1546 (defun delete-child-in-all-frames (child &optional
(close-methode 'delete-window
))
1547 "Delete child in all frames from *root-frame*"
1548 (when (prevent-current-*-equal-child child
)
1549 (delete-child-in-frames child
*root-frame
* close-methode
)))
1551 (defun delete-child-and-children-in-frames (child root
&optional
(close-methode 'delete-window
))
1552 "Delete child and its children in the frame root and in all its children
1553 Warning:frame window and gc are freeed."
1554 (when (and (frame-p child
) (frame-child child
))
1555 (dolist (ch (frame-child child
))
1556 (delete-child-and-children-in-frames ch root close-methode
)))
1557 (delete-child-in-frames child root close-methode
))
1559 (defun delete-child-and-children-in-all-frames (child &optional
(close-methode 'delete-window
))
1560 "Delete child and its children in all frames from *root-frame*"
1561 (when (prevent-current-*-equal-child child
)
1562 (when (frame-p child
)
1563 (delete-child-and-children-in-frames child
*root-frame
* close-methode
))
1564 (when (xlib:window-p child
)
1565 (funcall close-methode child
))))
1568 (defun clean-windows-in-all-frames ()
1569 "Remove all xlib:windows present in *root-frame* and not in the xlib tree"
1570 (let ((x-tree (xlib:query-tree
*root
*)))
1571 (with-all-frames (*root-frame
* frame
)
1572 (dolist (child (frame-child frame
))
1573 (when (xlib:window-p child
)
1574 (unless (member child x-tree
:test
#'xlib
:window-equal
)
1575 (when (prevent-current-*-equal-child child
)
1576 (setf (frame-child frame
)
1577 (child-remove child
(frame-child frame
))))))))))
1581 (defun do-all-frames-nw-hook (window)
1582 "Call nw-hook of each frame."
1583 (catch 'nw-hook-loop
1585 (with-all-frames (*root-frame
* frame
)
1586 (awhen (frame-nw-hook frame
)
1587 (setf found
(call-hook it frame window
))))
1592 (defun process-new-window (window)
1593 "When a new window is created (or when we are scanning initial
1594 windows), this function dresses the window up and gets it ready to be
1596 (setf (xlib:window-event-mask window
) *window-events
*)
1597 (set-window-state window
+normal-state
+)
1598 (setf (x-drawable-border-width window
) (case (window-type window
)
1599 (:normal
*border-size
*)
1601 (:transient
*border-size
*)
1602 (:dialog
*border-size
*)
1604 (grab-all-buttons window
)
1605 (unless (never-managed-window-p window
)
1606 (unless (do-all-frames-nw-hook window
)
1607 (call-hook *default-nw-hook
* *root-frame
* window
)))
1608 (netwm-add-in-client-list window
))
1613 (defun with-all-mapped-windows (screen fun
)
1614 (let ((all-windows (get-all-windows)))
1615 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1616 (unless (child-member win all-windows
)
1617 (let ((map-state (xlib:window-map-state win
))
1618 (wm-state (window-state win
)))
1619 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1620 (eql win
*no-focus-window
*)
1621 (is-notify-window-p win
))
1622 (when (or (eql map-state
:viewable
)
1623 (eql wm-state
+iconic-state
+))
1624 (funcall fun win
))))))))
1626 (defun store-root-background ()
1627 (with-all-mapped-windows *screen
* #'hide-window
)
1628 (setf *background-image
* (xlib:create-pixmap
:width
(xlib:screen-width
*screen
*)
1629 :height
(xlib:screen-height
*screen
*)
1630 :depth
(xlib:screen-root-depth
*screen
*)
1632 *background-gc
* (xlib:create-gcontext
:drawable
*background-image
*
1633 :foreground
(get-color *frame-foreground
*)
1634 :background
(get-color *frame-background
*)
1635 :font
*default-font
*
1636 :line-style
:solid
))
1637 (xlib:copy-area
*root
* *background-gc
*
1638 0 0 (xlib:screen-width
*screen
*) (xlib:screen-height
*screen
*)
1639 *background-image
* 0 0)
1640 (with-all-mapped-windows *screen
* #'unhide-window
))
1645 (defun hide-existing-windows (screen)
1646 "Hide all existing windows in screen"
1647 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1652 (defun process-existing-windows (screen)
1653 "Windows present when clfswm starts up must be absorbed by clfswm."
1654 (setf *in-process-existing-windows
* t
)
1656 (all-windows (get-all-windows))
1657 (all-frame-windows (get-all-frame-windows)))
1658 (dolist (win (xlib:query-tree
(xlib:screen-root screen
)))
1659 (unless (or (child-member win all-windows
)
1660 (child-member win all-frame-windows
))
1661 (let ((map-state (xlib:window-map-state win
))
1662 (wm-state (window-state win
)))
1663 (unless (or (eql (xlib:window-override-redirect win
) :on
)
1664 (eql win
*no-focus-window
*)
1665 (is-notify-window-p win
)
1666 (never-managed-window-p win
))
1667 (when (or (eql map-state
:viewable
)
1668 (eql wm-state
+iconic-state
+))
1669 (format t
"Processing ~S: type=~A ~S~%" (xlib:wm-name win
) (window-type win
) win
)
1671 (process-new-window win
)
1674 (pushnew (xlib:window-id win
) id-list
))))))
1675 (netwm-set-client-list id-list
))
1676 (setf *in-process-existing-windows
* nil
))
1679 ;;; Child order manipulation functions
1680 (defun put-child-on-top (child parent
)
1681 "Put the child on top of its parent children"
1682 (when (frame-p parent
)
1683 (setf (frame-child parent
) (cons child
(child-remove child
(frame-child parent
)))
1684 (frame-selected-pos parent
) 0)))
1686 (defun put-child-on-bottom (child parent
)
1687 "Put the child at the bottom of its parent children"
1688 (when (frame-p parent
)
1689 (setf (frame-child parent
) (append (child-remove child
(frame-child parent
)) (list child
))
1690 (frame-selected-pos parent
) 0)))
1693 (let ((last-child nil
))
1694 (defun manage-focus (window root-x root-y
)
1695 (case (if (frame-p (current-child))
1696 (frame-focus-policy (current-child))
1697 *default-focus-policy
*)
1698 (:sloppy
(focus-window window
))
1699 (:sloppy-strict
(when (and (frame-p (current-child))
1700 (child-member window
(frame-child (current-child))))
1701 (focus-window window
)))
1702 (:sloppy-select
(let* ((child (find-child-under-mouse root-x root-y
))
1703 (parent (find-parent-frame child
)))
1704 (unless (or (child-root-p child
)
1705 (child-equal-p (typecase child
1706 (xlib:window parent
)
1709 (focus-all-children child parent
)
1710 (show-all-children))))
1711 (:sloppy-select-window
(let* ((child (find-child-under-mouse root-x root-y
))
1712 (parent (find-parent-frame child
))
1713 (need-warp-pointer (not (or (frame-p child
)
1714 (child-equal-p child
(frame-selected-child parent
))))))
1715 (unless (or (child-root-p child
)
1716 (child-equal-p child last-child
))
1717 (setf last-child child
)
1718 (when (focus-all-children child parent
)
1720 (when (and need-warp-pointer
1721 (not (eql (frame-data-slot (current-child) :tile-layout-keep-position
)
1724 (xlib:window
(xlib:warp-pointer
*root
*
1725 (truncate (+ (x-drawable-x child
)
1726 (/ (x-drawable-width child
) 2)))
1727 (truncate (+ (x-drawable-y child
)
1728 (/ (x-drawable-height child
) 2)))))
1729 (frame (xlib:warp-pointer
*root
*
1730 (+ (frame-rx child
) 10)
1731 (+ (frame-ry child
) 10))))))))))))