1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Utility
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2010 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 ;;; --------------------------------------------------------------------------
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
))))
76 (defun rename-current-child ()
77 "Rename the current child"
78 (let ((name (query-string (format nil
"New child name: (last: ~A)" (child-name *current-child
*))
79 (child-name *current-child
*))))
80 (rename-child *current-child
* name
)
84 (defun renumber-current-frame ()
85 "Renumber the current frame"
86 (when (frame-p *current-child
*)
87 (let ((number (query-number (format nil
"New child number: (last: ~A)" (frame-number *current-child
*))
88 (frame-number *current-child
*))))
89 (setf (frame-number *current-child
*) number
)
90 (leave-second-mode))))
95 (defun add-default-frame ()
96 "Add a default frame in the current frame"
97 (when (frame-p *current-child
*)
98 (let ((name (query-string "Frame name")))
99 (push (create-frame :name name
) (frame-child *current-child
*))))
103 (defun add-placed-frame ()
104 "Add a placed frame in the current frame"
105 (when (frame-p *current-child
*)
106 (let ((name (query-string "Frame name"))
107 (x (/ (query-number "Frame x in percent (%)") 100))
108 (y (/ (query-number "Frame y in percent (%)") 100))
109 (w (/ (query-number "Frame width in percent (%)") 100))
110 (h (/ (query-number "Frame height in percent (%)") 100)))
111 (push (create-frame :name name
:x x
:y y
:w w
:h h
)
112 (frame-child *current-child
*))))
117 (defun delete-focus-window-generic (close-fun)
118 (let ((window (xlib:input-focus
*display
*)))
119 (when (and window
(not (xlib:window-equal window
*no-focus-window
*)))
120 (when (child-equal-p window
*current-child
*)
121 (setf *current-child
* *current-root
*))
123 (delete-child-and-children-in-all-frames window close-fun
)
124 (show-all-children))))
126 (defun delete-focus-window ()
127 "Close focus window: Delete the focus window in all frames and workspaces"
128 (delete-focus-window-generic 'delete-window
))
130 (defun destroy-focus-window ()
131 "Kill focus window: Destroy the focus window in all frames and workspaces"
132 (delete-focus-window-generic 'destroy-window
))
134 (defun remove-focus-window ()
135 "Remove the focus window from the current frame"
136 (let ((window (xlib:input-focus
*display
*)))
137 (when (and window
(not (xlib:window-equal window
*no-focus-window
*)))
138 (setf *current-child
* *current-root
*)
140 (remove-child-in-frame window
(find-parent-frame window
))
141 (show-all-children))))
144 (defun unhide-all-windows-in-current-child ()
145 "Unhide all hidden windows into the current child"
146 (dolist (window (get-hidden-windows))
147 (unhide-window window
)
148 (process-new-window window
)
155 (defun find-window-under-mouse (x y
)
156 "Return the child window under the mouse"
158 (with-all-windows-frames-and-parent (*current-root
* child parent
)
159 (when (and (or (managed-window-p child parent
) (child-equal-p parent
*current-child
*))
160 (in-window child x y
))
162 (when (in-frame child x y
)
163 (setf win
(frame-window child
))))
169 (defun find-child-under-mouse-in-never-managed-windows (x y
)
170 "Return the child under mouse from never managed windows"
172 (dolist (win (xlib:query-tree
*root
*))
173 (unless (window-hidden-p win
)
174 (multiple-value-bind (never-managed raise
)
175 (never-managed-window-p win
)
176 (when (and never-managed raise
(in-window win x y
))
181 (defun find-child-under-mouse-in-child-tree (x y
&optional first-foundp
)
182 "Return the child under the mouse"
184 (with-all-windows-frames-and-parent (*current-root
* child parent
)
185 (when (and (not (window-hidden-p child
))
186 (or (managed-window-p child parent
) (child-equal-p parent
*current-child
*))
187 (in-window child x y
))
189 (return-from find-child-under-mouse-in-child-tree child
)
191 (when (in-frame child x y
)
193 (return-from find-child-under-mouse-in-child-tree child
)
198 (defun find-child-under-mouse (x y
&optional first-foundp also-never-managed
)
199 "Return the child under the mouse"
200 (or (and also-never-managed
201 (find-child-under-mouse-in-never-managed-windows x y
))
202 (find-child-under-mouse-in-child-tree x y first-foundp
)))
208 ;;; Selection functions
209 (defun clear-selection ()
210 "Clear the current selection"
211 (setf *child-selection
* nil
)
212 (display-frame-info *current-root
*))
214 (defun copy-current-child ()
215 "Copy the current child to the selection"
216 (pushnew *current-child
* *child-selection
*)
217 (display-frame-info *current-root
*))
220 (defun cut-current-child ()
221 "Cut the current child to the selection"
223 (hide-all *current-child
*)
224 (remove-child-in-frame *current-child
* (find-parent-frame *current-child
* *current-root
*))
225 (setf *current-child
* *current-root
*)
228 (defun remove-current-child ()
229 "Remove the current child from its parent frame"
230 (hide-all *current-child
*)
231 (remove-child-in-frame *current-child
* (find-parent-frame *current-child
* *current-root
*))
232 (setf *current-child
* *current-root
*)
235 (defun delete-current-child ()
236 "Delete the current child and its children in all frames"
237 (hide-all *current-child
*)
238 (delete-child-and-children-in-all-frames *current-child
*)
242 (defun paste-selection-no-clear ()
243 "Paste the selection in the current frame - Do not clear the selection after paste"
244 (let ((frame-dest (typecase *current-child
*
245 (xlib:window
(find-parent-frame *current-child
* *current-root
*))
246 (frame *current-child
*))))
248 (dolist (child *child-selection
*)
249 (unless (find-child-in-parent child frame-dest
)
250 (pushnew child
(frame-child frame-dest
))))
251 (show-all-children))))
253 (defun paste-selection ()
254 "Paste the selection in the current frame"
255 (paste-selection-no-clear)
256 (setf *child-selection
* nil
)
257 (display-frame-info *current-root
*))
262 ;;; Maximize function
263 (defun frame-toggle-maximize ()
264 "Maximize/Unmaximize the current frame in its parent frame"
265 (when (frame-p *current-child
*)
266 (let ((unmaximized-coords (frame-data-slot *current-child
* :unmaximized-coords
)))
267 (if unmaximized-coords
268 (with-slots (x y w h
) *current-child
*
269 (destructuring-bind (nx ny nw nh
) unmaximized-coords
270 (setf (frame-data-slot *current-child
* :unmaximized-coords
) nil
271 x nx y ny w nw h nh
)))
272 (with-slots (x y w h
) *current-child
*
273 (setf (frame-data-slot *current-child
* :unmaximized-coords
)
277 (leave-second-mode)))
287 ;;; CONFIG - Identify mode
288 (defun identify-key ()
291 (font (xlib:open-font
*display
* *identify-font-string
*))
292 (window (xlib:create-window
:parent
*root
*
294 :width
(- (xlib:screen-width
*screen
*) 2)
295 :height
(* 5 (+ (xlib:max-char-ascent font
) (xlib:max-char-descent font
)))
296 :background
(get-color *identify-background
*)
298 :border
(get-color *identify-border
*)
299 :colormap
(xlib:screen-default-colormap
*screen
*)
300 :event-mask
'(:exposure
)))
301 (gc (xlib:create-gcontext
:drawable window
302 :foreground
(get-color *identify-foreground
*)
303 :background
(get-color *identify-background
*)
305 :line-style
:solid
)))
306 (labels ((print-doc (msg hash-table-key pos code state
)
307 (let ((function (find-key-from-code hash-table-key code state
)))
308 (when (and function
(fboundp (first function
)))
309 (xlib:draw-glyphs
*pixmap-buffer
* gc
10 (+ (* pos
(+ (xlib:max-char-ascent font
) (xlib:max-char-descent font
))) 5)
310 (format nil
"~A ~A" msg
(documentation (first function
) 'function
))))))
311 (print-key (code state keysym key modifiers
)
312 (clear-pixmap-buffer window gc
)
313 (setf (xlib:gcontext-foreground gc
) (get-color *identify-foreground
*))
314 (xlib:draw-glyphs
*pixmap-buffer
* gc
5 (+ (xlib:max-char-ascent font
) 5)
315 (format nil
"Press a key to identify. Press 'q' to stop the identify loop."))
317 (xlib:draw-glyphs
*pixmap-buffer
* gc
10 (+ (* 2 (+ (xlib:max-char-ascent font
) (xlib:max-char-descent font
))) 5)
318 (format nil
"Code=~A KeySym=~S Key=~S Modifiers=~A"
319 code keysym key modifiers
))
320 (print-doc "Main mode : " *main-keys
* 3 code state
)
321 (print-doc "Second mode: " *second-keys
* 4 code state
))
322 (copy-pixmap-buffer window gc
))
323 (handle-identify-key (&rest event-slots
&key root code state
&allow-other-keys
)
324 (declare (ignore event-slots root
))
325 (let* ((modifiers (state->modifiers state
))
326 (key (keycode->char code state
))
327 (keysym (keysym->keysym-name
(keycode->keysym code modifiers
))))
328 (setf done
(and (equal key
#\q
) (equal modifiers
*default-modifiers
*)))
329 (dbg code keysym key modifiers
)
330 (print-key code state keysym key modifiers
)
332 (handle-identify (&rest event-slots
&key display event-key
&allow-other-keys
)
333 (declare (ignore display
))
335 (:key-press
(apply #'handle-identify-key event-slots
) t
)
336 (:exposure
(print-key nil nil nil nil nil
)))
338 (xgrab-pointer *root
* 92 93)
340 (format t
"~&Press 'q' to stop the identify loop~%")
341 (print-key nil nil nil nil nil
)
345 (when (xlib:event-listen
*display
* *loop-timeout
*)
346 (xlib:process-event
*display
* :handler
#'handle-identify
))
347 (xlib:display-finish-output
*display
*))
348 (xlib:destroy-window window
)
349 (xlib:close-font font
)
350 (xgrab-pointer *root
* 66 67)))))
357 (defun eval-from-query-string ()
358 "Eval a lisp form from the query input"
359 (let ((form (query-string (format nil
"Eval Lisp - ~A" (package-name *package
*))))
361 (when (and form
(not (equal form
"")))
362 (let ((printed-result
363 (with-output-to-string (*standard-output
*)
364 (setf result
(handler-case
365 (loop for i in
(multiple-value-list
366 (eval (read-from-string form
)))
367 collect
(format nil
"~S" i
))
369 (format nil
"~A" condition
)))))))
370 (info-mode (expand-newline (append (ensure-list (format nil
"> ~A" form
))
371 (ensure-list printed-result
)
372 (ensure-list result
)))
373 :width
(- (xlib:screen-width
*screen
*) 2))
374 (eval-from-query-string)))))
379 (defun run-program-from-query-string ()
380 "Run a program from the query input"
381 (multiple-value-bind (program return
)
382 (query-string "Run:")
383 (when (and (equal return
:return
) program
(not (equal program
"")))
384 (setf *second-mode-leave-function
* (let ((cmd (concatenate 'string
"cd $HOME && " program
)))
387 (leave-second-mode))))
392 ;;; Frame name actions
393 (defun ask-frame-name (msg)
395 (let ((all-frame-name nil
))
396 (with-all-frames (*root-frame
* frame
)
397 (awhen (frame-name frame
) (push it all-frame-name
)))
398 (query-string msg
"" all-frame-name
)))
401 ;;; Focus by functions
402 (defun focus-frame-by (frame)
403 (when (frame-p frame
)
404 (hide-all *current-root
*)
405 (focus-all-children frame
(or (find-parent-frame frame
*current-root
*)
406 (find-parent-frame frame
)
408 (show-all-children)))
411 (defun focus-frame-by-name ()
412 "Focus a frame by name"
413 (focus-frame-by (find-frame-by-name (ask-frame-name "Focus frame:")))
416 (defun focus-frame-by-number ()
417 "Focus a frame by number"
418 (focus-frame-by (find-frame-by-number (query-number "Focus frame by number:")))
422 ;;; Open by functions
423 (defun open-frame-by (frame)
424 (when (frame-p frame
)
425 (push (create-frame :name
(query-string "Frame name")) (frame-child frame
))
426 (show-all-children)))
430 (defun open-frame-by-name ()
431 "Open a new frame in a named frame"
432 (open-frame-by (find-frame-by-name (ask-frame-name "Open a new frame in: ")))
435 (defun open-frame-by-number ()
436 "Open a new frame in a numbered frame"
437 (open-frame-by (find-frame-by-number (query-number "Open a new frame in the group numbered:")))
441 ;;; Delete by functions
442 (defun delete-frame-by (frame)
443 (hide-all *current-root
*)
444 (unless (child-equal-p frame
*root-frame
*)
445 (when (child-equal-p frame
*current-root
*)
446 (setf *current-root
* *root-frame
*))
447 (when (child-equal-p frame
*current-child
*)
448 (setf *current-child
* *current-root
*))
449 (remove-child-in-frame frame
(find-parent-frame frame
)))
453 (defun delete-frame-by-name ()
454 "Delete a frame by name"
455 (delete-frame-by (find-frame-by-name (ask-frame-name "Delete frame: ")))
458 (defun delete-frame-by-number ()
459 "Delete a frame by number"
460 (delete-frame-by (find-frame-by-number (query-number "Delete frame by number:")))
465 (defun move-child-to (child frame-dest
)
466 (when (and child
(frame-p frame-dest
))
467 (hide-all *current-root
*)
468 (remove-child-in-frame child
(find-parent-frame child
))
469 (pushnew child
(frame-child frame-dest
))
470 (focus-all-children child frame-dest
)
471 (show-all-children)))
473 (defun move-current-child-by-name ()
474 "Move current child in a named frame"
475 (move-child-to *current-child
*
477 (ask-frame-name (format nil
"Move '~A' to frame: " (child-name *current-child
*)))))
480 (defun move-current-child-by-number ()
481 "Move current child in a numbered frame"
482 (move-child-to *current-child
*
483 (find-frame-by-number
484 (query-number (format nil
"Move '~A' to frame numbered:" (child-name *current-child
*)))))
489 (defun copy-child-to (child frame-dest
)
490 (when (and child
(frame-p frame-dest
))
491 (hide-all *current-root
*)
492 (pushnew child
(frame-child frame-dest
))
493 (focus-all-children child frame-dest
)
494 (show-all-children)))
496 (defun copy-current-child-by-name ()
497 "Copy current child in a named frame"
498 (copy-child-to *current-child
*
500 (ask-frame-name (format nil
"Copy '~A' to frame: " (child-name *current-child
*)))))
503 (defun copy-current-child-by-number ()
504 "Copy current child in a numbered frame"
505 (copy-child-to *current-child
*
506 (find-frame-by-number
507 (query-number (format nil
"Copy '~A' to frame numbered:" (child-name *current-child
*)))))
514 (defun show-all-frames-info ()
515 "Show all frames info windows"
516 (let ((*show-root-frame-p
* t
))
518 (with-all-frames (*current-root
* frame
)
519 (raise-window (frame-window frame
))
520 (display-frame-info frame
))))
522 (defun hide-all-frames-info ()
523 "Hide all frames info windows"
524 (with-all-windows (*current-root
* window
)
525 (raise-window window
))
526 (hide-child *current-root
*)
529 (defun show-all-frames-info-key ()
530 "Show all frames info windows until a key is release"
531 (show-all-frames-info)
532 (wait-no-key-or-button-press)
533 (hide-all-frames-info))
540 (defun move-frame (frame parent orig-x orig-y
)
541 (when (and frame parent
)
542 (hide-all-children frame
)
543 (with-slots (window) frame
544 (move-window window orig-x orig-y
#'display-frame-info
(list frame
))
545 (setf (frame-x frame
) (x-px->fl
(xlib:drawable-x window
) parent
)
546 (frame-y frame
) (y-px->fl
(xlib:drawable-y window
) parent
)))
547 (show-all-children)))
550 (defun resize-frame (frame parent orig-x orig-y
)
551 (when (and frame parent
)
552 (hide-all-children frame
)
553 (with-slots (window) frame
554 (resize-window window orig-x orig-y
#'display-frame-info
(list frame
))
555 (setf (frame-w frame
) (w-px->fl
(xlib:drawable-width window
) parent
)
556 (frame-h frame
) (h-px->fl
(xlib:drawable-height window
) parent
)))
557 (show-all-children)))
561 (defun mouse-click-to-focus-generic (window root-x root-y mouse-fn
)
562 "Focus the current frame or focus the current window parent
563 mouse-fun is #'move-frame or #'resize-frame"
565 (child (find-child-under-mouse root-x root-y
))
566 (parent (find-parent-frame child
))
567 (root-p (or (child-equal-p window
*root
*)
568 (and (frame-p *current-root
*)
569 (child-equal-p child
(frame-window *current-root
*))))))
570 (labels ((add-new-frame ()
571 (setf child
(create-frame)
572 parent
*current-root
*
573 mouse-fn
#'resize-frame
)
574 (place-frame child parent root-x root-y
10 10)
575 (map-window (frame-window child
))
576 (pushnew child
(frame-child *current-root
*))))
577 (when (or (not root-p
) *create-frame-on-root
*)
582 (unless (equal (type-of child
) 'frame
)
583 (setf child
(find-frame-window child
*current-root
*)))
584 (setf parent
(find-parent-frame child
)))))
585 (when (and child parent
586 (focus-all-children child parent
587 (not (and (child-equal-p *current-child
* *current-root
*)
588 (xlib:window-p
*current-root
*)))))
589 (when (show-all-children)
590 (setf to-replay nil
)))
591 (when (equal (type-of child
) 'frame
)
592 (funcall mouse-fn child parent root-x root-y
))
595 (replay-button-event)
596 (stop-button-event)))))
599 (defun mouse-click-to-focus-and-move (window root-x root-y
)
600 "Move and focus the current frame or focus the current window parent.
601 Or do actions on corners"
602 (or (do-corner-action root-x root-y
*corner-main-mode-left-button
*)
603 (mouse-click-to-focus-generic window root-x root-y
#'move-frame
)))
605 (defun mouse-click-to-focus-and-resize (window root-x root-y
)
606 "Resize and focus the current frame or focus the current window parent.
607 Or do actions on corners"
608 (or (do-corner-action root-x root-y
*corner-main-mode-right-button
*)
609 (mouse-click-to-focus-generic window root-x root-y
#'resize-frame
)))
611 (defun mouse-middle-click (window root-x root-y
)
612 "Do actions on corners"
613 (declare (ignore window
))
614 (or (do-corner-action root-x root-y
*corner-main-mode-middle-button
*)
615 (replay-button-event)))
620 (defun mouse-focus-move/resize-generic
(root-x root-y mouse-fn window-parent
)
621 "Focus the current frame or focus the current window parent
622 mouse-fun is #'move-frame or #'resize-frame.
623 Focus child and its parents -
624 For window: set current child to window or its parent according to window-parent"
625 (labels ((move/resize-managed
(child)
626 (let ((parent (find-parent-frame child
)))
627 (when (and (child-equal-p child
*current-root
*)
628 (frame-p *current-root
*))
629 (setf child
(create-frame)
630 parent
*current-root
*
631 mouse-fn
#'resize-frame
)
632 (place-frame child parent root-x root-y
10 10)
633 (map-window (frame-window child
))
634 (pushnew child
(frame-child *current-root
*)))
635 (focus-all-children child parent window-parent
)
639 (if (managed-window-p child parent
)
640 (funcall mouse-fn parent
(find-parent-frame parent
) root-x root-y
)
641 (funcall (cond ((eql mouse-fn
#'move-frame
) #'move-window
)
642 ((eql mouse-fn
#'resize-frame
) #'resize-window
))
643 child root-x root-y
)))
644 (frame (funcall mouse-fn child parent root-x root-y
)))
645 (show-all-children)))
646 (move/resize-never-managed
(child raise-fun
)
647 (funcall raise-fun child
)
648 (funcall (cond ((eql mouse-fn
#'move-frame
) #'move-window
)
649 ((eql mouse-fn
#'resize-frame
) #'resize-window
))
650 child root-x root-y
)))
651 (let ((child (find-child-under-mouse root-x root-y nil t
)))
652 (multiple-value-bind (never-managed raise-fun
)
653 (never-managed-window-p child
)
654 (if (and (xlib:window-p child
) never-managed raise-fun
)
655 (move/resize-never-managed child raise-fun
)
656 (move/resize-managed child
))))))
662 (defun test-mouse-binding (window root-x root-y
)
663 (dbg window root-x root-y
)
664 (replay-button-event))
668 (defun mouse-select-next-level (window root-x root-y
)
669 "Select the next level in frame"
670 (declare (ignore root-x root-y
))
671 (let ((frame (find-frame-window window
)))
672 (when (or frame
(xlib:window-equal window
*root
*))
674 (replay-button-event)))
678 (defun mouse-select-previous-level (window root-x root-y
)
679 "Select the previous level in frame"
680 (declare (ignore root-x root-y
))
681 (let ((frame (find-frame-window window
)))
682 (when (or frame
(xlib:window-equal window
*root
*))
683 (select-previous-level))
684 (replay-button-event)))
688 (defun mouse-enter-frame (window root-x root-y
)
689 "Enter in the selected frame - ie make it the root frame"
690 (declare (ignore root-x root-y
))
691 (let ((frame (find-frame-window window
)))
692 (when (or frame
(xlib:window-equal window
*root
*))
694 (replay-button-event)))
698 (defun mouse-leave-frame (window root-x root-y
)
699 "Leave the selected frame - ie make its parent the root frame"
700 (declare (ignore root-x root-y
))
701 (let ((frame (find-frame-window window
)))
702 (when (or frame
(xlib:window-equal window
*root
*))
704 (replay-button-event)))
709 ;;;;;| Various definitions
712 (defun show-help (&optional
(browser "dillo") (tempfile "/tmp/clfswm.html"))
713 "Show current keys and buttons bindings"
715 (produce-doc-html-in-file tempfile
))
717 (do-shell (format nil
"~A ~A" browser tempfile
)))
721 ;;; Bind or jump functions
722 (let ((key-slots (make-array 10 :initial-element nil
))
724 (defun bind-on-slot (&optional
(slot current-slot
))
725 "Bind current child to slot"
726 (setf (aref key-slots slot
) *current-child
*))
728 (defun remove-binding-on-slot ()
729 "Remove binding on slot"
730 (setf (aref key-slots current-slot
) nil
))
732 (defun jump-to-slot ()
734 (let ((jump-child (aref key-slots current-slot
)))
735 (when (find-child jump-child
*root-frame
*)
736 (hide-all *current-root
*)
737 (setf *current-root
* jump-child
738 *current-child
* *current-root
*)
739 (focus-all-children *current-child
* *current-child
*)
740 (show-all-children))))
742 (defun bind-or-jump (n)
743 "Bind or jump to a slot (a frame or a window)"
744 (setf current-slot
(- n
1))
745 (let ((default-bind `("b" bind-on-slot
746 ,(format nil
"Bind slot ~A on child: ~A" n
(child-fullname *current-child
*)))))
747 (info-mode-menu (aif (aref key-slots current-slot
)
749 ("BackSpace" remove-binding-on-slot
750 ,(format nil
"Remove slot ~A binding on child: ~A" n
(child-fullname *current-child
*)))
753 ,(format nil
"Jump to child: ~A" (aif (aref key-slots current-slot
)
755 "Not set - Please, bind it with 'b'")))
756 ("Return" jump-to-slot
"Same thing")
757 ("space" jump-to-slot
"Same thing"))
758 (list default-bind
))))))
762 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
763 ;;; Useful function for the second mode ;;;
764 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
765 (defmacro with-movement
(&body body
)
766 `(when (frame-p *current-child
*)
769 (display-all-frame-info)
770 (draw-second-mode-window)
771 (open-menu (find-menu 'frame-movement-menu
))))
775 (defun current-frame-pack-up ()
776 "Pack the current frame up"
777 (with-movement (pack-frame-up *current-child
* (find-parent-frame *current-child
* *current-root
*))))
779 (defun current-frame-pack-down ()
780 "Pack the current frame down"
781 (with-movement (pack-frame-down *current-child
* (find-parent-frame *current-child
* *current-root
*))))
783 (defun current-frame-pack-left ()
784 "Pack the current frame left"
785 (with-movement (pack-frame-left *current-child
* (find-parent-frame *current-child
* *current-root
*))))
787 (defun current-frame-pack-right ()
788 "Pack the current frame right"
789 (with-movement (pack-frame-right *current-child
* (find-parent-frame *current-child
* *current-root
*))))
792 (defun center-current-frame ()
793 "Center the current frame"
794 (with-movement (center-frame *current-child
*)))
797 (defun current-frame-fill-up ()
798 "Fill the current frame up"
799 (with-movement (fill-frame-up *current-child
* (find-parent-frame *current-child
* *current-root
*))))
801 (defun current-frame-fill-down ()
802 "Fill the current frame down"
803 (with-movement (fill-frame-down *current-child
* (find-parent-frame *current-child
* *current-root
*))))
805 (defun current-frame-fill-left ()
806 "Fill the current frame left"
807 (with-movement (fill-frame-left *current-child
* (find-parent-frame *current-child
* *current-root
*))))
809 (defun current-frame-fill-right ()
810 "Fill the current frame right"
811 (with-movement (fill-frame-right *current-child
* (find-parent-frame *current-child
* *current-root
*))))
813 (defun current-frame-fill-all-dir ()
814 "Fill the current frame in all directions"
816 (let ((parent (find-parent-frame *current-child
* *current-root
*)))
817 (fill-frame-up *current-child
* parent
)
818 (fill-frame-down *current-child
* parent
)
819 (fill-frame-left *current-child
* parent
)
820 (fill-frame-right *current-child
* parent
))))
822 (defun current-frame-fill-vertical ()
823 "Fill the current frame vertically"
825 (let ((parent (find-parent-frame *current-child
* *current-root
*)))
826 (fill-frame-up *current-child
* parent
)
827 (fill-frame-down *current-child
* parent
))))
829 (defun current-frame-fill-horizontal ()
830 "Fill the current frame horizontally"
832 (let ((parent (find-parent-frame *current-child
* *current-root
*)))
833 (fill-frame-left *current-child
* parent
)
834 (fill-frame-right *current-child
* parent
))))
838 (defun current-frame-resize-up ()
839 "Resize the current frame up to its half height"
840 (with-movement (resize-half-height-up *current-child
*)))
842 (defun current-frame-resize-down ()
843 "Resize the current frame down to its half height"
844 (with-movement (resize-half-height-down *current-child
*)))
846 (defun current-frame-resize-left ()
847 "Resize the current frame left to its half width"
848 (with-movement (resize-half-width-left *current-child
*)))
850 (defun current-frame-resize-right ()
851 "Resize the current frame right to its half width"
852 (with-movement (resize-half-width-right *current-child
*)))
854 (defun current-frame-resize-all-dir ()
855 "Resize down the current frame"
856 (with-movement (resize-frame-down *current-child
*)))
858 (defun current-frame-resize-all-dir-minimal ()
859 "Resize down the current frame to its minimal size"
860 (with-movement (resize-minimal-frame *current-child
*)))
863 ;;; Children navigation
864 (defun with-movement-select-next-brother ()
865 "Select the next brother frame"
866 (with-movement (select-next-brother)))
868 (defun with-movement-select-previous-brother ()
869 "Select the previous brother frame"
870 (with-movement (select-previous-brother)))
872 (defun with-movement-select-next-level ()
873 "Select the next level"
874 (with-movement (select-next-level)))
876 (defun with-movement-select-previous-level ()
877 "Select the previous levelframe"
878 (with-movement (select-previous-level)))
880 (defun with-movement-select-next-child ()
881 "Select the next child"
882 (with-movement (select-next-child)))
886 ;;; Adapt frame functions
887 (defun adapt-current-frame-to-window-hints-generic (width-p height-p
)
888 "Adapt the current frame to the current window minimal size hints"
889 (when (frame-p *current-child
*)
890 (let ((window (first (frame-child *current-child
*))))
891 (when (xlib:window-p window
)
892 (let* ((hints (xlib:wm-normal-hints window
))
893 (min-width (and hints
(xlib:wm-size-hints-min-width hints
)))
894 (min-height (and hints
(xlib:wm-size-hints-min-height hints
))))
895 (when (and width-p min-width
)
896 (setf (frame-rw *current-child
*) min-width
))
897 (when (and height-p min-height
)
898 (setf (frame-rh *current-child
*) min-height
))
899 (fixe-real-size *current-child
* (find-parent-frame *current-child
*))
900 (leave-second-mode))))))
902 (defun adapt-current-frame-to-window-hints ()
903 "Adapt the current frame to the current window minimal size hints"
904 (adapt-current-frame-to-window-hints-generic t t
))
906 (defun adapt-current-frame-to-window-width-hint ()
907 "Adapt the current frame to the current window minimal width hint"
908 (adapt-current-frame-to-window-hints-generic t nil
))
910 (defun adapt-current-frame-to-window-height-hint ()
911 "Adapt the current frame to the current window minimal height hint"
912 (adapt-current-frame-to-window-hints-generic nil t
))
917 ;;; Managed window type functions
918 (defun current-frame-manage-window-type-generic (type-list)
919 (when (frame-p *current-child
*)
920 (setf (frame-managed-type *current-child
*) type-list
921 (frame-forced-managed-window *current-child
*) nil
922 (frame-forced-unmanaged-window *current-child
*) nil
))
926 (defun current-frame-manage-window-type ()
927 "Change window types to be managed by a frame"
928 (when (frame-p *current-child
*)
929 (let* ((type-str (query-string "Managed window type: (all, normal, transient, maxsize, desktop, dock, toolbar, menu, utility, splash, dialog)"
930 (format nil
"~{~:(~A~) ~}" (frame-managed-type *current-child
*))))
931 (type-list (loop :for type
:in
(split-string type-str
)
932 :collect
(intern (string-upcase type
) :keyword
))))
933 (current-frame-manage-window-type-generic type-list
))))
936 (defun current-frame-manage-all-window-type ()
937 "Manage all window type"
938 (current-frame-manage-window-type-generic '(:all
)))
940 (defun current-frame-manage-only-normal-window-type ()
941 "Manage only normal window type"
942 (current-frame-manage-window-type-generic '(:normal
)))
944 (defun current-frame-manage-no-window-type ()
945 "Do not manage any window type"
946 (current-frame-manage-window-type-generic nil
))
955 ;;; Force window functions
956 (defun force-window-in-frame ()
957 "Force the current window to move in the frame (Useful only for unmanaged windows)"
959 (let ((parent (find-parent-frame window
)))
960 (setf (xlib:drawable-x window
) (frame-rx parent
)
961 (xlib:drawable-y window
) (frame-ry parent
))
962 (xlib:display-finish-output
*display
*)))
966 (defun force-window-center-in-frame ()
967 "Force the current window to move in the center of the frame (Useful only for unmanaged windows)"
969 (let ((parent (find-parent-frame window
)))
970 (setf (xlib:drawable-x window
) (truncate (+ (frame-rx parent
)
971 (/ (- (frame-rw parent
)
972 (xlib:drawable-width window
)) 2)))
973 (xlib:drawable-y window
) (truncate (+ (frame-ry parent
)
974 (/ (- (frame-rh parent
)
975 (xlib:drawable-height window
)) 2))))
976 (xlib:display-finish-output
*display
*)))
981 (defun display-current-window-info ()
982 "Display information on the current window"
984 (info-mode (list (format nil
"Window: ~A" window
)
985 (format nil
"Window name: ~A" (xlib:wm-name window
))
986 (format nil
"Window class: ~A" (xlib:get-wm-class window
))
987 (format nil
"Window type: ~:(~A~)" (window-type window
))
988 (format nil
"Window id: 0x~X" (xlib:window-id window
)))))
992 (defun manage-current-window ()
993 "Force to manage the current window by its parent frame"
995 (let ((parent (find-parent-frame window
)))
996 (with-slots ((managed forced-managed-window
)
997 (unmanaged forced-unmanaged-window
)) parent
998 (setf unmanaged
(child-remove window unmanaged
)
999 unmanaged
(remove (xlib:wm-name window
) unmanaged
:test
#'string-equal-p
))
1000 (pushnew window managed
))))
1001 (leave-second-mode))
1003 (defun unmanage-current-window ()
1004 "Force to not manage the current window by its parent frame"
1005 (with-current-window
1006 (let ((parent (find-parent-frame window
)))
1007 (with-slots ((managed forced-managed-window
)
1008 (unmanaged forced-unmanaged-window
)) parent
1009 (setf managed
(child-remove window managed
)
1010 managed
(remove (xlib:wm-name window
) managed
:test
#'string-equal-p
))
1011 (pushnew window unmanaged
))))
1012 (leave-second-mode))
1016 ;;; Moving child with the mouse button
1017 (defun mouse-move-child-over-frame (window root-x root-y
)
1018 "Move the child under the mouse cursor to another frame"
1019 (declare (ignore window
))
1020 (let ((child (find-child-under-mouse root-x root-y
)))
1021 (unless (child-equal-p child
*current-root
*)
1023 (remove-child-in-frame child
(find-parent-frame child
))
1024 (wait-mouse-button-release 50 51)
1025 (multiple-value-bind (x y
)
1026 (xlib:query-pointer
*root
*)
1027 (let ((dest (find-child-under-mouse x y
)))
1028 (when (xlib:window-p dest
)
1029 (setf dest
(find-parent-frame dest
)))
1030 (unless (child-equal-p child dest
)
1031 (move-child-to child dest
)
1032 (show-all-children))))))
1033 (stop-button-event))
1038 ;;; Hide/Show frame window functions
1039 (defun hide/show-frame-window
(frame value
)
1040 "Hide/show the frame window"
1041 (when (frame-p frame
)
1042 (setf (frame-show-window-p *current-child
*) value
)
1043 (show-all-children))
1044 (leave-second-mode))
1047 (defun hide-current-frame-window ()
1048 "Hide the current frame window"
1049 (hide/show-frame-window
*current-child
* nil
))
1051 (defun show-current-frame-window ()
1052 "Show the current frame window"
1053 (hide/show-frame-window
*current-child
* t
))
1057 ;;; Hide/Unhide current child
1058 (defun hide-current-child ()
1059 "Hide the current child"
1060 (unless (child-equal-p *current-child
* *current-root
*)
1061 (let ((parent (find-parent-frame *current-child
*)))
1062 (when (frame-p parent
)
1063 (with-slots (child hidden-children
) parent
1064 (hide-all *current-child
*)
1065 (setf child
(child-remove *current-child
* child
))
1066 (pushnew *current-child
* hidden-children
)
1067 (setf *current-child
* parent
))
1068 (show-all-children)))
1069 (leave-second-mode)))
1072 (defun frame-unhide-child (hidden frame-src frame-dest
)
1073 "Unhide a hidden child from frame-src in frame-dest"
1074 (with-slots (hidden-children) frame-src
1075 (setf hidden-children
(child-remove hidden hidden-children
)))
1076 (with-slots (child) frame-dest
1077 (pushnew hidden child
)))
1081 (defun unhide-a-child ()
1082 "Unhide a child in the current frame"
1083 (when (frame-p *current-child
*)
1084 (with-slots (child hidden-children
) *current-child
*
1085 (info-mode-menu (loop :for i
:from
0
1086 :for hidden
:in hidden-children
1087 :collect
(list (code-char (+ (char-code #\a) i
))
1090 (frame-unhide-child lhd
*current-child
* *current-child
*)))
1091 (format nil
"Unhide ~A" (child-fullname hidden
))))))
1092 (show-all-children))
1093 (leave-second-mode))
1096 (defun unhide-all-children ()
1097 "Unhide all current frame hidden children"
1098 (when (frame-p *current-child
*)
1099 (with-slots (child hidden-children
) *current-child
*
1100 (dolist (c hidden-children
)
1102 (setf hidden-children nil
))
1103 (show-all-children))
1104 (leave-second-mode))
1107 (defun unhide-a-child-from-all-frames ()
1108 "Unhide a child from all frames in the current frame"
1109 (when (frame-p *current-child
*)
1112 (with-all-frames (*root-frame
* frame
)
1113 (when (frame-hidden-children frame
)
1114 (push (format nil
"~A" (child-fullname frame
)) acc
)
1115 (dolist (hidden (frame-hidden-children frame
))
1116 (push (list (code-char (+ (char-code #\a) (incf keynum
)))
1119 (frame-unhide-child lhd frame
*current-child
*)))
1120 (format nil
"Unhide ~A" (child-fullname hidden
)))
1122 (info-mode-menu (nreverse acc
)))
1123 (show-all-children))
1124 (leave-second-mode))
1130 (let ((last-child nil
))
1131 (defun init-last-child ()
1132 (setf last-child nil
))
1133 (defun switch-to-last-child ()
1134 "Store the current child and switch to the previous one"
1135 (let ((current-child *current-child
*))
1137 (hide-all *current-root
*)
1138 (setf *current-root
* last-child
1139 *current-child
* *current-root
*)
1140 (focus-all-children *current-child
* *current-child
*)
1141 (show-all-children))
1142 (setf last-child current-child
))))
1150 ;;; Focus policy functions
1151 (defun set-focus-policy-generic (focus-policy)
1152 (when (frame-p *current-child
*)
1153 (setf (frame-focus-policy *current-child
*) focus-policy
))
1154 (leave-second-mode))
1157 (defun current-frame-set-click-focus-policy ()
1158 "Set a click focus policy for the current frame."
1159 (set-focus-policy-generic :click
))
1161 (defun current-frame-set-sloppy-focus-policy ()
1162 "Set a sloppy focus policy for the current frame."
1163 (set-focus-policy-generic :sloppy
))
1165 (defun current-frame-set-sloppy-strict-focus-policy ()
1166 "Set a (strict) sloppy focus policy only for windows in the current frame."
1167 (set-focus-policy-generic :sloppy-strict
))
1169 (defun current-frame-set-sloppy-select-policy ()
1170 "Set a sloppy select policy for the current frame."
1171 (set-focus-policy-generic :sloppy-select
))
1175 (defun set-focus-policy-generic-for-all (focus-policy)
1176 (with-all-frames (*root-frame
* frame
)
1177 (setf (frame-focus-policy frame
) focus-policy
))
1178 (leave-second-mode))
1181 (defun all-frames-set-click-focus-policy ()
1182 "Set a click focus policy for all frames."
1183 (set-focus-policy-generic-for-all :click
))
1185 (defun all-frames-set-sloppy-focus-policy ()
1186 "Set a sloppy focus policy for all frames."
1187 (set-focus-policy-generic-for-all :sloppy
))
1189 (defun all-frames-set-sloppy-strict-focus-policy ()
1190 "Set a (strict) sloppy focus policy for all frames."
1191 (set-focus-policy-generic-for-all :sloppy-strict
))
1193 (defun all-frames-set-sloppy-select-policy ()
1194 "Set a sloppy select policy for all frames."
1195 (set-focus-policy-generic-for-all :sloppy-select
))
1199 ;;; Ensure unique name/number functions
1200 (defun extract-number-from-name (name)
1201 (when (stringp name
)
1202 (let* ((pos (1+ (or (position #\. name
:from-end t
) -
1)))
1203 (number (parse-integer name
:junk-allowed t
:start pos
)))
1205 (if number
(subseq name
0 (1- pos
)) name
)))))
1210 (defun ensure-unique-name ()
1211 "Ensure that all children names are unique"
1212 (with-all-children (*root-frame
* child
)
1213 (multiple-value-bind (num1 name1
)
1214 (extract-number-from-name (child-name child
))
1215 (declare (ignore num1
))
1218 (with-all-children (*root-frame
* c
)
1219 (unless (child-equal-p child c
))
1220 (multiple-value-bind (num2 name2
)
1221 (extract-number-from-name (child-name c
))
1222 (when (string-equal name1 name2
)
1225 (when (> (length acc
) 1)
1226 (setf (child-name child
)
1227 (format nil
"~A.~A" name1
1228 (1+ (find-free-number (loop for i in acc when i collect
(1- i
)))))))))))
1229 (leave-second-mode))
1231 (defun ensure-unique-number ()
1232 "Ensure that all children numbers are unique"
1234 (with-all-frames (*root-frame
* frame
)
1235 (setf (frame-number frame
) (incf num
))))
1236 (leave-second-mode))
1240 ;;; Standard menu functions - Based on the XDG specifications
1241 (defparameter *xdg-section-list
* (append '(TextEditor FileManager WebBrowser
)
1242 '(AudioVideo Audio Video Development Education Game Graphics Network Office Settings System Utility
)
1243 '(TerminalEmulator Archlinux Screensaver
))
1244 "Config(Menu group): Standard menu sections")
1247 (defun um-create-xdg-section-list (menu)
1248 (dolist (section *xdg-section-list
*)
1249 (add-sub-menu menu
:next section
(format nil
"~A" section
) menu
)))
1251 (defun um-find-submenu (menu section-list
)
1253 (dolist (section section-list
)
1254 (awhen (find-toplevel-menu (intern (string-upcase section
) :clfswm
) menu
)
1258 (list (find-toplevel-menu 'Utility menu
)))))
1261 (defun um-extract-value (line)
1262 (second (split-string line
#\
=)))
1265 (defun um-add-desktop (desktop menu
)
1266 (let (name exec categories comment
)
1267 (when (probe-file desktop
)
1268 (with-open-file (stream desktop
:direction
:input
)
1269 (loop for line
= (read-line stream nil nil
)
1272 (cond ((first-position "Name=" line
) (setf name
(um-extract-value line
)))
1273 ((first-position "Exec=" line
) (setf exec
(um-extract-value line
)))
1274 ((first-position "Categories=" line
) (setf categories
(um-extract-value line
)))
1275 ((first-position "Comment=" line
) (setf comment
(um-extract-value line
))))
1276 (when (and name exec categories
)
1277 (let* ((sub-menu (um-find-submenu menu
(split-string categories
#\
;)))
1278 (fun-name (intern name
:clfswm
)))
1279 (setf (symbol-function fun-name
) (let ((do-exec exec
))
1282 (leave-second-mode)))
1283 (documentation fun-name
'function
) (format nil
"~A~A" name
(if comment
1284 (format nil
" - ~A" comment
)
1286 (dolist (m sub-menu
)
1287 (add-menu-key (menu-name m
) :next fun-name m
)))
1288 (setf name nil exec nil categories nil comment nil
)))))))
1291 (defun update-menus (&optional
(menu (make-menu :name
'main
:doc
"Main menu")))
1292 (um-create-xdg-section-list menu
)
1294 (found (make-hash-table :test
#'equal
)))
1295 (dolist (dir (remove-duplicates
1296 (split-string (getenv "XDG_DATA_DIRS") #\
:) :test
#'string-equal
))
1297 (dolist (desktop (directory (concatenate 'string dir
"/applications/**/*.desktop")))
1298 (unless (gethash (file-namestring desktop
) found
)
1299 (setf (gethash (file-namestring desktop
) found
) t
)
1300 (um-add-desktop desktop menu
)
1306 ;;; Close/Kill focused window
1308 (defun ask-close/kill-current-window
()
1309 "Close or kill the current window (ask before doing anything)"
1310 (let ((window (xlib:input-focus
*display
*)))
1312 (if (and window
(not (xlib:window-equal window
*no-focus-window
*)))
1313 `(,(format nil
"Focus window: ~A" (xlib:wm-name window
))
1314 (#\c delete-focus-window
"Close the focus window")
1315 (#\k destroy-focus-window
"Kill the focus window")
1316 (#\r remove-focus-window
)
1317 (#\u unhide-all-windows-in-current-child
))
1318 `(,(format nil
"Focus window: None")
1319 (#\u unhide-all-windows-in-current-child
))))))
1323 ;;; Other window manager functions
1324 (defun get-proc-list ()
1325 (let ((proc (do-shell "ps x -o pid=" nil t
))
1327 (loop for line
= (read-line proc nil nil
)
1329 do
(push line proc-list
))
1333 (defun run-other-window-manager ()
1334 (let ((proc-start (get-proc-list)))
1335 (do-shell *other-window-manager
* nil t
:terminal
)
1336 (let* ((proc-end (get-proc-list))
1337 (proc-diff (set-difference proc-end proc-start
:test
#'equal
)))
1338 (dbg 'killing-sigterm proc-diff
)
1339 (do-shell (format nil
"kill ~{ ~A ~} 2> /dev/null" proc-diff
) nil t
:terminal
)
1340 (dbg 'killing-sigkill proc-diff
)
1341 (do-shell (format nil
"kill -9 ~{ ~A ~} 2> /dev/null" proc-diff
) nil t
:terminal
)
1343 (setf *other-window-manager
* nil
)))
1346 (defun do-run-other-window-manager (window-manager)
1347 (setf *other-window-manager
* window-manager
)
1348 (throw 'exit-main-loop nil
))
1350 (defmacro def-run-other-window-manager
(name &optional definition
)
1351 (let ((definition (or definition name
)))
1352 `(defun ,(create-symbol "run-" name
) ()
1353 ,(format nil
"Run ~A" definition
)
1354 (do-run-other-window-manager ,(format nil
"~A" name
)))))
1356 (def-run-other-window-manager "xterm")
1357 (def-run-other-window-manager "icewm")
1358 (def-run-other-window-manager "twm")
1359 (def-run-other-window-manager "gnome-session" "Gnome")
1360 (def-run-other-window-manager "startkde" "KDE")
1361 (def-run-other-window-manager "xfce4-session" "XFCE")
1365 (do-run-other-window-manager "( lxsession & ); xterm -e \"echo ' /----------------------------------\\' ; echo ' | CLFSWM Note: |' ; echo ' | Close this window when done. |' ; echo ' \\----------------------------------/'; echo; echo; $SHELL\""))
1369 (do-run-other-window-manager "( xfce4-session &) ; xterm -e \"echo ' /----------------------------------\\' ; echo ' | CLFSWM Note: |' ; echo ' | Close this window when done. |' ; echo ' \\----------------------------------/'; echo; echo; $SHELL\""))
1372 (defun run-prompt-wm ()
1373 "Prompt for an other window manager"
1374 (let ((wm (query-string "Run an other window manager:" "icewm")))
1375 (do-run-other-window-manager wm
)))
1378 ;;; Hide or show unmanaged windows utility.
1379 (defun set-hide-unmanaged-window ()
1380 "Hide unmanaged windows when frame is not selected"
1381 (when (frame-p *current-child
*)
1382 (setf (frame-data-slot *current-child
* :unmanaged-window-action
) :hide
)
1383 (leave-second-mode)))
1385 (defun set-show-unmanaged-window ()
1386 "Show unmanaged windows when frame is not selected"
1387 (when (frame-p *current-child
*)
1388 (setf (frame-data-slot *current-child
* :unmanaged-window-action
) :show
)
1389 (leave-second-mode)))
1391 (defun set-default-hide-unmanaged-window ()
1392 "Set default behaviour to hide or not unmanaged windows when frame is not selected"
1393 (when (frame-p *current-child
*)
1394 (setf (frame-data-slot *current-child
* :unmanaged-window-action
) nil
)
1395 (leave-second-mode)))
1397 (defun set-globally-hide-unmanaged-window ()
1398 "Hide unmanaged windows by default. This is overriden by functions above"
1399 (setf *hide-unmanaged-window
* t
)
1400 (leave-second-mode))
1402 (defun set-globally-show-unmanaged-window ()
1403 "Show unmanaged windows by default. This is overriden by functions above"
1404 (setf *hide-unmanaged-window
* nil
)
1405 (leave-second-mode))
1408 ;;; Speed mouse movement.
1409 (let (minx miny maxx maxy history lx ly
)
1410 (labels ((middle (x1 x2
)
1411 (round (/ (+ x1 x2
) 2)))
1412 (reset-if-moved (x y
)
1413 (when (or (/= x
(or lx x
)) (/= y
(or ly y
)))
1414 (speed-mouse-reset)))
1415 (add-in-history (x y
)
1416 (push (list x y
) history
)))
1417 (defun speed-mouse-reset ()
1418 "Reset speed mouse coordinates"
1419 (setf minx nil miny nil maxx nil maxy nil history nil lx nil ly nil
))
1420 (defun speed-mouse-left ()
1421 "Speed move mouse to left"
1423 (reset-if-moved x y
)
1425 (add-in-history x y
)
1426 (setf lx
(middle (or minx
0) maxx
))
1427 (xlib:warp-pointer
*root
* lx y
)))
1428 (defun speed-mouse-right ()
1429 "Speed move mouse to right"
1431 (reset-if-moved x y
)
1433 (add-in-history x y
)
1434 (setf lx
(middle minx
(or maxx
(xlib:screen-width
*screen
*))))
1435 (xlib:warp-pointer
*root
* lx y
)))
1436 (defun speed-mouse-up ()
1437 "Speed move mouse to up"
1439 (reset-if-moved x y
)
1441 (add-in-history x y
)
1442 (setf ly
(middle (or miny
0) maxy
))
1443 (xlib:warp-pointer
*root
* x ly
)))
1444 (defun speed-mouse-down ()
1445 "Speed move mouse to down"
1447 (reset-if-moved x y
)
1449 (add-in-history x y
)
1450 (setf ly
(middle miny
(or maxy
(xlib:screen-height
*screen
*))))
1451 (xlib:warp-pointer
*root
* x ly
)))
1452 (defun speed-mouse-undo ()
1453 "Undo last speed mouse move"
1455 (let ((h (pop history
)))
1457 (destructuring-bind (bx by
) h
1461 (xlib:warp-pointer
*root
* lx ly
))))))
1462 (defun speed-mouse-first-history ()
1463 "Revert to the first speed move mouse"
1465 (let ((h (first (last history
))))
1469 (xlib:warp-pointer
*root
* lx ly
)))))))
1473 ;;; Notify window functions
1480 (labels ((text-string (tx)
1485 (get-color (typecase tx
1487 (t *notify-window-foreground
*)))))
1488 (defun is-notify-window-p (win)
1489 (when (and (xlib:window-p win
) (xlib:window-p window
))
1490 (xlib:window-equal win window
)))
1492 (defun refresh-notify-window ()
1493 (add-timer 0.1 #'refresh-notify-window
:refresh-notify-window
)
1494 (raise-window window
)
1495 (let ((text-height (- (xlib:font-ascent font
) (xlib:font-descent font
))))
1496 (loop for tx in text
1498 (setf (xlib:gcontext-foreground gc
) (text-color tx
))
1499 (xlib:draw-glyphs window gc
1500 (truncate (/ (- width
(* (xlib:max-char-width font
) (length (text-string tx
)))) 2))
1502 (text-string tx
)))))
1504 (defun close-notify-window ()
1505 (erase-timer :refresh-notify-window
)
1506 (setf *never-managed-window-list
*
1507 (remove (list #'is-notify-window-p
'raise-window
)
1508 *never-managed-window-list
* :test
#'equal
))
1510 (xlib:free-gcontext gc
))
1512 (xlib:destroy-window window
))
1514 (xlib:close-font font
))
1515 (xlib:display-finish-output
*display
*)
1520 (defun open-notify-window (text-list)
1521 (close-notify-window)
1522 (setf font
(xlib:open-font
*display
* *notify-window-font-string
*))
1523 (let ((text-height (- (xlib:font-ascent font
) (xlib:font-descent font
))))
1524 (setf text text-list
)
1525 (setf width
(* (xlib:max-char-width font
) (+ (loop for tx in text-list
1526 maximize
(length (text-string tx
))) 2))
1527 height
(+ (* text-height
(length text-list
) 2) text-height
))
1528 (with-placement (*notify-window-placement
* x y width height
)
1529 (setf window
(xlib:create-window
:parent
*root
*
1534 :background
(get-color *notify-window-background
*)
1536 :border
(get-color *notify-window-border
*)
1537 :colormap
(xlib:screen-default-colormap
*screen
*)
1538 :event-mask
'(:exposure
:key-press
))
1539 gc
(xlib:create-gcontext
:drawable window
1540 :foreground
(get-color *notify-window-foreground
*)
1541 :background
(get-color *notify-window-background
*)
1543 :line-style
:solid
))
1544 (when (frame-p *current-child
*)
1545 (setf current-child
*current-child
*)
1546 (push (list #'is-notify-window-p
'raise-window
) *never-managed-window-list
*))
1548 (refresh-notify-window)
1549 (xlib:display-finish-output
*display
*))))))
1552 (defun display-hello-window ()
1553 (open-notify-window '(("Welcome to CLFSWM" "yellow")
1554 "Press Alt+F1 for help"))
1555 (add-timer *notify-window-delay
* #'close-notify-window
))
1558 ;;; Run or raise functions
1559 (defun run-or-raise (raisep run-fn
&key
(maximized nil
))
1560 (let ((window (with-all-windows (*root-frame
* win
)
1561 (when (funcall raisep win
)
1564 (let ((parent (find-parent-frame window
)))
1565 (hide-all-children *current-root
*)
1566 (setf *current-child
* parent
)
1567 (put-child-on-top window parent
)
1569 (setf *current-root
* parent
))
1570 (focus-all-children window parent
)
1571 (show-all-children))