Skip to content

Commit 7d57723

Browse files
connorjclarkSiegeLord
authored andcommitted
Fix improper display boundary for cursors on OSX
`reshape` is called whenever the window's NSView changes size, and its job is to set the cursor tracking area. However, it was checking [NSOpenGLContext currentContext] existed before updating the tracking area. For some reason it was nil by the time `al_resize_display` is called. The logic for updating the tracking area doesn't seem to need this context, so it should be safe to delete this guard. ex_mouse_events is updated to resize the display. Without this patch, such a change to this example presents the bug: the ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY / ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY events are fired only for the lower-left quadrant of the display.
1 parent 7593741 commit 7d57723

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

examples/ex_mouse_events.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ int main(int argc, char **argv)
7575
abort_example("Error creating display\n");
7676
}
7777

78+
// Resize the display - this is to excercise the resizing code wrt.
79+
// the cursor display boundary, which requires some special care on some
80+
// platforms (such as OSX).
81+
al_resize_display(display, 640*1.5, 480*1.5);
82+
7883
al_hide_mouse_cursor(display);
7984

8085
cursor = al_load_bitmap("data/cursor.tga");

src/macosx/osxgl.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,12 @@ -(ALLEGRO_DISPLAY*) allegroDisplay
323323
- (void) reshape
324324
{
325325
[super reshape];
326-
if ([NSOpenGLContext currentContext] != nil) {
327-
ALLEGRO_DISPLAY_OSX_WIN* dpy = (ALLEGRO_DISPLAY_OSX_WIN*) dpy_ptr;
328326

329-
if (dpy->tracking) {
330-
[self removeTrackingArea: dpy->tracking];
331-
dpy->tracking = create_tracking_area(self);
332-
[self addTrackingArea: dpy->tracking];
333-
}
327+
ALLEGRO_DISPLAY_OSX_WIN* dpy = (ALLEGRO_DISPLAY_OSX_WIN*) dpy_ptr;
328+
if (dpy->tracking) {
329+
[self removeTrackingArea: dpy->tracking];
330+
dpy->tracking = create_tracking_area(self);
331+
[self addTrackingArea: dpy->tracking];
334332
}
335333
}
336334

0 commit comments

Comments
 (0)