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