1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Placement functions
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2011 Philippe Brochard <hocwp@free.fr>
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ;;; --------------------------------------------------------------------------
28 (defun get-placement-values (placement &optional
(width 0) (height 0))
30 (list (values (first placement
)
32 (function (funcall placement width height
))
34 (if (fboundp placement
)
35 (funcall placement width height
)
39 (defmacro with-placement
((placement x y
&optional
(width 0) (height 0)) &body body
)
40 `(multiple-value-bind (,x
,y
)
41 (get-placement-values ,placement
,width
,height
)
46 ;;(defun fun-placement (&optional width height)
47 ;; (declare (ignore width height))
50 ;;(defparameter *placement-test* (list 10 20))
51 ;;;;(defparameter *placement-test* #'fun-placement)
52 ;;;;(defparameter *placement-test* 'fun-placement)
55 ;; (with-placement (*placement-test* x y)
56 ;; (format t "X=~A Y=~A~%" x y)))
59 ;;; Absolute placement
61 (defun top-left-placement (&optional
(width 0) (height 0))
62 (declare (ignore width height
))
65 (defun top-middle-placement (&optional
(width 0) (height 0))
66 (declare (ignore height
))
67 (values (truncate (/ (- (xlib:screen-width
*screen
*) width
) 2))
70 (defun top-right-placement (&optional
(width 0) (height 0))
71 (declare (ignore height
))
72 (values (- (xlib:screen-width
*screen
*) width
(* *border-size
* 2))
77 (defun middle-left-placement (&optional
(width 0) (height 0))
78 (declare (ignore width
))
80 (truncate (/ (- (xlib:screen-height
*screen
*) height
) 2))))
82 (defun middle-middle-placement (&optional
(width 0) (height 0))
83 (values (truncate (/ (- (xlib:screen-width
*screen
*) width
) 2))
84 (truncate (/ (- (xlib:screen-height
*screen
*) height
) 2))))
86 (defun middle-right-placement (&optional
(width 0) (height 0))
87 (values (- (xlib:screen-width
*screen
*) width
(* *border-size
* 2))
88 (truncate (/ (- (xlib:screen-height
*screen
*) height
) 2))))
91 (defun bottom-left-placement (&optional
(width 0) (height 0))
92 (declare (ignore width
))
94 (- (xlib:screen-height
*screen
*) height
(* *border-size
* 2))))
96 (defun bottom-middle-placement (&optional
(width 0) (height 0))
97 (values (truncate (/ (- (xlib:screen-width
*screen
*) width
) 2))
98 (- (xlib:screen-height
*screen
*) height
(* *border-size
* 2))))
100 (defun bottom-right-placement (&optional
(width 0) (height 0))
101 (values (- (xlib:screen-width
*screen
*) width
(* *border-size
* 2))
102 (- (xlib:screen-height
*screen
*) height
(* *border-size
* 2))))
106 ;;; Current child placement
108 (defun current-child-coord ()
109 (typecase *current-child
*
110 (xlib:window
(values (xlib:drawable-x
*current-child
*)
111 (xlib:drawable-y
*current-child
*)
112 (xlib:drawable-width
*current-child
*)
113 (xlib:drawable-height
*current-child
*)))
114 (frame (values (frame-rx *current-child
*)
115 (frame-ry *current-child
*)
116 (frame-rw *current-child
*)
117 (frame-rh *current-child
*)))
118 (t (values 0 0 10 10))))
120 (defmacro with-current-child-coord
((x y w h
) &body body
)
121 `(multiple-value-bind (,x
,y
,w
,h
)
122 (current-child-coord)
126 (defun top-left-child-placement (&optional
(width 0) (height 0))
127 (declare (ignore width height
))
128 (with-current-child-coord (x y w h
)
129 (declare (ignore w h
))
133 (defun top-middle-child-placement (&optional
(width 0) (height 0))
134 (declare (ignore height
))
135 (with-current-child-coord (x y w h
)
137 (values (+ x
(truncate (/ (- w width
) 2)))
140 (defun top-right-child-placement (&optional
(width 0) (height 0))
141 (declare (ignore height
))
142 (with-current-child-coord (x y w h
)
144 (values (+ x
(- w width
2))
149 (defun middle-left-child-placement (&optional
(width 0) (height 0))
150 (declare (ignore width
))
151 (with-current-child-coord (x y w h
)
154 (+ y
(truncate (/ (- h height
) 2))))))
156 (defun middle-middle-child-placement (&optional
(width 0) (height 0))
157 (with-current-child-coord (x y w h
)
158 (values (+ x
(truncate (/ (- w width
) 2)))
159 (+ y
(truncate (/ (- h height
) 2))))))
161 (defun middle-right-child-placement (&optional
(width 0) (height 0))
162 (with-current-child-coord (x y w h
)
163 (values (+ x
(- w width
2))
164 (+ y
(truncate (/ (- h height
) 2))))))
167 (defun bottom-left-child-placement (&optional
(width 0) (height 0))
168 (declare (ignore width
))
169 (with-current-child-coord (x y w h
)
172 (+ y
(- h height
2)))))
174 (defun bottom-middle-child-placement (&optional
(width 0) (height 0))
175 (with-current-child-coord (x y w h
)
176 (values (+ x
(truncate (/ (- w width
) 2)))
177 (+ y
(- h height
2)))))
179 (defun bottom-right-child-placement (&optional
(width 0) (height 0))
180 (with-current-child-coord (x y w h
)
181 (values (+ x
(- w width
2))
182 (+ y
(- h height
2)))))