]> git.sesse.net Git - vlc/blob - modules/gui/macosx/embeddedwindow.m
macosx: Fix compilation. (NSUInteger) is 10.5 api change ???
[vlc] / modules / gui / macosx / embeddedwindow.m
1 /*****************************************************************************
2  * embeddedwindow.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2005-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Benjamin Pracht <bigben at videolan dot org>
8  *          Felix Paul Kühne <fkuehne at videolan dot org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 /* DisableScreenUpdates, SetSystemUIMode, ... */
30 #import <QuickTime/QuickTime.h>
31
32 #import "intf.h"
33 #import "controls.h"
34 #import "vout.h"
35 #import "embeddedwindow.h"
36 #import "fspanel.h"
37
38 /*****************************************************************************
39  * VLCEmbeddedWindow Implementation
40  *****************************************************************************/
41
42 @implementation VLCEmbeddedWindow
43
44 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
45 {
46     BOOL useTextured = YES;
47     if([[NSWindow class] instancesRespondToSelector:@selector(setContentBorderThickness:forEdge:)])
48     {
49         useTextured = NO;
50         windowStyle ^= NSTexturedBackgroundWindowMask;
51     }
52     self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
53     if(!useTextured)
54     {
55         [self setContentBorderThickness:32.0 forEdge:NSMinYEdge];
56     }
57     return self;
58 }
59
60 - (void)awakeFromNib
61 {
62     [self setDelegate: self];
63
64     [o_btn_backward setToolTip: _NS("Rewind")];
65     [o_btn_forward setToolTip: _NS("Fast Forward")];
66     [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
67     [o_btn_play setToolTip: _NS("Play")];
68     [o_slider setToolTip: _NS("Position")];
69
70     o_img_play = [NSImage imageNamed: @"play_embedded"];
71     o_img_pause = [NSImage imageNamed: @"pause_embedded"];
72     [self controlTintChanged];
73     [[NSNotificationCenter defaultCenter] addObserver: self
74                                              selector: @selector( controlTintChanged )
75                                                  name: NSControlTintDidChangeNotification
76                                                object: nil];
77
78     /* Useful to save o_view frame in fullscreen mode */
79     o_temp_view = [[NSView alloc] init];
80     [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
81
82     o_fullscreen_window = nil;
83     o_fullscreen_anim1 = o_fullscreen_anim2 = nil;
84
85     /* Not fullscreen when we wake up */
86     [o_btn_fullscreen setState: NO];
87     b_fullscreen = NO;
88
89     [self setMovableByWindowBackground:YES];
90
91     [self setDelegate:self];
92
93     /* Make sure setVisible: returns NO */
94     [self orderOut:self];
95     b_window_is_invisible = YES;
96     videoRatio = NSMakeSize( 0., 0. );
97 }
98
99 - (void)controlTintChanged
100 {
101     BOOL b_playing = NO;
102     if( [o_btn_play alternateImage] == o_img_play_pressed )
103         b_playing = YES;
104     
105     if( [NSColor currentControlTint] == NSGraphiteControlTint )
106     {
107         o_img_play_pressed = [NSImage imageNamed: @"play_embedded_graphite"];
108         o_img_pause_pressed = [NSImage imageNamed: @"pause_embedded_graphite"];
109         [o_btn_backward setAlternateImage: [NSImage imageNamed: @"skip_previous_embedded_graphite"]];
110         [o_btn_forward setAlternateImage: [NSImage imageNamed: @"skip_forward_embedded_graphite"]];
111         [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
112     }
113     else
114     {
115         o_img_play_pressed = [NSImage imageNamed: @"play_embedded_blue"];
116         o_img_pause_pressed = [NSImage imageNamed: @"pause_embedded_blue"];
117         [o_btn_backward setAlternateImage: [NSImage imageNamed: @"skip_previous_embedded_blue"]];
118         [o_btn_forward setAlternateImage: [NSImage imageNamed: @"skip_forward_embedded_blue"]];
119         [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
120     }
121     
122     if( b_playing )
123         [o_btn_play setAlternateImage: o_img_play_pressed];
124     else
125         [o_btn_play setAlternateImage: o_img_pause_pressed];
126 }
127
128 - (void)dealloc
129 {
130     [[NSNotificationCenter defaultCenter] removeObserver: self];
131     [o_img_play release];
132     [o_img_play_pressed release];
133     [o_img_pause release];
134     [o_img_pause_pressed release];
135     
136     [super dealloc];
137 }
138
139 - (void)setTime:(NSString *)o_arg_time position:(float)f_position
140 {
141     [o_time setStringValue: o_arg_time];
142     [o_slider setFloatValue: f_position];
143 }
144
145 - (void)playStatusUpdated:(int)i_status
146 {
147     if( i_status == PLAYING_S )
148     {
149         [o_btn_play setImage: o_img_pause];
150         [o_btn_play setAlternateImage: o_img_pause_pressed];
151         [o_btn_play setToolTip: _NS("Pause")];
152     }
153     else
154     {
155         [o_btn_play setImage: o_img_play];
156         [o_btn_play setAlternateImage: o_img_play_pressed];
157         [o_btn_play setToolTip: _NS("Play")];
158     }
159 }
160
161 - (void)setSeekable:(BOOL)b_seekable
162 {
163     [o_btn_forward setEnabled: b_seekable];
164     [o_btn_backward setEnabled: b_seekable];
165     [o_slider setEnabled: b_seekable];
166 }
167
168 - (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
169 {
170     [self setFrame: newFrame display: YES animate: YES];
171     return NO;
172 }
173
174 - (BOOL)windowShouldClose:(id)sender
175 {
176     playlist_t * p_playlist = pl_Yield( VLCIntf );
177
178     playlist_Stop( p_playlist );
179     vlc_object_release( p_playlist );
180     return YES;
181 }
182
183 - (NSView *)mainView
184 {
185     if (o_fullscreen_window)
186         return o_temp_view;
187     else
188         return o_view;
189 }
190
191 - (void)setVideoRatio:(NSSize)ratio
192 {
193     videoRatio = ratio;
194 }
195
196 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
197 {
198     if( videoRatio.height == 0. || videoRatio.width == 0. )
199         return proposedFrameSize;
200
201     NSRect viewRect = [o_view convertRect:[o_view bounds] toView: nil];
202     NSRect contentRect = [self contentRectForFrameRect:[self frame]];
203     float marginy = viewRect.origin.y + [self frame].size.height - contentRect.size.height;
204     float marginx = contentRect.size.width - viewRect.size.width;
205     proposedFrameSize.height = (proposedFrameSize.width - marginx) * videoRatio.height / videoRatio.width + marginy;
206
207     return proposedFrameSize;
208 }
209
210 /*****************************************************************************
211  * Fullscreen support
212  */
213
214 - (BOOL)isFullscreen
215 {
216     return b_fullscreen;
217 }
218
219 - (void)lockFullscreenAnimation
220 {
221     [o_animation_lock lock];
222 }
223
224 - (void)unlockFullscreenAnimation
225 {
226     [o_animation_lock unlock];
227 }
228
229 - (void)enterFullscreen
230 {
231     NSMutableDictionary *dict1, *dict2;
232     NSScreen *screen;
233     NSRect screen_rect;
234     NSRect rect;
235     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
236     BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
237
238     screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )]; 
239  
240     [self lockFullscreenAnimation];
241
242     if (!screen)
243     {
244         msg_Dbg( p_vout, "chosen screen isn't present, using current screen for fullscreen mode" );
245         screen = [self screen];
246     }
247     if (!screen)
248     {
249         msg_Dbg( p_vout, "Using deepest screen" );
250         screen = [NSScreen deepestScreen];
251     }
252
253     vlc_object_release( p_vout );
254
255     screen_rect = [screen frame];
256
257     [o_btn_fullscreen setState: YES];
258
259     [NSCursor setHiddenUntilMouseMoves: YES];
260  
261     if( blackout_other_displays )        
262         [screen blackoutOtherScreens];
263
264     /* Make sure we don't see the window flashes in float-on-top mode */
265     originalLevel = [self level];
266     [self setLevel:NSNormalWindowLevel];
267
268     /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
269     if (!o_fullscreen_window)
270     {
271         /* We can't change the styleMask of an already created NSWindow, so we create an other window, and do eye catching stuff */
272
273         rect = [[o_view superview] convertRect: [o_view frame] toView: nil]; /* Convert to Window base coord */
274         rect.origin.x += [self frame].origin.x;
275         rect.origin.y += [self frame].origin.y;
276         o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
277         [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
278         [o_fullscreen_window setCanBecomeKeyWindow: YES];
279
280         if (![self isVisible] || [self alphaValue] == 0.0 || MACOS_VERSION < 10.4f)
281         {
282             /* We don't animate if we are not visible or if we are running on
283              * Mac OS X <10.4 which doesn't support NSAnimation, instead we
284              * simply fade the display */
285             CGDisplayFadeReservationToken token;
286  
287             CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
288             CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
289  
290             if ([screen isMainScreen])
291                 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
292  
293             [[self contentView] replaceSubview:o_view with:o_temp_view];
294             [o_temp_view setFrame:[o_view frame]];
295             [o_fullscreen_window setContentView:o_view];
296
297             [o_fullscreen_window makeKeyAndOrderFront:self];
298
299             [o_fullscreen_window makeKeyAndOrderFront:self];
300             [o_fullscreen_window orderFront:self animate:YES];
301
302             [o_fullscreen_window setFrame:screen_rect display:YES];
303
304             CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
305             CGReleaseDisplayFadeReservation( token);
306
307             /* Will release the lock */
308             [self hasBecomeFullscreen];
309
310             return;
311         }
312  
313         /* Make sure we don't see the o_view disappearing of the screen during this operation */
314         DisableScreenUpdates();
315         [[self contentView] replaceSubview:o_view with:o_temp_view];
316         [o_temp_view setFrame:[o_view frame]];
317         [o_fullscreen_window setContentView:o_view];
318         [o_fullscreen_window makeKeyAndOrderFront:self];
319         EnableScreenUpdates();
320     }
321
322     if (MACOS_VERSION < 10.4f)
323     {
324         /* We were already fullscreen nothing to do when NSAnimation
325          * is not supported */
326         [self unlockFullscreenAnimation];
327         return;
328     }
329
330     /* We are in fullscreen (and no animation is running) */
331     if (b_fullscreen)
332     {
333         /* Make sure we are hidden */
334         [super orderOut: self];
335         [self unlockFullscreenAnimation];
336         return;
337     }
338
339     if (o_fullscreen_anim1)
340     {
341         [o_fullscreen_anim1 stopAnimation];
342         [o_fullscreen_anim1 release];
343     }
344     if (o_fullscreen_anim2)
345     {
346         [o_fullscreen_anim2 stopAnimation];
347         [o_fullscreen_anim2 release];
348     }
349  
350     if ([screen isMainScreen])
351         SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
352
353     dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
354     dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
355
356     [dict1 setObject:self forKey:NSViewAnimationTargetKey];
357     [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
358
359     [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
360     [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
361     [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
362
363     /* Strategy with NSAnimation allocation:
364         - Keep at most 2 animation at a time
365         - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
366     */
367     o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
368     o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
369
370     [dict1 release];
371     [dict2 release];
372
373     [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
374     [o_fullscreen_anim1 setDuration: 0.3];
375     [o_fullscreen_anim1 setFrameRate: 30];
376     [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
377     [o_fullscreen_anim2 setDuration: 0.2];
378     [o_fullscreen_anim2 setFrameRate: 30];
379
380     [o_fullscreen_anim2 setDelegate: self];
381     [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
382
383     [o_fullscreen_anim1 startAnimation];
384     /* fullscreenAnimation will be unlocked when animation ends */
385 }
386
387 - (void)hasBecomeFullscreen
388 {
389     [o_fullscreen_window makeFirstResponder: [[[VLCMain sharedInstance] getControls] getVoutView]];
390
391     [o_fullscreen_window makeKeyWindow];
392     [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
393
394     /* tell the fspanel to move itself to front next time it's triggered */
395     [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
396
397     if([self isVisible])
398         [super orderOut: self];
399
400     [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
401
402     b_fullscreen = YES;
403     [self unlockFullscreenAnimation];
404 }
405
406 - (void)leaveFullscreen
407 {
408     [self leaveFullscreenAndFadeOut: NO];
409 }
410
411 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
412 {
413     NSMutableDictionary *dict1, *dict2;
414     NSRect frame;
415
416     [self lockFullscreenAnimation];
417
418     b_fullscreen = NO;
419     [o_btn_fullscreen setState: NO];
420
421     /* We always try to do so */
422     [NSScreen unblackoutScreens];
423
424     /* Don't do anything if o_fullscreen_window is already closed */
425     if (!o_fullscreen_window)
426     {
427         [self unlockFullscreenAnimation];
428         return;
429     }
430
431     if (fadeout || MACOS_VERSION < 10.4f)
432     {
433         /* We don't animate if we are not visible or if we are running on
434         * Mac OS X <10.4 which doesn't support NSAnimation, instead we
435         * simply fade the display */
436         CGDisplayFadeReservationToken token;
437
438         CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
439         CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
440
441         [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
442         SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
443
444         /* Will release the lock */
445         [self hasEndedFullscreen];
446
447         /* Our window is hidden, and might be faded. We need to workaround that, so note it
448          * here */
449         b_window_is_invisible = YES;
450
451         CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
452         CGReleaseDisplayFadeReservation( token);
453         return;
454     }
455
456     [self setAlphaValue: 0.0];
457     [self orderFront: self];
458
459     [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
460     SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
461
462     if (o_fullscreen_anim1)
463     {
464         [o_fullscreen_anim1 stopAnimation];
465         [o_fullscreen_anim1 release];
466     }
467     if (o_fullscreen_anim2)
468     {
469         [o_fullscreen_anim2 stopAnimation];
470         [o_fullscreen_anim2 release];
471     }
472
473     frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
474     frame.origin.x += [self frame].origin.x;
475     frame.origin.y += [self frame].origin.y;
476
477     dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
478     [dict2 setObject:self forKey:NSViewAnimationTargetKey];
479     [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
480
481     o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
482     [dict2 release];
483
484     [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
485     [o_fullscreen_anim2 setDuration: 0.3];
486     [o_fullscreen_anim2 setFrameRate: 30];
487
488     [o_fullscreen_anim2 setDelegate: self];
489
490     dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
491
492     [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
493     [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
494     [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
495
496     o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
497     [dict1 release];
498
499     [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
500     [o_fullscreen_anim1 setDuration: 0.2];
501     [o_fullscreen_anim1 setFrameRate: 30];
502     [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
503
504     /* Make sure o_fullscreen_window is the frontmost window */
505     [o_fullscreen_window orderFront: self];
506
507     [o_fullscreen_anim1 startAnimation];
508     /* fullscreenAnimation will be unlocked when animation ends */
509 }
510
511 - (void)hasEndedFullscreen
512 {
513     /* This function is private and should be only triggered at the end of the fullscreen change animation */
514     /* Make sure we don't see the o_view disappearing of the screen during this operation */
515     DisableScreenUpdates();
516     [o_view retain];
517     [o_view removeFromSuperviewWithoutNeedingDisplay];
518     [[self contentView] replaceSubview:o_temp_view with:o_view];
519     [o_view release];
520     [o_view setFrame:[o_temp_view frame]];
521     [self makeFirstResponder: o_view];
522     if ([self isVisible])
523         [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
524     [o_fullscreen_window orderOut: self];
525     EnableScreenUpdates();
526
527     [o_fullscreen_window release];
528     o_fullscreen_window = nil;
529     [self setLevel:originalLevel];
530
531     [self unlockFullscreenAnimation];
532 }
533
534 - (void)animationDidEnd:(NSAnimation*)animation
535 {
536     NSArray *viewAnimations;
537
538     if ([animation currentValue] < 1.0)
539         return;
540
541     /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
542     viewAnimations = [o_fullscreen_anim2 viewAnimations];
543     if ([viewAnimations count] >=1 &&
544         [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
545     {
546         /* Fullscreen ended */
547         [self hasEndedFullscreen];
548     }
549     else
550     {
551         /* Fullscreen started */
552         [self hasBecomeFullscreen];
553     }
554 }
555
556 - (void)orderOut: (id)sender
557 {
558     [super orderOut: sender];
559
560     /* Make sure we leave fullscreen */
561     [self leaveFullscreenAndFadeOut: YES];
562 }
563
564 - (void)makeKeyAndOrderFront: (id)sender
565 {
566     /* Hack
567      * when we exit fullscreen and fade out, we may endup in
568      * having a window that is faded. We can't have it fade in unless we
569      * animate again. */
570
571     if(!b_window_is_invisible)
572     {
573         /* Make sure we don't do it too much */
574         [super makeKeyAndOrderFront: sender];
575         return;
576     }
577
578     [super setAlphaValue:0.0f];
579     [super makeKeyAndOrderFront: sender];
580
581     NSMutableDictionary * dict = [[[NSMutableDictionary alloc] initWithCapacity:2] autorelease];
582     [dict setObject:self forKey:NSViewAnimationTargetKey];
583     [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
584
585     NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
586
587     [anim setAnimationBlockingMode: NSAnimationNonblocking];
588     [anim setDuration: 0.1];
589     [anim setFrameRate: 30];
590
591     [anim startAnimation];
592     b_window_is_invisible = NO;
593
594     /* fullscreenAnimation will be unlocked when animation ends */
595 }
596
597
598
599 /* Make sure setFrame gets executed on main thread especially if we are animating.
600  * (Thus we won't block the video output thread) */
601 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
602 {
603     struct { NSRect frame; BOOL display; BOOL animate;} args;
604     NSData *packedargs;
605
606     args.frame = frame;
607     args.display = display;
608     args.animate = animate;
609
610     packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
611
612     [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
613                     withObject: packedargs waitUntilDone: YES];
614 }
615
616 - (void)setFrameOnMainThread:(NSData*)packedargs
617 {
618     struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
619
620     if( args->animate )
621     {
622         /* Make sure we don't block too long and set up a non blocking animation */
623         NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
624             self, NSViewAnimationTargetKey,
625             [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
626             [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
627
628         NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
629
630         [anim setAnimationBlockingMode: NSAnimationNonblocking];
631         [anim setDuration: 0.4];
632         [anim setFrameRate: 30];
633         [anim startAnimation];
634     }
635     else {
636         [super setFrame:args->frame display:args->display animate:args->animate];
637     }
638
639 }
640 @end