0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

cocoa: fix autohide in fullscreen

This commit is contained in:
Stefano Pigozzi 2015-03-08 15:19:17 +01:00
parent ce239f1577
commit 8ec9bce2d3
4 changed files with 26 additions and 5 deletions

View File

@ -166,7 +166,8 @@
- (BOOL)canHideCursor
{
return !self.hasMouseDown && [self containsMouseLocation];
return !self.hasMouseDown && [self containsMouseLocation]
&& [[self window] isKeyWindow];
}
- (void)mouseEntered:(NSEvent *)event

View File

@ -18,7 +18,7 @@
#import <Cocoa/Cocoa.h>
#include "video/out/vo.h"
@interface MpvCocoaAdapter : NSObject
@interface MpvCocoaAdapter : NSObject<NSWindowDelegate>
- (void)setNeedsResize;
- (void)signalMouseMovement:(NSPoint)point;
- (void)putKeyEvent:(NSEvent*)event;

View File

@ -63,12 +63,12 @@
- (void)windowDidResignKey:(NSNotification *)notification
{
[self.adapter didChangeMousePosition];
[self.adapter windowDidResignKey:notification];
}
- (void)windowDidBecomeKey:(NSNotification *)notification
{
[self.adapter didChangeMousePosition];
[self.adapter windowDidBecomeKey:notification];
}
- (BOOL)canBecomeMainWindow { return YES; }

View File

@ -60,6 +60,7 @@ struct vo_cocoa_state {
NSWindow *window;
NSView *view;
MpvVideoView *video;
MpvCocoaAdapter *adapter;
NSOpenGLContext *gl_ctx;
NSScreen *current_screen;
@ -258,7 +259,7 @@ static int vo_cocoa_set_cursor_visibility(struct vo *vo, bool *visible)
if (*visible) {
CGDisplayShowCursor(kCGDirectMainDisplay);
} else if ([v canHideCursor] && [s->window isKeyWindow]) {
} else if ([v canHideCursor]) {
CGDisplayHideCursor(kCGDirectMainDisplay);
} else {
*visible = true;
@ -457,6 +458,7 @@ static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
[parent addSubview:s->view];
// update the cursor position now that the view has been added.
[view signalMousePosition];
s->adapter = adapter;
#if HAVE_COCOA_APPLICATION
cocoa_register_menu_item_action(MPM_H_SIZE, @selector(halfSize));
@ -685,6 +687,13 @@ static void vo_cocoa_fullscreen(struct vo *vo)
draw_changes_after_next_frame(vo);
[(MpvEventsView *)s->view setFullScreen:opts->fullscreen];
if ([s->view window] != s->window) {
// cocoa implements fullscreen views by moving the view to a fullscreen
// window. Set that window delegate to the cocoa adapter to trigger
// calls to -windowDidResignKey: and -windowDidBecomeKey:
[[s->view window] setDelegate:s->adapter];
}
s->pending_events |= VO_EVENT_ICC_PROFILE_CHANGED;
s->pending_events |= VO_EVENT_RESIZE;
}
@ -853,4 +862,15 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
struct vo_cocoa_state *s = self.vout->cocoa;
[(MpvEventsView *)s->view signalMousePosition];
}
- (void)windowDidResignKey:(NSNotification *)notification
{
[self didChangeMousePosition];
}
- (void)windowDidBecomeKey:(NSNotification *)notification
{
[self didChangeMousePosition];
}
@end