From 4dcb43092bfac44d5e1280306d5fe99495f07416 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 25 Apr 2017 16:46:11 +0200 Subject: [PATCH] feat(app): show correctly windows on mac/GNU Linux/windows --- linphone-desktop/src/Utils.cpp | 10 +++++++++- linphone-desktop/src/Utils.hpp | 7 +++++++ linphone-desktop/src/app/App.cpp | 12 +++++++----- linphone-desktop/src/components/call/CallModel.cpp | 4 ++-- .../src/components/calls/CallsListModel.cpp | 2 +- linphone-desktop/ui/scripts/Utils/utils.js | 10 ++++++++++ linphone-desktop/ui/views/App/Main/MainWindow.js | 6 +----- 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/linphone-desktop/src/Utils.cpp b/linphone-desktop/src/Utils.cpp index a5acd2831..511e1826f 100644 --- a/linphone-desktop/src/Utils.cpp +++ b/linphone-desktop/src/Utils.cpp @@ -20,10 +20,18 @@ * Author: Ronan Abhamon */ - #include "Utils.hpp" +#include + +#include "Utils.hpp" // ============================================================================= +void Utils::smartShowWindow (QQuickWindow *window) { + window->show(); + window->raise(); + window->requestActivate(); +} + char *Utils::rstrstr (const char *a, const char *b) { size_t a_len = strlen(a); size_t b_len = strlen(b); diff --git a/linphone-desktop/src/Utils.hpp b/linphone-desktop/src/Utils.hpp index 98babd87a..4c3b9e20b 100644 --- a/linphone-desktop/src/Utils.hpp +++ b/linphone-desktop/src/Utils.hpp @@ -28,6 +28,8 @@ // ============================================================================= +class QQuickWindow; + namespace Utils { inline QString linphoneStringToQString (const std::string &string) { return QString::fromLocal8Bit(string.c_str(), static_cast(string.size())); @@ -50,6 +52,11 @@ namespace Utils { return findParentType(parent); } + // Bring a window to front. + // See: http://stackoverflow.com/questions/6087887/bring-window-to-front-raise-show-activatewindow-don-t-work + void smartShowWindow (QQuickWindow *window); + + // Reverse function of strstr. char *rstrstr (const char *a, const char *b); } diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp index 568185eac..848b3a3b8 100644 --- a/linphone-desktop/src/app/App.cpp +++ b/linphone-desktop/src/app/App.cpp @@ -163,7 +163,7 @@ void App::initContentApp () { QObject::connect( this, &App::receivedMessage, this, [this](int, QByteArray message) { if (message == "show") - getMainWindow()->showNormal(); + Utils::smartShowWindow(getMainWindow()); } ); } @@ -338,7 +338,9 @@ void App::setTrayIcon () { root->connect(quitAction, &QAction::triggered, this, &App::quit); QAction *restoreAction = new QAction("Restore", root); - root->connect(restoreAction, &QAction::triggered, root, &QQuickWindow::showNormal); + root->connect(restoreAction, &QAction::triggered, root, [root] { + Utils::smartShowWindow(root); + }); // trayIcon: Left click actions. QMenu *menu = new QMenu(); @@ -348,7 +350,7 @@ void App::setTrayIcon () { ) { if (reason == QSystemTrayIcon::Trigger) { if (root->visibility() == QWindow::Hidden) - root->showNormal(); + Utils::smartShowWindow(root); else root->hide(); } @@ -404,9 +406,9 @@ void App::openAppAfterInit () { setTrayIcon(); if (!mParser.isSet("iconified")) - getMainWindow()->showNormal(); + Utils::smartShowWindow(getMainWindow()); #else - getMainWindow()->showNormal(); + Utils::smartShowWindow(getMainWindow()); #endif // ifndef __APPLE__ } diff --git a/linphone-desktop/src/components/call/CallModel.cpp b/linphone-desktop/src/components/call/CallModel.cpp index 37d5dd964..2fec38a7c 100644 --- a/linphone-desktop/src/components/call/CallModel.cpp +++ b/linphone-desktop/src/components/call/CallModel.cpp @@ -148,7 +148,7 @@ void CallModel::accept () { params->enableVideo(false); setRecordFile(params); - App::getInstance()->getCallsWindow()->show(); + Utils::smartShowWindow(App::getInstance()->getCallsWindow()); mLinphoneCall->acceptWithParams(params); } @@ -160,7 +160,7 @@ void CallModel::acceptWithVideo () { params->enableVideo(true); setRecordFile(params); - App::getInstance()->getCallsWindow()->show(); + Utils::smartShowWindow(App::getInstance()->getCallsWindow()); mLinphoneCall->acceptWithParams(params); } diff --git a/linphone-desktop/src/components/calls/CallsListModel.cpp b/linphone-desktop/src/components/calls/CallsListModel.cpp index d30ea3886..62534372f 100644 --- a/linphone-desktop/src/components/calls/CallsListModel.cpp +++ b/linphone-desktop/src/components/calls/CallsListModel.cpp @@ -172,7 +172,7 @@ bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent) void CallsListModel::addCall (const shared_ptr &linphoneCall) { if (linphoneCall->getDir() == linphone::CallDirOutgoing) - App::getInstance()->getCallsWindow()->show(); + Utils::smartShowWindow(App::getInstance()->getCallsWindow()); CallModel *call = new CallModel(linphoneCall); diff --git a/linphone-desktop/ui/scripts/Utils/utils.js b/linphone-desktop/ui/scripts/Utils/utils.js index af8f1249c..5e5fbebbf 100644 --- a/linphone-desktop/ui/scripts/Utils/utils.js +++ b/linphone-desktop/ui/scripts/Utils/utils.js @@ -205,6 +205,16 @@ function setTimeout (parent, delay, cb) { return timer } +// ----------------------------------------------------------------------------- + +// Bring a window to front. +// See: http://stackoverflow.com/questions/6087887/bring-window-to-front-raise-show-activatewindow-don-t-work +function smartShowWindow (window) { + window.show() + window.raise() + window.requestActivate() +} + // ============================================================================= // GENERIC. // ============================================================================= diff --git a/linphone-desktop/ui/views/App/Main/MainWindow.js b/linphone-desktop/ui/views/App/Main/MainWindow.js index 796f61bf9..de36d0404 100644 --- a/linphone-desktop/ui/views/App/Main/MainWindow.js +++ b/linphone-desktop/ui/views/App/Main/MainWindow.js @@ -28,11 +28,7 @@ function unlockView () { function setView (view, props) { function apply (view, props) { - if (window.visibility === Window.Minimized) { - window.visibility = Window.AutomaticVisibility - } else { - window.setVisible(true) - } + Utils.smartShowWindow(window) var item = mainLoader.item