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