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