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>
This commit is contained in:
Jonas Dreßler 2021-02-27 11:27:23 +01:00 committed by Marge Bot
parent 7c83cbe135
commit 746230f8b6

View File

@ -609,12 +609,22 @@ var FocusTracker = class {
} }
_setCurrentRect(rect) { _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) { if (this._currentWindow) {
const frameRect = this._currentWindow.get_frame_rect(); const frameRect = this._currentWindow.get_frame_rect();
const grapheneFrameRect = new Graphene.Rect(); const grapheneFrameRect = new Graphene.Rect();
grapheneFrameRect.init(frameRect.x, frameRect.y, grapheneFrameRect.init(frameRect.x, frameRect.y,
frameRect.width, frameRect.height); frameRect.width, frameRect.height);
const rectInsideFrameRect = grapheneFrameRect.intersection(rect)[0];
if (!rectInsideFrameRect)
return;
rect.offset(-frameRect.x, -frameRect.y); rect.offset(-frameRect.x, -frameRect.y);
} }