1 /*****************************************************************************
2 * vout_vlc_wrapper.c: MacOS X plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: vout_vlc_wrapper.m,v 1.2 2002/05/18 18:48:24 massiot Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
28 #include <stdlib.h> /* free() */
29 #include <string.h> /* strerror() */
31 #include <videolan/vlc.h>
34 #include "video_output.h"
36 #include "interface.h"
39 #include "vout_vlc_wrapper.h"
41 /*****************************************************************************
42 * Vout_VLCWrapper implementation
43 *****************************************************************************/
44 @implementation Vout_VLCWrapper
46 static Vout_VLCWrapper *o_vout = nil;
48 + (Vout_VLCWrapper *)instance
52 o_vout = [[[Vout_VLCWrapper alloc] init] autorelease];
54 [[Vout_VLCWrapper sendPort] setDelegate: o_vout];
55 [[NSRunLoop currentRunLoop]
56 addPort: [Vout_VLCWrapper sendPort]
57 forMode: NSDefaultRunLoopMode];
71 return( p_main->p_intf->p_sys->o_port );
74 - (void)mouseEvent:(unsigned int)ui_status forVout:(void *)_p_vout
76 struct vout_thread_s *p_vout =
77 (struct vout_thread_s *)_p_vout;
79 if( ui_status & MOUSE_MOVED )
80 p_vout->p_sys->b_mouse_moved = 1;
81 if( ui_status & MOUSE_NOT_MOVED )
82 p_vout->p_sys->b_mouse_moved = 0;
83 if( ui_status & MOUSE_LAST_MOVED )
84 p_vout->p_sys->i_time_mouse_last_moved = mdate();
85 if( ui_status & MOUSE_NOT_LAST_MOVED )
86 p_vout->p_sys->i_time_mouse_last_moved = 0;
87 if( ui_status & MOUSE_DOWN )
89 if( p_vout->p_sys->b_mouse_pointer_visible )
91 CGDisplayHideCursor( kCGDirectMainDisplay );
95 CGDisplayShowCursor( kCGDirectMainDisplay );
97 p_vout->p_sys->b_mouse_pointer_visible = !p_vout->p_sys->b_mouse_pointer_visible;
101 - (BOOL)keyDown:(NSEvent *)o_event forVout:(void *)_p_vout
105 struct vout_thread_s *p_vout =
106 (struct vout_thread_s *)_p_vout;
108 if( [[o_event characters] length] )
110 key = [[o_event characters] characterAtIndex: 0];
116 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
120 p_main->p_intf->b_die = 1;
131 - (void)voutDidResize:(void *)_p_vout
133 vout_thread_t * p_vout = (vout_thread_t *)_p_vout;
135 p_vout->i_changes |= VOUT_SIZE_CHANGE;
140 @implementation Vout_VLCWrapper (Internal)
142 - (void)handlePortMessage:(NSPortMessage *)o_msg
145 struct vout_req_s *p_req;
147 o_req = [[o_msg components] lastObject];
148 p_req = *((struct vout_req_s **)[o_req bytes]);
150 [p_req->o_lock lock];
152 if( p_req->i_type == VOUT_REQ_CREATE_WINDOW )
156 p_req->p_vout->p_sys->o_window = [VLCWindow alloc];
157 [p_req->p_vout->p_sys->o_window
158 setWrapper: self forVout: (void *)p_req->p_vout];
159 [p_req->p_vout->p_sys->o_window setReleasedWhenClosed: YES];
161 if( p_req->p_vout->b_fullscreen )
163 [p_req->p_vout->p_sys->o_window
164 initWithContentRect: [[NSScreen mainScreen] frame]
165 styleMask: NSBorderlessWindowMask
166 backing: NSBackingStoreBuffered
167 defer: NO screen: [NSScreen mainScreen]];
169 [p_req->p_vout->p_sys->o_window
170 setLevel: CGShieldingWindowLevel()];
174 unsigned int i_stylemask = NSTitledWindowMask |
175 NSMiniaturizableWindowMask |
176 NSResizableWindowMask;
178 [p_req->p_vout->p_sys->o_window
179 initWithContentRect: p_req->p_vout->p_sys->s_rect
180 styleMask: i_stylemask
181 backing: NSBackingStoreBuffered
182 defer: NO screen: [NSScreen mainScreen]];
184 if( !p_req->p_vout->p_sys->b_pos_saved )
186 [p_req->p_vout->p_sys->o_window center];
190 o_view = [[VLCView alloc]
191 initWithWrapper: self forVout: (void *)p_req->p_vout];
192 [p_req->p_vout->p_sys->o_window setContentView: o_view];
193 [o_view autorelease];
196 p_req->p_vout->p_sys->p_qdport = [o_view qdPort];
197 [o_view unlockFocus];
199 [p_req->p_vout->p_sys->o_window setTitle: [NSString
200 stringWithCString: VOUT_TITLE]];
201 [p_req->p_vout->p_sys->o_window setAcceptsMouseMovedEvents: YES];
202 [p_req->p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
206 else if( p_req->i_type == VOUT_REQ_DESTROY_WINDOW )
208 if( !p_req->p_vout->b_fullscreen )
212 s_rect = [[p_req->p_vout->p_sys->o_window contentView] frame];
213 p_req->p_vout->p_sys->s_rect.size = s_rect.size;
215 s_rect = [p_req->p_vout->p_sys->o_window frame];
216 p_req->p_vout->p_sys->s_rect.origin = s_rect.origin;
218 p_req->p_vout->p_sys->b_pos_saved = 1;
221 p_req->p_vout->p_sys->p_qdport = nil;
222 [p_req->p_vout->p_sys->o_window close];
223 p_req->p_vout->p_sys->o_window = nil;
228 [p_req->o_lock unlockWithCondition: 1];