Mercurial > mplayer.hg
annotate libvo/vo_macosx.m @ 28180:781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
This allows to have multiple instances of MPlayerOSX running
without stepping on each other's toes.
Patch by Adrian Stutz % adrian A sttz P ch %
Original thread:
date: Tue, Dec 9, 2008 at 2:46 PM
subject: [MPlayer-dev-eng] [PATCH] vo_macosx: option to set shared buffer name to allow multiple instances
author | gpoirier |
---|---|
date | Tue, 30 Dec 2008 21:39:42 +0000 |
parents | b5898cb411da |
children | ec9c4610f10f |
rev | line source |
---|---|
15289 | 1 /* |
2 vo_macosx.m | |
3 by Nicolas Plourde <nicolasplourde@gmail.com> | |
4 | |
5 MPlayer Mac OSX video out module. | |
6 Copyright (c) Nicolas Plourde - 2005 | |
7 */ | |
8 | |
9 #import "vo_macosx.h" | |
16385 | 10 #include <sys/types.h> |
11 #include <sys/ipc.h> | |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
12 #include <sys/mman.h> |
28077 | 13 #include <unistd.h> |
27988 | 14 #include <CoreServices/CoreServices.h> |
15 //special workaround for Apple bug #6267445 | |
16 //(OSServices Power API disabled in OSServices.h for 64bit systems) | |
17 #ifndef __POWER__ | |
18 #include <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h> | |
19 #endif | |
15289 | 20 |
21 //MPLAYER | |
22 #include "config.h" | |
23 #include "fastmemcpy.h" | |
24 #include "video_out.h" | |
25 #include "video_out_internal.h" | |
26 #include "aspect.h" | |
27 #include "mp_msg.h" | |
28 #include "m_option.h" | |
28075
ca9badc94740
#include appropriate headers instead of locally declaring function prototypes.
diego
parents:
28051
diff
changeset
|
29 #include "mp_fifo.h" |
ca9badc94740
#include appropriate headers instead of locally declaring function prototypes.
diego
parents:
28051
diff
changeset
|
30 #include "libvo/sub.h" |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
31 #include "subopt-helper.h" |
15289 | 32 |
33 #include "input/input.h" | |
34 #include "input/mouse.h" | |
35 | |
36 #include "osdep/keycodes.h" | |
37 | |
38 //Cocoa | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
39 NSDistantObject *mplayerosxProxy; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
40 id <MPlayerOSXVOProto> mplayerosxProto; |
15611 | 41 MPlayerOpenGLView *mpGLView; |
15289 | 42 NSAutoreleasePool *autoreleasepool; |
43 OSType pixelFormat; | |
44 | |
16385 | 45 //shared memory |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
46 int shm_fd; |
16385 | 47 BOOL shared_buffer = false; |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
48 #define DEFAULT_BUFFER_NAME "mplayerosx" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
49 static char *buffer_name; |
16385 | 50 |
15728 | 51 //Screen |
52 int screen_id; | |
53 BOOL screen_force; | |
54 NSRect screen_frame; | |
55 NSScreen *screen_handle; | |
56 NSArray *screen_array; | |
15289 | 57 |
58 //image | |
59 unsigned char *image_data; | |
25180 | 60 // For double buffering |
61 static uint8_t image_page = 0; | |
62 static unsigned char *image_datas[2]; | |
63 | |
15289 | 64 static uint32_t image_width; |
65 static uint32_t image_height; | |
66 static uint32_t image_depth; | |
67 static uint32_t image_bytes; | |
68 static uint32_t image_format; | |
69 | |
70 //vo | |
71 static int isFullscreen; | |
15320 | 72 static int isOntop; |
15327 | 73 static int isRootwin; |
15289 | 74 extern float monitor_aspect; |
75 extern float movie_aspect; | |
76 static float old_movie_aspect; | |
25446 | 77 extern int enable_mouse_movements; |
15289 | 78 |
15731 | 79 static float winAlpha = 1; |
15289 | 80 static int int_pause = 0; |
81 | |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
82 static BOOL isLeopardOrLater; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
83 |
15289 | 84 static vo_info_t info = |
85 { | |
86 "Mac OSX Core Video", | |
87 "macosx", | |
88 "Nicolas Plourde <nicolas.plourde@gmail.com>", | |
89 "" | |
90 }; | |
91 | |
92 LIBVO_EXTERN(macosx) | |
93 | |
94 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) | |
95 { | |
96 switch (image_format) | |
97 { | |
98 case IMGFMT_RGB32: | |
99 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width); | |
100 break; | |
101 case IMGFMT_YUY2: | |
102 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2); | |
103 break; | |
104 } | |
105 } | |
106 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
107 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
15289 | 108 { |
16385 | 109 |
15728 | 110 //init screen |
111 screen_array = [NSScreen screens]; | |
112 if(screen_id < [screen_array count]) | |
15289 | 113 { |
15728 | 114 screen_handle = [screen_array objectAtIndex:screen_id]; |
15289 | 115 } |
15728 | 116 else |
117 { | |
118 mp_msg(MSGT_VO, MSGL_FATAL, "Get device error: Device ID %d do not exist, falling back to main device.\n", screen_id); | |
119 screen_handle = [screen_array objectAtIndex:0]; | |
120 screen_id = 0; | |
121 } | |
122 screen_frame = [screen_handle frame]; | |
25414
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
123 vo_screenwidth = screen_frame.size.width; |
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
124 vo_screenheight = screen_frame.size.height; |
16385 | 125 |
15289 | 126 //misc mplayer setup |
127 image_width = width; | |
128 image_height = height; | |
129 switch (image_format) | |
130 { | |
131 case IMGFMT_BGR32: | |
132 case IMGFMT_RGB32: | |
133 image_depth = 32; | |
134 break; | |
16385 | 135 case IMGFMT_YUY2: |
15289 | 136 image_depth = 16; |
137 break; | |
138 } | |
139 image_bytes = (image_depth + 7) / 8; | |
16385 | 140 |
141 if(!shared_buffer) | |
142 { | |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
143 image_data = malloc(image_width*image_height*image_bytes); |
25180 | 144 image_datas[0] = image_data; |
145 if (vo_doublebuffering) | |
146 image_datas[1] = malloc(image_width*image_height*image_bytes); | |
147 image_page = 0; | |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
148 |
16385 | 149 monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height; |
150 | |
151 //set aspect | |
152 panscan_init(); | |
153 aspect_save_orig(width,height); | |
154 aspect_save_prescale(d_width,d_height); | |
155 aspect_save_screenres(screen_frame.size.width, screen_frame.size.height); | |
156 aspect((int *)&d_width,(int *)&d_height,A_NOZOOM); | |
157 | |
158 movie_aspect = (float)d_width/(float)d_height; | |
159 old_movie_aspect = movie_aspect; | |
15726 | 160 |
16385 | 161 vo_fs = flags & VOFLAG_FULLSCREEN; |
162 | |
163 //config OpenGL View | |
164 [mpGLView config]; | |
165 [mpGLView reshape]; | |
166 } | |
167 else | |
168 { | |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
169 mp_msg(MSGT_VO, MSGL_INFO, "VO: [macosx] writing output to a shared buffer " |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
170 "named \"%s\".\n",buffer_name); |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
171 |
16385 | 172 movie_aspect = (float)d_width/(float)d_height; |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
173 |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
174 // create shared memory |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
175 shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
176 if (shm_fd == -1) |
16385 | 177 { |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
178 mp_msg(MSGT_VO, MSGL_FATAL, |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
179 "vo_macosx: failed to open shared memory. Error: %s\n", strerror(errno)); |
16385 | 180 return 1; |
181 } | |
182 | |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
183 |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
184 if (ftruncate(shm_fd, image_width*image_height*image_bytes) == -1) |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
185 { |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
186 mp_msg(MSGT_VO, MSGL_FATAL, |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
187 "vo_macosx: failed to size shared memory, possibly already in use. Error: %s\n", strerror(errno)); |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
188 shm_unlink(buffer_name); |
16385 | 189 return 1; |
190 } | |
191 | |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
192 image_data = mmap(NULL, image_width*image_height*image_bytes, |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
193 PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
194 |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
195 if (image_data == MAP_FAILED) |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
196 { |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
197 mp_msg(MSGT_VO, MSGL_FATAL, |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
198 "vo_macosx: failed to map shared memory. Error: %s\n", strerror(errno)); |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
199 shm_unlink(buffer_name); |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
200 return 1; |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
201 } |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
202 |
16385 | 203 //connnect to mplayerosx |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
204 mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithCString:buffer_name] host:nil]; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
205 if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
206 [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
207 mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
208 [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:(int)(movie_aspect*100)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
209 } |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
210 else { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
211 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
212 mplayerosxProxy = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
213 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
214 } |
16385 | 215 } |
15289 | 216 return 0; |
217 } | |
218 | |
219 static void check_events(void) | |
220 { | |
15611 | 221 [mpGLView check_events]; |
15289 | 222 } |
223 | |
224 static void draw_osd(void) | |
225 { | |
226 vo_draw_text(image_width, image_height, draw_alpha); | |
227 } | |
228 | |
229 static void flip_page(void) | |
230 { | |
16385 | 231 if(shared_buffer) |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
232 [mplayerosxProto render]; |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
233 else { |
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
234 [mpGLView setCurrentTexture]; |
16385 | 235 [mpGLView render]; |
25180 | 236 if (vo_doublebuffering) { |
237 image_page = 1 - image_page; | |
238 image_data = image_datas[image_page]; | |
239 } | |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
240 } |
15289 | 241 } |
242 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
243 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) |
15289 | 244 { |
245 return 0; | |
246 } | |
247 | |
248 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
249 static int draw_frame(uint8_t *src[]) |
15289 | 250 { |
251 switch (image_format) | |
252 { | |
253 case IMGFMT_BGR32: | |
254 case IMGFMT_RGB32: | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
23381
diff
changeset
|
255 fast_memcpy(image_data, src[0], image_width*image_height*image_bytes); |
15289 | 256 break; |
257 | |
258 case IMGFMT_YUY2: | |
259 memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2); | |
260 break; | |
261 } | |
16385 | 262 |
15289 | 263 return 0; |
264 } | |
265 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
266 static int query_format(uint32_t format) |
15289 | 267 { |
268 image_format = format; | |
269 | |
270 switch(format) | |
271 { | |
272 case IMGFMT_YUY2: | |
273 pixelFormat = kYUVSPixelFormat; | |
274 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
275 | |
276 case IMGFMT_RGB32: | |
277 case IMGFMT_BGR32: | |
278 pixelFormat = k32ARGBPixelFormat; | |
279 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
280 } | |
281 return 0; | |
282 } | |
283 | |
284 static void uninit(void) | |
285 { | |
16385 | 286 if(shared_buffer) |
287 { | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
288 [mplayerosxProto stop]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
289 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
290 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
291 mplayerosxProxy = nil; |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
292 |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
293 if (munmap(image_data, image_width*image_height*image_bytes) == -1) |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
294 mp_msg(MSGT_VO, MSGL_FATAL, "uninit: munmap failed. Error: %s\n", strerror(errno)); |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
295 |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
296 if (shm_unlink(buffer_name) == -1) |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
297 mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shm_unlink failed. Error: %s\n", strerror(errno)); |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
298 |
16385 | 299 } |
300 | |
21551 | 301 SetSystemUIMode( kUIModeNormal, 0); |
302 CGDisplayShowCursor(kCGDirectMainDisplay); | |
303 | |
304 if(mpGLView) | |
305 { | |
25136 | 306 NSAutoreleasePool *finalPool; |
24742
0bef706332b5
Fix deallocate bug which sometimes causes a crash when reinitializing.
nplourde
parents:
24698
diff
changeset
|
307 mpGLView = nil; |
21551 | 308 [autoreleasepool release]; |
25136 | 309 finalPool = [[NSAutoreleasePool alloc] init]; |
25078
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
310 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; |
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
311 [finalPool release]; |
21551 | 312 } |
25121 | 313 if (!shared_buffer) |
314 { | |
25180 | 315 free(image_datas[0]); |
316 if (vo_doublebuffering) | |
317 free(image_datas[1]); | |
318 image_datas[0] = NULL; | |
319 image_datas[1] = NULL; | |
25121 | 320 image_data = NULL; |
321 } | |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
322 |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
323 if (buffer_name) free(buffer_name); |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
324 buffer_name = NULL; |
15289 | 325 } |
326 | |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
327 static opt_t subopts[] = { |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
328 {"device_id", OPT_ARG_INT, &screen_id, (opt_test_f)int_non_neg}, |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
329 {"shared_buffer", OPT_ARG_BOOL, &shared_buffer, NULL}, |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
330 {"buffer_name", OPT_ARG_MSTRZ,&buffer_name, NULL}, |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
331 {NULL} |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
332 }; |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
333 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
334 static int preinit(const char *arg) |
15289 | 335 { |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
336 |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
337 // set defaults |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
338 screen_id = 0; |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
339 shared_buffer = false; |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
340 buffer_name = DEFAULT_BUFFER_NAME; |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
341 |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
342 if (subopt_parse(arg, subopts) != 0) { |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
343 mp_msg(MSGT_VO, MSGL_FATAL, |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
344 "\n-vo macosx command line help:\n" |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
345 "Example: mplayer -vo macosx:device_id=1:shared_buffer:buffer_name=mybuff\n" |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
346 "\nOptions:\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
347 " device_id=<0-...>\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
348 " Set screen device id for fullscreen.\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
349 " shared_buffer\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
350 " Write output to a shared memory buffer instead of displaying it.\n" |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
351 " buffer_name=<name>\n" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
352 " Name of the shared buffer created with shm_open() as well as\n" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
353 " the name of the NSConnection MPlayer will try to open.\n" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
354 " Setting buffer_name implicitly enables shared_buffer.\n" |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
355 "\n" ); |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
356 return -1; |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
357 } |
15728 | 358 |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
359 NSApplicationLoad(); |
15289 | 360 autoreleasepool = [[NSAutoreleasePool alloc] init]; |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
361 NSApp = [NSApplication sharedApplication]; |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
362 isLeopardOrLater = floor(NSAppKitVersionNumber) > 824; |
15726 | 363 |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
364 if (strcmp(buffer_name, DEFAULT_BUFFER_NAME)) |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
365 shared_buffer = true; |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
366 |
16385 | 367 if(!shared_buffer) |
16144 | 368 { |
27397
d47744b95b78
Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents:
27394
diff
changeset
|
369 #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL) |
17358
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
370 //this chunk of code is heavily based off SDL_macosx.m from SDL |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
371 ProcessSerialNumber myProc, frProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
372 Boolean sameProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
373 |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
374 if (GetFrontProcess(&frProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
375 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
376 if (GetCurrentProcess(&myProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
377 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
378 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
379 { |
27988 | 380 TransformProcessType(&myProc, kProcessTransformToForegroundApplication); |
17358
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
381 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
382 SetFrontProcess(&myProc); |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
383 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
384 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
385 #endif |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
386 |
16385 | 387 if(!mpGLView) |
388 { | |
389 mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]]; | |
390 [mpGLView autorelease]; | |
391 } | |
392 | |
393 [mpGLView display]; | |
394 [mpGLView preinit]; | |
16144 | 395 } |
396 | |
15289 | 397 return 0; |
398 } | |
399 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
400 static int control(uint32_t request, void *data, ...) |
15289 | 401 { |
402 switch (request) | |
403 { | |
26755
46f0b4d34fa1
cosmetics: Remove useless parentheses from from return statements.
diego
parents:
25468
diff
changeset
|
404 case VOCTRL_PAUSE: return int_pause = 1; |
46f0b4d34fa1
cosmetics: Remove useless parentheses from from return statements.
diego
parents:
25468
diff
changeset
|
405 case VOCTRL_RESUME: return int_pause = 0; |
15289 | 406 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
407 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE; |
15611 | 408 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
409 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE; |
15289 | 410 case VOCTRL_GET_PANSCAN: return VO_TRUE; |
15611 | 411 case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE; |
15289 | 412 } |
413 return VO_NOTIMPL; | |
414 } | |
415 | |
416 ////////////////////////////////////////////////////////////////////////// | |
417 // NSOpenGLView Subclass | |
418 ////////////////////////////////////////////////////////////////////////// | |
15611 | 419 @implementation MPlayerOpenGLView |
24076 | 420 - (void) preinit |
15289 | 421 { |
15726 | 422 //init menu |
423 [self initMenu]; | |
424 | |
425 //create window | |
15747
fbf14e1ab725
osx 10.3 dont like to have a window init with no size
nplourde
parents:
15737
diff
changeset
|
426 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) |
15726 | 427 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask |
428 backing:NSBackingStoreBuffered defer:NO]; | |
429 | |
16144 | 430 [window autorelease]; |
15726 | 431 [window setDelegate:mpGLView]; |
432 [window setContentView:mpGLView]; | |
433 [window setInitialFirstResponder:mpGLView]; | |
434 [window setAcceptsMouseMovedEvents:YES]; | |
435 [window setTitle:@"MPlayer - The Movie Player"]; | |
436 | |
437 isFullscreen = 0; | |
15855 | 438 winSizeMult = 1; |
15726 | 439 } |
440 | |
24076 | 441 - (void) config |
15726 | 442 { |
443 uint32_t d_width; | |
444 uint32_t d_height; | |
445 | |
25137 | 446 GLint swapInterval = 1; |
15726 | 447 |
448 NSRect frame; | |
15289 | 449 CVReturn error = kCVReturnSuccess; |
450 | |
15728 | 451 //config window |
15726 | 452 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); |
453 frame = NSMakeRect(0, 0, d_width, d_height); | |
454 [window setContentSize: frame.size]; | |
15570 | 455 |
15289 | 456 //create OpenGL Context |
457 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil]; | |
15647 | 458 |
15289 | 459 [self setOpenGLContext:glContext]; |
15647 | 460 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; |
15289 | 461 [glContext setView:self]; |
462 [glContext makeCurrentContext]; | |
463 | |
25180 | 464 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]); |
15289 | 465 if(error != kCVReturnSuccess) |
466 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error); | |
25180 | 467 if (vo_doublebuffering) { |
468 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]); | |
469 if(error != kCVReturnSuccess) | |
470 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Double Buffer(%d)\n", error); | |
471 } | |
15289 | 472 |
473 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); | |
474 if(error != kCVReturnSuccess) | |
475 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error); | |
476 | |
25180 | 477 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 478 if(error != kCVReturnSuccess) |
479 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
480 | |
15728 | 481 //show window |
482 [window center]; | |
483 [window makeKeyAndOrderFront:mpGLView]; | |
484 | |
15726 | 485 if(vo_rootwin) |
486 [mpGLView rootwin]; | |
487 | |
488 if(vo_fs) | |
489 [mpGLView fullscreen: NO]; | |
490 | |
491 if(vo_ontop) | |
492 [mpGLView ontop]; | |
15289 | 493 } |
494 | |
495 /* | |
15570 | 496 Init Menu |
497 */ | |
498 - (void)initMenu | |
499 { | |
21395 | 500 NSMenu *menu, *aspectMenu; |
15570 | 501 NSMenuItem *menuItem; |
502 | |
503 [NSApp setMainMenu:[[NSMenu alloc] init]]; | |
504 | |
505 //Create Movie Menu | |
506 menu = [[NSMenu alloc] initWithTitle:@"Movie"]; | |
507 menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem]; | |
508 kHalfScreenCmd = menuItem; | |
509 menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem]; | |
510 kNormalScreenCmd = menuItem; | |
511 menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem]; | |
512 kDoubleScreenCmd = menuItem; | |
513 menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem]; | |
514 kFullScreenCmd = menuItem; | |
15909 | 515 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem]; |
15570 | 516 |
517 aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"]; | |
518 menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
519 if(vo_keepaspect) [menuItem setState:NSOnState]; | |
520 kKeepAspectCmd = menuItem; | |
521 menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
522 if(vo_panscan) [menuItem setState:NSOnState]; | |
523 kPanScanCmd = menuItem; | |
15909 | 524 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [aspectMenu addItem:menuItem]; |
15570 | 525 menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; |
526 kAspectOrgCmd = menuItem; | |
527 menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
528 kAspectFullCmd = menuItem; | |
529 menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
530 kAspectWideCmd = menuItem; | |
531 menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""]; | |
532 [menuItem setSubmenu:aspectMenu]; | |
533 [menu addItem:menuItem]; | |
534 [aspectMenu release]; | |
535 | |
536 //Add to menubar | |
537 menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""]; | |
538 [menuItem setSubmenu:menu]; | |
539 [[NSApp mainMenu] addItem:menuItem]; | |
540 | |
541 //Create Window Menu | |
542 menu = [[NSMenu alloc] initWithTitle:@"Window"]; | |
543 | |
544 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem]; | |
545 menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem]; | |
546 | |
547 //Add to menubar | |
548 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; | |
549 [menuItem setSubmenu:menu]; | |
550 [[NSApp mainMenu] addItem:menuItem]; | |
551 [NSApp setWindowsMenu:menu]; | |
552 | |
553 [menu release]; | |
554 [menuItem release]; | |
555 } | |
556 | |
557 /* | |
558 Menu Action | |
559 */ | |
560 - (void)menuAction:(id)sender | |
561 { | |
562 uint32_t d_width; | |
563 uint32_t d_height; | |
564 NSRect frame; | |
565 | |
566 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); | |
15731 | 567 |
568 if(sender == kQuitCmd) | |
569 { | |
570 mplayer_put_key(KEY_ESC); | |
571 } | |
15570 | 572 |
573 if(sender == kHalfScreenCmd) | |
574 { | |
575 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
576 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 577 } |
578 | |
15855 | 579 winSizeMult = 0.5; |
580 frame.size.width = (d_width*winSizeMult); | |
581 frame.size.height = ((d_width/movie_aspect)*winSizeMult); | |
15570 | 582 [window setContentSize: frame.size]; |
583 [self reshape]; | |
584 } | |
585 if(sender == kNormalScreenCmd) | |
586 { | |
587 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
588 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 589 } |
590 | |
15855 | 591 winSizeMult = 1; |
15570 | 592 frame.size.width = d_width; |
593 frame.size.height = d_width/movie_aspect; | |
594 [window setContentSize: frame.size]; | |
595 [self reshape]; | |
596 } | |
597 if(sender == kDoubleScreenCmd) | |
598 { | |
599 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
600 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 601 } |
602 | |
15855 | 603 winSizeMult = 2; |
604 frame.size.width = d_width*winSizeMult; | |
605 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
15570 | 606 [window setContentSize: frame.size]; |
607 [self reshape]; | |
608 } | |
609 if(sender == kFullScreenCmd) | |
610 { | |
611 vo_fs = (!(vo_fs)); | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
612 [self fullscreen:NO]; |
15570 | 613 } |
614 | |
615 if(sender == kKeepAspectCmd) | |
616 { | |
617 vo_keepaspect = (!(vo_keepaspect)); | |
618 if(vo_keepaspect) | |
619 [kKeepAspectCmd setState:NSOnState]; | |
620 else | |
621 [kKeepAspectCmd setState:NSOffState]; | |
15909 | 622 |
623 [self reshape]; | |
15570 | 624 } |
625 | |
626 if(sender == kPanScanCmd) | |
627 { | |
628 vo_panscan = (!(vo_panscan)); | |
629 if(vo_panscan) | |
630 [kPanScanCmd setState:NSOnState]; | |
631 else | |
632 [kPanScanCmd setState:NSOffState]; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
633 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
634 [self panscan]; |
15570 | 635 } |
636 | |
637 if(sender == kAspectOrgCmd) | |
638 { | |
639 movie_aspect = old_movie_aspect; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
640 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
641 if(isFullscreen) |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
642 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
643 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
644 } |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
645 else |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
646 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
647 frame.size.width = d_width*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
648 frame.size.height = (d_width/movie_aspect)*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
649 [window setContentSize: frame.size]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
650 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
651 } |
15570 | 652 } |
653 | |
654 if(sender == kAspectFullCmd) | |
655 { | |
656 movie_aspect = 4.0f/3.0f; | |
15882 | 657 |
658 if(isFullscreen) | |
659 { | |
660 [self reshape]; | |
661 } | |
662 else | |
663 { | |
664 frame.size.width = d_width*winSizeMult; | |
665 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
666 [window setContentSize: frame.size]; | |
667 [self reshape]; | |
668 } | |
15570 | 669 } |
670 | |
671 if(sender == kAspectWideCmd) | |
672 { | |
673 movie_aspect = 16.0f/9.0f; | |
15882 | 674 |
675 if(isFullscreen) | |
676 { | |
677 [self reshape]; | |
678 } | |
679 else | |
680 { | |
681 frame.size.width = d_width*winSizeMult; | |
682 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
683 [window setContentSize: frame.size]; | |
684 [self reshape]; | |
685 } | |
15570 | 686 } |
687 } | |
688 | |
689 /* | |
15289 | 690 Setup OpenGL |
691 */ | |
692 - (void)prepareOpenGL | |
693 { | |
15339 | 694 glEnable(GL_BLEND); |
15289 | 695 glDisable(GL_DEPTH_TEST); |
696 glDepthMask(GL_FALSE); | |
697 glDisable(GL_CULL_FACE); | |
698 [self reshape]; | |
699 } | |
700 | |
701 /* | |
702 reshape OpenGL viewport | |
703 */ | |
704 - (void)reshape | |
705 { | |
706 uint32_t d_width; | |
707 uint32_t d_height; | |
708 float aspectX; | |
709 float aspectY; | |
710 int padding = 0; | |
711 | |
712 NSRect frame = [self frame]; | |
713 | |
714 glViewport(0, 0, frame.size.width, frame.size.height); | |
715 glMatrixMode(GL_PROJECTION); | |
716 glLoadIdentity(); | |
717 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | |
718 glMatrixMode(GL_MODELVIEW); | |
719 glLoadIdentity(); | |
720 | |
15729 | 721 //set texture frame |
15289 | 722 if(vo_keepaspect) |
723 { | |
15571 | 724 aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM); |
15289 | 725 d_height = ((float)d_width/movie_aspect); |
726 | |
727 aspectX = (float)((float)frame.size.width/(float)d_width); | |
728 aspectY = (float)((float)(frame.size.height)/(float)d_height); | |
729 | |
730 if((d_height*aspectX)>(frame.size.height)) | |
731 { | |
732 padding = (frame.size.width - d_width*aspectY)/2; | |
25424 | 733 textureFrame = NSMakeRect(padding, 0, d_width*aspectY, d_height*aspectY); |
15289 | 734 } |
735 else | |
736 { | |
737 padding = ((frame.size.height) - d_height*aspectX)/2; | |
25424 | 738 textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX); |
15289 | 739 } |
740 } | |
741 else | |
742 { | |
15729 | 743 textureFrame = frame; |
15289 | 744 } |
25446 | 745 vo_dwidth = textureFrame.size.width; |
746 vo_dheight = textureFrame.size.height; | |
15289 | 747 } |
748 | |
749 /* | |
750 Render frame | |
751 */ | |
752 - (void) render | |
753 { | |
21395 | 754 int curTime; |
755 | |
15289 | 756 glClear(GL_COLOR_BUFFER_BIT); |
757 | |
758 glEnable(CVOpenGLTextureGetTarget(texture)); | |
759 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
760 | |
761 glColor3f(1,1,1); | |
762 glBegin(GL_QUADS); | |
15729 | 763 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
25424 | 764 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i(textureFrame.origin.x-(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); |
765 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); | |
766 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 767 glEnd(); |
15339 | 768 glDisable(CVOpenGLTextureGetTarget(texture)); |
769 | |
770 //render resize box | |
771 if(!isFullscreen) | |
772 { | |
773 NSRect frame = [self frame]; | |
774 | |
775 glBegin(GL_LINES); | |
776 glColor4f(0.2, 0.2, 0.2, 0.5); | |
777 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
778 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
779 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
780 | |
781 glColor4f(0.4, 0.4, 0.4, 0.5); | |
782 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
783 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
784 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1); | |
785 | |
786 glColor4f(0.6, 0.6, 0.6, 0.5); | |
787 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
788 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
789 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
790 glEnd(); | |
791 } | |
15289 | 792 |
793 glFlush(); | |
794 | |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
795 curTime = TickCount()/60; |
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
796 |
28001 | 797 //auto hide mouse cursor (and future on-screen control?) |
15327 | 798 if(isFullscreen && !mouseHide && !isRootwin) |
15289 | 799 { |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
800 if( ((curTime - lastMouseHide) >= 5) || (lastMouseHide == 0) ) |
15289 | 801 { |
18057 | 802 CGDisplayHideCursor(kCGDirectMainDisplay); |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
803 mouseHide = TRUE; |
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
804 lastMouseHide = curTime; |
15289 | 805 } |
806 } | |
17546 | 807 |
17725 | 808 //update activity every 30 seconds to prevent |
17546 | 809 //screensaver from starting up. |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
810 if( ((curTime - lastScreensaverUpdate) >= 30) || (lastScreensaverUpdate == 0) ) |
17546 | 811 { |
812 UpdateSystemActivity(UsrActivity); | |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
813 lastScreensaverUpdate = curTime; |
17546 | 814 } |
15289 | 815 } |
816 | |
817 /* | |
818 Create OpenGL texture from current frame & set texco | |
819 */ | |
820 - (void) setCurrentTexture | |
821 { | |
822 CVReturn error = kCVReturnSuccess; | |
823 | |
25180 | 824 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 825 if(error != kCVReturnSuccess) |
826 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
827 | |
828 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
829 } | |
830 | |
831 /* | |
832 redraw win rect | |
833 */ | |
834 - (void) drawRect: (NSRect *) bounds | |
835 { | |
836 [self render]; | |
837 } | |
838 | |
839 /* | |
840 Toggle Fullscreen | |
841 */ | |
842 - (void) fullscreen: (BOOL) animate | |
843 { | |
844 static NSRect old_frame; | |
845 static NSRect old_view_frame; | |
15728 | 846 |
15573 | 847 panscan_calc(); |
848 | |
15289 | 849 //go fullscreen |
850 if(vo_fs) | |
851 { | |
15327 | 852 if(!isRootwin) |
853 { | |
15882 | 854 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
18057 | 855 CGDisplayHideCursor(kCGDirectMainDisplay); |
15327 | 856 mouseHide = YES; |
857 } | |
15289 | 858 |
859 old_frame = [window frame]; //save main window size & position | |
25413 | 860 if(screen_force) |
861 screen_frame = [screen_handle frame]; | |
25414
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
862 else { |
25413 | 863 screen_frame = [[window screen] frame]; |
25414
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
864 vo_screenwidth = screen_frame.size.width; |
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
865 vo_screenheight = screen_frame.size.height; |
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
866 } |
25413 | 867 |
15728 | 868 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
15289 | 869 old_view_frame = [self bounds]; |
870 | |
871 //fix origin for multi screen setup | |
15728 | 872 screen_frame.origin.x = 0; |
873 screen_frame.origin.y = 0; | |
874 [self setFrame:screen_frame]; | |
15289 | 875 [self setNeedsDisplay:YES]; |
876 [window setHasShadow:NO]; | |
877 isFullscreen = 1; | |
878 } | |
879 else | |
15882 | 880 { |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
881 SetSystemUIMode( kUIModeNormal, 0); |
15882 | 882 |
15289 | 883 isFullscreen = 0; |
18057 | 884 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 885 mouseHide = NO; |
886 | |
887 //revert window to previous setting | |
888 [self setFrame:old_view_frame]; | |
889 [self setNeedsDisplay:YES]; | |
16081
72c352edce8f
restore window shadow when quitting fullscreen mode
nplourde
parents:
15909
diff
changeset
|
890 [window setHasShadow:YES]; |
15289 | 891 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx |
892 } | |
893 } | |
894 | |
895 /* | |
896 Toggle ontop | |
897 */ | |
898 - (void) ontop | |
899 { | |
15320 | 900 if(vo_ontop) |
901 { | |
902 [window setLevel:NSScreenSaverWindowLevel]; | |
903 isOntop = YES; | |
904 } | |
905 else | |
906 { | |
907 [window setLevel:NSNormalWindowLevel]; | |
908 isOntop = NO; | |
909 } | |
15289 | 910 } |
911 | |
912 /* | |
913 Toggle panscan | |
914 */ | |
915 - (void) panscan | |
916 { | |
15331 | 917 panscan_calc(); |
15289 | 918 } |
919 | |
920 /* | |
15327 | 921 Toggle rootwin |
922 */ | |
923 - (void) rootwin | |
924 { | |
925 if(vo_rootwin) | |
926 { | |
927 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; | |
928 [window orderBack:self]; | |
929 isRootwin = YES; | |
930 } | |
931 else | |
932 { | |
933 [window setLevel:NSNormalWindowLevel]; | |
934 isRootwin = NO; | |
935 } | |
936 } | |
937 | |
938 /* | |
15289 | 939 Check event for new event |
940 */ | |
941 - (void) check_events | |
942 { | |
943 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
25178 | 944 if (event == nil) |
945 return; | |
15289 | 946 [NSApp sendEvent:event]; |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
947 // Without SDL's bootstrap code (include SDL.h in mplayer.c), |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
948 // on Leopard, we got trouble to get the play window auto focused |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
949 // when app is actived. Following code fix this problem. |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
26755
diff
changeset
|
950 #ifndef CONFIG_SDL |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
951 if (isLeopardOrLater && [event type] == NSAppKitDefined |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
952 && [event subtype] == NSApplicationActivatedEventType) { |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
953 [window makeMainWindow]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
954 [window makeKeyAndOrderFront:mpGLView]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
955 } |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
956 #endif |
15289 | 957 } |
958 | |
959 /* | |
15731 | 960 From NSView, respond to key equivalents. |
961 */ | |
962 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent | |
963 { | |
964 switch([theEvent keyCode]) | |
965 { | |
966 case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES; | |
967 case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES; | |
968 } | |
969 return NO; | |
970 } | |
971 | |
972 /* | |
15289 | 973 Process key event |
974 */ | |
975 - (void) keyDown: (NSEvent *) theEvent | |
976 { | |
977 unsigned int key; | |
978 | |
979 switch([theEvent keyCode]) | |
980 { | |
981 case 0x34: | |
982 case 0x24: key = KEY_ENTER; break; | |
983 case 0x35: key = KEY_ESC; break; | |
984 case 0x33: key = KEY_BACKSPACE; break; | |
985 case 0x3A: key = KEY_BACKSPACE; break; | |
986 case 0x3B: key = KEY_BACKSPACE; break; | |
987 case 0x38: key = KEY_BACKSPACE; break; | |
988 case 0x7A: key = KEY_F+1; break; | |
989 case 0x78: key = KEY_F+2; break; | |
990 case 0x63: key = KEY_F+3; break; | |
991 case 0x76: key = KEY_F+4; break; | |
992 case 0x60: key = KEY_F+5; break; | |
993 case 0x61: key = KEY_F+6; break; | |
994 case 0x62: key = KEY_F+7; break; | |
995 case 0x64: key = KEY_F+8; break; | |
996 case 0x65: key = KEY_F+9; break; | |
997 case 0x6D: key = KEY_F+10; break; | |
998 case 0x67: key = KEY_F+11; break; | |
999 case 0x6F: key = KEY_F+12; break; | |
1000 case 0x72: key = KEY_INSERT; break; | |
1001 case 0x75: key = KEY_DELETE; break; | |
1002 case 0x73: key = KEY_HOME; break; | |
1003 case 0x77: key = KEY_END; break; | |
1004 case 0x45: key = '+'; break; | |
1005 case 0x4E: key = '-'; break; | |
1006 case 0x30: key = KEY_TAB; break; | |
1007 case 0x74: key = KEY_PAGE_UP; break; | |
1008 case 0x79: key = KEY_PAGE_DOWN; break; | |
1009 case 0x7B: key = KEY_LEFT; break; | |
1010 case 0x7C: key = KEY_RIGHT; break; | |
1011 case 0x7D: key = KEY_DOWN; break; | |
1012 case 0x7E: key = KEY_UP; break; | |
1013 case 0x43: key = '*'; break; | |
1014 case 0x4B: key = '/'; break; | |
24107 | 1015 case 0x4C: key = KEY_KPENTER; break; |
15289 | 1016 case 0x41: key = KEY_KPDEC; break; |
1017 case 0x52: key = KEY_KP0; break; | |
1018 case 0x53: key = KEY_KP1; break; | |
1019 case 0x54: key = KEY_KP2; break; | |
1020 case 0x55: key = KEY_KP3; break; | |
1021 case 0x56: key = KEY_KP4; break; | |
1022 case 0x57: key = KEY_KP5; break; | |
1023 case 0x58: key = KEY_KP6; break; | |
1024 case 0x59: key = KEY_KP7; break; | |
1025 case 0x5B: key = KEY_KP8; break; | |
1026 case 0x5C: key = KEY_KP9; break; | |
1027 default: key = *[[theEvent characters] UTF8String]; break; | |
1028 } | |
1029 mplayer_put_key(key); | |
1030 } | |
1031 | |
1032 /* | |
1033 Process mouse button event | |
1034 */ | |
1035 - (void) mouseMoved: (NSEvent *) theEvent | |
1036 { | |
15327 | 1037 if(isFullscreen && !isRootwin) |
15289 | 1038 { |
18057 | 1039 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 1040 mouseHide = NO; |
1041 } | |
25468
a77c438fedf7
Do not send mouse movements events in root win mode.
ulion
parents:
25446
diff
changeset
|
1042 if (enable_mouse_movements && !isRootwin) { |
25446 | 1043 NSPoint p =[self convertPoint:[theEvent locationInWindow] fromView:nil]; |
1044 if ([self mouse:p inRect:textureFrame]) { | |
1045 char cmdstr[40]; | |
1046 snprintf(cmdstr, sizeof(cmdstr), "set_mouse_pos %i %i", | |
1047 (int)(vo_fs ? p.x : (p.x - textureFrame.origin.x)), | |
1048 (int)(vo_fs ? [self frame].size.height - p.y: (NSMaxY(textureFrame) - p.y))); | |
1049 mp_input_queue_cmd(mp_input_parse_cmd(cmdstr)); | |
1050 } | |
1051 } | |
15289 | 1052 } |
1053 | |
1054 - (void) mouseDown: (NSEvent *) theEvent | |
1055 { | |
1056 [self mouseEvent: theEvent]; | |
1057 } | |
1058 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1059 - (void) mouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1060 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1061 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1062 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1063 |
15289 | 1064 - (void) rightMouseDown: (NSEvent *) theEvent |
1065 { | |
1066 [self mouseEvent: theEvent]; | |
1067 } | |
1068 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1069 - (void) rightMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1070 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1071 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1072 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1073 |
15289 | 1074 - (void) otherMouseDown: (NSEvent *) theEvent |
1075 { | |
1076 [self mouseEvent: theEvent]; | |
1077 } | |
1078 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1079 - (void) otherMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1080 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1081 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1082 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1083 |
15289 | 1084 - (void) scrollWheel: (NSEvent *) theEvent |
1085 { | |
1086 if([theEvent deltaY] > 0) | |
1087 mplayer_put_key(MOUSE_BTN3); | |
1088 else | |
1089 mplayer_put_key(MOUSE_BTN4); | |
1090 } | |
1091 | |
1092 - (void) mouseEvent: (NSEvent *) theEvent | |
1093 { | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1094 if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 ) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1095 { |
25422 | 1096 int buttonNumber = [theEvent buttonNumber]; |
1097 // Fix to mplayer defined button order: left, middle, right | |
1098 if (buttonNumber == 1) | |
1099 buttonNumber = 2; | |
25423 | 1100 else if (buttonNumber == 2) |
1101 buttonNumber = 1; | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1102 switch([theEvent type]) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1103 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1104 case NSLeftMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1105 case NSRightMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1106 case NSOtherMouseDown: |
25422 | 1107 mplayer_put_key((MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN); |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1108 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1109 case NSLeftMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1110 case NSRightMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1111 case NSOtherMouseUp: |
25422 | 1112 mplayer_put_key(MOUSE_BTN0 + buttonNumber); |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1113 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1114 } |
15289 | 1115 } |
1116 } | |
1117 | |
1118 /* | |
1119 NSResponder | |
1120 */ | |
1121 - (BOOL) acceptsFirstResponder | |
1122 { | |
1123 return YES; | |
1124 } | |
1125 | |
1126 - (BOOL) becomeFirstResponder | |
1127 { | |
1128 return YES; | |
1129 } | |
1130 | |
1131 - (BOOL) resignFirstResponder | |
1132 { | |
1133 return YES; | |
1134 } | |
15325 | 1135 |
1136 - (void)windowWillClose:(NSNotification *)aNotification | |
1137 { | |
21551 | 1138 mpGLView = NULL; |
15325 | 1139 mplayer_put_key(KEY_ESC); |
1140 } | |
1141 @end |