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