2 * MACDRV Cocoa window code
4 * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #import "cocoa_window.h"
23 #include "macdrv_cocoa.h"
25 #import "cocoa_event.h"
28 static NSUInteger style_mask_for_features(const struct macdrv_window_features* wf)
30 NSUInteger style_mask;
34 style_mask = NSTitledWindowMask;
35 if (wf->close_button) style_mask |= NSClosableWindowMask;
36 if (wf->minimize_button) style_mask |= NSMiniaturizableWindowMask;
37 if (wf->resizable) style_mask |= NSResizableWindowMask;
38 if (wf->utility) style_mask |= NSUtilityWindowMask;
40 else style_mask = NSBorderlessWindowMask;
46 static BOOL frame_intersects_screens(NSRect frame, NSArray* screens)
49 for (screen in screens)
51 if (NSIntersectsRect(frame, [screen frame]))
58 @interface WineContentView : NSView
62 @interface WineWindow ()
64 @property (nonatomic) BOOL disabled;
65 @property (nonatomic) BOOL noActivate;
66 @property (nonatomic) BOOL floating;
67 @property (retain, nonatomic) NSWindow* latentParentWindow;
69 @property (nonatomic) void* hwnd;
70 @property (retain, readwrite, nonatomic) WineEventQueue* queue;
72 @property (nonatomic) void* surface;
73 @property (nonatomic) pthread_mutex_t* surface_mutex;
75 @property (copy, nonatomic) NSBezierPath* shape;
76 @property (nonatomic) BOOL shapeChangedSinceLastDraw;
77 @property (readonly, nonatomic) BOOL needsTransparency;
79 @property (nonatomic) BOOL colorKeyed;
80 @property (nonatomic) CGFloat colorKeyRed, colorKeyGreen, colorKeyBlue;
81 @property (nonatomic) BOOL usePerPixelAlpha;
83 + (void) flipRect:(NSRect*)rect;
88 @implementation WineContentView
95 - (void) drawRect:(NSRect)rect
97 WineWindow* window = (WineWindow*)[self window];
99 if (window.surface && window.surface_mutex &&
100 !pthread_mutex_lock(window.surface_mutex))
105 if (!get_surface_region_rects(window.surface, &rects, &count) || count)
110 imageRect = NSRectToCGRect(rect);
111 image = create_surface_image(window.surface, &imageRect, FALSE);
115 CGContextRef context;
119 NSBezierPath* surfaceClip = [NSBezierPath bezierPath];
121 for (i = 0; i < count; i++)
122 [surfaceClip appendBezierPathWithRect:NSRectFromCGRect(rects[i])];
123 [surfaceClip addClip];
126 [window.shape addClip];
128 if (window.colorKeyed)
130 CGImageRef maskedImage;
131 CGFloat components[] = { window.colorKeyRed - 0.5, window.colorKeyRed + 0.5,
132 window.colorKeyGreen - 0.5, window.colorKeyGreen + 0.5,
133 window.colorKeyBlue - 0.5, window.colorKeyBlue + 0.5 };
134 maskedImage = CGImageCreateWithMaskingColors(image, components);
137 CGImageRelease(image);
142 context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
143 CGContextSetBlendMode(context, kCGBlendModeCopy);
144 CGContextDrawImage(context, imageRect, image);
146 CGImageRelease(image);
148 if (window.shapeChangedSinceLastDraw || window.colorKeyed ||
149 window.usePerPixelAlpha)
151 window.shapeChangedSinceLastDraw = FALSE;
152 [window invalidateShadow];
157 pthread_mutex_unlock(window.surface_mutex);
161 /* By default, NSView will swallow right-clicks in an attempt to support contextual
162 menus. We need to bypass that and allow the event to make it to the window. */
163 - (void) rightMouseDown:(NSEvent*)theEvent
165 [[self window] rightMouseDown:theEvent];
171 @implementation WineWindow
173 @synthesize disabled, noActivate, floating, latentParentWindow, hwnd, queue;
174 @synthesize surface, surface_mutex;
175 @synthesize shape, shapeChangedSinceLastDraw;
176 @synthesize colorKeyed, colorKeyRed, colorKeyGreen, colorKeyBlue;
177 @synthesize usePerPixelAlpha;
179 + (WineWindow*) createWindowWithFeatures:(const struct macdrv_window_features*)wf
180 windowFrame:(NSRect)window_frame
182 queue:(WineEventQueue*)queue
185 WineContentView* contentView;
187 [self flipRect:&window_frame];
189 window = [[[self alloc] initWithContentRect:window_frame
190 styleMask:style_mask_for_features(wf)
191 backing:NSBackingStoreBuffered
192 defer:YES] autorelease];
194 if (!window) return nil;
195 window->normalStyleMask = [window styleMask];
197 /* Standardize windows to eliminate differences between titled and
198 borderless windows and between NSWindow and NSPanel. */
199 [window setHidesOnDeactivate:NO];
200 [window setReleasedWhenClosed:NO];
202 [window disableCursorRects];
203 [window setShowsResizeIndicator:NO];
204 [window setHasShadow:wf->shadow];
205 [window setColorSpace:[NSColorSpace genericRGBColorSpace]];
206 [window setDelegate:window];
208 window.queue = queue;
210 contentView = [[[WineContentView alloc] initWithFrame:NSZeroRect] autorelease];
213 [contentView setAutoresizesSubviews:NO];
215 [window setContentView:contentView];
217 /* In case Cocoa adjusted the frame we tried to set, generate a frame-changed
218 event. The back end will ignore it if nothing actually changed. */
219 [window windowDidResize:nil];
227 [latentParentWindow release];
232 + (void) flipRect:(NSRect*)rect
234 rect->origin.y = NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]) - NSMaxY(*rect);
237 - (void) adjustFeaturesForState
239 NSUInteger style = normalStyleMask;
242 style &= ~NSResizableWindowMask;
243 if (style != [self styleMask])
244 [self setStyleMask:style];
246 if (style & NSClosableWindowMask)
247 [[self standardWindowButton:NSWindowCloseButton] setEnabled:!self.disabled];
248 if (style & NSMiniaturizableWindowMask)
249 [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled:!self.disabled];
252 - (void) setWindowFeatures:(const struct macdrv_window_features*)wf
254 normalStyleMask = style_mask_for_features(wf);
255 [self adjustFeaturesForState];
256 [self setHasShadow:wf->shadow];
259 - (void) setMacDrvState:(const struct macdrv_window_state*)state
262 NSWindowCollectionBehavior behavior;
264 self.disabled = state->disabled;
265 self.noActivate = state->no_activate;
267 self.floating = state->floating;
268 level = state->floating ? NSFloatingWindowLevel : NSNormalWindowLevel;
269 if (level != [self level])
270 [self setLevel:level];
272 behavior = NSWindowCollectionBehaviorDefault;
273 if (state->excluded_by_expose)
274 behavior |= NSWindowCollectionBehaviorTransient;
276 behavior |= NSWindowCollectionBehaviorManaged;
277 if (state->excluded_by_cycle)
279 behavior |= NSWindowCollectionBehaviorIgnoresCycle;
280 if ([self isVisible])
281 [NSApp removeWindowsItem:self];
285 behavior |= NSWindowCollectionBehaviorParticipatesInCycle;
286 if ([self isVisible])
287 [NSApp addWindowsItem:self title:[self title] filename:NO];
289 [self setCollectionBehavior:behavior];
292 /* Returns whether or not the window was ordered in, which depends on if
293 its frame intersects any screen. */
294 - (BOOL) orderBelow:(WineWindow*)prev orAbove:(WineWindow*)next
296 BOOL on_screen = frame_intersects_screens([self frame], [NSScreen screens]);
299 [NSApp transformProcessToForeground];
302 [self orderWindow:NSWindowBelow relativeTo:[prev windowNumber]];
304 [self orderWindow:NSWindowAbove relativeTo:[next windowNumber]];
305 if (latentParentWindow)
307 [latentParentWindow addChildWindow:self ordered:NSWindowAbove];
308 self.latentParentWindow = nil;
311 /* Cocoa may adjust the frame when the window is ordered onto the screen.
312 Generate a frame-changed event just in case. The back end will ignore
313 it if nothing actually changed. */
314 [self windowDidResize:nil];
316 if (![self isExcludedFromWindowsMenu])
317 [NSApp addWindowsItem:self title:[self title] filename:NO];
325 self.latentParentWindow = [self parentWindow];
326 [latentParentWindow removeChildWindow:self];
328 [NSApp removeWindowsItem:self];
331 - (BOOL) setFrameIfOnScreen:(NSRect)contentRect
333 NSArray* screens = [NSScreen screens];
334 BOOL on_screen = [self isVisible];
335 NSRect frame, oldFrame;
337 if (![screens count]) return on_screen;
339 /* Origin is (left, top) in a top-down space. Need to convert it to
340 (left, bottom) in a bottom-up space. */
341 [[self class] flipRect:&contentRect];
345 on_screen = frame_intersects_screens(contentRect, screens);
350 oldFrame = [self frame];
351 frame = [self frameRectForContentRect:contentRect];
352 if (!NSEqualRects(frame, oldFrame))
354 if (NSEqualSizes(frame.size, oldFrame.size))
355 [self setFrameOrigin:frame.origin];
357 [self setFrame:frame display:YES];
360 /* In case Cocoa adjusted the frame we tried to set, generate a frame-changed
361 event. The back end will ignore it if nothing actually changed. */
362 [self windowDidResize:nil];
367 - (void) setMacDrvParentWindow:(WineWindow*)parent
369 if ([self parentWindow] != parent)
371 [[self parentWindow] removeChildWindow:self];
372 self.latentParentWindow = nil;
373 if ([self isVisible] && parent)
374 [parent addChildWindow:self ordered:NSWindowAbove];
376 self.latentParentWindow = parent;
380 - (void) setDisabled:(BOOL)newValue
382 if (disabled != newValue)
385 [self adjustFeaturesForState];
389 - (BOOL) needsTransparency
391 return self.shape || self.colorKeyed || self.usePerPixelAlpha;
394 - (void) checkTransparency
396 if (![self isOpaque] && !self.needsTransparency)
398 [self setBackgroundColor:[NSColor windowBackgroundColor]];
399 [self setOpaque:YES];
401 else if ([self isOpaque] && self.needsTransparency)
403 [self setBackgroundColor:[NSColor clearColor]];
408 - (void) setShape:(NSBezierPath*)newShape
410 if (shape == newShape) return;
411 if (shape && newShape && [shape isEqual:newShape]) return;
415 [[self contentView] setNeedsDisplayInRect:[shape bounds]];
419 [[self contentView] setNeedsDisplayInRect:[newShape bounds]];
421 shape = [newShape copy];
422 self.shapeChangedSinceLastDraw = TRUE;
424 [self checkTransparency];
427 - (void) postMouseButtonEvent:(NSEvent *)theEvent pressed:(int)pressed
429 CGPoint pt = CGEventGetLocation([theEvent CGEvent]);
432 event.type = MOUSE_BUTTON;
433 event.window = (macdrv_window)[self retain];
434 event.mouse_button.button = [theEvent buttonNumber];
435 event.mouse_button.pressed = pressed;
436 event.mouse_button.x = pt.x;
437 event.mouse_button.y = pt.y;
438 event.mouse_button.time_ms = [NSApp ticksForEventTime:[theEvent timestamp]];
440 [queue postEvent:&event];
447 [NSApp transformProcessToForeground];
449 /* If a borderless window is offscreen, orderFront: won't move
450 it onscreen like it would for a titled window. Do that ourselves. */
451 screens = [NSScreen screens];
452 if (!([self styleMask] & NSTitledWindowMask) && ![self isVisible] &&
453 !frame_intersects_screens([self frame], screens))
455 NSScreen* primaryScreen = [screens objectAtIndex:0];
456 NSRect frame = [primaryScreen frame];
457 [self setFrameTopLeftPoint:NSMakePoint(NSMinX(frame), NSMaxY(frame))];
458 frame = [self constrainFrameRect:[self frame] toScreen:primaryScreen];
459 [self setFrame:frame display:YES];
462 [self orderFront:nil];
463 causing_becomeKeyWindow = TRUE;
464 [self makeKeyWindow];
465 causing_becomeKeyWindow = FALSE;
466 if (latentParentWindow)
468 [latentParentWindow addChildWindow:self ordered:NSWindowAbove];
469 self.latentParentWindow = nil;
471 if (![self isExcludedFromWindowsMenu])
472 [NSApp addWindowsItem:self title:[self title] filename:NO];
474 /* Cocoa may adjust the frame when the window is ordered onto the screen.
475 Generate a frame-changed event just in case. The back end will ignore
476 it if nothing actually changed. */
477 [self windowDidResize:nil];
482 * ---------- NSWindow method overrides ----------
484 - (BOOL) canBecomeKeyWindow
486 if (causing_becomeKeyWindow) return YES;
487 if (self.disabled || self.noActivate) return NO;
488 return [self isKeyWindow];
491 - (BOOL) canBecomeMainWindow
493 return [self canBecomeKeyWindow];
496 - (BOOL) isExcludedFromWindowsMenu
498 return !([self collectionBehavior] & NSWindowCollectionBehaviorParticipatesInCycle);
501 - (BOOL) validateMenuItem:(NSMenuItem *)menuItem
503 if ([menuItem action] == @selector(makeKeyAndOrderFront:))
504 return [self isKeyWindow] || (!self.disabled && !self.noActivate);
505 return [super validateMenuItem:menuItem];
508 /* We don't call this. It's the action method of the items in the Window menu. */
509 - (void) makeKeyAndOrderFront:(id)sender
511 if (![self isKeyWindow] && !self.disabled && !self.noActivate)
512 [NSApp windowGotFocus:self];
515 - (void) sendEvent:(NSEvent*)event
517 if ([event type] == NSLeftMouseDown)
519 /* Since our windows generally claim they can't be made key, clicks
520 in their title bars are swallowed by the theme frame stuff. So,
521 we hook directly into the event stream and assume that any click
522 in the window will activate it, if Wine and the Win32 program
524 if (![self isKeyWindow] && !self.disabled && !self.noActivate)
525 [NSApp windowGotFocus:self];
528 [super sendEvent:event];
533 * ---------- NSResponder method overrides ----------
535 - (void) mouseDown:(NSEvent *)theEvent { [self postMouseButtonEvent:theEvent pressed:1]; }
536 - (void) rightMouseDown:(NSEvent *)theEvent { [self mouseDown:theEvent]; }
537 - (void) otherMouseDown:(NSEvent *)theEvent { [self mouseDown:theEvent]; }
539 - (void) mouseUp:(NSEvent *)theEvent { [self postMouseButtonEvent:theEvent pressed:0]; }
540 - (void) rightMouseUp:(NSEvent *)theEvent { [self mouseUp:theEvent]; }
541 - (void) otherMouseUp:(NSEvent *)theEvent { [self mouseUp:theEvent]; }
545 * ---------- NSWindowDelegate methods ----------
547 - (void)windowDidBecomeKey:(NSNotification *)notification
549 if (causing_becomeKeyWindow) return;
551 [NSApp windowGotFocus:self];
554 - (void)windowDidMove:(NSNotification *)notification
556 [self windowDidResize:notification];
559 - (void)windowDidResize:(NSNotification *)notification
562 NSRect frame = [self contentRectForFrameRect:[self frame]];
564 [[self class] flipRect:&frame];
566 /* Coalesce events by discarding any previous ones still in the queue. */
567 [queue discardEventsMatchingMask:event_mask_for_type(WINDOW_FRAME_CHANGED)
570 event.type = WINDOW_FRAME_CHANGED;
571 event.window = (macdrv_window)[self retain];
572 event.window_frame_changed.frame = NSRectToCGRect(frame);
573 [queue postEvent:&event];
576 - (BOOL)windowShouldClose:(id)sender
579 event.type = WINDOW_CLOSE_REQUESTED;
580 event.window = (macdrv_window)[self retain];
581 [queue postEvent:&event];
588 /***********************************************************************
589 * macdrv_create_cocoa_window
591 * Create a Cocoa window with the given content frame and features (e.g.
592 * title bar, close box, etc.).
594 macdrv_window macdrv_create_cocoa_window(const struct macdrv_window_features* wf,
595 CGRect frame, void* hwnd, macdrv_event_queue queue)
597 __block WineWindow* window;
600 window = [[WineWindow createWindowWithFeatures:wf
601 windowFrame:NSRectFromCGRect(frame)
603 queue:(WineEventQueue*)queue] retain];
606 return (macdrv_window)window;
609 /***********************************************************************
610 * macdrv_destroy_cocoa_window
612 * Destroy a Cocoa window.
614 void macdrv_destroy_cocoa_window(macdrv_window w)
616 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
617 WineWindow* window = (WineWindow*)w;
619 [window.queue discardEventsMatchingMask:-1 forWindow:window];
626 /***********************************************************************
627 * macdrv_get_window_hwnd
629 * Get the hwnd that was set for the window at creation.
631 void* macdrv_get_window_hwnd(macdrv_window w)
633 WineWindow* window = (WineWindow*)w;
637 /***********************************************************************
638 * macdrv_set_cocoa_window_features
640 * Update a Cocoa window's features.
642 void macdrv_set_cocoa_window_features(macdrv_window w,
643 const struct macdrv_window_features* wf)
645 WineWindow* window = (WineWindow*)w;
648 [window setWindowFeatures:wf];
652 /***********************************************************************
653 * macdrv_set_cocoa_window_state
655 * Update a Cocoa window's state.
657 void macdrv_set_cocoa_window_state(macdrv_window w,
658 const struct macdrv_window_state* state)
660 WineWindow* window = (WineWindow*)w;
663 [window setMacDrvState:state];
667 /***********************************************************************
668 * macdrv_set_cocoa_window_title
670 * Set a Cocoa window's title.
672 void macdrv_set_cocoa_window_title(macdrv_window w, const unsigned short* title,
675 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
676 WineWindow* window = (WineWindow*)w;
677 NSString* titleString;
680 titleString = [NSString stringWithCharacters:title length:length];
684 [window setTitle:titleString];
685 if ([window isVisible] && ![window isExcludedFromWindowsMenu])
686 [NSApp changeWindowsItem:window title:titleString filename:NO];
692 /***********************************************************************
693 * macdrv_order_cocoa_window
695 * Reorder a Cocoa window relative to other windows. If prev is
696 * non-NULL, it is ordered below that window. Else, if next is non-NULL,
697 * it is ordered above that window. Otherwise, it is ordered to the
700 * Returns true if the window has actually been ordered onto the screen
701 * (i.e. if its frame intersects with a screen). Otherwise, false.
703 int macdrv_order_cocoa_window(macdrv_window w, macdrv_window prev,
706 WineWindow* window = (WineWindow*)w;
707 __block BOOL on_screen;
710 on_screen = [window orderBelow:(WineWindow*)prev
711 orAbove:(WineWindow*)next];
717 /***********************************************************************
718 * macdrv_hide_cocoa_window
720 * Hides a Cocoa window.
722 void macdrv_hide_cocoa_window(macdrv_window w)
724 WineWindow* window = (WineWindow*)w;
731 /***********************************************************************
732 * macdrv_set_cocoa_window_frame
734 * Move a Cocoa window. If the window has been moved out of the bounds
735 * of the desktop, it is ordered out. (This routine won't ever order a
736 * window in, though.)
738 * Returns true if the window is on screen; false otherwise.
740 int macdrv_set_cocoa_window_frame(macdrv_window w, const CGRect* new_frame)
742 WineWindow* window = (WineWindow*)w;
743 __block BOOL on_screen;
746 on_screen = [window setFrameIfOnScreen:NSRectFromCGRect(*new_frame)];
752 /***********************************************************************
753 * macdrv_get_cocoa_window_frame
755 * Gets the frame of a Cocoa window.
757 void macdrv_get_cocoa_window_frame(macdrv_window w, CGRect* out_frame)
759 WineWindow* window = (WineWindow*)w;
764 frame = [window contentRectForFrameRect:[window frame]];
765 [[window class] flipRect:&frame];
766 *out_frame = NSRectToCGRect(frame);
770 /***********************************************************************
771 * macdrv_set_cocoa_parent_window
773 * Sets the parent window for a Cocoa window. If parent is NULL, clears
776 void macdrv_set_cocoa_parent_window(macdrv_window w, macdrv_window parent)
778 WineWindow* window = (WineWindow*)w;
781 [window setMacDrvParentWindow:(WineWindow*)parent];
785 /***********************************************************************
786 * macdrv_set_window_surface
788 void macdrv_set_window_surface(macdrv_window w, void *surface, pthread_mutex_t *mutex)
790 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
791 WineWindow* window = (WineWindow*)w;
794 window.surface = surface;
795 window.surface_mutex = mutex;
801 /***********************************************************************
802 * macdrv_window_needs_display
804 * Mark a window as needing display in a specified rect (in non-client
807 void macdrv_window_needs_display(macdrv_window w, CGRect rect)
809 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
810 WineWindow* window = (WineWindow*)w;
813 [[window contentView] setNeedsDisplayInRect:NSRectFromCGRect(rect)];
819 /***********************************************************************
820 * macdrv_set_window_shape
822 * Sets the shape of a Cocoa window from an array of rectangles. If
823 * rects is NULL, resets the window's shape to its frame.
825 void macdrv_set_window_shape(macdrv_window w, const CGRect *rects, int count)
827 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
828 WineWindow* window = (WineWindow*)w;
831 if (!rects || !count)
838 path = [NSBezierPath bezierPath];
839 for (i = 0; i < count; i++)
840 [path appendBezierPathWithRect:NSRectFromCGRect(rects[i])];
848 /***********************************************************************
849 * macdrv_set_window_alpha
851 void macdrv_set_window_alpha(macdrv_window w, CGFloat alpha)
853 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
854 WineWindow* window = (WineWindow*)w;
856 [window setAlphaValue:alpha];
861 /***********************************************************************
862 * macdrv_set_window_color_key
864 void macdrv_set_window_color_key(macdrv_window w, CGFloat keyRed, CGFloat keyGreen,
867 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
868 WineWindow* window = (WineWindow*)w;
871 window.colorKeyed = TRUE;
872 window.colorKeyRed = keyRed;
873 window.colorKeyGreen = keyGreen;
874 window.colorKeyBlue = keyBlue;
875 [window checkTransparency];
881 /***********************************************************************
882 * macdrv_clear_window_color_key
884 void macdrv_clear_window_color_key(macdrv_window w)
886 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
887 WineWindow* window = (WineWindow*)w;
890 window.colorKeyed = FALSE;
891 [window checkTransparency];
897 /***********************************************************************
898 * macdrv_window_use_per_pixel_alpha
900 void macdrv_window_use_per_pixel_alpha(macdrv_window w, int use_per_pixel_alpha)
902 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
903 WineWindow* window = (WineWindow*)w;
906 window.usePerPixelAlpha = use_per_pixel_alpha;
907 [window checkTransparency];
913 /***********************************************************************
914 * macdrv_give_cocoa_window_focus
916 * Makes the Cocoa window "key" (gives it keyboard focus). This also
917 * orders it front and, if its frame was not within the desktop bounds,
918 * Cocoa will typically move it on-screen.
920 void macdrv_give_cocoa_window_focus(macdrv_window w)
922 WineWindow* window = (WineWindow*)w;
925 [window makeFocused];