fix: ui call view

This patch fix the problems:
- exit full screen mode when call is finished
- clean up last video picture when call is finished
- hide call options if no mouse activity detected
- resize video to use full screen

Change-Id: I7544dd616e88e35cacf3ca8c60d65aedbfe14860
Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
diff --git a/src/CurrentCallVC.mm b/src/CurrentCallVC.mm
index 0993f93..2d8f351 100644
--- a/src/CurrentCallVC.mm
+++ b/src/CurrentCallVC.mm
@@ -177,6 +177,8 @@
     [loadingIndicator setInnerMargin:30];
 
     [self.videoView setCallDelegate:self];
+    CGColor* color = [[[NSColor blackColor] colorWithAlphaComponent:0.2] CGColor];
+    [headerContainer.layer setBackgroundColor:color];
 }
 
 -(void) updateDurationLabel
@@ -217,7 +219,6 @@
     if (convIt != accountInfo_->conversationModel->allFilteredConversations().end())
         [personLabel setStringValue:bestNameForConversation(*convIt, *accountInfo_->conversationModel)];
     [timeSpentLabel setStringValue:@(callModel->getFormattedCallDuration(callUid_).c_str())];
-    [timeSpentLabel setHidden:NO];
     if (refreshDurationTimer == nil)
         refreshDurationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                                 target:self
@@ -227,13 +228,12 @@
     [stateLabel setStringValue:@(to_string(currentCall.status).c_str())];
 
     if (firstRun) {
-        //QVariant photo = GlobalInstances::pixmapManipulator().callPhoto(current, QSize(100,100));
+       // QVariant photo = GlobalInstances::pixmapManipulator().callPhoto(currentCall, QSize(100,100), NO);
         //[personPhoto setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
     }
 
     // Default values for this views
     [loadingIndicator setHidden:YES];
-    [videoView setShouldAcceptInteractions:NO];
     [ringingPanel setHidden:YES];
     [outgoingPanel setHidden:YES];
     [controlsPanel setHidden:NO];
@@ -263,6 +263,7 @@
         case Status::PEER_PAUSED:
         case Status::INACTIVE:
         case Status::IN_PROGRESS:
+            [timeSpentLabel setHidden:NO];
         case Status::CONNECTED:
         case Status::AUTO_ANSWERING:
             break;
@@ -350,6 +351,8 @@
                                          &lrc::api::NewCallModel::remotePreviewStarted,
                                          [self](const std::string& callId, Video::Renderer* renderer) {
                                              NSLog(@"Video started!");
+                                             [videoView setShouldAcceptInteractions:YES];
+                                             [self mouseIsMoving: NO];
                                              [self connectVideoRenderer:renderer];
                                          });
 
@@ -413,6 +416,8 @@
     videoHolder.started = QObject::connect(renderer,
                      &Video::Renderer::started,
                      [=]() {
+                         [self mouseIsMoving: NO];
+                         [videoView setShouldAcceptInteractions:YES];
                          QObject::disconnect(videoHolder.frameUpdated);
                          videoHolder.frameUpdated = QObject::connect(renderer,
                                                                      &Video::Renderer::frameUpdated,
@@ -424,6 +429,8 @@
     videoHolder.stopped = QObject::connect(renderer,
                      &Video::Renderer::stopped,
                      [=]() {
+                         [self mouseIsMoving: YES];
+                         [videoView setShouldAcceptInteractions:NO];
                          QObject::disconnect(videoHolder.frameUpdated);
                          [(CallLayer*)videoView.layer setVideoRunning:NO];
                      });
@@ -516,6 +523,7 @@
     QObject::disconnect(previewHolder.started);
     QObject::disconnect(self.messageConnection);
     [previewView.layer setContents:nil];
+    [(CallLayer*)videoView.layer setVideoRunning:NO];
 
     [_brokerPopoverVC performClose:self];
     [self.addToContactPopover performClose:self];
@@ -546,7 +554,8 @@
     auto* convModel = accountInfo_->conversationModel.get();
 
     // when call comes in we want to show the controls/header
-    [self mouseIsMoving:YES];
+    [self mouseIsMoving: YES];
+    [videoView setShouldAcceptInteractions: NO];
 
     [self connectVideoSignals];
     /* check if text media is already present */
@@ -604,6 +613,7 @@
     }
 
     if (!animate) {
+        [self cleanUp];
         [self.view setHidden:YES];
         return;
     }
diff --git a/src/views/CallLayer.mm b/src/views/CallLayer.mm
index 444fe2f..f04a9eb 100644
--- a/src/views/CallLayer.mm
+++ b/src/views/CallLayer.mm
@@ -180,10 +180,21 @@
 
         GLint inScalingUniform = glGetUniformLocation(sProg, "in_Scaling");
 
-        if (ratio < 1.0)
-            glUniform2f(inScalingUniform, 1.0, ratio);
-        else
-            glUniform2f(inScalingUniform, 1.0/ratio, 1.0);
+        float multiplier = MAX(frameRatio, ratio);
+        if((viewRatio >= 1 && frameRatio >= 1) ||
+           (viewRatio < 1 && frameRatio < 1) ||
+           (ratio > 0.5 && ratio < 1.5) ) {
+            if (ratio > 1.0)
+                glUniform2f(inScalingUniform, 1.0, 1.0 * ratio);
+            else
+                glUniform2f(inScalingUniform, 1.0/ratio, 1.0);
+        } else {
+            if (ratio < 1.0)
+                glUniform2f(inScalingUniform, 1.0, 1.0 * ratio);
+            else
+                glUniform2f(inScalingUniform, 1.0/ratio, 1.0);
+
+        }
     }
     [currentFrameLk unlock];
 
diff --git a/src/views/CallView.mm b/src/views/CallView.mm
index c70338a..e0ebfc4 100644
--- a/src/views/CallView.mm
+++ b/src/views/CallView.mm
@@ -201,10 +201,10 @@
 
 - (void)mouseMoved:(NSEvent *)theEvent
 {
-    [NSObject cancelPreviousPerformRequestsWithTarget:self]; // cancel showContextualMenu
-    [self performSelector:@selector(mouseIdle:) withObject:theEvent afterDelay:3];
-    if (self.callDelegate)
-        [self.callDelegate mouseIsMoving:YES];
+        [NSObject cancelPreviousPerformRequestsWithTarget:self]; // cancel showContextualMenu
+        [self performSelector:@selector(mouseIdle:) withObject:theEvent afterDelay:3];
+        if (self.callDelegate && shouldAcceptInteractions)
+            [self.callDelegate mouseIsMoving:YES];
 }
 
 - (void) mouseIdle:(NSEvent *)theEvent
@@ -225,8 +225,9 @@
     else if([theEvent clickCount] == 2)
     {
         [NSObject cancelPreviousPerformRequestsWithTarget:self]; // cancel showContextualMenu
-        if(self.callDelegate)
+        if(self.callDelegate) {
             [self.callDelegate callShouldToggleFullScreen];
+        }
     }
 }