stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [STUMP] [PATCH] Allow *new-window-prefered-frame* callback to return


From: David Hansen
Subject: Re: [STUMP] [PATCH] Allow *new-window-prefered-frame* callback to return a list of preferences.
Date: Sat, 10 May 2008 19:49:26 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux)

On Fri, 9 May 2008 17:11:30 -0700 Shawn Betts wrote:

> On Sat, Apr 26, 2008 at 11:28 AM, David Hansen <address@hidden> wrote:
>> Hello,
>>
>> this turned out to be useful for me:
>
> Hi David,
>
> Thanks for the patch! There are a couple issues with it, however. Can
> you resend a patch that contains only the changes relevant to the
> feature? There are some unrelated indenting and code changes that make
> you patch difficult to read. And while you're fixing that can you
> update the patch to the latest in git? core.lisp was rearranged and
> now the code in your patch is in window.lisp.

Not sure if that is easier to read now...  At least it leaves the
overlong lines as is.

BTW, would you mind to M-% prefered RET preferred ?  That would be a
huge ugly diff but a bit less embarrassing ;-)

diff --git a/window.lisp b/window.lisp
index 20b3335..87f91e4 100644
--- a/window.lisp
+++ b/window.lisp
@@ -821,41 +821,55 @@ than the root window's width and height."
 (defun pick-prefered-frame (window)
   (let* ((group (window-group window))
          (frames (group-frames group))
-         (default (tile-group-current-frame group)))
-    (or
-     (if (or (functionp *new-window-prefered-frame*)
-             (and (symbolp *new-window-prefered-frame*)
-                  (fboundp *new-window-prefered-frame*)))
-         (handler-case
-             (funcall *new-window-prefered-frame* window)
-           (error (c)
-             (message "^1*^BError while calling 
^b^3**new-window-prefered-frame*^1*^B: ^n~a" c)
-             nil))
-         (loop for i in *new-window-prefered-frame*
-               thereis (case i
-                         (:last
-                          ;; last-frame can be stale
-                          (and (> (length frames) 1)
-                               (tile-group-last-frame group)))
-                         (:unfocused
-                          (find-if (lambda (f)
-                                     (not (eq f (tile-group-current-frame 
group))))
-                                   frames))
-                         (:empty
-                          (find-if (lambda (f)
-                                     (null (frame-window f)))
-                                   frames))
-                         (:choice
-                          ;; Transient windows sometimes specify a location
-                          ;; relative to the TRANSIENT_FOR window. Just ignore
-                          ;; these hints.
-                          (unless (find (window-type window) '(:transient 
:dialog))
-                            (let ((hints (window-normal-hints window)))
-                              (when (and hints 
(xlib:wm-size-hints-user-specified-position-p hints))
-                                (find-frame group (window-x window) (window-y 
window))))))
-                         (t             ; :focused
-                          (tile-group-current-frame group)))))
-     default)))
+         (default (tile-group-current-frame group))
+         (prefered-frame (or *new-window-prefered-frame* default)))
+    (when (or (functionp *new-window-prefered-frame*)
+              (and (symbolp *new-window-prefered-frame*)
+                   (fboundp *new-window-prefered-frame*)))
+      (setq prefered-frame
+            (handler-case
+                (funcall *new-window-prefered-frame* window)
+              (error (c)
+                (message "^1*^BError while calling 
^b^3**new-window-prefered-frame*^1*^B: ^n~a" c)
+                default))))
+    (cond
+      ;; If we already have a frame use it.
+      ((frame-p prefered-frame)
+       prefered-frame)
+      ;; If `prefered-frame' is a list of keyword use it to determine the
+      ;; frame.  The sanity check doesn't cover not recognized keywords.  We
+      ;; simply fall back to the default then.
+      ((and (listp prefered-frame)
+            (every #'keywordp prefered-frame))
+       (loop for i in prefered-frame
+          thereis (case i
+                    (:last
+                     ;; last-frame can be stale
+                     (and (> (length frames) 1)
+                          (tile-group-last-frame group)))
+                    (:unfocused
+                     (find-if (lambda (f)
+                                (not (eq f (tile-group-current-frame group))))
+                              frames))
+                    (:empty
+                     (find-if (lambda (f)
+                                (null (frame-window f)))
+                              frames))
+                    (:choice
+                     ;; Transient windows sometimes specify a location
+                     ;; relative to the TRANSIENT_FOR window. Just ignore
+                     ;; these hints.
+                     (unless (find (window-type window) '(:transient :dialog))
+                       (let ((hints (window-normal-hints window)))
+                         (when (and hints 
(xlib:wm-size-hints-user-specified-position-p hints))
+                           (find-frame group (window-x window) (window-y 
window))))))
+                    (t                  ; :focused or not recognized keyword
+                     default))))
+      ;; Not well formed `*new-window-prefered-frame*'.  Message an error and
+      ;; return the default.
+      (t (message "^1*^BInvalid ^b^3**new-window-prefered-frame*^1*^B: ^n~a"
+                  prefered-frame)
+         default))))
 
 (defun add-window (screen xwin)
   (screen-add-mapped-window screen xwin)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]