From 746230f8b68fee9efb314f0acade5f65c626c2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Sat, 27 Feb 2021 11:27:23 +0100 Subject: [PATCH] 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: --- js/ui/keyboard.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js index 651a560fa..37b077d12 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); }