]> git.sesse.net Git - vlc/blob - plugins/macosx/vout_vlc_wrapper.m
Mac OS X interface :
[vlc] / plugins / macosx / vout_vlc_wrapper.m
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.4 2002/06/01 23:42:04 massiot Exp $
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> 
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28 #include <stdlib.h>                                                /* free() */
29 #include <string.h>                                            /* strerror() */
30
31 #include <vlc/vlc.h>
32 #include <vlc/intf.h>
33 #include <vlc/vout.h>
34
35 #include "stream_control.h"
36 #include "input_ext-intf.h"
37
38 #include "macosx.h"
39 #include "vout_vlc_wrapper.h"
40
41 /*****************************************************************************
42  * Vout_VLCWrapper implementation 
43  *****************************************************************************/
44 @implementation Vout_VLCWrapper
45
46 static Vout_VLCWrapper *o_vout = nil;
47
48 + (Vout_VLCWrapper *)instance
49 {
50     if( o_vout == nil )
51     {
52         o_vout = [[[Vout_VLCWrapper alloc] init] autorelease];
53
54         [[Vout_VLCWrapper sendPort] setDelegate: o_vout];
55         [[NSRunLoop currentRunLoop]
56             addPort: [Vout_VLCWrapper sendPort]
57             forMode: NSDefaultRunLoopMode];
58     }
59
60     return( o_vout );
61 }
62
63 - (void)dealloc
64 {
65     o_vout = nil;
66     [super dealloc];
67 }
68
69 + (NSPort *)sendPort
70 {
71     return( p_main->p_intf->p_sys->o_port );
72 }
73
74 - (void)mouseEvent:(unsigned int)ui_status forVout:(void *)_p_vout
75 {
76     vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
77
78     if( ui_status & MOUSE_MOVED ) 
79         p_vout->p_sys->b_mouse_moved = 1;
80     if( ui_status & MOUSE_NOT_MOVED ) 
81         p_vout->p_sys->b_mouse_moved = 0;
82     if( ui_status & MOUSE_LAST_MOVED ) 
83         p_vout->p_sys->i_time_mouse_last_moved = mdate();
84     if( ui_status & MOUSE_NOT_LAST_MOVED )
85         p_vout->p_sys->i_time_mouse_last_moved = 0;
86     if( ui_status & MOUSE_DOWN )
87     {
88         if( p_vout->p_sys->b_mouse_pointer_visible )
89         {
90             CGDisplayHideCursor( kCGDirectMainDisplay );
91         }
92         else
93         {
94             CGDisplayShowCursor( kCGDirectMainDisplay );
95         }
96         p_vout->p_sys->b_mouse_pointer_visible = !p_vout->p_sys->b_mouse_pointer_visible;
97     }
98 }
99
100 - (BOOL)keyDown:(NSEvent *)o_event forVout:(void *)_p_vout
101 {
102     unichar key = 0;
103
104     vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
105
106     if( [[o_event characters] length] )
107     {
108         key = [[o_event characters] characterAtIndex: 0];
109     }
110
111     switch( key )
112     {
113         case 'f': case 'F':
114             p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
115             break;
116
117         case (unichar)0x1b: /* escape */
118             if ( p_vout->b_fullscreen )
119             {
120                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
121             }
122             break;
123
124         case 'q': case 'Q':
125             p_vout->p_vlc->b_die = 1;
126             break;
127
128         case ' ':
129             if ( p_input_bank->pp_input[0] != NULL )
130             {
131                 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PAUSE );
132
133                 vlc_mutex_lock( &p_main->p_playlist->change_lock );
134                 p_main->p_playlist->b_stopped = 0;
135                 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
136             }
137             break;
138
139         default:
140             return( NO );
141             break;
142     }
143
144     return( YES );
145 }
146
147 - (void)voutDidResize:(void *)_p_vout
148 {
149     vout_thread_t * p_vout = (vout_thread_t *)_p_vout;
150
151     p_vout->i_changes |= VOUT_SIZE_CHANGE;
152 }
153
154 @end
155
156 @implementation Vout_VLCWrapper (Internal)
157
158 - (void)handlePortMessage:(NSPortMessage *)o_msg
159 {
160     NSData *o_req;
161     struct vout_req_s *p_req;
162
163     o_req = [[o_msg components] lastObject];
164     p_req = *((struct vout_req_s **)[o_req bytes]);
165
166     [p_req->o_lock lock];
167
168     if( p_req->i_type == VOUT_REQ_CREATE_WINDOW )
169     {
170         VLCView *o_view;
171
172         p_req->p_vout->p_sys->o_window = [VLCWindow alloc];
173         [p_req->p_vout->p_sys->o_window 
174             setWrapper: self forVout: (void *)p_req->p_vout];
175         [p_req->p_vout->p_sys->o_window setReleasedWhenClosed: YES];
176
177         if( p_req->p_vout->b_fullscreen )
178         {
179             [p_req->p_vout->p_sys->o_window 
180                 initWithContentRect: [[NSScreen mainScreen] frame] 
181                 styleMask: NSBorderlessWindowMask 
182                 backing: NSBackingStoreBuffered
183                 defer: NO screen: [NSScreen mainScreen]];
184
185             [p_req->p_vout->p_sys->o_window 
186                 setLevel: CGShieldingWindowLevel()];
187         }
188         else
189         {
190             unsigned int i_stylemask = NSTitledWindowMask |
191                                        NSMiniaturizableWindowMask |
192                                        NSResizableWindowMask;
193
194             [p_req->p_vout->p_sys->o_window 
195                 initWithContentRect: p_req->p_vout->p_sys->s_rect 
196                 styleMask: i_stylemask
197                 backing: NSBackingStoreBuffered
198                 defer: NO screen: [NSScreen mainScreen]];
199
200             if( !p_req->p_vout->p_sys->b_pos_saved )
201             {
202                 [p_req->p_vout->p_sys->o_window center];
203             }
204         }
205
206         o_view = [[VLCView alloc] 
207             initWithWrapper: self forVout: (void *)p_req->p_vout];
208         [p_req->p_vout->p_sys->o_window setContentView: o_view];
209         [o_view autorelease];
210
211         [o_view lockFocus];
212         p_req->p_vout->p_sys->p_qdport = [o_view qdPort];
213         [o_view unlockFocus];
214
215         [p_req->p_vout->p_sys->o_window setTitle: [NSString 
216             stringWithCString: VOUT_TITLE]];
217         [p_req->p_vout->p_sys->o_window setAcceptsMouseMovedEvents: YES];
218         [p_req->p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
219
220         p_req->i_result = 1;
221     }
222     else if( p_req->i_type == VOUT_REQ_DESTROY_WINDOW )
223     {
224         if( !p_req->p_vout->b_fullscreen )
225         {
226             NSRect s_rect;
227
228             s_rect = [[p_req->p_vout->p_sys->o_window contentView] frame];
229             p_req->p_vout->p_sys->s_rect.size = s_rect.size;
230
231             s_rect = [p_req->p_vout->p_sys->o_window frame];
232             p_req->p_vout->p_sys->s_rect.origin = s_rect.origin;
233
234             p_req->p_vout->p_sys->b_pos_saved = 1;
235         }
236
237         p_req->p_vout->p_sys->p_qdport = nil;
238         [p_req->p_vout->p_sys->o_window close];
239         p_req->p_vout->p_sys->o_window = nil;
240
241         p_req->i_result = 1;
242     }
243
244     [p_req->o_lock unlockWithCondition: 1];
245 }
246
247 @end