2012-03-04 22:04:07 +01:00
|
|
|
/*
|
|
|
|
* Cocoa OpenGL Backend
|
|
|
|
*
|
2013-09-03 21:18:28 +02:00
|
|
|
* This file is part of mpv.
|
2012-03-04 22:04:07 +01:00
|
|
|
*
|
2013-09-03 21:18:28 +02:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2012-03-04 22:04:07 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2013-09-03 21:18:28 +02:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2012-03-04 22:04:07 +01:00
|
|
|
* 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
|
2013-09-03 21:18:28 +02:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2012-03-04 22:04:07 +01:00
|
|
|
*/
|
|
|
|
|
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>
|
2015-02-03 18:16:02 +01:00
|
|
|
#import <IOKit/IOKitLib.h>
|
|
|
|
#include <mach/mach.h>
|
2012-04-14 15:02:28 +02:00
|
|
|
|
2014-10-05 22:31:33 +02:00
|
|
|
#import "cocoa_common.h"
|
|
|
|
#import "video/out/cocoa/window.h"
|
|
|
|
#import "video/out/cocoa/events_view.h"
|
|
|
|
#import "video/out/cocoa/video_view.h"
|
2013-09-03 21:18:28 +02:00
|
|
|
#import "video/out/cocoa/mpvadapter.h"
|
|
|
|
|
2014-10-04 11:47:17 +02:00
|
|
|
#include "osdep/threads.h"
|
2013-10-05 14:39:27 +02:00
|
|
|
#include "osdep/macosx_compat.h"
|
2014-04-16 04:38:19 +02:00
|
|
|
#include "osdep/macosx_events_objc.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2012-07-21 10:37:13 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2015-05-02 18:09:01 +02:00
|
|
|
#include "osdep/macosx_application.h"
|
|
|
|
#include "osdep/macosx_application_objc.h"
|
2014-04-16 04:52:24 +02:00
|
|
|
|
2013-12-17 03:35:43 +01:00
|
|
|
#include "options/options.h"
|
2013-09-03 21:18:28 +02:00
|
|
|
#include "video/out/vo.h"
|
2014-05-06 22:00:17 +02:00
|
|
|
#include "win_state.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-12-17 03:35:43 +01:00
|
|
|
#include "input/input.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
#include "talloc.h"
|
|
|
|
|
2013-12-17 03:35:43 +01:00
|
|
|
#include "common/msg.h"
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2014-02-25 00:04:30 +01:00
|
|
|
#define CF_RELEASE(a) if ((a) != NULL) CFRelease(a)
|
2014-10-04 11:47:17 +02:00
|
|
|
#define cocoa_lock(s) pthread_mutex_lock(&s->mutex)
|
|
|
|
#define cocoa_unlock(s) pthread_mutex_unlock(&s->mutex)
|
2014-02-25 00:04:30 +01:00
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
static void vo_cocoa_fullscreen(struct vo *vo);
|
2015-03-07 08:48:07 +01:00
|
|
|
static void cocoa_rm_fs_screen_profile_observer(struct vo_cocoa_state *s);
|
2013-07-21 10:33:18 +02:00
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
struct vo_cocoa_state {
|
2014-10-05 14:28:33 +02:00
|
|
|
NSWindow *window;
|
2014-10-08 19:23:47 +02:00
|
|
|
NSView *view;
|
2014-10-05 22:31:33 +02:00
|
|
|
MpvVideoView *video;
|
2015-03-08 15:19:17 +01:00
|
|
|
MpvCocoaAdapter *adapter;
|
2013-09-03 21:18:28 +02:00
|
|
|
NSOpenGLContext *gl_ctx;
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2013-05-29 00:14:34 +02:00
|
|
|
NSScreen *current_screen;
|
|
|
|
NSScreen *fs_screen;
|
2015-02-03 21:43:20 +01:00
|
|
|
double screen_fps;
|
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
|
|
|
|
2014-10-05 19:31:21 +02:00
|
|
|
int pending_events;
|
|
|
|
|
2014-10-04 17:13:41 +02:00
|
|
|
bool waiting_frame;
|
2014-10-18 18:30:22 +02:00
|
|
|
bool skip_swap_buffer;
|
2014-10-05 19:16:23 +02:00
|
|
|
bool embedded; // wether we are embedding in another GUI
|
2012-09-16 20:53:04 +02:00
|
|
|
|
|
|
|
IOPMAssertionID power_mgmt_assertion;
|
2015-02-03 18:16:02 +01:00
|
|
|
io_connect_t light_sensor;
|
|
|
|
uint64_t last_lmuvalue;
|
|
|
|
int last_lux;
|
|
|
|
IONotificationPortRef light_sensor_io_port;
|
2013-01-20 17:15:37 +01:00
|
|
|
|
2014-10-04 11:47:17 +02:00
|
|
|
pthread_mutex_t mutex;
|
2013-08-01 08:23:53 +02:00
|
|
|
struct mp_log *log;
|
2014-01-06 14:17:14 +01:00
|
|
|
|
|
|
|
uint32_t old_dwidth;
|
|
|
|
uint32_t old_dheight;
|
2014-02-25 00:04:30 +01:00
|
|
|
|
2015-01-07 18:47:27 +01:00
|
|
|
NSData *icc_wnd_profile;
|
|
|
|
NSData *icc_fs_profile;
|
2014-02-25 00:04:30 +01:00
|
|
|
id fs_icc_changed_ns_observer;
|
2014-10-18 18:30:22 +02:00
|
|
|
|
|
|
|
void (*resize_redraw)(struct vo *vo, int w, int h);
|
2013-03-04 14:23:06 +01:00
|
|
|
};
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2015-03-07 09:11:47 +01:00
|
|
|
static void with_cocoa_lock(struct vo_cocoa_state *s, void(^block)(void))
|
2014-04-28 21:50:38 +02:00
|
|
|
{
|
2014-10-04 11:47:17 +02:00
|
|
|
cocoa_lock(s);
|
|
|
|
block();
|
|
|
|
cocoa_unlock(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void with_cocoa_lock_on_main_thread(struct vo *vo, void(^block)(void))
|
|
|
|
{
|
2015-03-07 09:11:47 +01:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2014-10-18 14:26:37 +02:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2015-03-07 09:11:47 +01:00
|
|
|
with_cocoa_lock(s, block);
|
2014-10-18 14:26:37 +02:00
|
|
|
});
|
2014-04-28 21:50:38 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 14:28:33 +02:00
|
|
|
static void queue_new_video_size(struct vo *vo, int w, int h)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
if ([s->window conformsToProtocol: @protocol(MpvSizing)]) {
|
|
|
|
id<MpvSizing> win = (id<MpvSizing>) s->window;
|
|
|
|
[win queueNewVideoSize:NSMakeSize(w, h)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 08:48:07 +01:00
|
|
|
static void enable_power_management(struct vo_cocoa_state *s)
|
2012-09-16 20:53:04 +02:00
|
|
|
{
|
|
|
|
if (!s->power_mgmt_assertion) return;
|
|
|
|
IOPMAssertionRelease(s->power_mgmt_assertion);
|
|
|
|
s->power_mgmt_assertion = kIOPMNullAssertionID;
|
|
|
|
}
|
|
|
|
|
2015-03-07 08:48:07 +01:00
|
|
|
static void disable_power_management(struct vo_cocoa_state *s)
|
2012-09-16 20:53:04 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-05 22:58:02 +01:00
|
|
|
static const char macosx_icon[] =
|
|
|
|
#include "osdep/macosx_icon.inc"
|
|
|
|
;
|
|
|
|
|
|
|
|
static void set_application_icon(NSApplication *app)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSData *icon_data = [NSData dataWithBytesNoCopy:(void *)macosx_icon
|
|
|
|
length:sizeof(macosx_icon)
|
|
|
|
freeWhenDone:NO];
|
|
|
|
NSImage *icon = [[NSImage alloc] initWithData:icon_data];
|
|
|
|
[app setApplicationIconImage:icon];
|
|
|
|
[icon release];
|
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:16:02 +01:00
|
|
|
static int lmuvalue_to_lux(uint64_t v)
|
|
|
|
{
|
|
|
|
// the polinomial approximation for apple lmu value -> lux was empirically
|
|
|
|
// derived by firefox developers (Apple provides no documentation).
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=793728
|
|
|
|
double power_c4 = 1/pow((double)10,27);
|
|
|
|
double power_c3 = 1/pow((double)10,19);
|
|
|
|
double power_c2 = 1/pow((double)10,12);
|
|
|
|
double power_c1 = 1/pow((double)10,5);
|
|
|
|
|
|
|
|
double term4 = -3.0 * power_c4 * pow(v,4);
|
|
|
|
double term3 = 2.6 * power_c3 * pow(v,3);
|
|
|
|
double term2 = -3.4 * power_c2 * pow(v,2);
|
|
|
|
double term1 = 3.9 * power_c1 * v;
|
|
|
|
|
|
|
|
int lux = ceil(term4 + term3 + term2 + term1 - 0.19);
|
|
|
|
return lux > 0 ? lux : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void light_sensor_cb(void *ctx, io_service_t srv, natural_t mtype, void *msg)
|
|
|
|
{
|
|
|
|
struct vo *vo = ctx;
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
uint32_t outputs = 2;
|
|
|
|
uint64_t values[outputs];
|
|
|
|
|
|
|
|
kern_return_t kr = IOConnectCallMethod(
|
|
|
|
s->light_sensor, 0, NULL, 0, NULL, 0, values, &outputs, nil, 0);
|
|
|
|
|
|
|
|
if (kr == KERN_SUCCESS) {
|
|
|
|
uint64_t mean = (values[0] + values[1]) / 2;
|
|
|
|
if (s->last_lmuvalue != mean) {
|
|
|
|
s->last_lmuvalue = mean;
|
|
|
|
s->last_lux = lmuvalue_to_lux(s->last_lmuvalue);
|
|
|
|
s->pending_events |= VO_EVENT_AMBIENT_LIGHTING_CHANGED;
|
|
|
|
vo_wakeup(vo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cocoa_init_light_sensor(struct vo *vo)
|
|
|
|
{
|
|
|
|
with_cocoa_lock_on_main_thread(vo, ^{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
io_service_t srv = IOServiceGetMatchingService(
|
|
|
|
kIOMasterPortDefault, IOServiceMatching("AppleLMUController"));
|
|
|
|
if (srv == IO_OBJECT_NULL) {
|
|
|
|
MP_VERBOSE(vo, "can't find an ambient light sensor\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// subscribe to notifications from the light sensor driver
|
|
|
|
s->light_sensor_io_port = IONotificationPortCreate(kIOMasterPortDefault);
|
|
|
|
IONotificationPortSetDispatchQueue(
|
|
|
|
s->light_sensor_io_port, dispatch_get_main_queue());
|
|
|
|
|
|
|
|
io_object_t n;
|
|
|
|
IOServiceAddInterestNotification(
|
|
|
|
s->light_sensor_io_port, srv, kIOGeneralInterest, light_sensor_cb,
|
|
|
|
vo, &n);
|
|
|
|
|
|
|
|
kern_return_t kr = IOServiceOpen(srv, mach_task_self(), 0,
|
|
|
|
&s->light_sensor);
|
|
|
|
IOObjectRelease(srv);
|
|
|
|
if (kr != KERN_SUCCESS) {
|
|
|
|
MP_WARN(vo, "can't start ambient light sensor connection\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
light_sensor_cb(vo, 0, 0, NULL);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-07 08:48:07 +01:00
|
|
|
static void cocoa_uninit_light_sensor(struct vo_cocoa_state *s)
|
2015-02-03 18:16:02 +01:00
|
|
|
{
|
2015-03-07 19:27:13 +01:00
|
|
|
if (s->light_sensor_io_port) {
|
|
|
|
IONotificationPortDestroy(s->light_sensor_io_port);
|
|
|
|
IOObjectRelease(s->light_sensor);
|
|
|
|
}
|
2015-02-03 18:16:02 +01:00
|
|
|
}
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
int vo_cocoa_init(struct vo *vo)
|
|
|
|
{
|
2015-03-07 08:48:07 +01:00
|
|
|
struct vo_cocoa_state *s = talloc_zero(NULL, struct vo_cocoa_state);
|
2013-09-03 21:18:28 +02:00
|
|
|
*s = (struct vo_cocoa_state){
|
2014-10-04 17:13:41 +02:00
|
|
|
.waiting_frame = false,
|
2013-09-03 21:18:28 +02:00
|
|
|
.power_mgmt_assertion = kIOPMNullAssertionID,
|
|
|
|
.log = mp_log_new(s, vo->log, "cocoa"),
|
2014-10-05 19:16:23 +02:00
|
|
|
.embedded = vo->opts->WinID >= 0,
|
2013-09-03 21:18:28 +02:00
|
|
|
};
|
2014-10-04 11:47:17 +02:00
|
|
|
mpthread_mutex_init_recursive(&s->mutex);
|
2013-09-03 21:18:28 +02:00
|
|
|
vo->cocoa = s;
|
2015-03-07 09:11:47 +01:00
|
|
|
cocoa_init_light_sensor(vo);
|
2011-10-15 18:44:00 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-10-08 19:23:47 +02:00
|
|
|
static int 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;
|
|
|
|
|
2014-10-08 19:23:47 +02:00
|
|
|
if (s->embedded)
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
|
|
|
|
MpvEventsView *v = (MpvEventsView *) s->view;
|
|
|
|
|
2013-09-18 08:34:28 +02:00
|
|
|
if (*visible) {
|
2013-05-17 00:29:42 +02:00
|
|
|
CGDisplayShowCursor(kCGDirectMainDisplay);
|
2015-03-08 15:19:17 +01:00
|
|
|
} else if ([v canHideCursor]) {
|
2013-05-17 00:29:42 +02:00
|
|
|
CGDisplayHideCursor(kCGDirectMainDisplay);
|
2013-09-18 08:34:28 +02:00
|
|
|
} else {
|
|
|
|
*visible = true;
|
2013-05-17 00:29:42 +02:00
|
|
|
}
|
2014-10-08 19:23:47 +02:00
|
|
|
|
|
|
|
return VO_TRUE;
|
2013-05-17 00:29:42 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 18:30:22 +02: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;
|
|
|
|
}
|
|
|
|
|
2011-10-15 18:44:00 +02:00
|
|
|
void vo_cocoa_uninit(struct vo *vo)
|
|
|
|
{
|
2015-01-01 14:38:08 +01:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
|
|
|
|
with_cocoa_lock_on_main_thread(vo, ^{
|
2015-03-07 08:48:07 +01:00
|
|
|
enable_power_management(s);
|
|
|
|
cocoa_uninit_light_sensor(s);
|
|
|
|
cocoa_rm_fs_screen_profile_observer(s);
|
2011-10-15 18:44:00 +02:00
|
|
|
|
2014-10-27 19:10:52 +01:00
|
|
|
[s->gl_ctx release];
|
2015-01-01 14:38:08 +01:00
|
|
|
|
|
|
|
// needed to stop resize events triggered by the event's view -clear
|
|
|
|
// causing many uses after free
|
|
|
|
[s->video removeFromSuperview];
|
|
|
|
|
2014-10-27 19:10:52 +01:00
|
|
|
[s->view removeFromSuperview];
|
2015-03-07 08:48:07 +01:00
|
|
|
[(MpvEventsView *)s->view clear];
|
2014-11-25 14:44:27 +01:00
|
|
|
[s->view release];
|
2014-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
// if using --wid + libmpv there's no window to release
|
|
|
|
if (s->window)
|
|
|
|
[s->window release];
|
2015-01-01 14:38:08 +01:00
|
|
|
|
2015-03-07 08:48:07 +01:00
|
|
|
talloc_free(s);
|
|
|
|
});
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 08:23:53 +02:00
|
|
|
static int get_screen_handle(struct vo *vo, int identifier, NSWindow *window,
|
|
|
|
NSScreen **screen) {
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2013-02-17 16:35:44 +01:00
|
|
|
NSArray *screens = [NSScreen screens];
|
|
|
|
int n_of_displays = [screens count];
|
|
|
|
|
|
|
|
if (identifier >= n_of_displays) { // check if the identifier is out of bounds
|
2013-08-01 08:23:53 +02:00
|
|
|
MP_INFO(s, "Screen ID %d does not exist, falling back to main "
|
|
|
|
"device\n", identifier);
|
2013-02-17 16:35:44 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
static void vo_cocoa_update_screens_pointers(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-08-01 08:23:53 +02:00
|
|
|
get_screen_handle(vo, opts->screen_id, s->window, &s->current_screen);
|
|
|
|
get_screen_handle(vo, opts->fsscreen_id, s->window, &s->fs_screen);
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2015-02-03 21:43:20 +01:00
|
|
|
static void vo_cocoa_update_screen_fps(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
NSScreen *screen = vo->opts->fullscreen ? s->fs_screen : s->current_screen;
|
|
|
|
NSDictionary* sinfo = [screen deviceDescription];
|
|
|
|
NSNumber* sid = [sinfo objectForKey:@"NSScreenNumber"];
|
|
|
|
CGDirectDisplayID did = [sid longValue];
|
|
|
|
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(did);
|
|
|
|
s->screen_fps = CGDisplayModeGetRefreshRate(mode);
|
|
|
|
CGDisplayModeRelease(mode);
|
2015-02-03 22:59:54 +01:00
|
|
|
|
2015-02-03 21:43:20 +01:00
|
|
|
if (s->screen_fps == 0.0) {
|
2015-02-03 22:59:54 +01:00
|
|
|
// Fallback to using Nominal refresh rate from DisplayLink,
|
|
|
|
// CVDisplayLinkGet *Actual* OutputVideoRefreshPeriod seems to
|
|
|
|
// return 0 as well if CG returns 0
|
|
|
|
CVDisplayLinkRef link;
|
|
|
|
CVDisplayLinkCreateWithCGDisplay(did, &link);
|
|
|
|
const CVTime t = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
|
|
|
|
if (!(t.flags & kCVTimeIsIndefinite))
|
|
|
|
s->screen_fps = (t.timeScale / (double) t.timeValue);
|
|
|
|
CVDisplayLinkRelease(link);
|
2015-02-03 21:43:20 +01:00
|
|
|
}
|
2015-03-14 12:33:09 +01:00
|
|
|
|
|
|
|
s->pending_events |= VO_EVENT_WIN_STATE;
|
2015-02-03 21:43:20 +01:00
|
|
|
}
|
|
|
|
|
2014-05-06 22:00:17 +02:00
|
|
|
static void vo_cocoa_update_screen_info(struct vo *vo, struct mp_rect *out_rc)
|
2011-10-15 18:44:00 +02:00
|
|
|
{
|
2012-09-13 09:32:59 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2012-11-10 20:19:21 +01:00
|
|
|
|
2014-10-08 19:23:47 +02:00
|
|
|
if (s->embedded)
|
|
|
|
return;
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
vo_cocoa_update_screens_pointers(vo);
|
2015-02-03 21:43:20 +01:00
|
|
|
vo_cocoa_update_screen_fps(vo);
|
2013-05-29 00:14:34 +02:00
|
|
|
|
2014-05-06 22:00:17 +02:00
|
|
|
if (out_rc) {
|
|
|
|
NSRect r = [s->current_screen frame];
|
|
|
|
*out_rc = (struct mp_rect){0, 0, r.size.width, r.size.height};
|
|
|
|
}
|
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;
|
2014-10-08 19:23:47 +02:00
|
|
|
NSRect frame = [s->video frameInPixels];
|
2012-08-07 10:31:39 +02:00
|
|
|
vo->dwidth = frame.size.width;
|
|
|
|
vo->dheight = frame.size.height;
|
2013-09-03 21:18:28 +02:00
|
|
|
[s->gl_ctx update];
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2014-10-05 14:28:33 +02:00
|
|
|
|
2011-12-07 12:42:04 +01:00
|
|
|
if (ontop) {
|
2013-10-12 20:57:28 +02:00
|
|
|
// +1 is not enough as that will show the icon layer on top of the
|
|
|
|
// menubar when the application is not frontmost. so use +2
|
|
|
|
s->window_level = NSMainMenuWindowLevel + 2;
|
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-06-11 21:20:46 +02:00
|
|
|
[[s->view window] setLevel:s->window_level];
|
|
|
|
[s->window setLevel:s->window_level];
|
2011-12-07 12:42:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-05 19:16:23 +02:00
|
|
|
static int vo_cocoa_ontop(struct vo *vo)
|
2011-12-07 12:42:04 +01:00
|
|
|
{
|
2014-10-05 19:16:23 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
if (s->embedded)
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
|
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);
|
2014-10-05 19:16:23 +02:00
|
|
|
return VO_TRUE;
|
2011-12-07 12:42:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-05 14:28:33 +02:00
|
|
|
static MpvVideoWindow *create_window(NSRect rect, NSScreen *s, bool border,
|
|
|
|
MpvCocoaAdapter *adapter)
|
2013-06-01 11:26:06 +02:00
|
|
|
{
|
2013-05-29 00:14:34 +02:00
|
|
|
int window_mask = 0;
|
2014-10-05 14:28:33 +02:00
|
|
|
if (border) {
|
2013-05-29 00:14:34 +02:00
|
|
|
window_mask = NSTitledWindowMask|NSClosableWindowMask|
|
|
|
|
NSMiniaturizableWindowMask|NSResizableWindowMask;
|
|
|
|
} else {
|
2013-12-07 15:19:32 +01:00
|
|
|
window_mask = NSBorderlessWindowMask|NSResizableWindowMask;
|
2013-05-29 00:14:34 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 14:28:33 +02:00
|
|
|
MpvVideoWindow *w =
|
|
|
|
[[MpvVideoWindow alloc] initWithContentRect:rect
|
2013-09-03 21:18:28 +02:00
|
|
|
styleMask:window_mask
|
|
|
|
backing:NSBackingStoreBuffered
|
2014-01-11 13:56:10 +01:00
|
|
|
defer:NO
|
2014-10-05 14:28:33 +02:00
|
|
|
screen:s];
|
|
|
|
w.adapter = adapter;
|
|
|
|
[w setDelegate: w];
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
|
2014-10-27 19:10:52 +01:00
|
|
|
MpvCocoaAdapter *adapter = [[MpvCocoaAdapter alloc] init];
|
2014-10-08 19:23:47 +02:00
|
|
|
adapter.vout = vo;
|
2014-10-05 14:28:33 +02:00
|
|
|
|
2014-10-12 00:17:48 +02:00
|
|
|
NSView *parent;
|
2014-10-05 19:16:23 +02:00
|
|
|
if (s->embedded) {
|
2014-10-12 00:17:48 +02:00
|
|
|
parent = (NSView *) (intptr_t) opts->WinID;
|
2014-10-05 14:28:33 +02:00
|
|
|
} else {
|
2014-10-12 00:17:48 +02:00
|
|
|
const NSRect wr =
|
|
|
|
NSMakeRect(win->x0, win->y0, win->x1 - win->x0, win->y1 - win->y0);
|
|
|
|
s->window = create_window(wr, s->current_screen, opts->border, adapter);
|
|
|
|
parent = [s->window contentView];
|
2014-10-05 14:28:33 +02:00
|
|
|
}
|
2012-10-15 22:03:08 +02:00
|
|
|
|
2014-10-12 00:17:48 +02:00
|
|
|
MpvEventsView *view = [[MpvEventsView alloc] initWithFrame:[parent bounds]];
|
|
|
|
view.adapter = adapter;
|
|
|
|
s->view = view;
|
|
|
|
[parent addSubview:s->view];
|
2015-02-16 23:27:06 +01:00
|
|
|
// update the cursor position now that the view has been added.
|
|
|
|
[view signalMousePosition];
|
2015-03-08 15:19:17 +01:00
|
|
|
s->adapter = adapter;
|
2014-10-12 00:17:48 +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
|
|
|
|
2014-10-05 22:31:33 +02:00
|
|
|
s->video = [[MpvVideoView alloc] initWithFrame:[s->view bounds]];
|
2014-10-06 09:58:22 +02:00
|
|
|
[s->video setWantsBestResolutionOpenGLSurface:YES];
|
|
|
|
|
2014-10-05 22:31:33 +02:00
|
|
|
[s->view addSubview:s->video];
|
|
|
|
[s->gl_ctx setView:s->video];
|
2014-10-27 19:10:52 +01:00
|
|
|
[s->video release];
|
2013-09-03 21:18:28 +02:00
|
|
|
|
2014-10-05 22:31:33 +02:00
|
|
|
s->video.adapter = adapter;
|
2014-10-27 19:18:29 +01:00
|
|
|
[adapter release];
|
2012-10-15 22:03:08 +02:00
|
|
|
|
2014-10-05 19:16:23 +02:00
|
|
|
if (!s->embedded) {
|
2014-10-05 14:28:33 +02:00
|
|
|
[s->window setRestorable:NO];
|
|
|
|
[s->window makeMainWindow];
|
|
|
|
[s->window makeKeyAndOrderFront:nil];
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
}
|
2012-10-15 22:03:08 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 19:16:23 +02:00
|
|
|
static int cocoa_set_window_title(struct vo *vo, const char *title)
|
2013-06-16 10:57:36 +02:00
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2014-10-05 19:16:23 +02:00
|
|
|
if (s->embedded)
|
|
|
|
return VO_NOTIMPL;
|
2014-10-05 14:28:33 +02:00
|
|
|
|
2013-12-25 17:58:34 +01:00
|
|
|
void *talloc_ctx = talloc_new(NULL);
|
|
|
|
struct bstr btitle = bstr_sanitize_utf8_latin1(talloc_ctx, bstr0(title));
|
|
|
|
NSString *nstitle = [NSString stringWithUTF8String:btitle.start];
|
2014-12-20 11:43:42 +01:00
|
|
|
if (nstitle) {
|
2013-12-25 17:58:34 +01:00
|
|
|
[s->window setTitle: nstitle];
|
2014-12-20 11:43:42 +01:00
|
|
|
[s->window displayIfNeeded];
|
|
|
|
}
|
2013-12-25 17:58:34 +01:00
|
|
|
talloc_free(talloc_ctx);
|
2014-10-05 19:16:23 +02:00
|
|
|
return VO_TRUE;
|
2013-06-16 10:57:36 +02:00
|
|
|
}
|
|
|
|
|
2015-03-07 08:48:07 +01:00
|
|
|
static void cocoa_rm_fs_screen_profile_observer(struct vo_cocoa_state *s)
|
2014-02-25 00:04:30 +01:00
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
removeObserver:s->fs_icc_changed_ns_observer];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cocoa_add_fs_screen_profile_observer(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
|
|
|
|
if (s->fs_icc_changed_ns_observer)
|
2015-03-07 08:48:07 +01:00
|
|
|
cocoa_rm_fs_screen_profile_observer(s);
|
2014-02-25 00:04:30 +01:00
|
|
|
|
|
|
|
if (vo->opts->fsscreen_id < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
void (^nblock)(NSNotification *n) = ^(NSNotification *n) {
|
2015-01-26 02:21:00 +01:00
|
|
|
s->pending_events |= VO_EVENT_ICC_PROFILE_CHANGED;
|
2014-02-25 00:04:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
s->fs_icc_changed_ns_observer = [[NSNotificationCenter defaultCenter]
|
|
|
|
addObserverForName:NSScreenColorSpaceDidChangeNotification
|
|
|
|
object:s->fs_screen
|
|
|
|
queue:nil
|
|
|
|
usingBlock:nblock];
|
|
|
|
}
|
|
|
|
|
2014-07-08 08:17:15 +02:00
|
|
|
void vo_cocoa_create_nsgl_ctx(struct vo *vo, void *ctx)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
s->gl_ctx = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx];
|
|
|
|
[s->gl_ctx makeCurrentContext];
|
|
|
|
}
|
|
|
|
|
|
|
|
void vo_cocoa_release_nsgl_ctx(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
[s->gl_ctx release];
|
2014-07-19 11:56:36 +02:00
|
|
|
s->gl_ctx = nil;
|
2014-07-08 08:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int vo_cocoa_config_window(struct vo *vo, uint32_t flags, void *gl_ctx)
|
2012-10-15 22:03:08 +02:00
|
|
|
{
|
2013-05-12 23:51:58 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2014-10-04 19:19:53 +02:00
|
|
|
with_cocoa_lock_on_main_thread(vo, ^{
|
2014-05-06 22:00:17 +02:00
|
|
|
struct mp_rect screenrc;
|
|
|
|
vo_cocoa_update_screen_info(vo, &screenrc);
|
|
|
|
|
|
|
|
struct vo_win_geometry geo;
|
|
|
|
vo_calc_window_geometry(vo, &screenrc, &geo);
|
|
|
|
vo_apply_window_geometry(vo, &geo);
|
|
|
|
|
|
|
|
uint32_t width = vo->dwidth;
|
|
|
|
uint32_t height = vo->dheight;
|
|
|
|
|
2014-01-06 14:17:14 +01:00
|
|
|
bool reset_size = s->old_dwidth != width || s->old_dheight != height;
|
|
|
|
s->old_dwidth = width;
|
|
|
|
s->old_dheight = height;
|
|
|
|
|
2014-10-08 19:23:47 +02:00
|
|
|
if (!(flags & VOFLAG_HIDDEN) && !s->view) {
|
2014-10-05 14:28:33 +02:00
|
|
|
create_ui(vo, &geo.win, geo.flags);
|
|
|
|
}
|
2014-07-15 21:33:19 +02:00
|
|
|
|
2014-10-05 22:38:26 +02:00
|
|
|
if (!s->embedded && s->window) {
|
2014-01-06 14:17:14 +01:00
|
|
|
if (reset_size)
|
2014-10-05 14:28:33 +02:00
|
|
|
queue_new_video_size(vo, width, height);
|
2014-01-06 14:17:14 +01:00
|
|
|
vo_cocoa_fullscreen(vo);
|
2014-02-25 00:04:30 +01:00
|
|
|
cocoa_add_fs_screen_profile_observer(vo);
|
2014-10-05 22:38:26 +02:00
|
|
|
cocoa_set_window_title(vo, vo_get_window_title(vo));
|
|
|
|
vo_set_level(vo, vo->opts->ontop);
|
2013-05-11 00:22:23 +02:00
|
|
|
}
|
2014-10-05 14:28:33 +02:00
|
|
|
|
|
|
|
// trigger a resize -> don't set vo->dwidth and vo->dheight directly
|
2015-02-16 23:27:06 +01:00
|
|
|
// since this block is executed asynchronously to the video
|
2014-10-05 14:28:33 +02:00
|
|
|
// reconfiguration code.
|
2014-10-05 19:31:21 +02:00
|
|
|
s->pending_events |= VO_EVENT_RESIZE;
|
2013-09-03 21:18:28 +02:00
|
|
|
});
|
2014-12-05 22:58:02 +01:00
|
|
|
|
2015-01-16 19:24:25 +01:00
|
|
|
if (!s->embedded) {
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
set_application_icon(NSApp);
|
|
|
|
}
|
2013-06-01 11:26:06 +02:00
|
|
|
return 0;
|
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;
|
2013-09-28 14:53:55 +02:00
|
|
|
|
2013-03-04 14:23:06 +01:00
|
|
|
if (current) {
|
2014-10-04 11:47:17 +02:00
|
|
|
cocoa_lock(s);
|
|
|
|
if (s->gl_ctx) [s->gl_ctx makeCurrentContext];
|
2013-03-04 14:23:06 +01:00
|
|
|
} else {
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
2014-10-04 11:47:17 +02:00
|
|
|
cocoa_unlock(s);
|
2013-03-04 14:23:06 +01:00
|
|
|
}
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 18:30:22 +02:00
|
|
|
static void vo_cocoa_resize_redraw(struct vo *vo, int width, int height)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
|
|
|
|
if (!s->gl_ctx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!s->resize_redraw)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vo_cocoa_set_current_context(vo, true);
|
|
|
|
|
|
|
|
[s->gl_ctx update];
|
|
|
|
s->resize_redraw(vo, width, height);
|
|
|
|
s->skip_swap_buffer = true;
|
|
|
|
|
|
|
|
[s->gl_ctx flushBuffer];
|
|
|
|
vo_cocoa_set_current_context(vo, false);
|
|
|
|
}
|
|
|
|
|
2014-10-04 17:13:41 +02:00
|
|
|
static void draw_changes_after_next_frame(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
if (!s->waiting_frame) {
|
|
|
|
s->waiting_frame = true;
|
|
|
|
NSDisableScreenUpdates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 18:25:29 +02:00
|
|
|
bool vo_cocoa_start_frame(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
|
|
|
|
s->skip_swap_buffer = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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;
|
2014-11-01 17:25:38 +01:00
|
|
|
|
|
|
|
if (s->skip_swap_buffer && !s->waiting_frame) {
|
2014-10-18 18:30:22 +02:00
|
|
|
s->skip_swap_buffer = false;
|
2015-05-01 18:25:29 +02:00
|
|
|
s->pending_events |= VO_EVENT_EXPOSE;
|
2014-10-18 18:30:22 +02:00
|
|
|
} else {
|
|
|
|
[s->gl_ctx flushBuffer];
|
|
|
|
}
|
|
|
|
|
2014-10-04 17:13:41 +02:00
|
|
|
if (s->waiting_frame) {
|
|
|
|
s->waiting_frame = false;
|
|
|
|
NSEnableScreenUpdates();
|
|
|
|
}
|
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;
|
2014-10-05 19:31:21 +02:00
|
|
|
int events = s->pending_events;
|
2014-10-05 22:32:23 +02:00
|
|
|
s->pending_events = 0;
|
2013-01-20 16:53:51 +01:00
|
|
|
|
2014-10-05 22:31:33 +02:00
|
|
|
if (events & VO_EVENT_RESIZE) {
|
2013-02-23 18:28:22 +01:00
|
|
|
resize_window(vo);
|
2014-10-05 22:31:33 +02:00
|
|
|
}
|
2013-01-20 16:53:51 +01:00
|
|
|
|
2014-10-05 19:31:21 +02:00
|
|
|
return events;
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 19:16:23 +02:00
|
|
|
static int vo_cocoa_fullscreen_sync(struct vo *vo)
|
2013-09-03 21:18:28 +02:00
|
|
|
{
|
2014-10-05 19:16:23 +02:00
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
|
|
|
|
|
|
|
if (s->embedded)
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
|
2014-10-04 11:47:17 +02:00
|
|
|
with_cocoa_lock_on_main_thread(vo, ^{
|
2013-09-03 21:18:28 +02:00
|
|
|
vo_cocoa_fullscreen(vo);
|
|
|
|
});
|
2014-10-05 19:16:23 +02:00
|
|
|
|
|
|
|
return VO_TRUE;
|
2013-09-03 21:18:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vo_cocoa_fullscreen(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-09-03 21:18:28 +02:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
|
2014-10-08 19:23:47 +02:00
|
|
|
if (s->embedded)
|
|
|
|
return;
|
|
|
|
|
2014-05-06 22:00:17 +02:00
|
|
|
vo_cocoa_update_screen_info(vo, NULL);
|
2013-09-03 21:18:28 +02:00
|
|
|
|
2014-10-05 18:07:27 +02:00
|
|
|
draw_changes_after_next_frame(vo);
|
2014-10-08 19:23:47 +02:00
|
|
|
[(MpvEventsView *)s->view setFullScreen:opts->fullscreen];
|
2013-09-03 21:18:28 +02:00
|
|
|
|
2015-03-08 15:19:17 +01:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2015-01-26 02:21:00 +01:00
|
|
|
s->pending_events |= VO_EVENT_ICC_PROFILE_CHANGED;
|
2014-10-05 23:38:12 +02:00
|
|
|
s->pending_events |= VO_EVENT_RESIZE;
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2015-01-07 18:47:27 +01:00
|
|
|
static void vo_cocoa_control_get_icc_profile(struct vo *vo, void *arg)
|
2014-02-25 00:04:30 +01:00
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = vo->cocoa;
|
2015-01-07 18:47:27 +01:00
|
|
|
bstr *p = arg;
|
2014-02-25 00:04:30 +01:00
|
|
|
|
2014-05-06 22:00:17 +02:00
|
|
|
vo_cocoa_update_screen_info(vo, NULL);
|
2014-02-25 00:04:30 +01:00
|
|
|
|
2015-01-07 18:47:27 +01:00
|
|
|
NSScreen *screen = vo->opts->fullscreen ? s->fs_screen : s->current_screen;
|
|
|
|
NSData *profile = [[screen colorSpace] ICCProfileData];
|
2014-02-25 00:04:30 +01:00
|
|
|
|
2015-01-07 18:47:27 +01:00
|
|
|
p->start = talloc_memdup(NULL, (void *)[profile bytes], [profile length]);
|
|
|
|
p->len = [profile length];
|
2014-02-25 00:04:30 +01:00
|
|
|
}
|
|
|
|
|
2013-05-15 18:17:18 +02:00
|
|
|
int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
|
|
|
|
{
|
2015-01-17 02:45:17 +01:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
|
2013-05-15 18:17:18 +02:00
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_CHECK_EVENTS:
|
|
|
|
*events |= vo_cocoa_check_events(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_FULLSCREEN:
|
2015-01-17 02:45:17 +01:00
|
|
|
opts->fullscreen = !opts->fullscreen;
|
2014-10-05 19:16:23 +02:00
|
|
|
return vo_cocoa_fullscreen_sync(vo);
|
2013-05-15 18:17:18 +02:00
|
|
|
case VOCTRL_ONTOP:
|
2014-10-05 19:16:23 +02:00
|
|
|
return vo_cocoa_ontop(vo);
|
2014-09-04 22:53:50 +02:00
|
|
|
case VOCTRL_GET_UNFS_WINDOW_SIZE: {
|
2013-11-22 08:41:34 +01:00
|
|
|
int *s = arg;
|
2015-03-07 09:11:47 +01:00
|
|
|
with_cocoa_lock(vo->cocoa, ^{
|
2013-11-22 08:41:34 +01:00
|
|
|
NSSize size = [vo->cocoa->view frame].size;
|
|
|
|
s[0] = size.width;
|
|
|
|
s[1] = size.height;
|
|
|
|
});
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2014-09-04 22:53:50 +02:00
|
|
|
case VOCTRL_SET_UNFS_WINDOW_SIZE: {
|
2014-10-24 20:27:28 +02:00
|
|
|
int *s = arg;
|
|
|
|
int w, h;
|
|
|
|
w = s[0];
|
|
|
|
h = s[1];
|
|
|
|
with_cocoa_lock_on_main_thread(vo, ^{
|
|
|
|
queue_new_video_size(vo, w, h);
|
2013-11-22 08:41:34 +01:00
|
|
|
});
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2015-03-08 17:40:01 +01:00
|
|
|
case VOCTRL_GET_WIN_STATE: {
|
|
|
|
with_cocoa_lock(vo->cocoa, ^{
|
2015-03-09 12:00:37 +01:00
|
|
|
const bool minimized = [[vo->cocoa->view window] isMiniaturized];
|
|
|
|
*(int *)arg = minimized ? VO_WIN_STATE_MINIMIZED : 0;
|
2015-03-08 17:40:01 +01:00
|
|
|
});
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2013-09-08 09:16:19 +02:00
|
|
|
case VOCTRL_SET_CURSOR_VISIBILITY:
|
2014-10-08 19:23:47 +02:00
|
|
|
return vo_cocoa_set_cursor_visibility(vo, arg);
|
2013-09-03 21:18:28 +02:00
|
|
|
case VOCTRL_UPDATE_WINDOW_TITLE:
|
2014-10-05 19:16:23 +02:00
|
|
|
return cocoa_set_window_title(vo, (const char *) arg);
|
2013-06-14 00:03:32 +02:00
|
|
|
case VOCTRL_RESTORE_SCREENSAVER:
|
2015-03-07 08:48:07 +01:00
|
|
|
enable_power_management(vo->cocoa);
|
2013-05-15 18:17:18 +02:00
|
|
|
return VO_TRUE;
|
2013-06-14 00:03:32 +02:00
|
|
|
case VOCTRL_KILL_SCREENSAVER:
|
2015-03-07 08:48:07 +01:00
|
|
|
disable_power_management(vo->cocoa);
|
2013-05-15 18:17:18 +02:00
|
|
|
return VO_TRUE;
|
2015-01-07 18:47:27 +01:00
|
|
|
case VOCTRL_GET_ICC_PROFILE:
|
|
|
|
vo_cocoa_control_get_icc_profile(vo, arg);
|
2014-02-25 00:04:30 +01:00
|
|
|
return VO_TRUE;
|
2015-02-03 21:43:20 +01:00
|
|
|
case VOCTRL_GET_DISPLAY_FPS:
|
2015-02-03 22:59:54 +01:00
|
|
|
if (vo->cocoa->screen_fps > 0.0) {
|
|
|
|
*(double *)arg = vo->cocoa->screen_fps;
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2015-02-03 18:16:02 +01:00
|
|
|
case VOCTRL_GET_AMBIENT_LUX:
|
|
|
|
if (vo->cocoa->light_sensor != IO_OBJECT_NULL) {
|
|
|
|
*(int *)arg = vo->cocoa->last_lux;
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2013-05-15 18:17:18 +02:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
@implementation MpvCocoaAdapter
|
|
|
|
@synthesize vout = _video_output;
|
2013-07-20 11:22:50 +02:00
|
|
|
|
2014-10-18 18:30:22 +02:00
|
|
|
- (void)performAsyncResize:(NSSize)size {
|
2014-12-04 22:52:51 +01:00
|
|
|
struct vo_cocoa_state *s = self.vout->cocoa;
|
|
|
|
if (!s->waiting_frame)
|
|
|
|
vo_cocoa_resize_redraw(self.vout, size.width, size.height);
|
2014-10-04 11:47:17 +02:00
|
|
|
}
|
|
|
|
|
2014-10-17 19:15:17 +02:00
|
|
|
- (BOOL)keyboardEnabled {
|
|
|
|
return !!mp_input_vo_keyboard_enabled(self.vout->input_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)mouseEnabled {
|
|
|
|
return !!mp_input_mouse_enabled(self.vout->input_ctx);
|
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
- (void)setNeedsResize {
|
|
|
|
struct vo_cocoa_state *s = self.vout->cocoa;
|
2014-10-05 19:31:21 +02:00
|
|
|
s->pending_events |= VO_EVENT_RESIZE;
|
2014-10-04 17:11:39 +02:00
|
|
|
vo_wakeup(self.vout);
|
2013-09-02 08:21:03 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
- (void)recalcMovableByWindowBackground:(NSPoint)p
|
2013-06-22 10:42:50 +02:00
|
|
|
{
|
2013-09-03 21:18:28 +02:00
|
|
|
BOOL movable = NO;
|
|
|
|
if (![self isInFullScreenMode]) {
|
|
|
|
movable = !mp_input_test_dragging(self.vout->input_ctx, p.x, p.y);
|
2013-06-22 10:42:50 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
[self.vout->cocoa->window setMovableByWindowBackground:movable];
|
2011-12-08 11:17:59 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
- (void)signalMouseMovement:(NSPoint)point {
|
2014-10-17 19:15:17 +02:00
|
|
|
mp_input_set_mouse_pos(self.vout->input_ctx, point.x, point.y);
|
|
|
|
[self recalcMovableByWindowBackground:point];
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 22:11:12 +02:00
|
|
|
- (void)putKeyEvent:(NSEvent*)event
|
|
|
|
{
|
2014-10-17 19:15:17 +02:00
|
|
|
cocoa_put_key_event(event);
|
2014-10-09 22:11:12 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
- (void)putKey:(int)mpkey withModifiers:(int)modifiers
|
2013-07-21 10:33:18 +02:00
|
|
|
{
|
2014-10-17 19:15:17 +02:00
|
|
|
cocoa_put_key_with_modifiers(mpkey, modifiers);
|
2013-07-21 10:33:18 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
- (void)putAxis:(int)mpkey delta:(float)delta;
|
2013-07-21 10:33:18 +02:00
|
|
|
{
|
2014-10-17 19:15:17 +02:00
|
|
|
mp_input_put_axis(self.vout->input_ctx, mpkey, delta);
|
2013-07-21 10:33:18 +02:00
|
|
|
}
|
|
|
|
|
2013-11-22 08:43:02 +01:00
|
|
|
- (void)putCommand:(char*)cmd
|
|
|
|
{
|
2014-03-13 04:34:56 +01:00
|
|
|
char *cmd_ = ta_strdup(NULL, cmd);
|
|
|
|
mp_cmd_t *cmdt = mp_input_parse_cmd(self.vout->input_ctx, bstr0(cmd_), "");
|
2013-11-22 08:43:02 +01:00
|
|
|
mp_input_queue_cmd(self.vout->input_ctx, cmdt);
|
2014-03-13 04:34:56 +01:00
|
|
|
ta_free(cmd_);
|
2013-11-22 08:43:02 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
- (BOOL)isInFullScreenMode {
|
|
|
|
return self.vout->opts->fullscreen;
|
2011-10-15 18:44:00 +02:00
|
|
|
}
|
2013-06-01 22:52:21 +02:00
|
|
|
|
2013-09-03 21:18:28 +02:00
|
|
|
- (NSScreen *)fsScreen {
|
|
|
|
struct vo_cocoa_state *s = self.vout->cocoa;
|
|
|
|
return s->fs_screen;
|
2013-07-21 10:33:18 +02:00
|
|
|
}
|
2014-01-04 17:17:33 +01:00
|
|
|
|
2014-12-01 18:05:30 +01:00
|
|
|
- (BOOL)fsModeAllScreens
|
|
|
|
{
|
|
|
|
return self.vout->opts->fs_black_out_screens;
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:17:33 +01:00
|
|
|
- (void)handleFilesArray:(NSArray *)files
|
|
|
|
{
|
2014-04-16 04:38:19 +02:00
|
|
|
[[EventsResponder sharedInstance] handleFilesArray:files];
|
2014-01-04 17:17:33 +01:00
|
|
|
}
|
2014-02-25 00:04:30 +01:00
|
|
|
|
|
|
|
- (void)didChangeWindowedScreenProfile:(NSScreen *)screen
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = self.vout->cocoa;
|
2015-01-26 02:21:00 +01:00
|
|
|
s->pending_events |= VO_EVENT_ICC_PROFILE_CHANGED;
|
2014-02-25 00:04:30 +01:00
|
|
|
}
|
2015-03-08 11:00:29 +01:00
|
|
|
|
|
|
|
- (void)didChangeMousePosition
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = self.vout->cocoa;
|
|
|
|
[(MpvEventsView *)s->view signalMousePosition];
|
|
|
|
}
|
2015-03-08 15:19:17 +01:00
|
|
|
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self didChangeMousePosition];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self didChangeMousePosition];
|
|
|
|
}
|
|
|
|
|
2015-03-08 17:40:01 +01:00
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = self.vout->cocoa;
|
|
|
|
s->pending_events |= VO_EVENT_WIN_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
struct vo_cocoa_state *s = self.vout->cocoa;
|
|
|
|
s->pending_events |= VO_EVENT_WIN_STATE;
|
|
|
|
}
|
|
|
|
|
2013-07-21 10:33:18 +02:00
|
|
|
@end
|