intf.m 6.49 KB
Newer Older
1 2 3
/*****************************************************************************
 * intf.m: MacOS X interface module
 *****************************************************************************
4
 * Copyright (C) 2002-2012 VLC authors and VideoLAN
5 6
 * $Id$
 *
7
 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
8
 *          Felix Paul Kühne <fkuehne at videolan dot org>
9
 *
10 11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13
 * (at your option) any later version.
14
 *
15 16
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
20 21 22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
28 29 30
#import <stdlib.h>                                      /* malloc(), free() */
#import <sys/param.h>                                    /* for MAXPATHLEN */
#import <string.h>
31
#ifdef HAVE_CONFIG_H
32
# import "config.h"
33
#endif
34
#include <unistd.h>
35

36 37
#include <vlc_common.h>
#include <vlc_playlist.h>
38
#include <vlc_interface.h>
39
#include <vlc_vout_window.h>
40

41
#import "VLCMinimalVoutWindow.h"
42 43 44 45

/*****************************************************************************
 * Local prototypes.
 *****************************************************************************/
46
static void Run (intf_thread_t *p_intf);
47 48 49 50

/*****************************************************************************
 * OpenIntf: initialize interface
 *****************************************************************************/
51
int OpenIntf (vlc_object_t *p_this)
52 53
{
    intf_thread_t *p_intf = (intf_thread_t*) p_this;
54
    msg_Dbg(p_intf, "Using minimal macosx interface");
55

56
    p_intf->p_sys = NULL;
57

58
    Run(p_intf);
59

60
    return VLC_SUCCESS;
61 62 63 64 65
}

/*****************************************************************************
 * CloseIntf: destroy interface
 *****************************************************************************/
66
void CloseIntf (vlc_object_t *p_this)
67 68 69
{
    intf_thread_t *p_intf = (intf_thread_t*) p_this;

70
    free(p_intf->p_sys);
71 72
}

73 74 75 76 77 78 79
/* Dock Connection */
typedef struct CPSProcessSerNum
{
        UInt32                lo;
        UInt32                hi;
} CPSProcessSerNum;

80 81 82
extern OSErr    CPSGetCurrentProcess(CPSProcessSerNum *psn);
extern OSErr    CPSEnableForegroundOperation(CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
extern OSErr    CPSSetFrontProcess(CPSProcessSerNum *psn);
83

84

85 86 87
/*****************************************************************************
 * Run: main loop
 *****************************************************************************/
88
static void Run(intf_thread_t *p_intf)
89
{
90
    CPSProcessSerNum PSN;
91 92 93 94 95 96 97
    @autoreleasepool {
        [NSApplication sharedApplication];
        if (!CPSGetCurrentProcess(&PSN))
            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
                if (!CPSSetFrontProcess(&PSN))
                    [NSApplication sharedApplication];
    }
98 99
}

100 101 102 103 104 105 106
/*****************************************************************************
 * Vout window management
 *****************************************************************************/
static int WindowControl(vout_window_t *, int i_query, va_list);

int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
{
107 108 109 110
    if (cfg->type != VOUT_WINDOW_TYPE_INVALID
     && cfg->type != VOUT_WINDOW_TYPE_NSOBJECT)
        return VLC_EGENERIC;

111 112
    @autoreleasepool {
        NSRect proposedVideoViewPosition = NSMakeRect(cfg->x, cfg->y, cfg->width, cfg->height);
113

114 115
        VLCMinimalVoutWindow *o_window = [[VLCMinimalVoutWindow alloc] initWithContentRect:proposedVideoViewPosition];
        [o_window makeKeyAndOrderFront:nil];
116

117 118 119 120
        if (!o_window) {
            msg_Err(p_wnd, "window creation failed");
            return VLC_EGENERIC;
        }
121

122 123
        msg_Dbg(p_wnd, "returning video window with proposed position x=%i, y=%i, width=%i, height=%i", cfg->x, cfg->y, cfg->width, cfg->height);
        p_wnd->handle.nsobject = (void *)CFBridgingRetain([o_window contentView]);
124

125 126 127
        p_wnd->type = VOUT_WINDOW_TYPE_NSOBJECT;
        p_wnd->control = WindowControl;
    }
128

129
    vout_window_SetFullScreen(p_wnd, cfg->is_fullscreen);
130 131 132 133 134
    return VLC_SUCCESS;
}

static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
{
135
    NSWindow * o_window = [(__bridge id)p_wnd->handle.nsobject window];
136 137 138 139 140
    if (!o_window) {
        msg_Err(p_wnd, "failed to recover cocoa window");
        return VLC_EGENERIC;
    }

141
    switch (i_query) {
142 143 144
        case VOUT_WINDOW_SET_STATE:
        {
            unsigned i_state = va_arg(args, unsigned);
145 146 147

            [o_window setLevel: i_state];

148 149 150 151
            return VLC_SUCCESS;
        }
        case VOUT_WINDOW_SET_SIZE:
        {
152 153 154 155 156 157 158 159
            @autoreleasepool {
                NSRect theFrame = [o_window frame];
                unsigned int i_width  = va_arg(args, unsigned int);
                unsigned int i_height = va_arg(args, unsigned int);
                theFrame.size.width = i_width;
                theFrame.size.height = i_height;
                [o_window setFrame: theFrame display: YES animate: YES];
            }
160 161 162 163
            return VLC_SUCCESS;
        }
        case VOUT_WINDOW_SET_FULLSCREEN:
        {
164 165 166 167 168 169 170 171
            @autoreleasepool {
                int i_full = va_arg(args, int);

                if (i_full)
                    [o_window performSelectorOnMainThread:@selector(enterFullscreen) withObject:nil waitUntilDone:NO];
                else
                    [o_window performSelectorOnMainThread:@selector(leaveFullscreen) withObject:nil waitUntilDone:NO];
            }
172 173 174 175 176 177 178 179 180 181
            return VLC_SUCCESS;
        }
        default:
            msg_Warn(p_wnd, "unsupported control query");
            return VLC_EGENERIC;
    }
}

void WindowClose(vout_window_t *p_wnd)
{
182 183 184 185 186
    @autoreleasepool {
        NSWindow * o_window = [(__bridge id)p_wnd->handle.nsobject window];
        if (o_window)
            o_window = nil;
    }
187
}