Skip to content

Commit

Permalink
cocoa: fix dragging out of focus window
Browse files Browse the repository at this point in the history
fffab30 introduced a small regression where the cursor couldn't be
unhidden after refocusing. the problem is that no mouseUp event was
reported in our events_view. work around this with a separate event
monitor. this also fixes another regression when the window is being
dragged from the title bar.

mpv-player#4174
  • Loading branch information
Akemi committed Feb 21, 2017
1 parent aeddc49 commit c824a02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions osdep/macosx_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static const NSEventType NSEventTypeKeyUp = NSKeyUp;

static const NSEventMask NSEventMaskKeyDown = NSKeyDownMask;
static const NSEventMask NSEventMaskKeyUp = NSKeyUpMask;
static const NSEventMask NSEventMaskLeftMouseUp = NSLeftMouseUpMask;

#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10)
typedef NSUInteger NSEventModifierFlags;
Expand Down
1 change: 0 additions & 1 deletion video/out/cocoa/events_view.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ - (void)mouseUp:(NSEvent *)event
{
if ([self.adapter mouseEnabled]) {
[self mouseUpEvent:event];
[self.adapter mouseUp];
} else {
[super mouseUp:event];
}
Expand Down
26 changes: 21 additions & 5 deletions video/out/cocoa_common.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
bool cursor_visibility;
bool cursor_visibility_wanted;
bool window_is_dragged;
id event_monitor_mouseup;

bool embedded; // wether we are embedding in another GUI

Expand Down Expand Up @@ -352,6 +353,23 @@ static void vo_cocoa_uninit_displaylink(struct vo_cocoa_state *s)
CVDisplayLinkRelease(s->link);
}

static void cocoa_add_event_monitor(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;

s->event_monitor_mouseup = [NSEvent
addLocalMonitorForEventsMatchingMask: NSEventMaskLeftMouseUp
handler:^NSEvent*(NSEvent* event) {
s->window_is_dragged = false;
return event;
}];
}

static void cocoa_rm_event_monitor(struct vo *vo)
{
[NSEvent removeMonitor:vo->cocoa->event_monitor_mouseup];
}

void vo_cocoa_init(struct vo *vo)
{
struct vo_cocoa_state *s = talloc_zero(NULL, struct vo_cocoa_state);
Expand All @@ -372,6 +390,8 @@ void vo_cocoa_init(struct vo *vo)
vo_cocoa_init_displaylink(vo);
cocoa_init_light_sensor(vo);
cocoa_add_screen_reconfiguration_observer(vo);
cocoa_add_event_monitor(vo);

if (!s->embedded) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
set_application_icon(NSApp);
Expand Down Expand Up @@ -426,6 +446,7 @@ void vo_cocoa_uninit(struct vo *vo)
vo_cocoa_signal_swap(s);
cocoa_uninit_light_sensor(s);
cocoa_rm_screen_reconfiguration_observer(vo);
cocoa_rm_event_monitor(vo);

[s->nsgl_ctx release];
CGLReleaseContext(s->cgl_ctx);
Expand Down Expand Up @@ -1059,9 +1080,4 @@ - (void)windowWillMove:(NSNotification *)notification
self.vout->cocoa->window_is_dragged = true;
}

- (void)mouseUp
{
self.vout->cocoa->window_is_dragged = false;
}

@end

0 comments on commit c824a02

Please sign in to comment.