From c62ac0cae77a4dbe7807c7638af5dc708f8c5933 Mon Sep 17 00:00:00 2001
From: Mnikolenko ProductEngine <mnikolenko@productengine.com>
Date: Thu, 11 Sep 2014 11:59:19 +0300
Subject: [PATCH] MAINT-3569 FIXED Handle window hide/unhide and
 minimize/unminimize events on mac.

---
 indra/llwindow/llopenglview-objc.mm  | 18 ++++++++++++++++++
 indra/llwindow/llwindowmacosx-objc.h |  2 ++
 indra/llwindow/llwindowmacosx.cpp    | 16 ++++++++++++++++
 indra/newview/llappdelegate-objc.mm  | 10 ++++++++++
 4 files changed, 46 insertions(+)

diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm
index 1bb93d05d6c..1b5804ec83d 100644
--- a/indra/llwindow/llopenglview-objc.mm
+++ b/indra/llwindow/llopenglview-objc.mm
@@ -124,6 +124,14 @@ attributedStringInfo getSegments(NSAttributedString *str)
 {
 	[[NSNotificationCenter defaultCenter] addObserver:self
 											 selector:@selector(windowResized:) name:NSWindowDidResizeNotification
+											   object:[self window]];    
+ 
+    [[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(windowWillMiniaturize:) name:NSWindowWillMiniaturizeNotification
+											   object:[self window]];
+    
+    [[NSNotificationCenter defaultCenter] addObserver:self
+											 selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification
 											   object:[self window]];
 }
 
@@ -141,6 +149,16 @@ attributedStringInfo getSegments(NSAttributedString *str)
     }
 }
 
+- (void)windowWillMiniaturize:(NSNotification *)notification;
+{
+    callWindowHide();
+}
+
+- (void)windowDidDeminiaturize:(NSNotification *)notification;
+{
+    callWindowUnhide();
+}
+
 - (void)dealloc
 {
 	[[NSNotificationCenter defaultCenter] removeObserver:self];
diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h
index d64525fbdd7..f02052ca6ad 100755
--- a/indra/llwindow/llwindowmacosx-objc.h
+++ b/indra/llwindow/llwindowmacosx-objc.h
@@ -116,6 +116,8 @@ void callScrollMoved(float delta);
 void callMouseExit();
 void callWindowFocus();
 void callWindowUnfocus();
+void callWindowHide();
+void callWindowUnhide();
 void callDeltaUpdate(float *delta, unsigned int mask);
 void callMiddleMouseDown(float *pos, unsigned int mask);
 void callMiddleMouseUp(float *pos, unsigned int mask);
diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp
index 18d51520156..e8d0a8bdb80 100755
--- a/indra/llwindow/llwindowmacosx.cpp
+++ b/indra/llwindow/llwindowmacosx.cpp
@@ -349,6 +349,22 @@ void callWindowUnfocus()
 	gWindowImplementation->getCallbacks()->handleFocusLost(gWindowImplementation);
 }
 
+void callWindowHide()
+{	
+	if ( gWindowImplementation && gWindowImplementation->getCallbacks() )
+	{
+		gWindowImplementation->getCallbacks()->handleActivate(gWindowImplementation, false);
+	}
+}
+
+void callWindowUnhide()
+{	
+	if ( gWindowImplementation && gWindowImplementation->getCallbacks() )
+	{
+		gWindowImplementation->getCallbacks()->handleActivate(gWindowImplementation, true);
+	}
+}
+
 void callDeltaUpdate(float *delta, MASK mask)
 {
 	gWindowImplementation->updateMouseDeltas(delta);
diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm
index 988058aad34..549df80fa1a 100644
--- a/indra/newview/llappdelegate-objc.mm
+++ b/indra/newview/llappdelegate-objc.mm
@@ -84,6 +84,16 @@
 	callWindowUnfocus();
 }
 
+- (void) applicationDidHide:(NSNotification *)notification
+{
+	callWindowHide();
+}
+
+- (void) applicationDidUnhide:(NSNotification *)notification
+{
+	callWindowUnhide();
+}
+
 - (NSApplicationDelegateReply) applicationShouldTerminate:(NSApplication *)sender
 {
 	if (!runMainLoop())
-- 
GitLab