1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Utility
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 ;;; --------------------------------------------------------------------------
29 ;;; Configuration file
30 (defun xdg-config-home ()
31 (aif (getenv "XDG_CONFIG_HOME")
32 (pathname-directory (concatenate 'string it
"/"))
33 (append (pathname-directory (user-homedir-pathname)) '(".config"))))
36 (let ((saved-conf-name nil
))
37 (defun conf-file-name (&optional alternate-name
)
38 (unless (and saved-conf-name
(not alternate-name
))
39 (let* ((user-conf (probe-file (merge-pathnames (user-homedir-pathname) #p
".clfswmrc")))
40 (etc-conf (probe-file #p
"/etc/clfswmrc"))
41 (config-user-conf (probe-file (make-pathname :directory
(append (xdg-config-home) '("clfswm"))
43 (alternate-conf (and alternate-name
(probe-file alternate-name
))))
44 (setf saved-conf-name
(or alternate-conf config-user-conf user-conf etc-conf
))))
45 (print saved-conf-name
)
51 (defun load-contrib (file)
52 "Load a file in the contrib directory"
53 (let ((truename (merge-pathnames file
*contrib-dir
*)))
54 (format t
"Loading contribution file: ~A~%" truename
)
55 (when (probe-file truename
)
56 (load truename
:verbose nil
))))
59 (defun reload-clfswm ()
61 (format t
"~&-*- Reloading CLFSWM -*-~%")
62 (asdf:oos
'asdf
:load-op
:clfswm
)
67 (defun query-yes-or-no (formatter &rest args
)
68 (let ((rep (query-string (apply #'format nil formatter args
) "" '("Yes" "No"))))
70 (char= (char rep
0) #\y
)
71 (char= (char rep
0) #\Y
))))
75 (defun banish-pointer ()
76 "Move the pointer to the lower right corner of the screen"
77 (with-placement (*banish-pointer-placement
* x y
)
78 (xlib:warp-pointer
*root
* x y
)))
83 ;;; Root functions utility
84 (defun show-current-root ()
85 (when *have-to-show-current-root
*
86 (let ((*notify-window-placement
* *show-current-root-placement
*))
87 (notify-message *show-current-root-delay
* *show-current-root-message
*))))
89 (defun select-generic-root (fun restart-menu
)
91 (let* ((current-root (find-root (current-child)))
92 (parent (find-parent-frame (root-original current-root
))))
94 (setf (frame-child parent
) (funcall fun
(frame-child parent
)))
95 (let ((new-root (find-root (frame-selected-child parent
))))
96 (setf (current-child) (aif (root-current-child new-root
)
98 (frame-selected-child parent
))))))
102 (open-menu (find-menu 'root-menu
))
103 (leave-second-mode)))
105 (defun select-next-root ()
106 "Select the next root"
107 (select-generic-root #'rotate-list nil
))
109 (defun select-previous-root ()
110 "Select the previous root"
111 (select-generic-root #'anti-rotate-list nil
))
114 (defun select-next-root-restart-menu ()
115 "Select the next root"
116 (select-generic-root #'rotate-list t
))
118 (defun select-previous-root-restart-menu ()
119 "Select the previous root"
120 (select-generic-root #'anti-rotate-list t
))
123 (defun rotate-root-geometry-generic (fun restart-menu
)
126 (show-all-children t
)
129 (open-menu (find-menu 'root-menu
))
130 (leave-second-mode)))
133 (defun rotate-root-geometry-next ()
134 "Rotate root geometry to next root"
135 (rotate-root-geometry-generic #'rotate-root-geometry nil
))
137 (defun rotate-root-geometry-previous ()
138 "Rotate root geometry to previous root"
139 (rotate-root-geometry-generic #'anti-rotate-root-geometry nil
))
141 (defun rotate-root-geometry-next-restart-menu ()
142 "Rotate root geometry to next root"
143 (rotate-root-geometry-generic #'rotate-root-geometry t
))
145 (defun rotate-root-geometry-previous-restart-menu ()
146 "Rotate root geometry to previous root"
147 (rotate-root-geometry-generic #'anti-rotate-root-geometry t
))
151 (defun exchange-root-geometry-with-mouse ()
152 "Exchange two root geometry pointed with the mouse"
153 (open-notify-window '("Select the first root to exchange"))
154 (wait-no-key-or-button-press)
155 (wait-mouse-button-release)
156 (close-notify-window)
157 (multiple-value-bind (x1 y1
) (xlib:query-pointer
*root
*)
158 (open-notify-window '("Select the second root to exchange"))
159 (wait-no-key-or-button-press)
160 (wait-mouse-button-release)
161 (close-notify-window)
162 (multiple-value-bind (x2 y2
) (xlib:query-pointer
*root
*)
163 (exchange-root-geometry (find-root-by-coordinates x1 y1
)
164 (find-root-by-coordinates x2 y2
))))
169 (defun change-current-root-geometry ()
170 "Change the current root geometry"
171 (let* ((root (find-root (current-child)))
172 (x (query-number "New root X position" (root-x root
)))
173 (y (query-number "New root Y position" (root-y root
)))
174 (w (query-number "New root width" (root-w root
)))
175 (h (query-number "New root height" (root-h root
))))
176 (setf (root-x root
) x
(root-y root
) y
177 (root-w root
) w
(root-h root
) h
)
180 (leave-second-mode)))
184 (defun display-all-frame-info ()
185 (with-all-frames (*root-frame
* frame
)
186 (display-frame-info frame
)))
188 (defun display-all-root-frame-info ()
189 (with-all-root-child (root)
190 (display-frame-info root
)))
194 (defun place-window-from-hints (window)
195 "Place a window from its hints"
196 (let* ((hints (xlib:wm-normal-hints window
))
197 (min-width (or (and hints
(xlib:wm-size-hints-min-width hints
)) 0))
198 (min-height (or (and hints
(xlib:wm-size-hints-min-height hints
)) 0))
199 (max-width (or (and hints
(xlib:wm-size-hints-max-width hints
)) (x-drawable-width *root
*)))
200 (max-height (or (and hints
(xlib:wm-size-hints-max-height hints
)) (x-drawable-height *root
*)))
201 (rwidth (or (and hints
(or (xlib:wm-size-hints-width hints
) (xlib:wm-size-hints-base-width hints
)))
202 (x-drawable-width window
)))
203 (rheight (or (and hints
(or (xlib:wm-size-hints-height hints
) (xlib:wm-size-hints-base-height hints
)))
204 (x-drawable-height window
))))
205 (setf (x-drawable-width window
) (min (max min-width rwidth
*default-window-width
*) max-width
)
206 (x-drawable-height window
) (min (max min-height rheight
*default-window-height
*) max-height
))
207 (with-placement (*unmanaged-window-placement
* x y
(x-drawable-width window
) (x-drawable-height window
))
208 (setf (x-drawable-x window
) x
209 (x-drawable-y window
) y
))
210 (xlib:display-finish-output
*display
*)))
213 (defun rename-current-child ()
214 "Rename the current child"
215 (let ((name (query-string (format nil
"New child name: (last: ~A)" (child-name (current-child)))
216 (child-name (current-child)))))
217 (rename-child (current-child) name
)
218 (leave-second-mode)))
221 (defun ask-child-transparency (msg child
)
222 (let ((trans (query-number (format nil
"New ~A transparency: (last: ~A)"
224 (* 100 (child-transparency child
)))
225 (* 100 (child-transparency child
)))))
226 (when (numberp trans
)
227 (setf (child-transparency child
) (float (/ trans
100))))))
229 (defun set-current-child-transparency ()
230 "Set the current child transparency"
231 (ask-child-transparency "child" (current-child))
235 (defun ask-child-border-size (msg child
)
236 (let ((size (query-number (format nil
"New ~A border size: (last: ~A)"
238 (child-border-size child
))
239 (child-border-size child
))))
241 (setf (child-border-size child
) size
))))
244 (defun set-current-child-border-size ()
245 "Set the current child border size"
246 (ask-child-border-size "child" (current-child))
250 (defun renumber-current-frame ()
251 "Renumber the current frame"
252 (when (frame-p (current-child))
253 (let ((number (query-number (format nil
"New child number: (last: ~A)" (frame-number (current-child)))
254 (frame-number (current-child)))))
255 (setf (frame-number (current-child)) number
)
256 (leave-second-mode))))
261 (defun add-default-frame ()
262 "Add a default frame in the current frame"
263 (when (frame-p (current-child))
264 (let ((name (query-string "Frame name")))
265 (push (create-frame :name name
) (frame-child (current-child)))))
268 (defun add-frame-in-parent-frame ()
269 "Add a frame in the parent frame (and reorganize parent frame)"
270 (let ((parent (find-parent-frame (current-child))))
271 (when (and parent
(not (child-original-root-p (current-child))))
272 (let ((new-frame (create-frame)))
273 (pushnew new-frame
(frame-child parent
))
274 (awhen (child-root-p (current-child))
275 (change-root it parent
))
276 (setf (current-child) parent
)
277 (set-layout-once #'tile-space-layout
)
278 (setf (current-child) new-frame
)
279 (leave-second-mode)))))
284 (defun add-placed-frame ()
285 "Add a placed frame in the current frame"
286 (when (frame-p (current-child))
287 (let ((name (query-string "Frame name"))
288 (x (/ (query-number "Frame x in percent (%)") 100))
289 (y (/ (query-number "Frame y in percent (%)") 100))
290 (w (/ (query-number "Frame width in percent (%)" 100) 100))
291 (h (/ (query-number "Frame height in percent (%)" 100) 100)))
292 (push (create-frame :name name
:x x
:y y
:w w
:h h
)
293 (frame-child (current-child)))))
298 (defun delete-focus-window-generic (close-fun)
299 (with-focus-window (window)
300 (when (child-equal-p window
(current-child))
301 (setf (current-child) (find-current-root)))
302 (delete-child-and-children-in-all-frames window close-fun
)))
304 (defun delete-focus-window ()
305 "Close focus window: Delete the focus window in all frames and workspaces"
306 (delete-focus-window-generic 'delete-window
))
308 (defun destroy-focus-window ()
309 "Kill focus window: Destroy the focus window in all frames and workspaces"
310 (delete-focus-window-generic 'destroy-window
))
312 (defun remove-focus-window ()
313 "Remove the focus window from the current frame"
314 (with-focus-window (window)
315 (setf (current-child) (find-current-root))
317 (remove-child-in-frame window
(find-parent-frame window
))
318 (show-all-children)))
321 (defun unhide-all-windows-in-current-child ()
322 "Unhide all hidden windows into the current child"
323 (dolist (window (get-hidden-windows))
324 (unhide-window window
)
325 (process-new-window window
)
332 (defun find-window-under-mouse (x y
)
333 "Return the child window under the mouse"
335 (with-all-root-child (root)
336 (with-all-windows-frames-and-parent (root child parent
)
337 (when (and (or (managed-window-p child parent
) (child-equal-p parent
(current-child)))
338 (not (window-hidden-p child
))
339 (in-window child x y
))
341 (when (in-frame child x y
)
342 (setf win
(frame-window child
)))))
348 (defun find-child-under-mouse-in-never-managed-windows (x y
)
349 "Return the child under mouse from never managed windows"
351 (dolist (win (xlib:query-tree
*root
*))
352 (unless (window-hidden-p win
)
353 (multiple-value-bind (never-managed raise
)
354 (never-managed-window-p win
)
355 (when (and never-managed raise
(in-window win x y
))
360 (defun find-child-under-mouse-in-child-tree (x y
&optional first-foundp
)
361 "Return the child under the mouse"
363 (with-all-root-child (root)
364 (with-all-windows-frames (root child
)
365 (when (and (not (window-hidden-p child
))
366 (in-window child x y
))
368 (return-from find-child-under-mouse-in-child-tree child
)
370 (when (in-frame child x y
)
372 (return-from find-child-under-mouse-in-child-tree child
)
378 (defun find-child-under-mouse (x y
&optional first-foundp also-never-managed
)
379 "Return the child under the mouse"
380 (or (and also-never-managed
381 (find-child-under-mouse-in-never-managed-windows x y
))
382 (find-child-under-mouse-in-child-tree x y first-foundp
)))
388 ;;; Selection functions
389 (defun clear-selection ()
390 "Clear the current selection"
391 (setf *child-selection
* nil
)
392 (display-all-root-frame-info))
394 (defun copy-current-child ()
395 "Copy the current child to the selection"
396 (pushnew (current-child) *child-selection
*)
397 (display-all-root-frame-info))
400 (defun cut-current-child (&optional
(show-now t
))
401 "Cut the current child to the selection"
402 (unless (child-root-p (current-child))
403 (let ((parent (find-parent-frame (current-child))))
404 (hide-all (current-child))
406 (remove-child-in-frame (current-child) (find-parent-frame (current-child) (find-current-root)))
408 (setf (current-child) parent
))
410 (show-all-children t
))
413 (defun remove-current-child ()
414 "Remove the current child from its parent frame"
415 (unless (child-root-p (current-child))
416 (let ((parent (find-parent-frame (current-child))))
417 (hide-all (current-child))
418 (remove-child-in-frame (current-child) (find-parent-frame (current-child) (find-current-root)))
420 (setf (current-child) parent
))
421 (show-all-children t
)
422 (leave-second-mode))))
424 (defun delete-current-child ()
425 "Delete the current child and its children in all frames"
426 (unless (child-root-p (current-child))
427 (hide-all (current-child))
428 (delete-child-and-children-in-all-frames (current-child))
429 (show-all-children t
)
430 (leave-second-mode)))
433 (defun paste-selection-no-clear ()
434 "Paste the selection in the current frame - Do not clear the selection after paste"
435 (when (frame-p (current-child))
436 (dolist (child *child-selection
*)
437 (unless (find-child-in-parent child
(current-child))
438 (pushnew child
(frame-child (current-child)) :test
#'child-equal-p
)))
439 (show-all-children)))
441 (defun paste-selection ()
442 "Paste the selection in the current frame"
443 (when (frame-p (current-child))
444 (paste-selection-no-clear)
445 (setf *child-selection
* nil
)
446 (display-all-root-frame-info)))
449 (defun copy-focus-window ()
450 "Copy the focus window to the selection"
451 (with-focus-window (window)
452 (with-current-child (window)
453 (copy-current-child))))
456 (defun cut-focus-window ()
457 "Cut the focus window to the selection"
458 (with-focus-window (window)
459 (setf (current-child) (with-current-child (window)
460 (cut-current-child nil
)))
461 (show-all-children t
)))
468 ;;; Maximize function
469 (defun frame-toggle-maximize ()
470 "Maximize/Unmaximize the current frame in its parent frame"
471 (when (frame-p (current-child))
472 (let ((unmaximized-coords (frame-data-slot (current-child) :unmaximized-coords
)))
473 (if unmaximized-coords
474 (with-slots (x y w h
) (current-child)
475 (destructuring-bind (nx ny nw nh
) unmaximized-coords
476 (setf (frame-data-slot (current-child) :unmaximized-coords
) nil
477 x nx y ny w nw h nh
)))
478 (with-slots (x y w h
) (current-child)
479 (setf (frame-data-slot (current-child) :unmaximized-coords
)
483 (leave-second-mode)))
493 ;;; CONFIG - Identify mode
494 (defun identify-key ()
497 (font (xlib:open-font
*display
* *identify-font-string
*))
498 (window (xlib:create-window
:parent
*root
*
500 :width
(- (xlib:screen-width
*screen
*) (* *border-size
* 2))
501 :height
(* 5 (+ (xlib:max-char-ascent font
) (xlib:max-char-descent font
)))
502 :background
(get-color *identify-background
*)
503 :border-width
*border-size
*
504 :border
(get-color *identify-border
*)
505 :colormap
(xlib:screen-default-colormap
*screen
*)
506 :event-mask
'(:exposure
)))
507 (gc (xlib:create-gcontext
:drawable window
508 :foreground
(get-color *identify-foreground
*)
509 :background
(get-color *identify-background
*)
511 :line-style
:solid
)))
512 (setf (window-transparency window
) *identify-transparency
*)
513 (labels ((print-doc (msg hash-table-key pos code state
)
514 (let ((function (find-key-from-code hash-table-key code state
)))
515 (when (and function
(fboundp (first function
)))
516 (xlib:draw-glyphs
*pixmap-buffer
* gc
10 (+ (* pos
(+ (xlib:max-char-ascent font
) (xlib:max-char-descent font
))) 5)
517 (format nil
"~A ~A" msg
(documentation (first function
) 'function
))))))
518 (print-key (code state keysym key modifiers
)
519 (clear-pixmap-buffer window gc
)
520 (setf (xlib:gcontext-foreground gc
) (get-color *identify-foreground
*))
521 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (+ (xlib:max-char-ascent font
) 5)
522 (format nil
"Press a key to identify. Press 'q' to stop the identify loop."))
524 (xlib:draw-glyphs
*pixmap-buffer
* gc
10 (+ (* 2 (+ (xlib:max-char-ascent font
) (xlib:max-char-descent font
))) 5)
525 (format nil
"Code=~A KeySym=~S Key=~S Modifiers=~A"
526 code keysym key modifiers
))
527 (print-doc "Main mode : " *main-keys
* 3 code state
)
528 (print-doc "Second mode: " *second-keys
* 4 code state
))
529 (copy-pixmap-buffer window gc
))
530 (handle-identify-key (&rest event-slots
&key root code state
&allow-other-keys
)
531 (declare (ignore event-slots root
))
532 (let* ((modifiers (state->modifiers state
))
533 (key (keycode->char code state
))
534 (keysym (keysym->keysym-name
(keycode->keysym code modifiers
))))
535 (setf done
(and (equal key
#\q
) (equal modifiers
*default-modifiers
*)))
536 (dbg code keysym key modifiers
)
537 (print-key code state keysym key modifiers
)
539 (handle-identify (&rest event-slots
&key display event-key
&allow-other-keys
)
540 (declare (ignore display
))
542 (:key-press
(apply #'handle-identify-key event-slots
) t
)
543 (:exposure
(print-key nil nil nil nil nil
)))
545 (xgrab-pointer *root
* 92 93)
547 (format t
"~&Press 'q' to stop the identify loop~%")
548 (print-key nil nil nil nil nil
)
552 (with-xlib-protect (:Identify-Loop nil
)
553 (when (xlib:event-listen
*display
* *loop-timeout
*)
554 (xlib:process-event
*display
* :handler
#'handle-identify
))
555 (xlib:display-finish-output
*display
*)))
557 (xlib:destroy-window window
)
558 (xlib:close-font font
)
559 (xgrab-pointer *root
* 66 67))))))
566 (let ((all-symbols (collect-all-symbols)))
567 (defun eval-from-query-string ()
568 "Eval a lisp form from the query input"
569 (let ((form (query-string (format nil
"Eval Lisp <~A> " (package-name *package
*))
572 (when (and form
(not (equal form
"")))
573 (let ((printed-result
574 (with-output-to-string (*standard-output
*)
575 (setf result
(handler-case
576 (loop for i in
(multiple-value-list
577 (eval (read-from-string form
)))
578 collect
(format nil
"~S" i
))
580 (format nil
"~A" condition
)))))))
581 (let ((ret (info-mode (expand-newline (append (ensure-list (format nil
"> ~A" form
))
582 (ensure-list printed-result
)
583 (ensure-list result
)))
584 :width
(- (xlib:screen-width
*screen
*) 2))))
585 (when (or (search "defparameter" form
:test
#'string-equal
)
586 (search "defvar" form
:test
#'string-equal
))
587 (let ((elem (split-string form
)))
588 (pushnew (string-downcase (if (string= (first elem
) "(") (third elem
) (second elem
)))
589 all-symbols
:test
#'string
=)))
590 (when (search "in-package" form
:test
#'string-equal
)
591 (let ((*notify-window-placement
* 'middle-middle-root-placement
))
592 (open-notify-window '("Collecting all symbols for Lisp REPL completion."))
593 (setf all-symbols
(collect-all-symbols))
594 (close-notify-window)))
596 (eval-from-query-string))))))))
602 (let ((commands (command-in-path)))
603 (defun run-program-from-query-string ()
604 "Run a program from the query input"
605 (multiple-value-bind (program return
)
606 (query-string "Run:" "" commands
)
607 (when (and (equal return
:return
) program
(not (equal program
"")))
608 (setf *second-mode-leave-function
* (let ((cmd (concatenate 'string
"cd $HOME && " program
)))
611 (leave-second-mode)))))
616 ;;; Frame name actions
617 (defun ask-frame-name (msg)
619 (let ((all-frame-name nil
))
620 (with-all-frames (*root-frame
* frame
)
621 (awhen (frame-name frame
) (push it all-frame-name
)))
622 (query-string msg
"" all-frame-name
)))
625 ;;; Focus by functions
626 (defun focus-frame-by (frame)
627 (when (frame-p frame
)
628 (focus-all-children frame
(or (find-parent-frame frame
(find-current-root))
629 (find-parent-frame frame
)
631 (show-all-children t
)))
634 (defun focus-frame-by-name ()
635 "Focus a frame by name"
636 (focus-frame-by (find-frame-by-name (ask-frame-name "Focus frame:")))
639 (defun focus-frame-by-number ()
640 "Focus a frame by number"
641 (focus-frame-by (find-frame-by-number (query-number "Focus frame by number:")))
645 ;;; Open by functions
646 (defun open-frame-by (frame)
647 (when (frame-p frame
)
648 (push (create-frame :name
(query-string "Frame name")) (frame-child frame
))
649 (show-all-children)))
653 (defun open-frame-by-name ()
654 "Open a new frame in a named frame"
655 (open-frame-by (find-frame-by-name (ask-frame-name "Open a new frame in: ")))
658 (defun open-frame-by-number ()
659 "Open a new frame in a numbered frame"
660 (open-frame-by (find-frame-by-number (query-number "Open a new frame in the group numbered:")))
664 ;;; Delete by functions
665 (defun delete-frame-by (frame)
666 (unless (or (child-equal-p frame
*root-frame
*)
667 (child-root-p frame
))
668 (when (child-equal-p frame
(current-child))
669 (setf (current-child) (find-current-root)))
670 (remove-child-in-frame frame
(find-parent-frame frame
)))
671 (show-all-children t
))
674 (defun delete-frame-by-name ()
675 "Delete a frame by name"
676 (delete-frame-by (find-frame-by-name (ask-frame-name "Delete frame: ")))
679 (defun delete-frame-by-number ()
680 "Delete a frame by number"
681 (delete-frame-by (find-frame-by-number (query-number "Delete frame by number:")))
686 (defun move-child-to (child frame-dest
)
687 (when (and child
(frame-p frame-dest
))
688 (remove-child-in-frame child
(find-parent-frame child
))
689 (pushnew child
(frame-child frame-dest
))
690 (focus-all-children child frame-dest
)
691 (show-all-children t
)))
693 (defun move-current-child-by-name ()
694 "Move current child in a named frame"
695 (move-child-to (current-child)
697 (ask-frame-name (format nil
"Move '~A' to frame: " (child-name (current-child))))))
700 (defun move-current-child-by-number ()
701 "Move current child in a numbered frame"
702 (move-child-to (current-child)
703 (find-frame-by-number
704 (query-number (format nil
"Move '~A' to frame numbered:" (child-name (current-child))))))
709 (defun copy-child-to (child frame-dest
)
710 (when (and child
(frame-p frame-dest
))
711 (pushnew child
(frame-child frame-dest
))
712 (focus-all-children child frame-dest
)
713 (show-all-children t
)))
715 (defun copy-current-child-by-name ()
716 "Copy current child in a named frame"
717 (copy-child-to (current-child)
719 (ask-frame-name (format nil
"Copy '~A' to frame: " (child-name (current-child))))))
722 (defun copy-current-child-by-number ()
723 "Copy current child in a numbered frame"
724 (copy-child-to (current-child)
725 (find-frame-by-number
726 (query-number (format nil
"Copy '~A' to frame numbered:" (child-name (current-child))))))
733 (defun show-all-frames-info ()
734 "Show all frames info windows"
735 (let ((*show-root-frame-p
* t
))
737 (with-all-root-child (root)
738 (with-all-frames (root frame
)
739 (raise-window (frame-window frame
))
740 (display-frame-info frame
)))))
742 (defun hide-all-frames-info ()
743 "Hide all frames info windows"
746 (defun show-all-frames-info-key ()
747 "Show all frames info windows until a key is release"
748 (show-all-frames-info)
749 (wait-no-key-or-button-press)
750 (hide-all-frames-info))
753 (defun move-frame (frame parent orig-x orig-y
)
754 (when (and frame parent
(not (child-root-p frame
)))
755 (hide-all-children frame
)
756 (with-slots (window) frame
757 (move-window window orig-x orig-y
#'display-frame-info
(list frame
))
758 (setf (frame-x frame
) (x-px->fl
(x-drawable-x window
) parent
)
759 (frame-y frame
) (y-px->fl
(x-drawable-y window
) parent
)))
760 (show-all-children)))
762 (defun resize-frame (frame parent orig-x orig-y
)
763 (when (and frame parent
(not (child-root-p frame
)))
764 (hide-all-children frame
)
765 (with-slots (window) frame
766 (resize-window window orig-x orig-y
#'display-frame-info
(list frame
))
767 (setf (frame-w frame
) (w-px->fl
(anti-adj-border-wh (x-drawable-width window
) frame
) parent
)
768 (frame-h frame
) (h-px->fl
(anti-adj-border-wh (x-drawable-height window
) frame
) parent
)))
769 (show-all-children)))
773 (defun mouse-click-to-focus-generic (root-x root-y mouse-fn
)
774 "Focus the current frame or focus the current window parent
775 mouse-fun is #'move-frame or #'resize-frame"
777 (child (find-child-under-mouse root-x root-y
))
778 (parent (find-parent-frame child
))
779 (root-p (child-root-p child
)))
780 (labels ((add-new-frame ()
781 (when (frame-p child
)
784 mouse-fn
#'resize-frame
785 (current-child) child
)
786 (place-frame child parent root-x root-y
10 10)
787 (map-window (frame-window child
))
788 (pushnew child
(frame-child parent
)))))
789 (when (and root-p
*create-frame-on-root
*)
791 (when (and (frame-p child
) (not (child-root-p child
)))
792 (funcall mouse-fn child parent root-x root-y
))
793 (when (and child parent
794 (focus-all-children child parent
(not (child-root-p child
))))
795 (when (show-all-children)
796 (setf to-replay nil
)))
798 (replay-button-event)
799 (stop-button-event)))))
802 (defun mouse-click-to-focus-and-move (window root-x root-y
)
803 "Move and focus the current frame or focus the current window parent.
804 Or do actions on corners"
805 (declare (ignore window
))
806 (or (do-corner-action root-x root-y
*corner-main-mode-left-button
*)
807 (mouse-click-to-focus-generic root-x root-y
#'move-frame
)))
809 (defun mouse-click-to-focus-and-resize (window root-x root-y
)
810 "Resize and focus the current frame or focus the current window parent.
811 Or do actions on corners"
812 (declare (ignore window
))
813 (or (do-corner-action root-x root-y
*corner-main-mode-right-button
*)
814 (mouse-click-to-focus-generic root-x root-y
#'resize-frame
)))
816 (defun mouse-middle-click (window root-x root-y
)
817 "Do actions on corners"
818 (declare (ignore window
))
819 (or (do-corner-action root-x root-y
*corner-main-mode-middle-button
*)
820 (replay-button-event)))
825 (defun mouse-focus-move/resize-generic
(root-x root-y mouse-fn window-parent
)
826 "Focus the current frame or focus the current window parent
827 mouse-fun is #'move-frame or #'resize-frame.
828 Focus child and its parents -
829 For window: set current child to window or its parent according to window-parent"
830 (labels ((move/resize-managed
(child)
831 (let ((parent (find-parent-frame child
)))
834 (child-root-p child
))
837 mouse-fn
#'resize-frame
)
838 (place-frame child parent root-x root-y
10 10)
839 (map-window (frame-window child
))
840 (push child
(frame-child parent
)))
841 (focus-all-children child parent window-parent
)
845 (if (managed-window-p child parent
)
846 (funcall mouse-fn parent
(find-parent-frame parent
) root-x root-y
)
847 (funcall (cond ((or (eql mouse-fn
#'move-frame
)
848 (eql mouse-fn
#'move-frame-constrained
))
850 ((or (eql mouse-fn
#'resize-frame
)
851 (eql mouse-fn
#'resize-frame-constrained
))
853 child root-x root-y
)))
854 (frame (funcall mouse-fn child parent root-x root-y
)))
855 (show-all-children)))
856 (move/resize-never-managed
(child raise-fun
)
857 (funcall raise-fun child
)
858 (funcall (cond ((eql mouse-fn
#'move-frame
) #'move-window
)
859 ((eql mouse-fn
#'resize-frame
) #'resize-window
))
860 child root-x root-y
)))
861 (let ((child (find-child-under-mouse root-x root-y nil t
)))
862 (multiple-value-bind (never-managed raise-fun
)
863 (never-managed-window-p child
)
864 (if (and (xlib:window-p child
) never-managed raise-fun
)
865 (move/resize-never-managed child raise-fun
)
866 (move/resize-managed child
))))))
869 (defun test-mouse-binding (window root-x root-y
)
870 (dbg window root-x root-y
)
871 (replay-button-event))
875 (defun mouse-select-next-level (window root-x root-y
)
876 "Select the next level in frame"
877 (declare (ignore root-x root-y
))
878 (let ((frame (find-frame-window window
)))
879 (when (or frame
(xlib:window-equal window
*root
*))
881 (replay-button-event)))
885 (defun mouse-select-previous-level (window root-x root-y
)
886 "Select the previous level in frame"
887 (declare (ignore root-x root-y
))
888 (let ((frame (find-frame-window window
)))
889 (when (or frame
(xlib:window-equal window
*root
*))
890 (select-previous-level))
891 (replay-button-event)))
895 (defun mouse-enter-frame (window root-x root-y
)
896 "Enter in the selected frame - ie make it the root frame"
897 (declare (ignore root-x root-y
))
898 (let ((frame (find-frame-window window
)))
899 (when (or frame
(xlib:window-equal window
*root
*))
901 (replay-button-event)))
905 (defun mouse-leave-frame (window root-x root-y
)
906 "Leave the selected frame - ie make its parent the root frame"
907 (declare (ignore root-x root-y
))
908 (let ((frame (find-frame-window window
)))
909 (when (or frame
(xlib:window-equal window
*root
*))
911 (replay-button-event)))
916 ;;;;;| Various definitions
919 (defun show-help (&optional
(browser "dillo") (tempfile "/tmp/clfswm.html"))
920 "Show current keys and buttons bindings"
922 (produce-doc-html-in-file tempfile
))
924 (do-shell (format nil
"~A ~A" browser tempfile
)))
928 ;;; Bind or jump functions
929 (let ((key-slots (make-array 10 :initial-element nil
))
931 (defun reset-bind-or-jump-slots ()
933 (setf (aref key-slots i
) nil
)))
935 (defun bind-on-slot (&optional
(slot current-slot
))
936 "Bind current child to slot"
937 (setf (aref key-slots slot
) (current-child)))
939 (defun remove-binding-on-slot ()
940 "Remove binding on slot"
941 (setf (aref key-slots current-slot
) nil
))
943 (defun jump-to-slot ()
945 (let ((jump-child (aref key-slots current-slot
)))
946 (when (and jump-child
(find-child jump-child
*root-frame
*))
947 (unless (find-child-in-all-root jump-child
)
948 (change-root (find-root jump-child
) jump-child
))
949 (setf (current-child) jump-child
)
950 (focus-all-children jump-child jump-child
)
951 (show-all-children t
))))
953 (defun bind-or-jump (n)
954 "Bind or jump to a slot (a frame or a window)"
955 (setf current-slot
(- n
1))
956 (let ((default-bind `("b" bind-on-slot
957 ,(format nil
"Bind slot ~A on child: ~A" n
(child-fullname (current-child))))))
958 (info-mode-menu (aif (aref key-slots current-slot
)
960 ("BackSpace" remove-binding-on-slot
961 ,(format nil
"Remove slot ~A binding on child: ~A" n
(child-fullname (current-child))))
964 ,(format nil
"Jump to child: ~A" (aif (aref key-slots current-slot
)
966 "Not set - Please, bind it with 'b'")))
967 ("Return" jump-to-slot
"Same thing")
968 ("space" jump-to-slot
"Same thing"))
969 (list default-bind
))))))
973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
974 ;;; Useful function for the second mode ;;;
975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
976 (defmacro with-movement
(&body body
)
977 `(when (frame-p (current-child))
980 (display-all-frame-info)
981 (draw-second-mode-window)
982 (open-menu (find-menu 'frame-movement-menu
))))
986 (defun current-frame-pack-up ()
987 "Pack the current frame up"
988 (with-movement (pack-frame-up (current-child) (find-parent-frame (current-child) (find-current-root)))))
990 (defun current-frame-pack-down ()
991 "Pack the current frame down"
992 (with-movement (pack-frame-down (current-child) (find-parent-frame (current-child) (find-current-root)))))
994 (defun current-frame-pack-left ()
995 "Pack the current frame left"
996 (with-movement (pack-frame-left (current-child) (find-parent-frame (current-child) (find-current-root)))))
998 (defun current-frame-pack-right ()
999 "Pack the current frame right"
1000 (with-movement (pack-frame-right (current-child) (find-parent-frame (current-child) (find-current-root)))))
1003 (defun center-current-frame ()
1004 "Center the current frame"
1005 (with-movement (center-frame (current-child))))
1008 (defun current-frame-fill-up ()
1009 "Fill the current frame up"
1010 (with-movement (fill-frame-up (current-child) (find-parent-frame (current-child) (find-current-root)))))
1012 (defun current-frame-fill-down ()
1013 "Fill the current frame down"
1014 (with-movement (fill-frame-down (current-child) (find-parent-frame (current-child) (find-current-root)))))
1016 (defun current-frame-fill-left ()
1017 "Fill the current frame left"
1018 (with-movement (fill-frame-left (current-child) (find-parent-frame (current-child) (find-current-root)))))
1020 (defun current-frame-fill-right ()
1021 "Fill the current frame right"
1022 (with-movement (fill-frame-right (current-child) (find-parent-frame (current-child) (find-current-root)))))
1024 (defun current-frame-fill-all-dir ()
1025 "Fill the current frame in all directions"
1027 (let ((parent (find-parent-frame (current-child) (find-current-root))))
1028 (fill-frame-up (current-child) parent
)
1029 (fill-frame-down (current-child) parent
)
1030 (fill-frame-left (current-child) parent
)
1031 (fill-frame-right (current-child) parent
))))
1033 (defun current-frame-fill-vertical ()
1034 "Fill the current frame vertically"
1036 (let ((parent (find-parent-frame (current-child) (find-current-root))))
1037 (fill-frame-up (current-child) parent
)
1038 (fill-frame-down (current-child) parent
))))
1040 (defun current-frame-fill-horizontal ()
1041 "Fill the current frame horizontally"
1043 (let ((parent (find-parent-frame (current-child) (find-current-root))))
1044 (fill-frame-left (current-child) parent
)
1045 (fill-frame-right (current-child) parent
))))
1049 (defun current-frame-resize-up ()
1050 "Resize the current frame up to its half height"
1051 (with-movement (resize-half-height-up (current-child))))
1053 (defun current-frame-resize-down ()
1054 "Resize the current frame down to its half height"
1055 (with-movement (resize-half-height-down (current-child))))
1057 (defun current-frame-resize-left ()
1058 "Resize the current frame left to its half width"
1059 (with-movement (resize-half-width-left (current-child))))
1061 (defun current-frame-resize-right ()
1062 "Resize the current frame right to its half width"
1063 (with-movement (resize-half-width-right (current-child))))
1065 (defun current-frame-resize-all-dir ()
1066 "Resize down the current frame"
1067 (with-movement (resize-frame-down (current-child))))
1069 (defun current-frame-resize-all-dir-minimal ()
1070 "Resize down the current frame to its minimal size"
1071 (with-movement (resize-minimal-frame (current-child))))
1074 ;;; Children navigation
1075 (defun with-movement-select-next-brother ()
1076 "Select the next brother frame"
1077 (with-movement (select-next-brother-simple)))
1079 (defun with-movement-select-previous-brother ()
1080 "Select the previous brother frame"
1081 (with-movement (select-previous-brother-simple)))
1083 (defun with-movement-select-next-level ()
1084 "Select the next level"
1085 (with-movement (select-next-level)))
1087 (defun with-movement-select-previous-level ()
1088 "Select the previous levelframe"
1089 (with-movement (select-previous-level)))
1091 (defun with-movement-select-next-child ()
1092 "Select the next child"
1093 (with-movement (select-next-child-simple)))
1097 ;;; Adapt frame functions
1098 (defun adapt-current-frame-to-window-hints-generic (width-p height-p
)
1099 "Adapt the current frame to the current window minimal size hints"
1100 (when (frame-p (current-child))
1101 (let ((window (first (frame-child (current-child)))))
1102 (when (xlib:window-p window
)
1103 (let* ((hints (xlib:wm-normal-hints window
))
1104 (min-width (and hints
(xlib:wm-size-hints-min-width hints
)))
1105 (min-height (and hints
(xlib:wm-size-hints-min-height hints
))))
1106 (when (and width-p min-width
)
1107 (setf (frame-rw (current-child)) min-width
))
1108 (when (and height-p min-height
)
1109 (setf (frame-rh (current-child)) min-height
))
1110 (fixe-real-size (current-child) (find-parent-frame (current-child)))
1111 (leave-second-mode))))))
1113 (defun adapt-current-frame-to-window-hints ()
1114 "Adapt the current frame to the current window minimal size hints"
1115 (adapt-current-frame-to-window-hints-generic t t
))
1117 (defun adapt-current-frame-to-window-width-hint ()
1118 "Adapt the current frame to the current window minimal width hint"
1119 (adapt-current-frame-to-window-hints-generic t nil
))
1121 (defun adapt-current-frame-to-window-height-hint ()
1122 "Adapt the current frame to the current window minimal height hint"
1123 (adapt-current-frame-to-window-hints-generic nil t
))
1128 ;;; Managed window type functions
1129 (defun current-frame-manage-window-type-generic (type-list)
1130 (when (frame-p (current-child))
1131 (setf (frame-managed-type (current-child)) type-list
1132 (frame-forced-managed-window (current-child)) nil
1133 (frame-forced-unmanaged-window (current-child)) nil
))
1134 (leave-second-mode))
1137 (defun current-frame-manage-window-type ()
1138 "Change window types to be managed by a frame"
1139 (when (frame-p (current-child))
1140 (let* ((type-str (query-string "Managed window type: (all, normal, transient, maxsize, desktop, dock, toolbar, menu, utility, splash, dialog)"
1141 (format nil
"~{~:(~A~) ~}" (frame-managed-type (current-child)))))
1142 (type-list (loop :for type
:in
(split-string type-str
)
1143 :collect
(intern (string-upcase type
) :keyword
))))
1144 (current-frame-manage-window-type-generic type-list
))))
1147 (defun current-frame-manage-all-window-type ()
1148 "Manage all window type"
1149 (current-frame-manage-window-type-generic '(:all
)))
1151 (defun current-frame-manage-only-normal-window-type ()
1152 "Manage only normal window type"
1153 (current-frame-manage-window-type-generic '(:normal
)))
1155 (defun current-frame-manage-no-window-type ()
1156 "Do not manage any window type"
1157 (current-frame-manage-window-type-generic nil
))
1166 ;;; Force window functions
1167 (defun force-window-in-frame ()
1168 "Force the current window to move in the frame (Useful only for unmanaged windows)"
1169 (with-current-window
1170 (let ((parent (find-parent-frame window
)))
1171 (setf (x-drawable-x window
) (frame-rx parent
)
1172 (x-drawable-y window
) (frame-ry parent
))
1173 (xlib:display-finish-output
*display
*)))
1174 (leave-second-mode))
1177 (defun force-window-center-in-frame ()
1178 "Force the current window to move in the center of the frame (Useful only for unmanaged windows)"
1179 (with-current-window
1180 (let ((parent (find-parent-frame window
)))
1181 (setf (x-drawable-x window
) (truncate (+ (frame-rx parent
)
1182 (/ (- (frame-rw parent
)
1183 (x-drawable-width window
)) 2)))
1184 (x-drawable-y window
) (truncate (+ (frame-ry parent
)
1185 (/ (- (frame-rh parent
)
1186 (x-drawable-height window
)) 2))))
1187 (xlib:display-finish-output
*display
*)))
1188 (leave-second-mode))
1192 (defun display-current-window-info ()
1193 "Display information on the current window"
1194 (with-current-window
1195 (info-mode (list (format nil
"Window: ~A" window
)
1196 (format nil
"Window name: ~A" (xlib:wm-name window
))
1197 (format nil
"Window class: ~A" (xlib:get-wm-class window
))
1198 (format nil
"Window type: ~:(~A~)" (window-type window
))
1199 (format nil
"Window id: 0x~X" (xlib:window-id window
))
1200 (format nil
"Window transparency: ~A" (* 100 (window-transparency window
))))))
1201 (leave-second-mode))
1203 (defun set-current-window-transparency ()
1204 "Set the current window transparency"
1205 (with-current-window
1206 (ask-child-transparency "window" window
))
1207 (leave-second-mode))
1210 (defun manage-current-window ()
1211 "Force to manage the current window by its parent frame"
1212 (with-current-window
1213 (let ((parent (find-parent-frame window
)))
1214 (with-slots ((managed forced-managed-window
)
1215 (unmanaged forced-unmanaged-window
)) parent
1216 (setf unmanaged
(child-remove window unmanaged
)
1217 unmanaged
(remove (xlib:wm-name window
) unmanaged
:test
#'string-equal-p
))
1218 (pushnew window managed
))))
1219 (leave-second-mode))
1221 (defun unmanage-current-window ()
1222 "Force to not manage the current window by its parent frame"
1223 (with-current-window
1224 (let ((parent (find-parent-frame window
)))
1225 (with-slots ((managed forced-managed-window
)
1226 (unmanaged forced-unmanaged-window
)) parent
1227 (setf managed
(child-remove window managed
)
1228 managed
(remove (xlib:wm-name window
) managed
:test
#'string-equal-p
))
1229 (pushnew window unmanaged
))))
1230 (leave-second-mode))
1234 ;;; Moving child with the mouse button
1235 (defun mouse-move-child-over-frame (window root-x root-y
)
1236 "Move the child under the mouse cursor to another frame"
1237 (declare (ignore window
))
1238 (let ((child (find-child-under-mouse root-x root-y
)))
1239 (unless (child-root-p child
)
1241 (remove-child-in-frame child
(find-parent-frame child
))
1242 (wait-mouse-button-release 50 51)
1243 (multiple-value-bind (x y
)
1244 (xlib:query-pointer
*root
*)
1245 (let ((dest (find-child-under-mouse x y
)))
1246 (when (xlib:window-p dest
)
1247 (setf dest
(find-parent-frame dest
)))
1248 (unless (child-equal-p child dest
)
1249 (move-child-to child dest
)
1250 (show-all-children))))))
1251 (stop-button-event))
1256 ;;; Hide/Show frame window functions
1257 (defun hide/show-frame-window
(frame value
)
1258 "Hide/show the frame window"
1259 (when (frame-p frame
)
1260 (setf (frame-show-window-p (current-child)) value
)
1261 (show-all-children))
1262 (leave-second-mode))
1265 (defun hide-current-frame-window ()
1266 "Hide the current frame window"
1267 (hide/show-frame-window
(current-child) nil
))
1269 (defun show-current-frame-window ()
1270 "Show the current frame window"
1271 (hide/show-frame-window
(current-child) t
))
1275 ;;; Hide/Unhide current child
1276 (defun hide-current-child ()
1277 "Hide the current child"
1278 (unless (child-root-p (current-child))
1279 (let ((parent (find-parent-frame (current-child))))
1280 (when (frame-p parent
)
1281 (with-slots (child hidden-children
) parent
1282 (hide-all (current-child))
1283 (setf child
(child-remove (current-child) child
))
1284 (pushnew (current-child) hidden-children
)
1285 (setf (current-child) parent
))
1286 (show-all-children)))
1287 (leave-second-mode)))
1290 (defun frame-unhide-child (hidden frame-src frame-dest
)
1291 "Unhide a hidden child from frame-src in frame-dest"
1292 (with-slots (hidden-children) frame-src
1293 (setf hidden-children
(child-remove hidden hidden-children
)))
1294 (with-slots (child) frame-dest
1295 (pushnew hidden child
)))
1299 (defun unhide-a-child ()
1300 "Unhide a child in the current frame"
1301 (when (frame-p (current-child))
1302 (with-slots (child hidden-children
) (current-child)
1303 (info-mode-menu (loop :for i
:from
0
1304 :for hidden
:in hidden-children
1305 :collect
(list (code-char (+ (char-code #\a) i
))
1308 (frame-unhide-child lhd
(current-child) (current-child))))
1309 (format nil
"Unhide ~A" (child-fullname hidden
))))))
1310 (show-all-children))
1311 (leave-second-mode))
1314 (defun unhide-all-children ()
1315 "Unhide all current frame hidden children"
1316 (when (frame-p (current-child))
1317 (with-slots (child hidden-children
) (current-child)
1318 (dolist (c hidden-children
)
1320 (setf hidden-children nil
))
1321 (show-all-children))
1322 (leave-second-mode))
1325 (defun unhide-a-child-from-all-frames ()
1326 "Unhide a child from all frames in the current frame"
1327 (when (frame-p (current-child))
1330 (with-all-frames (*root-frame
* frame
)
1331 (when (frame-hidden-children frame
)
1332 (push (format nil
"~A" (child-fullname frame
)) acc
)
1333 (dolist (hidden (frame-hidden-children frame
))
1334 (push (list (code-char (+ (char-code #\a) (incf keynum
)))
1337 (frame-unhide-child lhd frame
(current-child))))
1338 (format nil
"Unhide ~A" (child-fullname hidden
)))
1340 (info-mode-menu (nreverse acc
)))
1341 (show-all-children))
1342 (leave-second-mode))
1348 (let ((last-child nil
))
1349 (defun init-last-child ()
1350 (setf last-child nil
))
1351 (defun switch-to-last-child ()
1352 "Store the current child and switch to the previous one"
1353 (let ((current-child (current-child)))
1355 (change-root (find-root last-child
) last-child
)
1356 (setf (current-child) last-child
)
1357 (focus-all-children (current-child) (current-child))
1358 (show-all-children t
))
1359 (setf last-child current-child
))
1360 (leave-second-mode)))
1368 ;;; Focus policy functions
1369 (defun set-focus-policy-generic (focus-policy)
1370 (when (frame-p (current-child))
1371 (setf (frame-focus-policy (current-child)) focus-policy
))
1372 (leave-second-mode))
1375 (defun current-frame-set-click-focus-policy ()
1376 "Set a click focus policy for the current frame."
1377 (set-focus-policy-generic :click
))
1379 (defun current-frame-set-sloppy-focus-policy ()
1380 "Set a sloppy focus policy for the current frame."
1381 (set-focus-policy-generic :sloppy
))
1383 (defun current-frame-set-sloppy-strict-focus-policy ()
1384 "Set a (strict) sloppy focus policy only for windows in the current frame."
1385 (set-focus-policy-generic :sloppy-strict
))
1387 (defun current-frame-set-sloppy-select-policy ()
1388 "Set a sloppy select policy for the current frame."
1389 (set-focus-policy-generic :sloppy-select
))
1393 (defun set-focus-policy-generic-for-all (focus-policy)
1394 (with-all-frames (*root-frame
* frame
)
1395 (setf (frame-focus-policy frame
) focus-policy
))
1396 (leave-second-mode))
1399 (defun all-frames-set-click-focus-policy ()
1400 "Set a click focus policy for all frames."
1401 (set-focus-policy-generic-for-all :click
))
1403 (defun all-frames-set-sloppy-focus-policy ()
1404 "Set a sloppy focus policy for all frames."
1405 (set-focus-policy-generic-for-all :sloppy
))
1407 (defun all-frames-set-sloppy-strict-focus-policy ()
1408 "Set a (strict) sloppy focus policy for all frames."
1409 (set-focus-policy-generic-for-all :sloppy-strict
))
1411 (defun all-frames-set-sloppy-select-policy ()
1412 "Set a sloppy select policy for all frames."
1413 (set-focus-policy-generic-for-all :sloppy-select
))
1417 ;;; Ensure unique name/number functions
1418 (defun extract-number-from-name (name)
1419 (when (stringp name
)
1420 (let* ((pos (1+ (or (position #\. name
:from-end t
) -
1)))
1421 (number (parse-integer name
:junk-allowed t
:start pos
)))
1423 (if number
(subseq name
0 (1- pos
)) name
)))))
1428 (defun ensure-unique-name ()
1429 "Ensure that all children names are unique"
1430 (with-all-children (*root-frame
* child
)
1431 (multiple-value-bind (num1 name1
)
1432 (extract-number-from-name (child-name child
))
1433 (declare (ignore num1
))
1436 (with-all-children (*root-frame
* c
)
1437 (unless (child-equal-p child c
))
1438 (multiple-value-bind (num2 name2
)
1439 (extract-number-from-name (child-name c
))
1440 (when (string-equal name1 name2
)
1443 (when (> (length acc
) 1)
1444 (setf (child-name child
)
1445 (format nil
"~A.~A" name1
1446 (1+ (find-free-number (loop for i in acc when i collect
(1- i
)))))))))))
1447 (leave-second-mode))
1449 (defun ensure-unique-number ()
1450 "Ensure that all children numbers are unique"
1452 (with-all-frames (*root-frame
* frame
)
1453 (setf (frame-number frame
) (incf num
))))
1454 (leave-second-mode))
1458 ;;; Standard menu functions - Based on the XDG specifications
1459 (defun um-create-xdg-section-list (menu)
1460 (dolist (section *xdg-section-list
*)
1461 (add-sub-menu menu
:next section
(format nil
"~A" section
) menu
))
1462 (unless (find-toplevel-menu 'Utility menu
)
1463 (add-sub-menu menu
:next
'Utility
(format nil
"~A" 'Utility
) menu
)))
1465 (defun um-find-submenu (menu section-list
)
1467 (dolist (section section-list
)
1468 (awhen (find-toplevel-menu (intern (string-upcase section
) :clfswm
) menu
)
1472 (list (find-toplevel-menu 'Utility menu
)))))
1475 (defun um-extract-value (line)
1476 (second (split-string line
#\
=)))
1479 (defun um-add-desktop (desktop menu
)
1480 (let (name exec categories comment
)
1481 (when (probe-file desktop
)
1482 (with-open-file (stream desktop
:direction
:input
)
1483 (loop for line
= (read-line stream nil nil
)
1486 (cond ((first-position "Name=" line
) (setf name
(um-extract-value line
)))
1487 ((first-position "Exec=" line
) (setf exec
(um-extract-value line
)))
1488 ((first-position "Categories=" line
) (setf categories
(um-extract-value line
)))
1489 ((first-position "Comment=" line
) (setf comment
(um-extract-value line
))))
1490 (when (and name exec categories
)
1491 (let* ((sub-menu (um-find-submenu menu
(split-string categories
#\
;)))
1492 (fun-name (intern name
:clfswm
)))
1493 (setf (symbol-function fun-name
) (let ((do-exec exec
))
1496 (leave-second-mode)))
1497 (documentation fun-name
'function
) (format nil
"~A~A" name
(if comment
1498 (format nil
" - ~A" comment
)
1500 (dolist (m sub-menu
)
1501 (add-menu-key (menu-name m
) :next fun-name m
)))
1502 (setf name nil exec nil categories nil comment nil
)))))))
1505 (defun update-menus (&optional
(menu (make-menu :name
'main
:doc
"Main menu")))
1506 (um-create-xdg-section-list menu
)
1508 (found (make-hash-table :test
#'equal
)))
1509 (dolist (dir (remove-duplicates
1510 (split-string (or (getenv "XDG_DATA_DIRS") "/usr/local/share/:/usr/share/")
1511 #\
:) :test
#'string-equal
))
1512 (dolist (desktop (directory (concatenate 'string dir
"/applications/**/*.desktop")))
1513 (unless (gethash (file-namestring desktop
) found
)
1514 (setf (gethash (file-namestring desktop
) found
) t
)
1515 (um-add-desktop desktop menu
)
1521 ;;; Close/Kill focused window
1523 (defun ask-close/kill-current-window
()
1524 "Close or kill the current window (ask before doing anything)"
1525 (let ((window (xlib:input-focus
*display
*))
1526 (*info-mode-placement
* *ask-close
/kill-placement
*))
1528 (if (and window
(not (xlib:window-equal window
*no-focus-window
*)))
1529 `(,(format nil
"Focus window: ~A" (xlib:wm-name window
))
1530 (#\s delete-focus-window
"Close the focus window")
1531 (#\k destroy-focus-window
"Kill the focus window")
1532 (#\x cut-focus-window
)
1533 (#\c copy-focus-window
)
1534 (#\v paste-selection
))
1535 `(,(format nil
"Focus window: None")
1536 (#\v paste-selection
))))
1541 ;;; Other window manager functions
1542 (defun get-proc-list ()
1543 (let ((proc (do-shell "ps x -o pid=" nil t
))
1545 (loop for line
= (read-line proc nil nil
)
1547 do
(push line proc-list
))
1551 (defun run-other-window-manager ()
1552 (let ((proc-start (get-proc-list)))
1553 (do-shell *other-window-manager
* nil t
:terminal
)
1554 (let* ((proc-end (get-proc-list))
1555 (proc-diff (set-difference proc-end proc-start
:test
#'equal
)))
1556 (dbg 'killing-sigterm proc-diff
)
1557 (do-shell (format nil
"kill ~{ ~A ~} 2> /dev/null" proc-diff
) nil t
:terminal
)
1558 (dbg 'killing-sigkill proc-diff
)
1559 (do-shell (format nil
"kill -9 ~{ ~A ~} 2> /dev/null" proc-diff
) nil t
:terminal
)
1561 (setf *other-window-manager
* nil
)))
1564 (defun do-run-other-window-manager (window-manager)
1565 (setf *other-window-manager
* window-manager
)
1566 (throw 'exit-main-loop nil
))
1568 (defmacro def-run-other-window-manager
(name &optional definition
)
1569 (let ((definition (or definition name
)))
1570 `(defun ,(create-symbol "run-" name
) ()
1571 ,(format nil
"Run ~A" definition
)
1572 (do-run-other-window-manager ,(format nil
"~A" name
)))))
1574 (def-run-other-window-manager "xterm")
1575 (def-run-other-window-manager "icewm")
1576 (def-run-other-window-manager "twm")
1577 (def-run-other-window-manager "gnome-session" "Gnome")
1578 (def-run-other-window-manager "startkde" "KDE")
1579 (def-run-other-window-manager "xfce4-session" "XFCE")
1583 (do-run-other-window-manager "( lxsession & ); xterm -e \"echo ' /----------------------------------\\' ; echo ' | CLFSWM Note: |' ; echo ' | Close this window when done. |' ; echo ' \\----------------------------------/'; echo; echo; $SHELL\""))
1587 (do-run-other-window-manager "( xfce4-session &) ; xterm -e \"echo ' /----------------------------------\\' ; echo ' | CLFSWM Note: |' ; echo ' | Close this window when done. |' ; echo ' \\----------------------------------/'; echo; echo; $SHELL\""))
1590 (defun run-prompt-wm ()
1591 "Prompt for an other window manager"
1592 (let ((wm (query-string "Run an other window manager:" "icewm")))
1593 (do-run-other-window-manager wm
)))
1596 ;;; Hide or show unmanaged windows utility.
1597 (defun set-hide-unmanaged-window ()
1598 "Hide unmanaged windows when frame is not selected"
1599 (when (frame-p (current-child))
1600 (setf (frame-data-slot (current-child) :unmanaged-window-action
) :hide
)
1601 (leave-second-mode)))
1603 (defun set-show-unmanaged-window ()
1604 "Show unmanaged windows when frame is not selected"
1605 (when (frame-p (current-child))
1606 (setf (frame-data-slot (current-child) :unmanaged-window-action
) :show
)
1607 (leave-second-mode)))
1609 (defun set-default-hide-unmanaged-window ()
1610 "Set default behaviour to hide or not unmanaged windows when frame is not selected"
1611 (when (frame-p (current-child))
1612 (setf (frame-data-slot (current-child) :unmanaged-window-action
) nil
)
1613 (leave-second-mode)))
1615 (defun set-globally-hide-unmanaged-window ()
1616 "Hide unmanaged windows by default. This is overriden by functions above"
1617 (setf *hide-unmanaged-window
* t
)
1618 (leave-second-mode))
1620 (defun set-globally-show-unmanaged-window ()
1621 "Show unmanaged windows by default. This is overriden by functions above"
1622 (setf *hide-unmanaged-window
* nil
)
1623 (leave-second-mode))
1626 ;;; Speed mouse movement.
1627 (let (minx miny maxx maxy history lx ly
)
1628 (labels ((middle (x1 x2
)
1629 (round (/ (+ x1 x2
) 2)))
1630 (reset-if-moved (x y
)
1631 (when (or (/= x
(or lx x
)) (/= y
(or ly y
)))
1632 (speed-mouse-reset)))
1633 (add-in-history (x y
)
1634 (push (list x y
) history
)))
1635 (defun speed-mouse-reset ()
1636 "Reset speed mouse coordinates"
1637 (setf minx nil miny nil maxx nil maxy nil history nil lx nil ly nil
))
1638 (defun speed-mouse-left ()
1639 "Speed move mouse to left"
1641 (reset-if-moved x y
)
1643 (add-in-history x y
)
1644 (setf lx
(middle (or minx
0) maxx
))
1645 (xlib:warp-pointer
*root
* lx y
)))
1646 (defun speed-mouse-right ()
1647 "Speed move mouse to right"
1649 (reset-if-moved x y
)
1651 (add-in-history x y
)
1652 (setf lx
(middle minx
(or maxx
(xlib:screen-width
*screen
*))))
1653 (xlib:warp-pointer
*root
* lx y
)))
1654 (defun speed-mouse-up ()
1655 "Speed move mouse to up"
1657 (reset-if-moved x y
)
1659 (add-in-history x y
)
1660 (setf ly
(middle (or miny
0) maxy
))
1661 (xlib:warp-pointer
*root
* x ly
)))
1662 (defun speed-mouse-down ()
1663 "Speed move mouse to down"
1665 (reset-if-moved x y
)
1667 (add-in-history x y
)
1668 (setf ly
(middle miny
(or maxy
(xlib:screen-height
*screen
*))))
1669 (xlib:warp-pointer
*root
* x ly
)))
1670 (defun speed-mouse-undo ()
1671 "Undo last speed mouse move"
1673 (let ((h (pop history
)))
1675 (destructuring-bind (bx by
) h
1679 (xlib:warp-pointer
*root
* lx ly
))))))
1680 (defun speed-mouse-first-history ()
1681 "Revert to the first speed move mouse"
1683 (let ((h (first (last history
))))
1687 (xlib:warp-pointer
*root
* lx ly
)))))))
1691 ;;; Notify window functions
1698 (labels ((text-string (tx)
1703 (get-color (typecase tx
1705 (t *notify-window-foreground
*)))))
1706 (defun is-notify-window-p (win)
1707 (when (and (xlib:window-p win
) (xlib:window-p window
))
1708 (xlib:window-equal win window
)))
1710 (defun raise-notify-window ()
1711 (raise-window window
))
1713 (defun refresh-notify-window ()
1714 (add-timer 0.1 #'refresh-notify-window
:refresh-notify-window
)
1715 (when (and window gc font
)
1716 (raise-window window
)
1717 (let ((text-height (- (xlib:font-ascent font
) (xlib:font-descent font
))))
1718 (loop for tx in text
1720 (setf (xlib:gcontext-foreground gc
) (text-color tx
))
1721 (xlib:draw-glyphs window gc
1722 (truncate (/ (- width
(* (xlib:max-char-width font
) (length (text-string tx
)))) 2))
1724 (text-string tx
))))))
1726 (defun close-notify-window ()
1727 (erase-timer :refresh-notify-window
)
1728 (setf *never-managed-window-list
*
1729 (remove (list #'is-notify-window-p
'raise-window
)
1730 *never-managed-window-list
* :test
#'equal
))
1732 (xlib:free-gcontext gc
))
1734 (xlib:destroy-window window
))
1736 (xlib:close-font font
))
1737 (xlib:display-finish-output
*display
*)
1742 (defun open-notify-window (text-list)
1743 (close-notify-window)
1744 (setf font
(xlib:open-font
*display
* *notify-window-font-string
*))
1745 (let ((text-height (- (xlib:font-ascent font
) (xlib:font-descent font
))))
1746 (setf text text-list
)
1747 (setf width
(* (xlib:max-char-width font
) (+ (loop for tx in text-list
1748 maximize
(length (text-string tx
))) 2))
1749 height
(+ (* text-height
(length text-list
) 2) text-height
))
1750 (with-placement (*notify-window-placement
* x y width height
)
1751 (setf window
(xlib:create-window
:parent
*root
*
1756 :background
(get-color *notify-window-background
*)
1757 :border-width
*border-size
*
1758 :border
(get-color *notify-window-border
*)
1759 :colormap
(xlib:screen-default-colormap
*screen
*)
1760 :event-mask
'(:exposure
:key-press
))
1761 gc
(xlib:create-gcontext
:drawable window
1762 :foreground
(get-color *notify-window-foreground
*)
1763 :background
(get-color *notify-window-background
*)
1765 :line-style
:solid
))
1766 (setf (window-transparency window
) *notify-window-transparency
*)
1767 (when (frame-p (current-child))
1768 (setf current-child
(current-child)))
1769 (add-in-never-managed-window-list (list 'is-notify-window-p
'raise-window
))
1771 (refresh-notify-window)
1772 (xlib:display-finish-output
*display
*))))))
1774 (defun notify-message (delay &rest messages
)
1775 (erase-timer :close-notify-window
)
1776 (funcall #'open-notify-window messages
)
1777 (add-timer delay
#'close-notify-window
:close-notify-window
))
1780 (defun display-hello-window ()
1781 (notify-message *notify-window-delay
*
1782 '("Welcome to CLFSWM" "yellow")
1783 "Press Alt+F1 for help"))
1786 ;;; Run or raise functions
1787 (defun run-or-raise (raisep run-fn
&key
(maximized nil
))
1788 (let ((window (with-all-windows (*root-frame
* win
)
1789 (when (funcall raisep win
)
1792 (let ((parent (find-parent-frame window
)))
1793 (setf (current-child) parent
)
1794 (put-child-on-top window parent
)
1796 (change-root (find-root parent
) parent
))
1797 (focus-all-children window parent
)
1798 (show-all-children t
))
1801 ;;; Transparency setting
1802 (defun inc-transparency (window root-x root-y
)
1803 "Increment the child under mouse transparency"
1804 (declare (ignore root-x root-y
))
1805 (unless *in-second-mode
* (stop-button-event))
1806 (incf (child-transparency window
) 0.1))
1808 (defun dec-transparency (window root-x root-y
)
1809 "Decrement the child under mouse transparency"
1810 (declare (ignore root-x root-y
))
1811 (unless *in-second-mode
* (stop-button-event))
1812 (decf (child-transparency window
) 0.1))
1814 (defun inc-transparency-slow (window root-x root-y
)
1815 "Increment slowly the child under mouse transparency"
1816 (declare (ignore root-x root-y
))
1817 (unless *in-second-mode
* (stop-button-event))
1818 (incf (child-transparency window
) 0.01))
1820 (defun dec-transparency-slow (window root-x root-y
)
1821 "Decrement slowly the child under mouse transparency"
1822 (declare (ignore root-x root-y
))
1823 (unless *in-second-mode
* (stop-button-event))
1824 (decf (child-transparency window
) 0.01))
1827 (defun key-inc-transparency ()
1828 "Increment the current window transparency"
1829 (with-current-window
1830 (incf (child-transparency window
) 0.1)))
1832 (defun key-dec-transparency ()
1833 "Decrement the current window transparency"
1834 (with-current-window
1835 (decf (child-transparency window
) 0.1)))
1841 ;;; Geometry change functions
1842 (defun swap-frame-geometry ()
1843 "Swap current brother frame geometry"
1844 (when (frame-p (current-child))
1845 (let ((parent (find-parent-frame (current-child))))
1846 (when (frame-p parent
)
1847 (let ((brother (second (frame-child parent
))))
1848 (when (frame-p brother
)
1849 (rotatef (frame-x (current-child)) (frame-x brother
))
1850 (rotatef (frame-y (current-child)) (frame-y brother
))
1851 (rotatef (frame-w (current-child)) (frame-w brother
))
1852 (rotatef (frame-h (current-child)) (frame-h brother
))
1853 (show-all-children t
)
1854 (leave-second-mode)))))))
1856 (defun rotate-frame-geometry-generic (fun)
1857 "(Rotate brother frame geometry"
1858 (when (frame-p (current-child))
1859 (let ((parent (find-parent-frame (current-child))))
1860 (when (frame-p parent
)
1861 (let* ((child-list (funcall fun
(frame-child parent
)))
1862 (first (first child-list
)))
1863 (dolist (child (rest child-list
))
1864 (when (and (frame-p first
) (frame-p child
))
1865 (rotatef (frame-x first
) (frame-x child
))
1866 (rotatef (frame-y first
) (frame-y child
))
1867 (rotatef (frame-w first
) (frame-w child
))
1868 (rotatef (frame-h first
) (frame-h child
))
1869 (setf first child
)))
1870 (show-all-children t
))))))
1873 (defun rotate-frame-geometry ()
1874 "Rotate brother frame geometry"
1875 (rotate-frame-geometry-generic #'identity
))
1877 (defun anti-rotate-frame-geometry ()
1878 "Anti rotate brother frame geometry"
1879 (rotate-frame-geometry-generic #'reverse
))