2012-03-04 22:04:07 +01:00
|
|
|
/*
|
|
|
|
* Cocoa OpenGL Backend
|
|
|
|
*
|
|
|
|
* This file is part of mplayer2.
|
|
|
|
*
|
|
|
|
* mplayer2 is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mplayer2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with mplayer2. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
#import <Cocoa/Cocoa.h>
|
2012-08-07 10:31:39 +02:00
|
|
|
#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor
|
2012-09-16 20:53:04 +02:00
|
|
|
#import <IOKit/pwr_mgt/IOPMLib.h>
|
2012-04-14 15:02:28 +02:00
|
|
|
#include <dlfcn.h>
|
2013-01-20 17:15:37 +01:00
|
|
|
#include <libavutil/common.h>
|
2012-04-14 15:02:28 +02:00
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
#include "cocoa_common.h"
|
|
|
|
|
2012-07-21 10:37:13 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/options.h"
|
|
|
|
#include "vo.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
#include "aspect.h"
|
|
|
|
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/mp_fifo.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
#include "talloc.h"
|
|
|
|
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/input/input.h"
|
|
|
|
#include "core/input/keycodes.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
#include "osx_common.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/mp_msg.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-02-23 18:28:22 +01:00
|
|
|
#include "osdep/macosx_application.h"
|
|
|
|
|
2013-02-19 21:21:50 +01:00
|
|
|
#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
|
2011-10-15 18:44:00 +02:00
|
|
|
#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
|
|
|
|
|
2013-02-19 21:21:50 +01:00
|
|
|
static bool LeftAltPressed(NSEvent *event)
|
|
|
|
{
|
|
|
|
return ([event modifierFlags] & NSLeftAlternateKeyMask) ==
|
|
|
|
NSLeftAlternateKeyMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool RightAltPressed(NSEvent *event)
|
|
|
|
{
|
|
|
|
return ([event modifierFlags] & NSRightAlternateKeyMask) ==
|
|
|
|
NSRightAlternateKeyMask;
|
|
|
|
}
|
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
@interface GLMPlayerWindow : NSWindow <NSWindowDelegate>
|
2012-09-16 16:18:57 +02:00
|
|
|
- (BOOL)canBecomeKeyWindow;
|
|
|
|
- (BOOL)canBecomeMainWindow;
|
|
|
|
- (void)fullscreen;
|
|
|
|
- (void)mulSize:(float)multiplier;
|
2013-04-17 21:22:22 +02:00
|
|
|
- (int)titleHeight;
|
|
|
|
- (NSRect)clipFrame:(NSRect)frame withContentAspect:(NSSize) aspect;
|
2012-09-16 16:18:57 +02:00
|
|
|
- (void)setContentSize:(NSSize)newSize keepCentered:(BOOL)keepCentered;
|
2013-03-04 14:23:06 +01:00
|
|
|
@property(nonatomic, assign) struct vo *videoOutput;
|
2011-10-15 18:44:00 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GLMPlayerOpenGLView : NSView
|
2013-05-29 00:14:34 +02:00
|
|
|
@property(nonatomic, assign) struct vo *videoOutput;
|
2013-05-30 22:40:04 +02:00
|
|
|
- (BOOL)containsCurrentMouseLocation;
|
2013-05-29 00:14:34 +02:00
|
|
|
- (void)mouseEvent:(NSEvent *)theEvent;
|
2013-06-01 17:58:08 +02:00
|
|
|
@property(nonatomic, assign, getter=hasMouseDown) BOOL mouseDown;
|
2011-10-15 18:44:00 +02:00
|
|
|
@end
|
|
|
|
|
2013-06-01 22:52:21 +02:00
|
|
|
@interface NSScreen (mpvadditions)
|
|
|
|
- (BOOL)hasDock;
|
|
|
|
- (BOOL)hasMenubar;
|
|
|
|
@end
|
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
struct vo_cocoa_input_queue {
|
|
|
|
NSMutableArray *fifo;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int vo_cocoa_input_queue_free(void *ptr)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_input_queue *iq = ptr;
|
|
|
|
[iq->fifo release];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vo_cocoa_input_queue *vo_cocoa_input_queue_init(void *talloc_ctx)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_input_queue *iq = talloc_ptrtype(talloc_ctx, iq);
|
|
|
|
*iq = (struct vo_cocoa_input_queue) {
|
|
|
|
.fifo = [[NSMutableArray alloc] init],
|
|
|
|
};
|
|
|
|
talloc_set_destructor(iq, vo_cocoa_input_queue_free);
|
|
|
|
return iq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cocoa_async_put_key(struct vo_cocoa_input_queue *iq, int key)
|
|
|
|
{
|
|
|
|
@synchronized (iq->fifo) {
|
|
|
|
[iq->fifo addObject:[NSNumber numberWithInt:key]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cocoa_sync_get_key(struct vo_cocoa_input_queue *iq)
|
|
|
|
{
|
|
|
|
int r = -1;
|
|
|
|
|
|
|
|
@synchronized (iq->fifo) {
|
|
|
|
if ([iq->fifo count] > 0) {
|
|
|
|
r = [[iq->fifo objectAtIndex:0] intValue];
|
|
|
|
[iq->fifo removeObjectAtIndex:0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
struct vo_cocoa_state {
|
|
|
|
GLMPlayerWindow *window;
|
2013-05-29 00:14:34 +02:00
|
|
|
GLMPlayerOpenGLView *view;
|
2011-10-15 18:44:00 +02:00
|
|
|
NSOpenGLContext *glContext;
|
2011-12-11 12:26:00 +01:00
|
|
|
NSOpenGLPixelFormat *pixelFormat;
|
2011-10-15 18:44:00 +02:00
|
|
|
|
|
|
|
NSSize current_video_size;
|
|
|
|
NSSize previous_video_size;
|
|
|
|
|
2013-05-29 00:14:34 +02:00
|
|
|
NSScreen *current_screen;
|
|
|
|
NSScreen *fs_screen;
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2012-09-30 00:32:53 +02:00
|
|
|
NSInteger window_level;
|
2011-12-07 12:42:04 +01:00
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
struct aspect_data aspdat;
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
bool did_resize;
|
2013-03-04 14:23:06 +01:00
|
|
|
bool did_async_resize;
|
2011-10-15 18:44:00 +02:00
|
|
|
bool out_fs_resize;
|
2012-09-16 20:53:04 +02:00
|
|
|
|
|
|
|
IOPMAssertionID power_mgmt_assertion;
|
2013-01-20 17:15:37 +01:00
|
|
|
|
|
|
|
CGFloat accumulated_scroll;
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-05-13 23:25:35 +02:00
|
|
|
NSLock *lock;
|
2013-05-12 23:51:58 +02:00
|
|
|
bool enable_resize_redraw;
|
2013-03-04 14:23:06 +01:00
|
|
|
void (*resize_redraw)(struct vo *vo, int w, int h);
|
|
|
|
|
|
|
|
struct vo_cocoa_input_queue *input_queue;
|
|
|
|
};
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
static struct vo_cocoa_state *vo_cocoa_init_state(struct vo *vo)
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = talloc_ptrtype(vo, s);
|
2011-10-15 18:44:00 +02:00
|
|
|
*s = (struct vo_cocoa_state){
|
|
|
|
.did_resize = NO,
|
2013-03-04 14:23:06 +01:00
|
|
|
.did_async_resize = NO,
|
2011-10-15 18:44:00 +02:00
|
|
|
.current_video_size = {0,0},
|
|
|
|
.previous_video_size = {0,0},
|
|
|
|
.out_fs_resize = NO,
|
2012-09-16 20:53:04 +02:00
|
|
|
.power_mgmt_assertion = kIOPMNullAssertionID,
|
2013-01-20 17:15:37 +01:00
|
|
|
.accumulated_scroll = 0,
|
2013-05-13 23:25:35 +02:00
|
|
|
.lock = [[NSLock alloc] init],
|
2013-03-04 14:23:06 +01:00
|
|
|
.input_queue = vo_cocoa_input_queue_init(s),
|
2013-05-12 23:51:58 +02:00
|
|
|
.enable_resize_redraw = NO,
|
2011-10-15 18:44:00 +02:00
|
|
|
};
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
static NSRect to_pixels(struct vo *vo, NSRect frame)
|
2012-04-03 08:13:12 +02:00
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-05-29 00:14:34 +02:00
|
|
|
return [s->view convertRectToBacking: frame];
|
2012-04-03 08:13:12 +02:00
|
|
|
}
|
|
|
|
|
2012-04-14 15:02:28 +02:00
|
|
|
void *vo_cocoa_glgetaddr(const char *s)
|
|
|
|
{
|
|
|
|
void *ret = NULL;
|
|
|
|
void *handle = dlopen(
|
|
|
|
"/System/Library/Frameworks/OpenGL.framework/OpenGL",
|
|
|
|
RTLD_LAZY | RTLD_LOCAL);
|
|
|
|
if (!handle)
|
|
|
|
return NULL;
|
|
|
|
ret = dlsym(handle, s);
|
|
|
|
dlclose(handle);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-16 20:53:04 +02:00
|
|
|
static void enable_power_management(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
if (!s->power_mgmt_assertion) return;
|
|
|
|
IOPMAssertionRelease(s->power_mgmt_assertion);
|
|
|
|
s->power_mgmt_assertion = kIOPMNullAssertionID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_power_management(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
if (s->power_mgmt_assertion) return;
|
2013-05-28 16:53:17 +02:00
|
|
|
IOPMAssertionCreateWithName(
|
|
|
|
kIOPMAssertionTypePreventUserIdleDisplaySleep,
|
|
|
|
kIOPMAssertionLevelOn,
|
2013-05-28 18:00:34 +02:00
|
|
|
CFSTR("io.mpv.video_playing_back"),
|
2013-05-28 16:53:17 +02:00
|
|
|
&s->power_mgmt_assertion);
|
2012-09-16 20:53:04 +02:00
|
|
|
}
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
int vo_cocoa_init(struct vo *vo)
|
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
vo->cocoa = vo_cocoa_init_state(vo);
|
2013-02-02 14:20:24 +01:00
|
|
|
vo->wakeup_period = 0.02;
|
2012-09-16 20:53:04 +02:00
|
|
|
disable_power_management(vo);
|
2011-10-15 18:44:00 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-06-01 00:35:46 +02:00
|
|
|
static void vo_cocoa_set_cursor_visibility(struct vo *vo, bool visible)
|
2013-05-17 00:29:42 +02:00
|
|
|
{
|
2013-06-01 00:35:46 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
|
2013-05-17 00:29:42 +02:00
|
|
|
if (visible) {
|
2013-06-01 00:35:46 +02:00
|
|
|
// show cursor unconditionally
|
2013-05-17 00:29:42 +02:00
|
|
|
CGDisplayShowCursor(kCGDirectMainDisplay);
|
2013-06-01 17:58:08 +02:00
|
|
|
} else if (vo->opts->fs &&
|
|
|
|
[s->view containsCurrentMouseLocation] &&
|
|
|
|
![s->view hasMouseDown]) {
|
2013-06-01 00:35:46 +02:00
|
|
|
// only hide cursor if in fullscreen and the video view contains the
|
|
|
|
// mouse location
|
2013-05-17 00:29:42 +02:00
|
|
|
CGDisplayHideCursor(kCGDirectMainDisplay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
void vo_cocoa_uninit(struct vo *vo)
|
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-06-01 00:35:46 +02:00
|
|
|
vo_cocoa_set_cursor_visibility(vo, true);
|
2013-03-04 14:23:06 +01:00
|
|
|
enable_power_management(vo);
|
|
|
|
[NSApp setPresentationOptions:NSApplicationPresentationDefault];
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
[s->window release];
|
|
|
|
s->window = nil;
|
|
|
|
[s->glContext release];
|
|
|
|
s->glContext = nil;
|
|
|
|
});
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-16 20:53:04 +02:00
|
|
|
void vo_cocoa_pause(struct vo *vo)
|
|
|
|
{
|
|
|
|
enable_power_management(vo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void vo_cocoa_resume(struct vo *vo)
|
|
|
|
{
|
|
|
|
disable_power_management(vo);
|
|
|
|
}
|
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
void vo_cocoa_register_resize_callback(struct vo *vo,
|
|
|
|
void (*cb)(struct vo *vo, int w, int h))
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
s->resize_redraw = cb;
|
|
|
|
}
|
|
|
|
|
2013-02-17 16:35:44 +01:00
|
|
|
static int get_screen_handle(int identifier, NSWindow *window, NSScreen **screen) {
|
|
|
|
NSArray *screens = [NSScreen screens];
|
|
|
|
int n_of_displays = [screens count];
|
|
|
|
|
|
|
|
if (identifier >= n_of_displays) { // check if the identifier is out of bounds
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[cocoa] Screen ID %d does not exist, "
|
|
|
|
"falling back to main device\n", identifier);
|
|
|
|
identifier = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (identifier < 0) {
|
|
|
|
// default behaviour gets either the window screen or the main screen
|
|
|
|
// if window is not available
|
|
|
|
if (! (*screen = [window screen]) )
|
|
|
|
*screen = [screens objectAtIndex:0];
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
*screen = [screens objectAtIndex:(identifier)];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
static void update_screen_info(struct vo *vo)
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-03-04 22:41:27 +01:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2013-05-29 00:14:34 +02:00
|
|
|
get_screen_handle(opts->screen_id, s->window, &s->current_screen);
|
|
|
|
get_screen_handle(opts->fsscreen_id, s->window, &s->fs_screen);
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 00:14:34 +02:00
|
|
|
static void vo_cocoa_update_screen_info(struct vo *vo)
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-03-04 22:41:27 +01:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2012-11-10 20:19:21 +01:00
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
update_screen_info(vo);
|
2013-05-29 00:14:34 +02:00
|
|
|
|
|
|
|
NSRect r = [s->current_screen frame];
|
|
|
|
|
|
|
|
aspect_save_screenres(vo, r.size.width, r.size.height);
|
|
|
|
opts->screenwidth = r.size.width;
|
|
|
|
opts->screenheight = r.size.height;
|
|
|
|
vo->xinerama_x = r.origin.x;
|
|
|
|
vo->xinerama_y = r.origin.y;
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
static void resize_window(struct vo *vo)
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-05-29 00:14:34 +02:00
|
|
|
NSRect frame = to_pixels(vo, [s->view frame]);
|
2012-08-07 10:31:39 +02:00
|
|
|
vo->dwidth = frame.size.width;
|
|
|
|
vo->dheight = frame.size.height;
|
2011-10-15 18:44:00 +02:00
|
|
|
[s->glContext update];
|
|
|
|
}
|
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
static void vo_set_level(struct vo *vo, int ontop)
|
2011-12-07 12:42:04 +01:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2011-12-07 12:42:04 +01:00
|
|
|
if (ontop) {
|
2013-02-03 14:00:11 +01:00
|
|
|
s->window_level = NSNormalWindowLevel + 1;
|
2011-12-07 12:42:04 +01:00
|
|
|
} else {
|
2012-09-30 00:32:53 +02:00
|
|
|
s->window_level = NSNormalWindowLevel;
|
2011-12-07 12:42:04 +01:00
|
|
|
}
|
|
|
|
|
2013-02-03 11:39:30 +01:00
|
|
|
[s->window setLevel:s->window_level];
|
2011-12-07 12:42:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void vo_cocoa_ontop(struct vo *vo)
|
|
|
|
{
|
2013-03-04 22:41:27 +01:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
opts->ontop = !opts->ontop;
|
|
|
|
vo_set_level(vo, opts->ontop);
|
2011-12-07 12:42:04 +01:00
|
|
|
}
|
|
|
|
|
2012-10-15 22:03:08 +02:00
|
|
|
static void update_state_sizes(struct vo_cocoa_state *s,
|
|
|
|
uint32_t d_width, uint32_t d_height)
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
|
|
|
if (s->current_video_size.width > 0 || s->current_video_size.height > 0)
|
|
|
|
s->previous_video_size = s->current_video_size;
|
|
|
|
s->current_video_size = NSMakeSize(d_width, d_height);
|
2012-10-15 22:03:08 +02:00
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
static void resize_window_from_stored_size(struct vo *vo)
|
2012-10-15 22:03:08 +02:00
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-06-01 11:26:06 +02:00
|
|
|
[s->window setContentSize:s->current_video_size keepCentered:YES];
|
|
|
|
[s->window setContentAspectRatio:s->current_video_size];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_window(struct vo *vo, uint32_t d_width, uint32_t d_height,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
|
|
|
|
const NSRect contentRect = NSMakeRect(0, 0, d_width, d_height);
|
2012-10-15 22:03:08 +02:00
|
|
|
|
2013-05-29 00:14:34 +02:00
|
|
|
int window_mask = 0;
|
2013-06-01 11:26:06 +02:00
|
|
|
if (opts->border) {
|
2013-05-29 00:14:34 +02:00
|
|
|
window_mask = NSTitledWindowMask|NSClosableWindowMask|
|
|
|
|
NSMiniaturizableWindowMask|NSResizableWindowMask;
|
|
|
|
} else {
|
|
|
|
window_mask = NSBorderlessWindowMask;
|
|
|
|
}
|
|
|
|
|
2012-10-15 22:03:08 +02:00
|
|
|
s->window =
|
2013-06-01 11:26:06 +02:00
|
|
|
[[GLMPlayerWindow alloc] initWithContentRect:contentRect
|
2013-05-29 00:14:34 +02:00
|
|
|
styleMask:window_mask
|
2012-10-15 22:03:08 +02:00
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
s->view = [[GLMPlayerOpenGLView alloc] initWithFrame:contentRect];
|
2013-05-29 00:14:34 +02:00
|
|
|
[s->view setWantsBestResolutionOpenGLSurface:YES];
|
2012-10-15 22:03:08 +02:00
|
|
|
|
2013-02-23 18:28:22 +01:00
|
|
|
cocoa_register_menu_item_action(MPM_H_SIZE, @selector(halfSize));
|
|
|
|
cocoa_register_menu_item_action(MPM_N_SIZE, @selector(normalSize));
|
|
|
|
cocoa_register_menu_item_action(MPM_D_SIZE, @selector(doubleSize));
|
|
|
|
cocoa_register_menu_item_action(MPM_MINIMIZE, @selector(performMiniaturize:));
|
|
|
|
cocoa_register_menu_item_action(MPM_ZOOM, @selector(performZoom:));
|
2012-10-15 22:03:08 +02:00
|
|
|
|
2013-02-23 18:28:22 +01:00
|
|
|
[s->window setRestorable:NO];
|
2013-05-29 00:14:34 +02:00
|
|
|
[s->window setContentView:s->view];
|
|
|
|
[s->view release];
|
2012-10-15 22:03:08 +02:00
|
|
|
[s->window setAcceptsMouseMovedEvents:YES];
|
2013-05-29 00:14:34 +02:00
|
|
|
[s->glContext setView:s->view];
|
2013-03-04 14:23:06 +01:00
|
|
|
s->window.videoOutput = vo;
|
2013-05-29 00:14:34 +02:00
|
|
|
s->view.videoOutput = vo;
|
2012-10-15 22:03:08 +02:00
|
|
|
|
|
|
|
[s->window setDelegate:s->window];
|
2013-02-23 18:28:22 +01:00
|
|
|
[s->window makeMainWindow];
|
2012-10-15 22:03:08 +02:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
[s->window setFrameOrigin:NSMakePoint(vo->dx, vo->dy)];
|
|
|
|
[s->window makeKeyAndOrderFront:nil];
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2013-03-15 20:51:32 +01:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
if (flags & VOFLAG_FULLSCREEN)
|
|
|
|
vo_cocoa_fullscreen(vo);
|
|
|
|
|
|
|
|
vo_set_level(vo, opts->ontop);
|
|
|
|
|
|
|
|
if (opts->native_fs) {
|
|
|
|
[s->window setCollectionBehavior:
|
|
|
|
NSWindowCollectionBehaviorFullScreenPrimary];
|
|
|
|
[NSApp setPresentationOptions:NSFullScreenWindowMask];
|
|
|
|
}
|
2012-10-15 22:03:08 +02:00
|
|
|
}
|
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
static NSOpenGLPixelFormatAttribute get_nsopengl_profile(int gl3profile) {
|
|
|
|
if (gl3profile) {
|
|
|
|
return NSOpenGLProfileVersion3_2Core;
|
|
|
|
} else {
|
|
|
|
return NSOpenGLProfileVersionLegacy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int create_gl_context(struct vo *vo, int gl3profile)
|
2013-05-29 00:14:34 +02:00
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-06-01 11:26:06 +02:00
|
|
|
|
|
|
|
NSOpenGLPixelFormatAttribute attr[] = {
|
|
|
|
NSOpenGLPFAOpenGLProfile,
|
|
|
|
get_nsopengl_profile(gl3profile),
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
s->pixelFormat =
|
|
|
|
[[[NSOpenGLPixelFormat alloc] initWithAttributes:attr] autorelease];
|
|
|
|
|
|
|
|
if (!s->pixelFormat) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,
|
|
|
|
"[cocoa] Trying to build invalid OpenGL pixel format\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->glContext =
|
|
|
|
[[NSOpenGLContext alloc] initWithFormat:s->pixelFormat
|
|
|
|
shareContext:nil];
|
|
|
|
|
|
|
|
[s->glContext makeCurrentContext];
|
|
|
|
|
|
|
|
return 0;
|
2013-05-29 00:14:34 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 22:03:08 +02:00
|
|
|
static void update_window(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
|
2013-05-29 00:14:34 +02:00
|
|
|
if (!CGSizeEqualToSize(s->current_video_size, s->previous_video_size)) {
|
2013-03-04 22:41:27 +01:00
|
|
|
if (vo->opts->fs) {
|
2012-10-15 22:03:08 +02:00
|
|
|
// we will resize as soon as we get out of fullscreen
|
|
|
|
s->out_fs_resize = YES;
|
2011-10-15 18:44:00 +02:00
|
|
|
} else {
|
2012-10-15 22:03:08 +02:00
|
|
|
// only if we are not in fullscreen and the video size did
|
|
|
|
// change we resize the window and set a new aspect ratio
|
2013-05-29 00:14:34 +02:00
|
|
|
resize_window_from_stored_size(vo);
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
2012-10-15 22:03:08 +02:00
|
|
|
}
|
2013-06-01 11:26:06 +02:00
|
|
|
|
|
|
|
[s->window setTitle:
|
|
|
|
[NSString stringWithUTF8String:vo_get_window_title(vo)]];
|
|
|
|
|
|
|
|
resize_window(vo);
|
2012-10-15 22:03:08 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
static void resize_redraw(struct vo *vo, int width, int height)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
if (s->resize_redraw) {
|
|
|
|
vo_cocoa_set_current_context(vo, true);
|
|
|
|
[s->glContext update];
|
|
|
|
s->resize_redraw(vo, width, height);
|
|
|
|
[s->glContext flushBuffer];
|
|
|
|
s->did_async_resize = YES;
|
|
|
|
vo_cocoa_set_current_context(vo, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-24 23:32:51 +01:00
|
|
|
int vo_cocoa_config_window(struct vo *vo, uint32_t d_width,
|
2012-10-15 22:03:08 +02:00
|
|
|
uint32_t d_height, uint32_t flags,
|
|
|
|
int gl3profile)
|
|
|
|
{
|
2013-05-12 23:51:58 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-06-01 11:26:06 +02:00
|
|
|
__block int ctxok = 0;
|
2013-05-12 23:51:58 +02:00
|
|
|
s->enable_resize_redraw = NO;
|
2013-03-03 21:29:32 +01:00
|
|
|
|
2013-05-12 23:51:58 +02:00
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
2013-03-04 14:23:06 +01:00
|
|
|
s->aspdat = vo->aspdat;
|
|
|
|
update_state_sizes(s, d_width, d_height);
|
2011-12-07 12:42:04 +01:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
if (flags & VOFLAG_HIDDEN) {
|
|
|
|
// This is certainly the first execution of vo_config_window and
|
|
|
|
// is called in order for an OpenGL based VO to perform detection
|
|
|
|
// of OpenGL extensions. On OSX to accomplish this task we are
|
|
|
|
// allowed only create a OpenGL context without attaching it to
|
|
|
|
// a drawable.
|
|
|
|
ctxok = create_gl_context(vo, gl3profile);
|
|
|
|
if (ctxok < 0) return;
|
|
|
|
} else if (!s->glContext || !s->window) {
|
|
|
|
// Either glContext+Window or Window alone are not created.
|
|
|
|
// Handle each of them independently. This is to handle correctly
|
|
|
|
// both VOs like vo_corevideo who skip the the OpenGL detection
|
|
|
|
// phase completly and generic OpenGL VOs who use VOFLAG_HIDDEN.
|
|
|
|
if (!s->glContext) {
|
|
|
|
ctxok = create_gl_context(vo, gl3profile);
|
|
|
|
if (ctxok < 0) return;
|
2013-05-29 22:30:05 +02:00
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
if (!s->window)
|
|
|
|
create_window(vo, d_width, d_height, flags);
|
2013-03-04 14:23:06 +01:00
|
|
|
}
|
2013-03-03 21:29:32 +01:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
if (s->window) {
|
|
|
|
// Everything is properly initialized
|
|
|
|
update_window(vo);
|
2013-05-11 00:22:23 +02:00
|
|
|
}
|
2013-03-04 14:23:06 +01:00
|
|
|
});
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
if (ctxok < 0)
|
|
|
|
return ctxok;
|
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
[vo->cocoa->glContext makeCurrentContext];
|
2013-05-12 23:51:58 +02:00
|
|
|
s->enable_resize_redraw = YES;
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-06-01 11:26:06 +02:00
|
|
|
return 0;
|
2013-03-04 14:23:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool resize_callback_registered(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-05-12 23:51:58 +02:00
|
|
|
return s->enable_resize_redraw && !!s->resize_redraw;
|
2013-03-04 14:23:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void vo_cocoa_set_current_context(struct vo *vo, bool current)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
if (current) {
|
|
|
|
[s->lock lock];
|
|
|
|
[s->glContext makeCurrentContext];
|
|
|
|
} else {
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
|
|
|
[s->lock unlock];
|
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
void vo_cocoa_swap_buffers(struct vo *vo)
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-03-04 14:23:06 +01:00
|
|
|
if (s->did_async_resize && resize_callback_registered(vo)) {
|
|
|
|
// when in live resize the GL view asynchronously updates itself from
|
|
|
|
// it's drawRect: implementation and calls flushBuffer. This means the
|
|
|
|
// backbuffer is probably in an inconsistent state, so we skip one
|
|
|
|
// flushBuffer call here on the playloop thread.
|
|
|
|
s->did_async_resize = NO;
|
|
|
|
} else {
|
|
|
|
[s->glContext flushBuffer];
|
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int vo_cocoa_check_events(struct vo *vo)
|
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-01-20 16:53:51 +01:00
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
int key = cocoa_sync_get_key(s->input_queue);
|
|
|
|
if (key >= 0) mplayer_put_key(vo->key_fifo, key);
|
|
|
|
|
2013-02-23 18:28:22 +01:00
|
|
|
if (s->did_resize) {
|
|
|
|
s->did_resize = NO;
|
|
|
|
resize_window(vo);
|
|
|
|
return VO_EVENT_RESIZE;
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
2013-01-20 16:53:51 +01:00
|
|
|
|
2013-02-23 18:28:22 +01:00
|
|
|
return 0;
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void vo_cocoa_fullscreen(struct vo *vo)
|
|
|
|
{
|
2013-05-13 23:19:44 +02:00
|
|
|
if (![NSThread isMainThread]) {
|
|
|
|
// This is the secondary thread, unlock since we are going to invoke a
|
|
|
|
// method synchronously on the GUI thread using Cocoa.
|
|
|
|
vo_cocoa_set_current_context(vo, false);
|
|
|
|
}
|
2013-03-04 14:23:06 +01:00
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-03-04 14:23:06 +01:00
|
|
|
[s->window performSelectorOnMainThread:@selector(fullscreen)
|
|
|
|
withObject:nil
|
|
|
|
waitUntilDone:YES];
|
|
|
|
|
2013-05-13 23:19:44 +02:00
|
|
|
|
|
|
|
if (![NSThread isMainThread]) {
|
|
|
|
// Now lock again!
|
|
|
|
vo_cocoa_set_current_context(vo, true);
|
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-05-15 18:17:18 +02:00
|
|
|
int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
|
|
|
|
{
|
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_CHECK_EVENTS:
|
|
|
|
*events |= vo_cocoa_check_events(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_FULLSCREEN:
|
|
|
|
vo_cocoa_fullscreen(vo);
|
|
|
|
*events |= VO_EVENT_RESIZE;
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_ONTOP:
|
|
|
|
vo_cocoa_ontop(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_UPDATE_SCREENINFO:
|
2013-05-29 00:14:34 +02:00
|
|
|
vo_cocoa_update_screen_info(vo);
|
2013-05-15 18:17:18 +02:00
|
|
|
return VO_TRUE;
|
2013-05-17 00:29:42 +02:00
|
|
|
case VOCTRL_SET_CURSOR_VISIBILITY: {
|
|
|
|
bool visible = *(bool *)arg;
|
2013-06-01 00:35:46 +02:00
|
|
|
vo_cocoa_set_cursor_visibility(vo, visible);
|
2013-05-17 00:29:42 +02:00
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2013-05-15 18:17:18 +02:00
|
|
|
case VOCTRL_PAUSE:
|
|
|
|
vo_cocoa_pause(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_RESUME:
|
|
|
|
vo_cocoa_resume(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-12-04 21:53:43 +01:00
|
|
|
int vo_cocoa_swap_interval(int enabled)
|
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
[[NSOpenGLContext currentContext] setValues:&enabled
|
|
|
|
forParameter:NSOpenGLCPSwapInterval];
|
2011-12-04 21:53:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
void *vo_cocoa_cgl_context(struct vo *vo)
|
2011-12-11 12:26:00 +01:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2011-12-11 12:26:00 +01:00
|
|
|
return [s->glContext CGLContextObj];
|
|
|
|
}
|
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
void *vo_cocoa_cgl_pixel_format(struct vo *vo)
|
2011-12-11 12:26:00 +01:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
return CGLGetPixelFormat(vo_cocoa_cgl_context(vo));
|
2011-12-11 12:26:00 +01:00
|
|
|
}
|
|
|
|
|
2012-09-13 09:32:59 +02:00
|
|
|
int vo_cocoa_cgl_color_size(struct vo *vo)
|
2012-05-14 16:33:06 +02:00
|
|
|
{
|
|
|
|
GLint value;
|
2012-09-13 09:32:59 +02:00
|
|
|
CGLDescribePixelFormat(vo_cocoa_cgl_pixel_format(vo), 0,
|
2012-05-14 16:33:06 +02:00
|
|
|
kCGLPFAColorSize, &value);
|
|
|
|
switch (value) {
|
|
|
|
case 32:
|
|
|
|
case 24:
|
|
|
|
return 8;
|
|
|
|
case 16:
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
@implementation GLMPlayerWindow
|
2013-03-04 14:23:06 +01:00
|
|
|
@synthesize videoOutput = _video_output;
|
2012-09-16 16:18:57 +02:00
|
|
|
- (void)windowDidResize:(NSNotification *) notification
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
if (self.videoOutput) {
|
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
2011-10-15 18:44:00 +02:00
|
|
|
s->did_resize = YES;
|
2012-10-19 23:47:03 +02:00
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
2013-05-30 13:41:56 +02:00
|
|
|
- (void)toggleMissionControlFullScreen:(BOOL)willBeFullscreen
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
|
|
|
|
|
|
|
if (willBeFullscreen) {
|
|
|
|
[self setContentResizeIncrements:NSMakeSize(1, 1)];
|
|
|
|
} else {
|
|
|
|
[self setContentAspectRatio:s->current_video_size];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self toggleFullScreen:nil];
|
|
|
|
}
|
|
|
|
- (void)toggleViewFullscreen:(BOOL)willBeFullscreen
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
|
|
|
|
|
|
|
if (willBeFullscreen) {
|
2013-06-01 22:52:21 +02:00
|
|
|
NSApplicationPresentationOptions popts =
|
|
|
|
NSApplicationPresentationDefault;
|
|
|
|
|
|
|
|
if ([s->fs_screen hasMenubar])
|
|
|
|
popts |= NSApplicationPresentationAutoHideMenuBar;
|
|
|
|
|
|
|
|
if ([s->fs_screen hasDock])
|
|
|
|
popts |= NSApplicationPresentationAutoHideDock;
|
|
|
|
|
2013-05-30 13:41:56 +02:00
|
|
|
NSDictionary *fsopts = @{
|
2013-06-01 22:52:21 +02:00
|
|
|
NSFullScreenModeWindowLevel : @(NSFloatingWindowLevel),
|
|
|
|
NSFullScreenModeAllScreens : @NO,
|
|
|
|
NSFullScreenModeApplicationPresentationOptions : @(popts)
|
2013-05-30 13:41:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
[s->view enterFullScreenMode:s->fs_screen withOptions:fsopts];
|
2013-05-31 12:58:54 +02:00
|
|
|
|
|
|
|
// The original "windowed" window will staty around since sending a
|
|
|
|
// view fullscreen wraps it in another window. This is noticeable when
|
|
|
|
// sending the View fullscreen to another screen. Make it go away
|
|
|
|
// manually.
|
|
|
|
[s->window orderOut:self];
|
2013-05-30 13:41:56 +02:00
|
|
|
} else {
|
|
|
|
[s->view exitFullScreenModeWithOptions:nil];
|
2013-05-31 12:58:54 +02:00
|
|
|
|
|
|
|
// Show the "windowed" window again.
|
|
|
|
[s->window makeKeyAndOrderFront:self];
|
2013-05-30 13:41:56 +02:00
|
|
|
[self makeFirstResponder:s->view];
|
|
|
|
}
|
|
|
|
}
|
2012-09-16 16:18:57 +02:00
|
|
|
- (void)fullscreen
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
2013-05-30 13:41:56 +02:00
|
|
|
struct mp_vo_opts *opts = self.videoOutput->opts;
|
|
|
|
|
|
|
|
vo_cocoa_update_screen_info(self.videoOutput);
|
2013-03-04 14:23:06 +01:00
|
|
|
|
2013-05-30 13:41:56 +02:00
|
|
|
// Go use the fullscreen API selected by the user. View-based or Mission
|
|
|
|
// Control.
|
2013-05-11 00:22:23 +02:00
|
|
|
if (opts->native_fs) {
|
2013-05-30 13:41:56 +02:00
|
|
|
[self toggleMissionControlFullScreen:!opts->fs];
|
|
|
|
} else {
|
|
|
|
[self toggleViewFullscreen:!opts->fs];
|
|
|
|
}
|
2013-05-11 00:22:23 +02:00
|
|
|
|
2013-05-30 13:41:56 +02:00
|
|
|
// Do common work such as setting mouse visibility and actually setting
|
|
|
|
// the new fullscreen state
|
|
|
|
if (!opts->fs) {
|
|
|
|
opts->fs = VO_TRUE;
|
2013-06-01 00:35:46 +02:00
|
|
|
vo_cocoa_set_cursor_visibility(self.videoOutput, false);
|
2013-05-11 00:22:23 +02:00
|
|
|
} else {
|
2013-05-30 13:41:56 +02:00
|
|
|
opts->fs = VO_FALSE;
|
2013-06-01 00:35:46 +02:00
|
|
|
vo_cocoa_set_cursor_visibility(self.videoOutput, true);
|
2013-05-11 00:22:23 +02:00
|
|
|
}
|
|
|
|
|
2013-05-30 13:41:56 +02:00
|
|
|
// Change window size if the core attempted to change it while we were in
|
|
|
|
// fullscreen. For example config() might have been called as a result of
|
|
|
|
// a new file changing the window size.
|
2013-05-29 00:14:34 +02:00
|
|
|
if (!opts->fs && s->out_fs_resize) {
|
|
|
|
resize_window_from_stored_size(self.videoOutput);
|
|
|
|
s->out_fs_resize = NO;
|
|
|
|
}
|
|
|
|
|
2013-05-30 13:41:56 +02:00
|
|
|
// Make the core aware of the view size change.
|
2013-03-04 14:23:06 +01:00
|
|
|
resize_window(self.videoOutput);
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-16 16:18:57 +02:00
|
|
|
- (BOOL)canBecomeMainWindow { return YES; }
|
|
|
|
- (BOOL)canBecomeKeyWindow { return YES; }
|
|
|
|
- (BOOL)windowShouldClose:(id)sender
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
|
|
|
cocoa_async_put_key(s->input_queue, MP_KEY_CLOSE_WIN);
|
2011-10-15 18:44:00 +02:00
|
|
|
// We have to wait for MPlayer to handle this,
|
|
|
|
// otherwise we are in trouble if the
|
2013-02-12 01:34:04 +01:00
|
|
|
// MP_KEY_CLOSE_WIN handler is disabled
|
2011-10-15 18:44:00 +02:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2012-09-16 16:18:57 +02:00
|
|
|
- (BOOL)isMovableByWindowBackground
|
2012-01-06 09:54:04 +01:00
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
if (self.videoOutput) {
|
|
|
|
return !self.videoOutput->opts->fs;
|
2013-03-04 23:23:12 +01:00
|
|
|
} else {
|
2013-05-13 23:05:20 +02:00
|
|
|
return YES;
|
2013-03-04 23:23:12 +01:00
|
|
|
}
|
2012-01-06 09:54:04 +01:00
|
|
|
}
|
|
|
|
|
2013-05-29 00:14:34 +02:00
|
|
|
- (void)normalSize { [self mulSize:1.0f]; }
|
|
|
|
|
|
|
|
- (void)halfSize { [self mulSize:0.5f];}
|
|
|
|
|
|
|
|
- (void)doubleSize { [self mulSize:2.0f];}
|
|
|
|
|
|
|
|
- (void)mulSize:(float)multiplier
|
|
|
|
{
|
|
|
|
if (!self.videoOutput->opts->fs) {
|
|
|
|
NSSize size = {
|
|
|
|
.width = self.videoOutput->cocoa->aspdat.prew * multiplier,
|
|
|
|
.height = self.videoOutput->cocoa->aspdat.preh * multiplier
|
|
|
|
};
|
|
|
|
[self setContentSize:size keepCentered:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)titleHeight
|
|
|
|
{
|
|
|
|
NSRect of = [self frame];
|
|
|
|
NSRect cb = [[self contentView] bounds];
|
|
|
|
return of.size.height - cb.size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)clipFrame:(NSRect)frame withContentAspect:(NSSize) aspect
|
|
|
|
{
|
|
|
|
NSRect vf = [[self screen] visibleFrame];
|
|
|
|
double ratio = (double)aspect.width / (double)aspect.height;
|
|
|
|
|
|
|
|
// clip frame to screens visibile frame
|
|
|
|
frame = CGRectIntersection(frame, vf);
|
|
|
|
|
|
|
|
NSSize s = frame.size;
|
|
|
|
s.height -= [self titleHeight];
|
|
|
|
|
|
|
|
if (s.width > s.height) {
|
|
|
|
s.width = ((double)s.height * ratio);
|
|
|
|
} else {
|
|
|
|
s.height = ((double)s.width * 1.0/ratio);
|
|
|
|
}
|
|
|
|
|
|
|
|
s.height += [self titleHeight];
|
|
|
|
frame.size = s;
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setCenteredContentSize:(NSSize)ns
|
|
|
|
{
|
|
|
|
#define get_center(x) NSMakePoint(CGRectGetMidX((x)), CGRectGetMidY((x)))
|
|
|
|
NSRect of = [self frame];
|
|
|
|
NSRect vf = [[self screen] visibleFrame];
|
|
|
|
NSPoint old_center = get_center(of);
|
|
|
|
|
|
|
|
NSRect nf = NSMakeRect(vf.origin.x, vf.origin.y,
|
|
|
|
ns.width, ns.height + [self titleHeight]);
|
|
|
|
|
|
|
|
nf = [self clipFrame:nf withContentAspect:ns];
|
|
|
|
|
|
|
|
NSPoint new_center = get_center(nf);
|
|
|
|
|
|
|
|
int dx0 = old_center.x - new_center.x;
|
|
|
|
int dy0 = old_center.y - new_center.y;
|
|
|
|
|
|
|
|
nf.origin.x += dx0;
|
|
|
|
nf.origin.y += dy0;
|
|
|
|
|
|
|
|
[self setFrame:nf display:YES animate:NO];
|
|
|
|
#undef get_center
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setContentSize:(NSSize)ns keepCentered:(BOOL)keepCentered
|
|
|
|
{
|
|
|
|
if (keepCentered) {
|
|
|
|
[self setCenteredContentSize:ns];
|
|
|
|
} else {
|
|
|
|
[self setContentSize:ns];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GLMPlayerOpenGLView
|
|
|
|
@synthesize videoOutput = _video_output;
|
2013-06-01 17:58:08 +02:00
|
|
|
@synthesize mouseDown = _mouse_down;
|
2013-05-29 00:14:34 +02:00
|
|
|
- (BOOL)acceptsFirstResponder { return YES; }
|
|
|
|
- (BOOL)becomeFirstResponder { return YES; }
|
|
|
|
- (BOOL)resignFirstResponder { return YES; }
|
|
|
|
|
|
|
|
- (void)keyDown:(NSEvent *)theEvent
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
2013-02-19 21:21:50 +01:00
|
|
|
NSString *chars;
|
|
|
|
|
|
|
|
if (RightAltPressed(theEvent))
|
|
|
|
chars = [theEvent characters];
|
2011-10-15 18:44:00 +02:00
|
|
|
else
|
2013-02-19 21:21:50 +01:00
|
|
|
chars = [theEvent charactersIgnoringModifiers];
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-02-19 21:21:50 +01:00
|
|
|
int key = convert_key([theEvent keyCode], *[chars UTF8String]);
|
2011-10-15 18:44:00 +02:00
|
|
|
|
|
|
|
if (key > -1) {
|
|
|
|
if ([theEvent modifierFlags] & NSShiftKeyMask)
|
2013-02-12 01:34:04 +01:00
|
|
|
key |= MP_KEY_MODIFIER_SHIFT;
|
2011-10-15 18:44:00 +02:00
|
|
|
if ([theEvent modifierFlags] & NSControlKeyMask)
|
2013-02-12 01:34:04 +01:00
|
|
|
key |= MP_KEY_MODIFIER_CTRL;
|
2013-02-19 21:21:50 +01:00
|
|
|
if (LeftAltPressed(theEvent))
|
2013-02-12 01:34:04 +01:00
|
|
|
key |= MP_KEY_MODIFIER_ALT;
|
2011-10-15 18:44:00 +02:00
|
|
|
if ([theEvent modifierFlags] & NSCommandKeyMask)
|
2013-02-12 01:34:04 +01:00
|
|
|
key |= MP_KEY_MODIFIER_META;
|
2013-03-04 14:23:06 +01:00
|
|
|
|
|
|
|
cocoa_async_put_key(s->input_queue, key);
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 22:40:04 +02:00
|
|
|
- (NSPoint) mouseLocation
|
2011-12-08 11:17:59 +01:00
|
|
|
{
|
2013-05-30 22:40:04 +02:00
|
|
|
NSPoint mLoc = [NSEvent mouseLocation];
|
2013-06-01 00:35:46 +02:00
|
|
|
NSPoint wLoc = [self.window convertScreenToBase:mLoc];
|
2013-05-30 22:40:04 +02:00
|
|
|
return [self convertPoint:wLoc fromView:nil];
|
|
|
|
}
|
2013-05-17 00:36:06 +02:00
|
|
|
|
2013-05-30 22:40:04 +02:00
|
|
|
- (BOOL)containsCurrentMouseLocation
|
|
|
|
{
|
2013-06-01 00:35:46 +02:00
|
|
|
NSRect vF = [[self.window screen] visibleFrame];
|
|
|
|
NSRect vFR = [self.window convertRectFromScreen:vF];
|
|
|
|
NSRect vFRV = [self convertRect:vFR fromView:nil];
|
|
|
|
|
|
|
|
// clip bounds to current visibleFrame
|
|
|
|
NSRect clippedBounds = CGRectIntersection([self bounds], vFRV);
|
|
|
|
return CGRectContainsPoint(clippedBounds, [self mouseLocation]);
|
2013-05-30 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)signalMouseMovement:(NSEvent *)event
|
|
|
|
{
|
|
|
|
if ([self containsCurrentMouseLocation]) {
|
|
|
|
NSPoint loc = [self mouseLocation];
|
|
|
|
loc.y = - loc.y + [self bounds].size.height;
|
|
|
|
vo_mouse_movement(self.videoOutput, loc.x, loc.y);
|
2013-05-17 00:36:06 +02:00
|
|
|
}
|
2011-12-08 11:17:59 +01:00
|
|
|
}
|
|
|
|
|
2013-05-29 00:14:34 +02:00
|
|
|
- (void)mouseMoved:(NSEvent *)evt { [self signalMouseMovement:evt]; }
|
|
|
|
- (void)mouseDragged:(NSEvent *)evt { [self signalMouseMovement:evt]; }
|
|
|
|
- (void)mouseDown:(NSEvent *)evt { [self mouseEvent:evt]; }
|
|
|
|
- (void)mouseUp:(NSEvent *)evt { [self mouseEvent:evt]; }
|
|
|
|
- (void)rightMouseDown:(NSEvent *)evt { [self mouseEvent:evt]; }
|
|
|
|
- (void)rightMouseUp:(NSEvent *)evt { [self mouseEvent:evt]; }
|
|
|
|
- (void)otherMouseDown:(NSEvent *)evt { [self mouseEvent:evt]; }
|
|
|
|
- (void)otherMouseUp:(NSEvent *)evt { [self mouseEvent:evt]; }
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2012-09-16 16:18:57 +02:00
|
|
|
- (void)scrollWheel:(NSEvent *)theEvent
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2013-03-04 14:23:06 +01:00
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
2013-01-20 17:15:37 +01:00
|
|
|
|
|
|
|
CGFloat delta;
|
|
|
|
// Use the dimention with the most delta as the scrolling one
|
|
|
|
if (FFABS([theEvent deltaY]) > FFABS([theEvent deltaX])) {
|
|
|
|
delta = [theEvent deltaY];
|
|
|
|
} else {
|
|
|
|
delta = - [theEvent deltaX];
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:53:17 +02:00
|
|
|
if ([theEvent hasPreciseScrollingDeltas]) {
|
2013-01-20 17:15:37 +01:00
|
|
|
s->accumulated_scroll += delta;
|
|
|
|
static const CGFloat threshold = 10;
|
|
|
|
while (s->accumulated_scroll >= threshold) {
|
|
|
|
s->accumulated_scroll -= threshold;
|
2013-03-04 14:23:06 +01:00
|
|
|
cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN3);
|
2013-01-20 17:15:37 +01:00
|
|
|
}
|
|
|
|
while (s->accumulated_scroll <= -threshold) {
|
|
|
|
s->accumulated_scroll += threshold;
|
2013-03-04 14:23:06 +01:00
|
|
|
cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN4);
|
2013-01-20 17:15:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (delta > 0)
|
2013-03-04 14:23:06 +01:00
|
|
|
cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN3);
|
2013-01-20 17:15:37 +01:00
|
|
|
else
|
2013-03-04 14:23:06 +01:00
|
|
|
cocoa_async_put_key(s->input_queue, MP_MOUSE_BTN4);
|
2013-01-20 17:15:37 +01:00
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-16 16:18:57 +02:00
|
|
|
- (void)mouseEvent:(NSEvent *)theEvent
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2012-02-03 23:50:44 +01:00
|
|
|
if ([theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9) {
|
2013-03-04 14:23:06 +01:00
|
|
|
struct vo_cocoa_state *s = self.videoOutput->cocoa;
|
2011-10-15 18:44:00 +02:00
|
|
|
int buttonNumber = [theEvent buttonNumber];
|
|
|
|
// Fix to mplayer defined button order: left, middle, right
|
2012-02-03 23:50:44 +01:00
|
|
|
if (buttonNumber == 1) buttonNumber = 2;
|
|
|
|
else if (buttonNumber == 2) buttonNumber = 1;
|
2011-10-15 18:44:00 +02:00
|
|
|
switch ([theEvent type]) {
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
2013-03-04 14:23:06 +01:00
|
|
|
cocoa_async_put_key(
|
|
|
|
s->input_queue,
|
|
|
|
(MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_DOWN);
|
2013-06-01 17:58:08 +02:00
|
|
|
self.mouseDown = YES;
|
2012-02-03 23:50:44 +01:00
|
|
|
// Looks like Cocoa doesn't create MouseUp events when we are
|
|
|
|
// doing the second click in a double click. Put in the key_fifo
|
|
|
|
// the key that would be put from the MouseUp handling code.
|
2013-06-01 17:58:08 +02:00
|
|
|
if([theEvent clickCount] == 2) {
|
2013-03-04 14:23:06 +01:00
|
|
|
cocoa_async_put_key(s->input_queue,
|
|
|
|
MP_MOUSE_BTN0 + buttonNumber);
|
2013-06-01 17:58:08 +02:00
|
|
|
self.mouseDown = NO;
|
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
break;
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
2013-03-04 14:23:06 +01:00
|
|
|
cocoa_async_put_key(s->input_queue,
|
|
|
|
MP_MOUSE_BTN0 + buttonNumber);
|
2013-06-01 17:58:08 +02:00
|
|
|
self.mouseDown = NO;
|
2011-10-15 18:44:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-16 16:18:57 +02:00
|
|
|
- (void)drawRect: (NSRect)rect
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2013-05-29 00:14:34 +02:00
|
|
|
struct vo *vo = [self videoOutput];
|
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
if (vo && resize_callback_registered(vo)) {
|
|
|
|
NSSize size = to_pixels(vo, [self bounds]).size;
|
|
|
|
resize_redraw(vo, size.width, size.height);
|
|
|
|
} else {
|
|
|
|
[[NSColor clearColor] set];
|
|
|
|
NSRectFill([self bounds]);
|
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
@end
|
2013-06-01 22:52:21 +02:00
|
|
|
|
|
|
|
@implementation NSScreen (mpvadditions)
|
|
|
|
- (BOOL)hasDock
|
|
|
|
{
|
|
|
|
NSRect vF = [self visibleFrame];
|
|
|
|
NSRect f = [self frame];
|
|
|
|
return
|
|
|
|
// The visible frame's width is smaller: dock is on left or right end
|
|
|
|
// of this method's receiver.
|
|
|
|
vF.size.width < f.size.width ||
|
|
|
|
// The visible frame's veritical origin is bigger is smaller: dock is
|
|
|
|
// on the bottom of this method's receiver.
|
|
|
|
vF.origin.y > f.origin.y;
|
|
|
|
|
|
|
|
}
|
|
|
|
- (BOOL)hasMenubar
|
|
|
|
{
|
|
|
|
return [self isEqual: [NSScreen screens][0]];
|
|
|
|
}
|
|
|
|
@end
|