Skip to content

Commit 5dcdcb8

Browse files
committedMay 18, 2022
FIX: Disable cursorRect updates from within macosx backend
We want to keep control of the cursor updates from within MPL, so don't allow the App to push a new cursor update when the window gets updated. This would happen when a TextView would get resized and update the frame.
1 parent f732864 commit 5dcdcb8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎src/_macosx.m

+6-4
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,8 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
936936
NSFont* font = [NSFont systemFontOfSize: 0.0];
937937
// rect.origin.x is now at the far right edge of the buttons
938938
// we want the messagebox to take up the rest of the toolbar area
939-
rect.size.width = bounds.size.width - rect.origin.x;
939+
// Make it a zero-width box if we don't have enough room
940+
rect.size.width = fmax(bounds.size.width - rect.origin.x, 0);
940941
rect.origin.x = bounds.size.width - rect.size.width;
941942
NSTextView* messagebox = [[[NSTextView alloc] initWithFrame: rect] autorelease];
942943
messagebox.textContainer.maximumNumberOfLines = 2;
@@ -989,14 +990,15 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
989990
[messagebox setFrame: rect];
990991
// We want to control the vertical position of
991992
// the rect by the content size to center it vertically
992-
// TODO: This seems to disable the cursor updates with newlines that
993-
// are included in the image hover text. It is only when trying
994-
// to set the frame height based on the contentRect's size.
995993
[messagebox.layoutManager ensureLayoutForTextContainer: messagebox.textContainer];
996994
NSRect contentRect = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
997995
rect.origin.y = 0.5 * (self->height - contentRect.size.height);
998996
rect.size.height = contentRect.size.height;
999997
[messagebox setFrame: rect];
998+
// Disable cursorRects so that the cursor doesn't get updated by events
999+
// in NSApp (like resizing TextViews), we want to handle the cursor
1000+
// changes from within MPL with set_cursor() ourselves
1001+
[[messagebox.superview window] disableCursorRects];
10001002
}
10011003

10021004
Py_RETURN_NONE;

0 commit comments

Comments
 (0)
Please sign in to comment.