[sawfish: 1/5] New focus mode operation focus-revert.



commit 4b0245ec532ded2d999dc83259d54b49d10f16a3
Author: Timo Korvola <tkorvola iki fi>
Date:   Mon Oct 1 09:19:21 2007 +0200

    New focus mode operation focus-revert.
    
    This replaces the logic in transient-unmap-window that was used to
    assign focus when the currently focused window closes.  Passing focus
    to the transient parent of the closing window still takes precedence,
    but if that is not an option, the decision is now delegated to the
    global focus mode.
    
    For now, I am trying to retain the old functionality.
    
    Conflicts:
    
    	lisp/sawfish/wm/focus.jl

 lisp/sawfish/wm/focus.jl           |   37 +++++++++++++++++++++++++++++++----
 lisp/sawfish/wm/state/transient.jl |   30 +++++++++-------------------
 2 files changed, 42 insertions(+), 25 deletions(-)
---
diff --git a/lisp/sawfish/wm/focus.jl b/lisp/sawfish/wm/focus.jl
index 16399a7..1f4aad5 100644
--- a/lisp/sawfish/wm/focus.jl
+++ b/lisp/sawfish/wm/focus.jl
@@ -28,6 +28,7 @@
 	    focus-push-map
 	    focus-pop-map
 	    warp-pointer-if-necessary
+            focus-revert
 	    focus-within-click-event)
 
     (open rep
@@ -77,7 +78,8 @@ click-to-focus button press event.")
 used to implement this focus mode, it will be called with arguments `(WINDOW
 EVENT-NAME)', where EVENT-NAME may be one of the following symbols:
 `pointer-in', `pointer-out', `focus-in', `focus-out', `add-window'
-`before-mode-change', `after-mode-change'"
+`before-mode-change', `after-mode-change', `warp-if-necessary' and
+`focus-revert'."
 
     (unless (memq name focus-modes)
       (setq focus-modes (nconc focus-modes (list name))))
@@ -132,6 +134,13 @@ EVENT-NAME)', where EVENT-NAME may be one of the following symbols:
   (define (warp-pointer-if-necessary #!optional (w (input-focus)))
     (focus-invoke-mode w 'warp-if-necessary))
 
+  ;; Put focus in some window that hopefully feels natural.  This is
+  ;; typically used when the window in focus has disappeared.  Thus
+  ;; there is no reference window.
+  (define (focus-revert)
+    (let ((fun (focus-mode-ref focus-mode)))
+      (when fun (fun nil 'focus-revert))))
+
 ;;; modes
 
   (define-focus-mode 'enter-exit
@@ -151,7 +160,12 @@ EVENT-NAME)', where EVENT-NAME may be one of the following symbols:
 	 (set-input-focus w))
 	((warp-if-necessary)
 	 (unless (eq (query-pointer-window) w)
-	   (warp-cursor-to-window w))))))
+	   (warp-cursor-to-window w)))
+        ((focus-revert)
+         (setq w (query-pointer-window))
+         (when (or (null w)
+                   (window-really-wants-input-p w))
+           (set-input-focus w))))))
 
   (define-focus-mode 'enter-only
     (lambda (w action . args)
@@ -164,7 +178,15 @@ EVENT-NAME)', where EVENT-NAME may be one of the following symbols:
 	((warp-if-necessary)
 	 (let ((current (query-pointer-window)))
 	   (unless (or (eq current w) (desktop-window-p current))
-	     (warp-cursor-to-window w)))))))
+	     (warp-cursor-to-window w))))
+        ((focus-revert)
+         (setq w (query-pointer-window))
+         (when (or (null w)
+                   (desktop-window-p w))
+           (setq w (window-order-most-recent)))
+         (when (or (null w)
+                   (window-really-wants-input-p w))
+           (set-input-focus w))))))
 
   (define (focus-click)
     (let ((w (current-event-window))
@@ -216,12 +238,17 @@ EVENT-NAME)', where EVENT-NAME may be one of the following symbols:
 	((after-mode-change)
 	 (unless (or (not (window-really-wants-input-p w))
 		     (eq w (input-focus)))
-	   (focus-push-map w click-to-focus-map))))))
+	   (focus-push-map w click-to-focus-map)))
+        ((focus-revert)
+         (setq w (window-order-most-recent))
+         (when (or (null w)
+                   (window-really-wants-input-p w))
+           (set-input-focus w))))))
 
   (define-focus-mode 'enter-click
     (lambda (w action . args)
       (case action
-        ((pointer-in warp-if-necessary)
+        ((pointer-in warp-if-necessary focus-revert)
          (apply (focus-mode-ref 'enter-only) w action args))
         ((focus-in focus-out add-window before-mode-change after-mode-change)
          (apply (focus-mode-ref 'click) w action args)))))
diff --git a/lisp/sawfish/wm/state/transient.jl b/lisp/sawfish/wm/state/transient.jl
index 737485f..beb44ed 100644
--- a/lisp/sawfish/wm/state/transient.jl
+++ b/lisp/sawfish/wm/state/transient.jl
@@ -37,6 +37,7 @@
 	  sawfish.wm.events
 	  sawfish.wm.custom
 	  sawfish.wm.commands
+          sawfish.wm.focus
 	  sawfish.wm.windows
 	  sawfish.wm.stacking
 	  sawfish.wm.viewport
@@ -191,26 +192,15 @@ the level of any transient windows it has."
 			 (or (window-order-most-recent
 			      #:windows (delq w (windows-in-group w)))
 			     (get-window-by-id (window-transient-p w))))))
-	(when (or (not parent)
-		  (not (window-mapped-p parent))
-		  (not (window-visible-p parent))
-		  (window-outside-viewport-p parent)
-		  (not (window-really-wants-input-p parent))
-                  (window-get parent 'desktop))
-	  ;; if no parent, choose the topmost window (if in click-to-focus
-	  ;; mode) or the window under the pointer otherwise
-	  (if (eq focus-mode 'click)
-	      (setq parent nil)
-	    (setq parent (query-pointer-window))
-	    (when (and (eq focus-mode 'enter-only)
-		       parent (desktop-window-p parent))
-	      ;; in sloppy-focus mode, don't want to focus on the
-	      ;; desktop window just because the pointer is under it
-	      (setq parent nil)))
-	  (unless (or parent (eq focus-mode 'enter-exit))
-	    (setq parent (window-order-most-recent))))
-	(when (or (null parent) (window-really-wants-input-p parent))
-	  (set-input-focus parent)))))
+	(if (or (not parent)
+                (not (window-mapped-p parent))
+                (not (window-visible-p parent))
+                (window-outside-viewport-p parent)
+                (not (window-really-wants-input-p parent))
+                (window-get parent 'desktop))
+            ;; No parent to give focus back to.
+            (focus-revert)
+          (set-input-focus parent)))))
 
   (add-hook 'map-notify-hook transient-map-window)
   (add-hook 'unmap-notify-hook transient-unmap-window)



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