[gnome-shell] keyboard: Ignore focus rects outside the window



commit 746230f8b68fee9efb314f0acade5f65c626c2b3
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Sat Feb 27 11:27:23 2021 +0100

    keyboard: Ignore focus rects outside the window
    
    Apparently some clients, including gtk don't "clip" the focus rectangle
    to their window bounds when scrolling the focus outside the window. This
    makes us shift up windows when the focus actually is no longer visible.
    
    This issue needs fixing in GTK, it should probably stop reporting
    focus changes when the focus moves outside of the visible view. We can
    still do a little bit better on our side though and "clip" the rectangle
    to the windows frame rect: If it moves out of the window, we simply stop
    updating our focus rect.
    
    The intersection check introduces a small problem though: Some clients
    (for example gedit) will give us a cursor rect that has a 0 width or
    height. This won't play well with graphene_rect_intersect()
    (GrapheneRects never intersect if they are 0-sized), so we set the size
    to 1 in case we get a 0-sized rectangle.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1728>

 js/ui/keyboard.js | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index 651a560fa1..37b077d12b 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -609,12 +609,22 @@ var FocusTracker = class {
     }
 
     _setCurrentRect(rect) {
+        // Some clients give us 0-sized rects, in that case set size to 1
+        if (rect.size.width <= 0)
+            rect.size.width = 1;
+        if (rect.size.height <= 0)
+            rect.size.height = 1;
+
         if (this._currentWindow) {
             const frameRect = this._currentWindow.get_frame_rect();
             const grapheneFrameRect = new Graphene.Rect();
             grapheneFrameRect.init(frameRect.x, frameRect.y,
                 frameRect.width, frameRect.height);
 
+            const rectInsideFrameRect = grapheneFrameRect.intersection(rect)[0];
+            if (!rectInsideFrameRect)
+                return;
+
             rect.offset(-frameRect.x, -frameRect.y);
         }
 


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