>From b1c8de076469acb25bfb2679fb75f03d02c1b685 Mon Sep 17 00:00:00 2001 From: Ben Spencer Date: Sat, 24 Oct 2009 15:12:05 +0100 Subject: [PATCH] Improved window-head for floating windows. It now determines which head the window overlaps most with, rather than just returning nil for windows that aren't entirely in one frame. --- floating-group.lisp | 24 +++++++++++++++--------- primitives.lisp | 4 ++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/floating-group.lisp b/floating-group.lisp index b5c03d1..157db97 100644 --- a/floating-group.lisp +++ b/floating-group.lisp @@ -66,15 +66,21 @@ ) (defmethod window-head ((window float-window)) - (dolist (head (screen-heads (group-screen (window-group window)))) - (when (and - (>= (window-x window) (frame-x head)) - (>= (window-y window) (frame-y head)) - (<= (+ (window-x window) (window-width window)) - (+ (frame-x head) (frame-width head))) - (<= (+ (window-y window) (window-height window)) - (+ (frame-y head) (frame-height head)))) - (return head)))) + (let ((best-head nil) + (best-overlap 0)) + (dolist (head (screen-heads (group-screen (window-group window)))) + (let ((overlap (* (get-overlap (window-x window) + (window-width window) + (frame-x head) + (frame-width head)) + (get-overlap (window-y window) + (window-height window) + (frame-y head) + (frame-height head))))) + (when (> overlap best-overlap) + (setf best-head head) + (setf best-overlap overlap)))) + best-head)) (defmethod window-visible-p ((win float-window)) (eql (window-state win) +normal-state+)) diff --git a/primitives.lisp b/primitives.lisp index 4fd7e41..b5eee78 100644 --- a/primitives.lisp +++ b/primitives.lisp @@ -589,6 +589,10 @@ positive direction." (+ inc max) min)))) +(defun get-overlap (s1 l1 s2 l2) + "Calculate the overlap between two lines on a one-dimensional scale" + (- (min (+ s1 l1) (+ s2 l2)) (max s1 s2))) + (defun remove-plist (plist &rest keys) "Remove the keys from the plist. Useful for re-using the &REST arg after removing some options." -- 1.6.5