Add Window::SetLayout method
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / macos / window-base-mac.mm
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "dali/public-api/adaptor-framework/window.h"
19 #include "dali/public-api/events/wheel-event.h"
20 #include <Carbon/Carbon.h>
21 #import <Cocoa/Cocoa.h>
22
23 // CLASS HEADER
24 #include <dali/internal/window-system/macos/window-base-mac.h>
25
26 // EXTERNAL_HEADERS
27 #include <dali/public-api/object/any.h>
28 #include <dali/integration-api/debug.h>
29
30 // INTERNAL HEADERS
31 #include <dali/internal/window-system/common/window-impl.h>
32 #include <dali/internal/window-system/common/window-render-surface.h>
33 #include <dali/internal/window-system/common/window-system.h>
34
35 #include <cmath>
36
37 using Dali::Internal::Adaptor::WindowBaseCocoa;
38
39 // Angle is default selecting CGL as its backend and because
40 // of that we are using NSOpenGLView. Ideally we should use
41 // Metal as the backend. When this happends, we must change
42 // the parent class to MTKView.
43 @interface CocoaView : NSOpenGLView
44 - (CocoaView *) initWithFrame:(NSRect) rect withImpl:(WindowBaseCocoa::Impl *) impl;
45 - (BOOL) isFlipped;
46 - (BOOL) wantsUpdateLayer;
47 - (BOOL) acceptsFirstResponder;
48 - (void) mouseDown:(NSEvent *) event;
49 - (void) mouseUp:(NSEvent *) event;
50 - (void) mouseDragged:(NSEvent *) event;
51 - (void) keyDown:(NSEvent *) event;
52 - (void) keyUp:(NSEvent *) event;
53 - (void) drawRect:(NSRect) dirtyRect;
54 - (void) prepareOpenGL;
55 @end
56
57 @interface WindowDelegate : NSObject <NSWindowDelegate>
58 - (WindowDelegate *) init:(WindowBaseCocoa::Impl *) impl;
59 - (void) windowDidBecomeKey:(NSNotification *) notification;
60 - (void) windowDidResignKey:(NSNotification *) notification;
61 - (void) windowWillClose:(NSNotification *) notification;
62 @end
63
64 namespace Dali::Internal::Adaptor
65 {
66
67 namespace
68 {
69
70 #if defined(DEBUG_ENABLED)
71 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW_BASE" );
72 #endif
73
74 // Converts a y coordinate from top to bottom coordinate
75 CGFloat BottomYCoordinate(CGFloat topYCoordinate, CGFloat windowHeight) noexcept
76 {
77   const auto screen = [NSScreen.mainScreen frame];
78   return screen.size.height - windowHeight - topYCoordinate;
79 }
80
81 NSRect PositionSizeToRect(const PositionSize &positionSize, bool flipped = false) noexcept
82 {
83   // positionSize assumes top-left coordinate system
84   // Cocoa assumes bottom-left coordinate system
85   // If NSView isFlipped method returns YES, then it uses top-left coordinate system
86   const auto windowHeight = static_cast<CGFloat>(positionSize.height);
87   const auto yGiven = static_cast<CGFloat>(positionSize.y);
88
89   CGFloat yWindow;
90   if (flipped)
91   {
92     yWindow = yGiven;
93   }
94   else
95   {
96     yWindow = BottomYCoordinate(yGiven, windowHeight);
97   }
98
99   return
100   {
101     .origin =
102     {
103       .x = static_cast<CGFloat>(positionSize.x),
104       .y = yWindow
105     },
106     .size =
107     {
108       .width = static_cast<CGFloat>(positionSize.width),
109       .height = windowHeight,
110     },
111   };
112 }
113
114 } // unnamed namespace
115
116 struct WindowBaseCocoa::Impl final
117 {
118   NSWindow *mWindow;
119   NSWindowController *mWinController;
120   WindowBaseCocoa *mThis;
121
122   Impl(const Impl &rhs) = delete;
123   Impl &operator<(const Impl &rhs) = delete;
124   Impl(const Impl &&rhs) = delete;
125   Impl &operator<(const Impl &&rhs) = delete;
126
127   Impl(
128     WindowBaseCocoa *pThis,
129     PositionSize positionSize,
130     Any surface,
131     bool isTransparent
132   );
133
134   ~Impl();
135
136   void OnFocus(bool focus)
137   {
138     mThis->mFocusChangedSignal.Emit(focus);
139   }
140
141   // Handle mouse events
142   void OnMouse(NSEvent *event, PointState::Type state);
143   void OnMouseWheel(NSEvent *event);
144   void OnKey(NSEvent *event, Integration::KeyEvent::State keyState);
145   void OnWindowDamaged(const NSRect &rect);
146
147   void OnRedraw(void)
148   {
149     mThis->mWindowRedrawRequestSignal.Emit();
150   }
151
152 private:
153   uint32_t GetKeyModifiers(NSEvent *event) const noexcept;
154   std::string GetKeyName(NSEvent *event) const;
155 };
156
157 WindowBaseCocoa::Impl::Impl(
158   WindowBaseCocoa *pThis,
159   PositionSize positionSize,
160   Any surface,
161   bool isTransparent
162 ) : mThis(pThis)
163 {
164   constexpr NSUInteger style =
165     NSWindowStyleMaskTitled
166     | NSWindowStyleMaskClosable
167     | NSWindowStyleMaskMiniaturizable
168     | NSWindowStyleMaskResizable;
169
170   mWindow = [[NSWindow alloc] initWithContentRect:PositionSizeToRect(positionSize)
171                                         styleMask:style
172                                           backing:NSBackingStoreBuffered
173                                             defer:NO];
174
175   mWindow.alphaValue = static_cast<CGFloat>(!isTransparent);
176   mWinController = [[NSWindowController alloc] initWithWindow:mWindow];
177
178   mWindow.delegate = [[WindowDelegate alloc] init:this];
179
180   NSView *view = [[CocoaView alloc] initWithFrame:PositionSizeToRect(positionSize, true)
181                                          withImpl:this];
182   NSPoint origin{0, 0};
183   [view setFrameOrigin:origin];
184
185   mWindow.contentView = view;
186
187   [mWindow makeKeyAndOrderFront:nil];
188 }
189
190 WindowBaseCocoa::Impl::~Impl()
191 {
192   [mWinController close];
193   [NSApp stop:nil];
194 }
195
196 void WindowBaseCocoa::Impl::OnMouse(NSEvent *event, PointState::Type state)
197 {
198   Integration::Point point;
199   point.SetDeviceId(event.deviceID);
200   point.SetState(state);
201   auto p = [event locationInWindow];
202   auto [x, y] = [mWindow.contentView convertPoint:p fromView:nil];
203   point.SetScreenPosition(Vector2(x, y));
204   point.SetRadius(std::sqrt(x*x + y*y));
205   point.SetPressure(event.pressure);
206
207   if (x == 0.0)
208   {
209     point.SetAngle(Degree(0.0));
210   }
211   else
212   {
213     point.SetAngle(Radian(std::atan(y/x)));
214   }
215
216   DALI_LOG_INFO(
217     gWindowBaseLogFilter,
218     Debug::Verbose,
219     "WindowBaseCocoa::Impl::OnMouse(%.1f, %.1f)\n",
220     x,
221     y
222   );
223
224   // timestamp is given in seconds, the signal expects it in milliseconds
225   mThis->mTouchEventSignal.Emit(point, event.timestamp * 1000);
226 }
227
228 void WindowBaseCocoa::Impl::OnMouseWheel(NSEvent *event)
229 {
230   auto p = [event locationInWindow];
231   auto [x, y] = [mWindow.contentView convertPoint:p fromView:nil];
232
233   const auto modifiers = GetKeyModifiers(event);
234   const Vector2 vec(x, y);
235   const auto timestamp = event.timestamp * 1000;
236
237   if (event.scrollingDeltaY)
238   {
239     Integration::WheelEvent wheelEvent(
240       Integration::WheelEvent::MOUSE_WHEEL,
241       0,
242       modifiers,
243       vec,
244       event.scrollingDeltaY < 0 ? -1 : 1,
245       timestamp
246     );
247
248     mThis->mWheelEventSignal.Emit(wheelEvent);
249   }
250
251   if (event.scrollingDeltaX)
252   {
253     Integration::WheelEvent wheelEvent(
254       Integration::WheelEvent::MOUSE_WHEEL,
255       0,
256       modifiers,
257       vec,
258       event.scrollingDeltaX < 0 ? -1 : 1,
259       timestamp
260     );
261
262     mThis->mWheelEventSignal.Emit(wheelEvent);
263   }
264 }
265
266 void WindowBaseCocoa::Impl::OnKey(NSEvent *event, Integration::KeyEvent::State keyState)
267 {
268   const std::string empty;
269
270   Integration::KeyEvent keyEvent(
271     GetKeyName(event),
272     empty,
273     [event.characters UTF8String],
274     event.keyCode,
275     GetKeyModifiers(event),
276     event.timestamp * 1000,
277     keyState,
278     empty,
279     empty,
280     Device::Class::NONE,
281     Device::Subclass::NONE
282   );
283
284   DALI_LOG_INFO(
285     gWindowBaseLogFilter,
286     Debug::Verbose,
287     "WindowBaseCocoa::Impl::OnKey(%s)\n",
288     [event.characters UTF8String]
289   );
290
291   mThis->mKeyEventSignal.Emit(keyEvent);
292 }
293
294 void WindowBaseCocoa::Impl::OnWindowDamaged(const NSRect &rect)
295 {
296   const DamageArea area(
297     rect.origin.x,
298     rect.origin.y,
299     rect.size.width,
300     rect.size.height
301   );
302
303   mThis->mWindowDamagedSignal.Emit(area);
304 }
305
306 uint32_t WindowBaseCocoa::Impl::GetKeyModifiers(NSEvent *event) const noexcept
307 {
308   uint32_t modifiers = 0;
309
310   if (event.modifierFlags & NSEventModifierFlagShift)
311   {
312     modifiers |= 1;
313   }
314
315   if (event.modifierFlags & NSEventModifierFlagControl)
316   {
317     modifiers |= 2;
318   }
319
320   if (event.modifierFlags & NSEventModifierFlagCommand)
321   {
322     modifiers |= 4;
323   }
324
325   return modifiers;
326 }
327
328 std::string WindowBaseCocoa::Impl::GetKeyName(NSEvent *event) const
329 {
330   switch (event.keyCode)
331   {
332     case kVK_Control:     return "Control";
333     case kVK_Shift:       return "Shift";
334     case kVK_Delete:      return "Backspace";
335     case kVK_Command:     return "Command";
336     case kVK_Tab:         return "Tab";
337     case kVK_Return:      return "Return";
338     case kVK_Escape:      return "Escape";
339     case kVK_Space:       return "Space";
340     case kVK_LeftArrow:   return "Left";
341     case kVK_UpArrow:     return "Up";
342     case kVK_RightArrow:  return "Right";
343     case kVK_DownArrow:   return "Down";
344     case kVK_ANSI_0:      return "0";
345     case kVK_ANSI_1:      return "1";
346     case kVK_ANSI_2:      return "2";
347     case kVK_ANSI_3:      return "3";
348     case kVK_ANSI_4:      return "4";
349     case kVK_ANSI_5:      return "5";
350     case kVK_ANSI_6:      return "6";
351     case kVK_ANSI_7:      return "7";
352     case kVK_ANSI_8:      return "8";
353     case kVK_ANSI_9:      return "9";
354     default:              return [event.characters UTF8String];
355   }
356
357   return "";
358 }
359
360 WindowBaseCocoa::WindowBaseCocoa(PositionSize positionSize, Any surface, bool isTransparent)
361   : mImpl(std::make_unique<Impl>(this, positionSize, surface, isTransparent))
362 {
363 }
364
365 WindowBaseCocoa::~WindowBaseCocoa()
366 {
367 }
368
369 Any WindowBaseCocoa::GetNativeWindow()
370 {
371   return mImpl->mWindow;
372 }
373
374 int WindowBaseCocoa::GetNativeWindowId()
375 {
376   return mImpl->mWindow.windowNumber;
377 }
378
379 std::string WindowBaseCocoa::GetNativeWindowResourceId()
380 {
381   return std::string();
382 }
383
384 EGLNativeWindowType WindowBaseCocoa::CreateEglWindow(int width, int height)
385 {
386   // XXX: this method is called from a secondary thread, but
387   // we can only resize the window from the main thread
388   //PositionSize size(0, 0, width, height);
389   //Resize(size);
390   return mImpl->mWindow.contentView.layer;
391 }
392
393 void WindowBaseCocoa::DestroyEglWindow()
394 {
395 }
396
397 void WindowBaseCocoa::SetEglWindowRotation( int angle )
398 {
399 }
400
401 void WindowBaseCocoa::SetEglWindowBufferTransform( int angle )
402 {
403 }
404
405 void WindowBaseCocoa::SetEglWindowTransform( int angle )
406 {
407 }
408
409 void WindowBaseCocoa::ResizeEglWindow( PositionSize positionSize )
410 {
411   Resize(positionSize);
412 }
413
414 bool WindowBaseCocoa::IsEglWindowRotationSupported()
415 {
416   return false;
417 }
418
419 void WindowBaseCocoa::Move( PositionSize positionSize )
420 {
421   const NSPoint p = {
422     .x = static_cast<CGFloat>(positionSize.x),
423     .y = static_cast<CGFloat>(positionSize.y),
424   };
425
426   [mImpl->mWindow setFrameTopLeftPoint:p];
427 }
428
429 void WindowBaseCocoa::Resize( PositionSize positionSize )
430 {
431   auto r = mImpl->mWindow.frame;
432   r.size.width = static_cast<CGFloat>(positionSize.width);
433   r.size.height = static_cast<CGFloat>(positionSize.height);
434   [mImpl->mWindow setFrame:r display:YES];
435
436   NSSize size =
437   {
438     .width = r.size.width,
439     .height = r.size.height,
440   };
441
442   [mImpl->mWindow.contentView setFrameSize:size];
443
444 }
445
446 void WindowBaseCocoa::MoveResize( PositionSize positionSize )
447 {
448   [mImpl->mWindow setFrame: PositionSizeToRect(positionSize) display:YES];
449
450   NSSize size =
451   {
452     .width = static_cast<CGFloat>(positionSize.width),
453     .height = static_cast<CGFloat>(positionSize.height),
454   };
455
456   [mImpl->mWindow.contentView setFrameSize:size];
457 }
458
459 void WindowBaseCocoa::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
460 {
461 }
462
463 void WindowBaseCocoa::SetClass( const std::string& name, const std::string& className )
464 {
465 }
466
467 void WindowBaseCocoa::Raise()
468 {
469   [mImpl->mWindow orderFront:nil];
470 }
471
472 void WindowBaseCocoa::Lower()
473 {
474   [mImpl->mWindow orderBack:nil];
475 }
476
477 void WindowBaseCocoa::Activate()
478 {
479   [mImpl->mWinController showWindow:nil];
480 }
481
482 void WindowBaseCocoa::Maximize(bool maximize)
483 {
484 }
485
486 bool WindowBaseCocoa::IsMaximized() const
487 {
488   return false;
489 }
490
491 void WindowBaseCocoa::SetMaximumSize(Dali::Window::WindowSize size)
492 {
493 }
494
495 void WindowBaseCocoa::Minimize(bool minimize)
496 {
497 }
498
499 bool WindowBaseCocoa::IsMinimized() const
500 {
501   return false;
502 }
503
504 void WindowBaseCocoa::SetMimimumSize(Dali::Window::WindowSize size)
505 {
506 }
507
508 void WindowBaseCocoa::SetAvailableAnlges( const std::vector< int >& angles )
509 {
510 }
511
512 void WindowBaseCocoa::SetPreferredAngle( int angle )
513 {
514 }
515
516 void WindowBaseCocoa::SetAcceptFocus( bool accept )
517 {
518 }
519
520 void WindowBaseCocoa::Show()
521 {
522   [mImpl->mWinController showWindow:nil];
523 }
524
525 void WindowBaseCocoa::Hide()
526 {
527   [mImpl->mWindow orderOut:nil];
528 }
529
530 unsigned int WindowBaseCocoa::GetSupportedAuxiliaryHintCount() const
531 {
532   return 0;
533 }
534
535 std::string WindowBaseCocoa::GetSupportedAuxiliaryHint( unsigned int index ) const
536 {
537   return std::string();
538 }
539
540 unsigned int WindowBaseCocoa::AddAuxiliaryHint( const std::string& hint, const std::string& value )
541 {
542   return 0;
543 }
544
545 bool WindowBaseCocoa::RemoveAuxiliaryHint( unsigned int id )
546 {
547   return false;
548 }
549
550 bool WindowBaseCocoa::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
551 {
552   return false;
553 }
554
555 std::string WindowBaseCocoa::GetAuxiliaryHintValue( unsigned int id ) const
556 {
557   return std::string();
558 }
559
560 unsigned int WindowBaseCocoa::GetAuxiliaryHintId( const std::string& hint ) const
561 {
562   return 0;
563 }
564
565 void WindowBaseCocoa::SetInputRegion( const Rect< int >& inputRegion )
566 {
567 }
568
569 void WindowBaseCocoa::SetType( Dali::WindowType type )
570 {
571 }
572
573 Dali::WindowType WindowBaseCocoa::GetType() const
574 {
575   return Dali::WindowType::NORMAL;
576 }
577
578 WindowOperationResult WindowBaseCocoa::SetNotificationLevel( WindowNotificationLevel level )
579 {
580   return WindowOperationResult::NOT_SUPPORTED;
581 }
582
583 WindowNotificationLevel WindowBaseCocoa::GetNotificationLevel() const
584 {
585   return WindowNotificationLevel::NONE;
586 }
587
588 void WindowBaseCocoa::SetOpaqueState( bool opaque )
589 {
590 }
591
592 WindowOperationResult WindowBaseCocoa::SetScreenOffMode(WindowScreenOffMode screenOffMode)
593 {
594   return WindowOperationResult::NOT_SUPPORTED;
595 }
596
597 WindowScreenOffMode WindowBaseCocoa::GetScreenOffMode() const
598 {
599   return WindowScreenOffMode::TIMEOUT;
600 }
601
602 WindowOperationResult WindowBaseCocoa::SetBrightness( int brightness )
603 {
604   return WindowOperationResult::NOT_SUPPORTED;
605 }
606
607 int WindowBaseCocoa::GetBrightness() const
608 {
609   return 0;
610 }
611
612 bool WindowBaseCocoa::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
613 {
614   return false;
615 }
616
617 bool WindowBaseCocoa::UngrabKey( Dali::KEY key )
618 {
619   return false;
620 }
621
622 bool WindowBaseCocoa::GrabKeyList(
623   const Dali::Vector< Dali::KEY >& key,
624   const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode,
625   Dali::Vector< bool >& result
626 )
627 {
628   return false;
629 }
630
631 bool WindowBaseCocoa::UngrabKeyList(
632   const Dali::Vector< Dali::KEY >& key,
633   Dali::Vector< bool >& result
634 )
635 {
636   return false;
637 }
638
639 void WindowBaseCocoa::GetDpi(
640   unsigned int& dpiHorizontal,
641   unsigned int& dpiVertical
642 )
643 {
644   auto *screen = [NSScreen mainScreen];
645   NSSize res = [screen.deviceDescription[NSDeviceResolution] sizeValue];
646   dpiHorizontal = res.width;
647   dpiVertical = res.height;
648 }
649
650 int WindowBaseCocoa::GetWindowRotationAngle() const
651 {
652   return 0;
653 }
654
655 int WindowBaseCocoa::GetScreenRotationAngle()
656 {
657   return 0;
658 }
659
660 void WindowBaseCocoa::SetWindowRotationAngle( int degree )
661 {
662 }
663
664 void WindowBaseCocoa::WindowRotationCompleted( int degree, int width, int height )
665 {
666 }
667
668 void WindowBaseCocoa::SetTransparency( bool transparent )
669 {
670   mImpl->mWindow.alphaValue = static_cast<CGFloat>(!transparent);
671 }
672
673 void WindowBaseCocoa::SetParent(WindowBase* parentWinBase, bool belowParent)
674 {
675   auto &parent = dynamic_cast<WindowBaseCocoa&>(*parentWinBase);
676   [mImpl->mWindow setParentWindow:parent.mImpl->mWindow];
677 }
678
679 int WindowBaseCocoa::CreateFrameRenderedSyncFence()
680 {
681   return -1;
682 }
683
684 int WindowBaseCocoa::CreateFramePresentedSyncFence()
685 {
686   return -1;
687 }
688
689 void WindowBaseCocoa::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
690 {
691 }
692
693 void WindowBaseCocoa::InitializeIme()
694 {
695 }
696
697 void WindowBaseCocoa::ImeWindowReadyToRender()
698 {
699 }
700
701 void WindowBaseCocoa::RequestMoveToServer()
702 {
703 }
704
705 void WindowBaseCocoa::RequestResizeToServer(WindowResizeDirection direction)
706 {
707 }
708
709 void WindowBaseCocoa::EnableFloatingMode(bool enable)
710 {
711 }
712
713 bool WindowBaseCocoa::IsFloatingModeEnabled() const
714 {
715   return false;
716 }
717
718 void WindowBaseCocoa::IncludeInputRegion(const Rect<int>& inputRegion)
719 {
720 }
721
722 void WindowBaseCocoa::ExcludeInputRegion(const Rect<int>& inputRegion)
723 {
724 }
725
726 } // namespace Dali::Internal::Adaptor
727
728 @implementation CocoaView
729 {
730   WindowBaseCocoa::Impl *mImpl;
731 }
732
733 - (CocoaView *) initWithFrame:(NSRect) rect withImpl:(WindowBaseCocoa::Impl *) impl
734 {
735   self = [super initWithFrame:rect];
736   if (self)
737   {
738     mImpl = impl;
739     self.wantsLayer = YES;
740     self.wantsBestResolutionOpenGLSurface = NO;
741   }
742
743   return self;
744 }
745
746 - (BOOL) isFlipped
747 {
748   return YES;
749 }
750
751 - (BOOL) wantsUpdateLayer
752 {
753   return YES;
754 }
755
756 - (BOOL) acceptsFirstResponder
757 {
758   return YES;
759 }
760
761 - (void) mouseDown:(NSEvent *) event
762 {
763   mImpl->OnMouse(event, Dali::PointState::DOWN);
764 }
765
766 - (void) mouseUp:(NSEvent *) event
767 {
768   mImpl->OnMouse(event, Dali::PointState::UP);
769 }
770
771 - (void) mouseDragged:(NSEvent *) event
772 {
773   mImpl->OnMouse(event, Dali::PointState::MOTION);
774 }
775
776 - (void) keyDown:(NSEvent *) event
777 {
778   mImpl->OnKey(event, Dali::Integration::KeyEvent::DOWN);
779 }
780
781 - (void) keyUp:(NSEvent *) event
782 {
783   mImpl->OnKey(event, Dali::Integration::KeyEvent::UP);
784 }
785
786 - (void) drawRect:(NSRect) dirtyRect
787 {
788   DALI_LOG_INFO(
789     Dali::Internal::Adaptor::gWindowBaseLogFilter,
790     Debug::Verbose,
791     "-[CocoaView drawRect:(%.1f, %.1f, %.1f, %.1f)]\n",
792     dirtyRect.origin.x,
793     dirtyRect.origin.y,
794     dirtyRect.size.width,
795     dirtyRect.size.height
796   );
797
798   mImpl->OnWindowDamaged(dirtyRect);
799 }
800
801 - (void) prepareOpenGL
802 {
803   auto ctx = CGLGetCurrentContext();
804   DALI_ASSERT_ALWAYS(ctx);
805
806   // Enable multithreading
807   if (auto err = CGLEnable(ctx, kCGLCEMPEngine); err != kCGLNoError)
808   {
809     DALI_LOG_ERROR("%s - %s", __PRETTY_FUNCTION__, CGLErrorString(err));
810   }
811 }
812 @end
813
814 @implementation WindowDelegate
815 {
816   WindowBaseCocoa::Impl *mImpl;
817 }
818
819 - (WindowDelegate *) init:(Dali::Internal::Adaptor::WindowBaseCocoa::Impl *) impl
820 {
821   self = [super init];
822   if (self)
823   {
824     mImpl = impl;
825   }
826   return self;
827 }
828
829 - (void) windowDidBecomeKey:(NSNotification *) notification
830 {
831   mImpl->OnFocus(true);
832 }
833
834 - (void) windowDidResignKey:(NSNotification *) notification
835 {
836   mImpl->OnFocus(false);
837 }
838
839 - (void) windowWillClose:(NSNotification *) notification
840 {
841   [NSApp stop:nil];
842 }
843 @end
844