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"
|
|
10
|
|
11 //MPLAYER
|
|
12 #include "config.h"
|
|
13 #include "fastmemcpy.h"
|
|
14 #include "video_out.h"
|
|
15 #include "video_out_internal.h"
|
|
16 #include "aspect.h"
|
|
17 #include "mp_msg.h"
|
|
18 #include "m_option.h"
|
|
19
|
|
20 #include "input/input.h"
|
|
21 #include "input/mouse.h"
|
|
22
|
|
23 #include "osdep/keycodes.h"
|
|
24
|
|
25 extern void mplayer_put_key(int code);
|
|
26
|
|
27 //Cocoa
|
|
28 CustomOpenGLView *glView;
|
|
29 NSAutoreleasePool *autoreleasepool;
|
|
30 OSType pixelFormat;
|
|
31
|
|
32 //Device
|
|
33 static int device_width;
|
|
34 static int device_height;
|
|
35 static int device_id;
|
|
36 static GDHandle device_handle;
|
|
37
|
|
38 //image
|
|
39 unsigned char *image_data;
|
|
40 static uint32_t image_width;
|
|
41 static uint32_t image_height;
|
|
42 static uint32_t image_depth;
|
|
43 static uint32_t image_bytes;
|
|
44 static uint32_t image_format;
|
|
45 static NSRect image_rec;
|
|
46
|
|
47 //vo
|
|
48 extern int vo_rootwin;
|
|
49 extern int vo_ontop;
|
|
50 extern int vo_fs;
|
|
51 static int isFullscreen;
|
15320
|
52 static int isOntop;
|
15327
|
53 static int isRootwin;
|
15289
|
54 extern float monitor_aspect;
|
|
55 extern int vo_keepaspect;
|
|
56 extern float movie_aspect;
|
|
57 static float old_movie_aspect;
|
|
58 extern float vo_panscan;
|
|
59
|
|
60 static int int_pause = 0;
|
|
61
|
|
62 static vo_info_t info =
|
|
63 {
|
|
64 "Mac OSX Core Video",
|
|
65 "macosx",
|
|
66 "Nicolas Plourde <nicolas.plourde@gmail.com>",
|
|
67 ""
|
|
68 };
|
|
69
|
|
70 LIBVO_EXTERN(macosx)
|
|
71
|
|
72 extern void mplayer_put_key(int code);
|
|
73 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));
|
|
74
|
|
75 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
|
|
76 {
|
|
77 switch (image_format)
|
|
78 {
|
|
79 case IMGFMT_RGB32:
|
|
80 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width);
|
|
81 break;
|
|
82 case IMGFMT_YUY2:
|
|
83 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2);
|
|
84 break;
|
|
85 }
|
|
86 }
|
|
87
|
|
88 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
|
|
89 {
|
|
90 int i;
|
|
91
|
|
92 //Get Main device info///////////////////////////////////////////////////
|
|
93 device_handle = GetMainDevice();
|
|
94
|
|
95 for(i=0; i<device_id; i++)
|
|
96 {
|
|
97 device_handle = GetNextDevice(device_handle);
|
|
98
|
|
99 if(device_handle == NULL)
|
|
100 {
|
|
101 mp_msg(MSGT_VO, MSGL_FATAL, "Get device error: Device ID %d do not exist, falling back to main device.\n", device_id);
|
|
102 device_handle = GetMainDevice();
|
|
103 device_id = 0;
|
|
104 break;
|
|
105 }
|
|
106 }
|
|
107
|
|
108 NSRect device_rect = [[NSScreen mainScreen] frame];
|
|
109 device_width = device_rect.size.width;
|
|
110 device_height = device_rect.size.height;
|
|
111 monitor_aspect = (float)device_width/(float)device_height;
|
|
112
|
|
113 //misc mplayer setup
|
|
114 image_width = width;
|
|
115 image_height = height;
|
|
116 switch (image_format)
|
|
117 {
|
|
118 case IMGFMT_BGR32:
|
|
119 case IMGFMT_RGB32:
|
|
120 image_depth = 32;
|
|
121 break;
|
|
122 case IMGFMT_YUY2:
|
|
123 image_depth = 16;
|
|
124 break;
|
|
125 }
|
|
126 image_bytes = (image_depth + 7) / 8;
|
|
127 image_data = (unsigned char*)malloc(image_width*image_height*image_bytes);
|
|
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(device_width,device_height);
|
|
134 aspect(&d_width,&d_height,A_NOZOOM);
|
|
135
|
|
136 movie_aspect = (float)d_width/(float)d_height;
|
|
137 old_movie_aspect = movie_aspect;
|
|
138
|
|
139 //init OpenGL View
|
|
140 glView = [[CustomOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, d_width, d_height) pixelFormat:[CustomOpenGLView defaultPixelFormat]];
|
|
141 [glView initOpenGLView];
|
|
142
|
|
143 vo_fs = flags & VOFLAG_FULLSCREEN;
|
|
144
|
15327
|
145 if(vo_rootwin)
|
|
146 [glView rootwin];
|
|
147
|
15289
|
148 if(vo_fs)
|
|
149 [glView fullscreen: NO];
|
|
150
|
|
151 if(vo_ontop)
|
|
152 [glView ontop];
|
|
153
|
|
154 return 0;
|
|
155 }
|
|
156
|
|
157 static void check_events(void)
|
|
158 {
|
|
159 [glView check_events];
|
|
160
|
|
161 //update activity every 60 seconds to prevent
|
|
162 //screensaver from starting up.
|
|
163 DateTimeRec d;
|
|
164 unsigned long curTime;
|
|
165 static unsigned long lastTime = 0;
|
|
166
|
|
167 GetTime(&d);
|
|
168 DateToSeconds( &d, &curTime);
|
|
169
|
|
170 if( ( (curTime - lastTime) >= 60) || (lastTime == 0))
|
|
171 {
|
|
172 UpdateSystemActivity(UsrActivity);
|
|
173 lastTime = curTime;
|
|
174 }
|
|
175 }
|
|
176
|
|
177 static void draw_osd(void)
|
|
178 {
|
|
179 vo_draw_text(image_width, image_height, draw_alpha);
|
|
180 }
|
|
181
|
|
182 static void flip_page(void)
|
|
183 {
|
|
184 [glView render];
|
|
185 }
|
|
186
|
|
187 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
|
|
188 {
|
|
189 [glView setCurrentTexture];
|
|
190 return 0;
|
|
191 }
|
|
192
|
|
193
|
|
194 static uint32_t draw_frame(uint8_t *src[])
|
|
195 {
|
|
196 switch (image_format)
|
|
197 {
|
|
198 case IMGFMT_BGR32:
|
|
199 case IMGFMT_RGB32:
|
|
200 memcpy(image_data, src[0], image_width*image_height*image_bytes);
|
|
201 break;
|
|
202
|
|
203 case IMGFMT_YUY2:
|
|
204 memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2);
|
|
205 break;
|
|
206 }
|
|
207 [glView setCurrentTexture];
|
|
208 return 0;
|
|
209 }
|
|
210
|
|
211 static uint32_t query_format(uint32_t format)
|
|
212 {
|
|
213 image_format = format;
|
|
214
|
|
215 switch(format)
|
|
216 {
|
|
217 case IMGFMT_YUY2:
|
|
218 pixelFormat = kYUVSPixelFormat;
|
|
219 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
|
|
220
|
|
221 case IMGFMT_RGB32:
|
|
222 case IMGFMT_BGR32:
|
|
223 pixelFormat = k32ARGBPixelFormat;
|
|
224 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
|
|
225 }
|
|
226 return 0;
|
|
227 }
|
|
228
|
|
229 static void uninit(void)
|
|
230 {
|
|
231 [autoreleasepool release];
|
|
232 }
|
|
233
|
|
234 static uint32_t preinit(const char *arg)
|
|
235 {
|
|
236 int parse_err = 0;
|
|
237
|
|
238 if(arg)
|
|
239 {
|
|
240 char *parse_pos = (char *)&arg[0];
|
|
241 while (parse_pos[0] && !parse_err)
|
|
242 {
|
|
243 if (strncmp (parse_pos, "device_id=", 10) == 0)
|
|
244 {
|
|
245 parse_pos = &parse_pos[10];
|
|
246 device_id = strtol(parse_pos, &parse_pos, 0);
|
|
247 }
|
|
248 if (parse_pos[0] == ':') parse_pos = &parse_pos[1];
|
|
249 else if (parse_pos[0]) parse_err = 1;
|
|
250 }
|
|
251 }
|
|
252
|
|
253 #if !defined (MACOSX_FINDER_SUPPORT) || !defined (HAVE_SDL)
|
|
254 //this chunk of code is heavily based off SDL_macosx.m from SDL
|
|
255 //it uses an Apple private function to request foreground operation
|
|
256 void CPSEnableForegroundOperation(ProcessSerialNumber* psn);
|
|
257 ProcessSerialNumber myProc, frProc;
|
|
258 Boolean sameProc;
|
|
259
|
|
260 if (GetFrontProcess(&frProc) == noErr)
|
|
261 {
|
|
262 if (GetCurrentProcess(&myProc) == noErr)
|
|
263 {
|
|
264 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc)
|
|
265 {
|
|
266 CPSEnableForegroundOperation(&myProc);
|
|
267 }
|
|
268 SetFrontProcess(&myProc);
|
|
269 }
|
|
270 }
|
|
271 #endif
|
|
272
|
|
273 NSApplicationLoad();
|
|
274 autoreleasepool = [[NSAutoreleasePool alloc] init];
|
|
275
|
|
276 return 0;
|
|
277 }
|
|
278
|
|
279 static uint32_t control(uint32_t request, void *data, ...)
|
|
280 {
|
|
281 switch (request)
|
|
282 {
|
|
283 case VOCTRL_PAUSE: return (int_pause=1);
|
|
284 case VOCTRL_RESUME: return (int_pause=0);
|
|
285 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data));
|
|
286 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); [glView ontop]; return VO_TRUE;
|
15327
|
287 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [glView rootwin]; return VO_TRUE;
|
15289
|
288 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); [glView fullscreen: YES]; return VO_TRUE;
|
|
289 case VOCTRL_GET_PANSCAN: return VO_TRUE;
|
|
290 case VOCTRL_SET_PANSCAN: [glView panscan]; return VO_TRUE;
|
|
291 }
|
|
292 return VO_NOTIMPL;
|
|
293 }
|
|
294
|
|
295 //////////////////////////////////////////////////////////////////////////
|
|
296 // NSOpenGLView Subclass
|
|
297 //////////////////////////////////////////////////////////////////////////
|
|
298 @implementation CustomOpenGLView
|
|
299 - (void) initOpenGLView
|
|
300 {
|
|
301 NSRect frame = [self frame];
|
|
302 CVReturn error = kCVReturnSuccess;
|
|
303
|
|
304 //create OpenGL Context
|
|
305 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
|
|
306
|
|
307
|
|
308 //create window
|
|
309 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, frame.size.width, frame.size.height)
|
|
310 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
|
|
311 backing:NSBackingStoreBuffered
|
|
312 defer:NO];
|
|
313
|
15325
|
314 [window setDelegate:self];
|
15289
|
315 [window setContentView:self];
|
|
316 [window setInitialFirstResponder:self];
|
|
317 [window setAcceptsMouseMovedEvents:YES];
|
|
318 [window setTitle:@"MPlayer - The Movie Player"];
|
|
319 [window center];
|
15327
|
320 [window makeKeyAndOrderFront:self];
|
15289
|
321
|
|
322 [self setOpenGLContext:glContext];
|
|
323 [glContext setView:self];
|
|
324 [glContext makeCurrentContext];
|
|
325
|
|
326 error = CVPixelBufferCreateWithBytes( NULL,
|
|
327 image_width, image_height,
|
|
328 pixelFormat,
|
|
329 image_data,
|
|
330 image_width*image_bytes,
|
|
331 NULL, NULL, NULL,
|
|
332 ¤tFrameBuffer);
|
|
333 if(error != kCVReturnSuccess)
|
|
334 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error);
|
|
335
|
|
336 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
|
|
337 if(error != kCVReturnSuccess)
|
|
338 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error);
|
|
339
|
|
340 error = CVOpenGLTextureCacheCreateTextureFromImage( NULL, textureCache, currentFrameBuffer, 0, &texture);
|
|
341 if(error != kCVReturnSuccess)
|
|
342 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error);
|
|
343
|
|
344 isFullscreen = 0;
|
|
345 }
|
|
346
|
|
347 /*
|
|
348 Setup OpenGL
|
|
349 */
|
|
350 - (void)prepareOpenGL
|
|
351 {
|
15339
|
352 glEnable(GL_BLEND);
|
15289
|
353 glDisable(GL_DEPTH_TEST);
|
|
354 glDepthMask(GL_FALSE);
|
|
355 glDisable(GL_CULL_FACE);
|
|
356 [self reshape];
|
|
357 }
|
|
358
|
|
359 /*
|
|
360 reshape OpenGL viewport
|
|
361 */
|
|
362 - (void)reshape
|
|
363 {
|
|
364 uint32_t d_width;
|
|
365 uint32_t d_height;
|
|
366 float aspectX;
|
|
367 float aspectY;
|
|
368 int padding = 0;
|
|
369
|
|
370 NSRect frame = [self frame];
|
|
371
|
|
372 glViewport(0, 0, frame.size.width, frame.size.height);
|
|
373 glMatrixMode(GL_PROJECTION);
|
|
374 glLoadIdentity();
|
|
375 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0);
|
|
376 glMatrixMode(GL_MODELVIEW);
|
|
377 glLoadIdentity();
|
|
378
|
|
379 //set image_rec
|
|
380 if(vo_keepaspect)
|
|
381 {
|
|
382 aspect( &d_width, &d_height, A_NOZOOM);
|
|
383 d_height = ((float)d_width/movie_aspect);
|
|
384
|
|
385 aspectX = (float)((float)frame.size.width/(float)d_width);
|
|
386 aspectY = (float)((float)(frame.size.height)/(float)d_height);
|
|
387
|
|
388 if((d_height*aspectX)>(frame.size.height))
|
|
389 {
|
|
390 padding = (frame.size.width - d_width*aspectY)/2;
|
|
391 image_rec.origin.x = padding;
|
|
392 image_rec.origin.y = 0;
|
|
393 image_rec.size.width = d_width*aspectY+padding;
|
|
394 image_rec.size.height = d_height*aspectY;
|
|
395 }
|
|
396 else
|
|
397 {
|
|
398 padding = ((frame.size.height) - d_height*aspectX)/2;
|
|
399 image_rec.origin.x = 0;
|
|
400 image_rec.origin.y = padding;
|
|
401 image_rec.size.width = d_width*aspectX;
|
|
402 image_rec.size.height = d_height*aspectX+padding;
|
|
403 }
|
|
404 }
|
|
405 else
|
|
406 {
|
|
407 image_rec = frame;
|
|
408 }
|
|
409 }
|
|
410
|
|
411 /*
|
|
412 Render frame
|
|
413 */
|
|
414 - (void) render
|
|
415 {
|
|
416 glClear(GL_COLOR_BUFFER_BIT);
|
|
417
|
|
418 glEnable(CVOpenGLTextureGetTarget(texture));
|
|
419 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture));
|
|
420
|
|
421 glColor3f(1,1,1);
|
|
422 glBegin(GL_QUADS);
|
15331
|
423 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( image_rec.origin.x-(vo_panscan_x >> 1), image_rec.origin.y-(vo_panscan_y >> 1));
|
|
424 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i( image_rec.origin.x-(vo_panscan_x >> 1), image_rec.size.height+(vo_panscan_y >> 1));
|
|
425 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i( image_rec.size.width+(vo_panscan_x >> 1), image_rec.size.height+(vo_panscan_y >> 1));
|
|
426 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i( image_rec.size.width+(vo_panscan_x >> 1), image_rec.origin.y-(vo_panscan_y >> 1));
|
15289
|
427 glEnd();
|
15339
|
428 glDisable(CVOpenGLTextureGetTarget(texture));
|
|
429
|
|
430 //render resize box
|
|
431 if(!isFullscreen)
|
|
432 {
|
|
433 NSRect frame = [self frame];
|
|
434
|
|
435 glBegin(GL_LINES);
|
|
436 glColor4f(0.2, 0.2, 0.2, 0.5);
|
|
437 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1);
|
|
438 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1);
|
|
439 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1);
|
|
440
|
|
441 glColor4f(0.4, 0.4, 0.4, 0.5);
|
|
442 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1);
|
|
443 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1);
|
|
444 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1);
|
|
445
|
|
446 glColor4f(0.6, 0.6, 0.6, 0.5);
|
|
447 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1);
|
|
448 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1);
|
|
449 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1);
|
|
450 glEnd();
|
|
451 }
|
15289
|
452
|
|
453 glFlush();
|
|
454
|
|
455 //auto hide mouse cursor and futur on-screen control?
|
15327
|
456 if(isFullscreen && !mouseHide && !isRootwin)
|
15289
|
457 {
|
|
458 DateTimeRec d;
|
|
459 unsigned long curTime;
|
|
460 static unsigned long lastTime = 0;
|
|
461
|
|
462 GetTime(&d);
|
|
463 DateToSeconds( &d, &curTime);
|
|
464
|
|
465 if( ((curTime - lastTime) >= 5) || (lastTime == 0) )
|
|
466 {
|
|
467 HideMenuBar();
|
|
468 HideCursor();
|
|
469 mouseHide = YES;
|
|
470 lastTime = curTime;
|
|
471 }
|
|
472 }
|
|
473 }
|
|
474
|
|
475 /*
|
|
476 Create OpenGL texture from current frame & set texco
|
|
477 */
|
|
478 - (void) setCurrentTexture
|
|
479 {
|
|
480 CVReturn error = kCVReturnSuccess;
|
|
481
|
|
482 error = CVOpenGLTextureCacheCreateTextureFromImage (NULL, textureCache, currentFrameBuffer, 0, &texture);
|
|
483 if(error != kCVReturnSuccess)
|
|
484 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error);
|
|
485
|
|
486 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft);
|
|
487 }
|
|
488
|
|
489 /*
|
|
490 redraw win rect
|
|
491 */
|
|
492 - (void) drawRect: (NSRect *) bounds
|
|
493 {
|
|
494 [self render];
|
|
495 }
|
|
496
|
|
497 /*
|
|
498 Toggle Fullscreen
|
|
499 */
|
|
500 - (void) fullscreen: (BOOL) animate
|
|
501 {
|
|
502 static NSRect old_frame;
|
|
503 static NSRect old_view_frame;
|
|
504 NSRect device_rect = [[window screen] frame];
|
|
505
|
|
506 //go fullscreen
|
|
507 if(vo_fs)
|
|
508 {
|
15327
|
509 if(!isRootwin)
|
|
510 {
|
|
511 //hide menubar and mouse if fullscreen on main display
|
|
512 HideMenuBar();
|
|
513 HideCursor();
|
|
514 mouseHide = YES;
|
|
515 }
|
15289
|
516
|
|
517 panscan_calc();
|
|
518 old_frame = [window frame]; //save main window size & position
|
|
519 [window setFrame:device_rect display:YES animate:animate]; //zoom-in window with nice useless sfx
|
|
520 old_view_frame = [self bounds];
|
|
521
|
|
522 //fix origin for multi screen setup
|
|
523 device_rect.origin.x = 0;
|
|
524 device_rect.origin.y = 0;
|
|
525 [self setFrame:device_rect];
|
|
526 [self setNeedsDisplay:YES];
|
|
527 [window setHasShadow:NO];
|
|
528 isFullscreen = 1;
|
|
529 }
|
|
530 else
|
|
531 {
|
|
532 isFullscreen = 0;
|
|
533 ShowMenuBar();
|
|
534 ShowCursor();
|
|
535 mouseHide = NO;
|
|
536
|
|
537 //revert window to previous setting
|
|
538 [self setFrame:old_view_frame];
|
|
539 [self setNeedsDisplay:YES];
|
|
540 [window setHasShadow:NO];
|
|
541 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx
|
|
542 }
|
|
543 }
|
|
544
|
|
545 /*
|
|
546 Toggle ontop
|
|
547 */
|
|
548 - (void) ontop
|
|
549 {
|
15320
|
550 if(vo_ontop)
|
|
551 {
|
|
552 [window setLevel:NSScreenSaverWindowLevel];
|
|
553 isOntop = YES;
|
|
554 }
|
|
555 else
|
|
556 {
|
|
557 [window setLevel:NSNormalWindowLevel];
|
|
558 isOntop = NO;
|
|
559 }
|
15289
|
560 }
|
|
561
|
|
562 /*
|
|
563 Toggle panscan
|
|
564 */
|
|
565 - (void) panscan
|
|
566 {
|
15331
|
567 panscan_calc();
|
15289
|
568 }
|
|
569
|
|
570 /*
|
15327
|
571 Toggle rootwin
|
|
572 */
|
|
573 - (void) rootwin
|
|
574 {
|
|
575 if(vo_rootwin)
|
|
576 {
|
|
577 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
|
|
578 [window orderBack:self];
|
|
579 isRootwin = YES;
|
|
580 }
|
|
581 else
|
|
582 {
|
|
583 [window setLevel:NSNormalWindowLevel];
|
|
584 isRootwin = NO;
|
|
585 }
|
|
586 }
|
|
587
|
|
588 /*
|
15289
|
589 Check event for new event
|
|
590 */
|
|
591 - (void) check_events
|
|
592 {
|
|
593 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES];
|
|
594 [NSApp sendEvent:event];
|
|
595 }
|
|
596
|
|
597 /*
|
|
598 Process key event
|
|
599 */
|
|
600 - (void) keyDown: (NSEvent *) theEvent
|
|
601 {
|
|
602 unsigned int key;
|
|
603
|
|
604 switch([theEvent keyCode])
|
|
605 {
|
|
606 case 0x34:
|
|
607 case 0x24: key = KEY_ENTER; break;
|
|
608 case 0x35: key = KEY_ESC; break;
|
|
609 case 0x33: key = KEY_BACKSPACE; break;
|
|
610 case 0x3A: key = KEY_BACKSPACE; break;
|
|
611 case 0x3B: key = KEY_BACKSPACE; break;
|
|
612 case 0x38: key = KEY_BACKSPACE; break;
|
|
613 case 0x7A: key = KEY_F+1; break;
|
|
614 case 0x78: key = KEY_F+2; break;
|
|
615 case 0x63: key = KEY_F+3; break;
|
|
616 case 0x76: key = KEY_F+4; break;
|
|
617 case 0x60: key = KEY_F+5; break;
|
|
618 case 0x61: key = KEY_F+6; break;
|
|
619 case 0x62: key = KEY_F+7; break;
|
|
620 case 0x64: key = KEY_F+8; break;
|
|
621 case 0x65: key = KEY_F+9; break;
|
|
622 case 0x6D: key = KEY_F+10; break;
|
|
623 case 0x67: key = KEY_F+11; break;
|
|
624 case 0x6F: key = KEY_F+12; break;
|
|
625 case 0x72: key = KEY_INSERT; break;
|
|
626 case 0x75: key = KEY_DELETE; break;
|
|
627 case 0x73: key = KEY_HOME; break;
|
|
628 case 0x77: key = KEY_END; break;
|
|
629 case 0x45: key = '+'; break;
|
|
630 case 0x4E: key = '-'; break;
|
|
631 case 0x30: key = KEY_TAB; break;
|
|
632 case 0x74: key = KEY_PAGE_UP; break;
|
|
633 case 0x79: key = KEY_PAGE_DOWN; break;
|
|
634 case 0x7B: key = KEY_LEFT; break;
|
|
635 case 0x7C: key = KEY_RIGHT; break;
|
|
636 case 0x7D: key = KEY_DOWN; break;
|
|
637 case 0x7E: key = KEY_UP; break;
|
|
638 case 0x43: key = '*'; break;
|
|
639 case 0x4B: key = '/'; break;
|
|
640 case 0x4C: key = KEY_BACKSPACE; break;
|
|
641 case 0x41: key = KEY_KPDEC; break;
|
|
642 case 0x52: key = KEY_KP0; break;
|
|
643 case 0x53: key = KEY_KP1; break;
|
|
644 case 0x54: key = KEY_KP2; break;
|
|
645 case 0x55: key = KEY_KP3; break;
|
|
646 case 0x56: key = KEY_KP4; break;
|
|
647 case 0x57: key = KEY_KP5; break;
|
|
648 case 0x58: key = KEY_KP6; break;
|
|
649 case 0x59: key = KEY_KP7; break;
|
|
650 case 0x5B: key = KEY_KP8; break;
|
|
651 case 0x5C: key = KEY_KP9; break;
|
|
652 default: key = *[[theEvent characters] UTF8String]; break;
|
|
653 }
|
|
654 mplayer_put_key(key);
|
|
655 }
|
|
656
|
|
657 /*
|
|
658 Process mouse button event
|
|
659 */
|
|
660 - (void) mouseMoved: (NSEvent *) theEvent
|
|
661 {
|
15327
|
662 if(isFullscreen && !isRootwin)
|
15289
|
663 {
|
|
664 ShowMenuBar();
|
|
665 ShowCursor();
|
|
666 mouseHide = NO;
|
|
667 }
|
|
668 }
|
|
669
|
|
670 - (void) mouseDown: (NSEvent *) theEvent
|
|
671 {
|
|
672 [self mouseEvent: theEvent];
|
|
673 }
|
|
674
|
|
675 - (void) rightMouseDown: (NSEvent *) theEvent
|
|
676 {
|
|
677 [self mouseEvent: theEvent];
|
|
678 }
|
|
679
|
|
680 - (void) otherMouseDown: (NSEvent *) theEvent
|
|
681 {
|
|
682 [self mouseEvent: theEvent];
|
|
683 }
|
|
684
|
|
685 - (void) scrollWheel: (NSEvent *) theEvent
|
|
686 {
|
|
687 if([theEvent deltaY] > 0)
|
|
688 mplayer_put_key(MOUSE_BTN3);
|
|
689 else
|
|
690 mplayer_put_key(MOUSE_BTN4);
|
|
691 }
|
|
692
|
|
693 - (void) mouseEvent: (NSEvent *) theEvent
|
|
694 {
|
|
695 switch( [theEvent buttonNumber] )
|
|
696 {
|
|
697 case 0: mplayer_put_key(MOUSE_BTN0);break;
|
|
698 case 1: mplayer_put_key(MOUSE_BTN1);break;
|
|
699 case 2: mplayer_put_key(MOUSE_BTN2);break;
|
|
700 }
|
|
701 }
|
|
702
|
|
703 /*
|
|
704 NSResponder
|
|
705 */
|
|
706 - (BOOL) acceptsFirstResponder
|
|
707 {
|
|
708 return YES;
|
|
709 }
|
|
710
|
|
711 - (BOOL) becomeFirstResponder
|
|
712 {
|
|
713 return YES;
|
|
714 }
|
|
715
|
|
716 - (BOOL) resignFirstResponder
|
|
717 {
|
|
718 return YES;
|
|
719 }
|
15325
|
720
|
|
721 - (void)windowWillClose:(NSNotification *)aNotification
|
|
722 {
|
|
723 mplayer_put_key(KEY_ESC);
|
|
724 }
|
|
725 @end
|