fix #LINQT-1641 main window steals focus on macos

This commit is contained in:
gaelle.braud 2025-02-03 14:39:06 +01:00
parent 37a0403c01
commit a4809bbde5
5 changed files with 280 additions and 255 deletions

View file

@ -866,6 +866,15 @@ void App::setMainWindow(QQuickWindow *data) {
} }
} }
QQuickWindow *App::getLastActiveWindow() const {
return mLastActiveWindow;
}
void App::setLastActiveWindow(QQuickWindow *data) {
if (mLastActiveWindow != data) {
mLastActiveWindow = data;
}
}
QSharedPointer<AccountList> App::getAccountList() const { QSharedPointer<AccountList> App::getAccountList() const {
return mAccountList; return mAccountList;
} }
@ -1059,7 +1068,7 @@ bool App::event(QEvent *event) {
receivedMessage(0, url.toLocal8Bit()); receivedMessage(0, url.toLocal8Bit());
} else if (event->type() == QEvent::ApplicationStateChange) { } else if (event->type() == QEvent::ApplicationStateChange) {
auto state = static_cast<QApplicationStateChangeEvent *>(event); auto state = static_cast<QApplicationStateChangeEvent *>(event);
if (state->applicationState() == Qt::ApplicationActive) Utils::smartShowWindow(getMainWindow()); if (state->applicationState() == Qt::ApplicationActive) Utils::smartShowWindow(getLastActiveWindow());
} }
return SingleApplication::event(event); return SingleApplication::event(event);

View file

@ -131,6 +131,9 @@ public:
QQuickWindow *getMainWindow() const; QQuickWindow *getMainWindow() const;
void setMainWindow(QQuickWindow *data); void setMainWindow(QQuickWindow *data);
QQuickWindow *getLastActiveWindow() const;
void setLastActiveWindow(QQuickWindow *data);
QSharedPointer<AccountList> getAccountList() const; QSharedPointer<AccountList> getAccountList() const;
void setAccountList(QSharedPointer<AccountList> data); void setAccountList(QSharedPointer<AccountList> data);
Q_INVOKABLE AccountList *getAccounts() const; Q_INVOKABLE AccountList *getAccounts() const;
@ -182,6 +185,7 @@ private:
QSystemTrayIcon *mSystemTrayIcon = nullptr; QSystemTrayIcon *mSystemTrayIcon = nullptr;
QQuickWindow *mMainWindow = nullptr; QQuickWindow *mMainWindow = nullptr;
QQuickWindow *mCallsWindow = nullptr; QQuickWindow *mCallsWindow = nullptr;
QQuickWindow *mLastActiveWindow = nullptr;
QSharedPointer<SettingsCore> mSettings; QSharedPointer<SettingsCore> mSettings;
QSharedPointer<AccountList> mAccountList; QSharedPointer<AccountList> mAccountList;
QSharedPointer<CallList> mCallList; QSharedPointer<CallList> mCallList;

View file

@ -212,6 +212,13 @@ QQuickWindow *Utils::getMainWindow() {
return win; return win;
} }
QQuickWindow *Utils::getLastActiveWindow() {
return App::getInstance()->getLastActiveWindow();
}
void Utils::setLastActiveWindow(QQuickWindow *data) {
App::getInstance()->setLastActiveWindow(data);
}
void Utils::showInformationPopup(const QString &title, void Utils::showInformationPopup(const QString &title,
const QString &description, const QString &description,
bool isSuccess, bool isSuccess,
@ -239,6 +246,7 @@ void Utils::smartShowWindow(QQuickWindow *window) {
if (window->visibility() == QWindow::Maximized) // Avoid to change visibility mode if (window->visibility() == QWindow::Maximized) // Avoid to change visibility mode
window->showNormal(); window->showNormal();
else window->show(); else window->show();
App::getInstance()->setLastActiveWindow(window);
window->raise(); // Raise ensure to get focus on Mac window->raise(); // Raise ensure to get focus on Mac
window->requestActivate(); window->requestActivate();
} }

View file

@ -75,6 +75,8 @@ public:
Q_INVOKABLE static void setupConference(ConferenceInfoGui *confGui); Q_INVOKABLE static void setupConference(ConferenceInfoGui *confGui);
Q_INVOKABLE static QQuickWindow *getMainWindow(); Q_INVOKABLE static QQuickWindow *getMainWindow();
Q_INVOKABLE static void openCallsWindow(CallGui *call); Q_INVOKABLE static void openCallsWindow(CallGui *call);
Q_INVOKABLE static QQuickWindow *getLastActiveWindow();
Q_INVOKABLE static void setLastActiveWindow(QQuickWindow *data);
Q_INVOKABLE static void showInformationPopup(const QString &title, Q_INVOKABLE static void showInformationPopup(const QString &title,
const QString &description, const QString &description,
bool isSuccess = true, bool isSuccess = true,

View file

@ -9,269 +9,271 @@ import DesktopToolsCpp
import 'qrc:/qt/qml/Linphone/view/Style/buttonStyle.js' as ButtonStyle import 'qrc:/qt/qml/Linphone/view/Style/buttonStyle.js' as ButtonStyle
ApplicationWindow { ApplicationWindow {
id: mainWindow id: mainWindow
x: 0 x: 0
y: 0 y: 0
width: Math.min(1512 * DefaultStyle.dp, Screen.desktopAvailableWidth) width: Math.min(1512 * DefaultStyle.dp, Screen.desktopAvailableWidth)
height: Math.min(982 * DefaultStyle.dp, Screen.desktopAvailableHeight) height: Math.min(982 * DefaultStyle.dp, Screen.desktopAvailableHeight)
property bool isFullscreen: visibility == Window.FullScreen onActiveChanged: UtilsCpp.setLastActiveWindow(this)
onIsFullscreenChanged: DesktopToolsCpp.screenSaverStatus = !isFullscreen
property bool isFullscreen: visibility == Window.FullScreen
onIsFullscreenChanged: DesktopToolsCpp.screenSaverStatus = !isFullscreen
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: mainWindow.contentItem.forceActiveFocus() onClicked: mainWindow.contentItem.forceActiveFocus()
} }
Component { Component {
id: popupComp id: popupComp
InformationPopup{} InformationPopup{}
} }
Component{ Component{
id: confirmPopupComp id: confirmPopupComp
Dialog { Dialog {
property var requestDialog property var requestDialog
property int index property int index
property var callback: requestDialog?.result property var callback: requestDialog?.result
signal closePopup(int index) signal closePopup(int index)
onClosed: closePopup(index) onClosed: closePopup(index)
text: requestDialog?.message text: requestDialog?.message
details: requestDialog?.details details: requestDialog?.details
firstButtonAccept: title.length === 0 firstButtonAccept: title.length === 0
secondButtonAccept: title.length !== 0 secondButtonAccept: title.length !== 0
Component.onCompleted: if (details.length != 0) radius = 0 Component.onCompleted: if (details.length != 0) radius = 0
// For C++, requestDialog need to be call directly // For C++, requestDialog need to be call directly
onAccepted: requestDialog ? requestDialog.result(1) : callback(1) onAccepted: requestDialog ? requestDialog.result(1) : callback(1)
onRejected: requestDialog ? requestDialog.result(0) : callback(0) onRejected: requestDialog ? requestDialog.result(0) : callback(0)
width: title.length === 0 ? 278 * DefaultStyle.dp : 637 * DefaultStyle.dp width: title.length === 0 ? 278 * DefaultStyle.dp : 637 * DefaultStyle.dp
} }
} }
Popup { Popup {
id: startCallPopup id: startCallPopup
property FriendGui contact property FriendGui contact
property bool videoEnabled property bool videoEnabled
// if currentCall, transfer call to contact // if currentCall, transfer call to contact
property CallGui currentCall property CallGui currentCall
onContactChanged: { onContactChanged: {
console.log("contact changed", contact) console.log("contact changed", contact)
} }
underlineColor: DefaultStyle.main1_500_main underlineColor: DefaultStyle.main1_500_main
anchors.centerIn: parent anchors.centerIn: parent
width: 370 * DefaultStyle.dp width: 370 * DefaultStyle.dp
modal: true modal: true
leftPadding: 15 * DefaultStyle.dp leftPadding: 15 * DefaultStyle.dp
rightPadding: 15 * DefaultStyle.dp rightPadding: 15 * DefaultStyle.dp
topPadding: 20 * DefaultStyle.dp topPadding: 20 * DefaultStyle.dp
bottomPadding: 25 * DefaultStyle.dp bottomPadding: 25 * DefaultStyle.dp
contentItem: ColumnLayout { contentItem: ColumnLayout {
spacing: 16 * DefaultStyle.dp spacing: 16 * DefaultStyle.dp
RowLayout { RowLayout {
spacing: 5 * DefaultStyle.dp spacing: 5 * DefaultStyle.dp
width: startCallPopup.width width: startCallPopup.width
Text { Text {
text: qsTr("Quelle addresse souhaitez-vous appeler ?") text: qsTr("Quelle addresse souhaitez-vous appeler ?")
wrapMode: Text.Wrap wrapMode: Text.Wrap
Layout.fillWidth: true Layout.fillWidth: true
font { font {
pixelSize: 16 * DefaultStyle.dp pixelSize: 16 * DefaultStyle.dp
weight: 800 * DefaultStyle.dp weight: 800 * DefaultStyle.dp
} }
} }
RoundButton { RoundButton {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
style: ButtonStyle.noBackground style: ButtonStyle.noBackground
Layout.preferredWidth: 24 * DefaultStyle.dp Layout.preferredWidth: 24 * DefaultStyle.dp
Layout.preferredHeight: 24 * DefaultStyle.dp Layout.preferredHeight: 24 * DefaultStyle.dp
icon.source:AppIcons.closeX icon.source:AppIcons.closeX
onClicked: startCallPopup.close() onClicked: startCallPopup.close()
} }
} }
ListView { ListView {
id: popuplist id: popuplist
model: VariantList { model: VariantList {
model: startCallPopup.contact && startCallPopup.contact.core.allAddresses || [] model: startCallPopup.contact && startCallPopup.contact.core.allAddresses || []
} }
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: contentHeight Layout.preferredHeight: contentHeight
spacing: 10 * DefaultStyle.dp spacing: 10 * DefaultStyle.dp
delegate: Item { delegate: Item {
width: popuplist.width width: popuplist.width
height: 56 * DefaultStyle.dp height: 56 * DefaultStyle.dp
ColumnLayout { ColumnLayout {
width: popuplist.width width: popuplist.width
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
spacing: 10 * DefaultStyle.dp spacing: 10 * DefaultStyle.dp
ColumnLayout { ColumnLayout {
spacing: 7 * DefaultStyle.dp spacing: 7 * DefaultStyle.dp
Text { Text {
Layout.leftMargin: 5 * DefaultStyle.dp Layout.leftMargin: 5 * DefaultStyle.dp
text: modelData.label + " :" text: modelData.label + " :"
font { font {
pixelSize: 13 * DefaultStyle.dp pixelSize: 13 * DefaultStyle.dp
weight: 700 * DefaultStyle.dp weight: 700 * DefaultStyle.dp
} }
} }
Text { Text {
Layout.leftMargin: 5 * DefaultStyle.dp Layout.leftMargin: 5 * DefaultStyle.dp
text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(modelData.address) : modelData.address text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(modelData.address) : modelData.address
font { font {
pixelSize: 14 * DefaultStyle.dp pixelSize: 14 * DefaultStyle.dp
weight: 400 * DefaultStyle.dp weight: 400 * DefaultStyle.dp
} }
} }
} }
Rectangle { Rectangle {
visible: index != popuplist.model.count - 1 visible: index != popuplist.model.count - 1
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 1 * DefaultStyle.dp Layout.preferredHeight: 1 * DefaultStyle.dp
color: DefaultStyle.main2_200 color: DefaultStyle.main2_200
} }
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
onClicked: { onClicked: {
if (startCallPopup.currentCall) startCallPopup.currentCall.core.lTransferCall(modelData.address) if (startCallPopup.currentCall) startCallPopup.currentCall.core.lTransferCall(modelData.address)
else UtilsCpp.createCall(modelData.address, {'localVideoEnabled': startCallPopup.videoEnabled}) else UtilsCpp.createCall(modelData.address, {'localVideoEnabled': startCallPopup.videoEnabled})
startCallPopup.close() startCallPopup.close()
} }
} }
} }
} }
} }
} }
function startCallWithContact(contact, videoEnabled, parentItem) { function startCallWithContact(contact, videoEnabled, parentItem) {
if (parentItem == undefined) parentItem = mainWindow.contentItem if (parentItem == undefined) parentItem = mainWindow.contentItem
startCallPopup.parent = parentItem startCallPopup.parent = parentItem
if (contact) { if (contact) {
console.log("START CALL WITH", contact.core.fullName, "addresses count", contact.core.allAddresses.length) console.log("START CALL WITH", contact.core.fullName, "addresses count", contact.core.allAddresses.length)
if (contact.core.allAddresses.length > 1) { if (contact.core.allAddresses.length > 1) {
startCallPopup.contact = contact startCallPopup.contact = contact
startCallPopup.videoEnabled = videoEnabled startCallPopup.videoEnabled = videoEnabled
startCallPopup.open() startCallPopup.open()
} else { } else {
var addressToCall = contact.core.defaultAddress.length === 0 var addressToCall = contact.core.defaultAddress.length === 0
? contact.core.phoneNumbers.length === 0 ? contact.core.phoneNumbers.length === 0
? "" ? ""
: contact.core.phoneNumbers[0].address : contact.core.phoneNumbers[0].address
: contact.core.defaultAddress : contact.core.defaultAddress
if (addressToCall.length != 0) UtilsCpp.createCall(addressToCall, {'localVideoEnabled':videoEnabled}) if (addressToCall.length != 0) UtilsCpp.createCall(addressToCall, {'localVideoEnabled':videoEnabled})
} }
} }
} }
function transferCallToContact(call, contact, parentItem) { function transferCallToContact(call, contact, parentItem) {
if (!call || !contact) return if (!call || !contact) return
if (parentItem == undefined) parentItem = mainWindow.contentItem if (parentItem == undefined) parentItem = mainWindow.contentItem
startCallPopup.parent = parentItem startCallPopup.parent = parentItem
if (contact) { if (contact) {
console.log("[AbstractWindow] Transfer call to", contact.core.fullName, "addresses count", contact.core.allAddresses.length, call) console.log("[AbstractWindow] Transfer call to", contact.core.fullName, "addresses count", contact.core.allAddresses.length, call)
if (contact.core.allAddresses.length > 1) { if (contact.core.allAddresses.length > 1) {
startCallPopup.contact = contact startCallPopup.contact = contact
startCallPopup.currentCall = call startCallPopup.currentCall = call
startCallPopup.open() startCallPopup.open()
} else { } else {
var addressToCall = contact.core.defaultAddress.length === 0 var addressToCall = contact.core.defaultAddress.length === 0
? contact.core.phoneNumbers.length === 0 ? contact.core.phoneNumbers.length === 0
? "" ? ""
: contact.core.phoneNumbers[0].address : contact.core.phoneNumbers[0].address
: contact.core.defaultAddress : contact.core.defaultAddress
if (addressToCall.length != 0) call.core.lTransferCall(addressToCall) if (addressToCall.length != 0) call.core.lTransferCall(addressToCall)
} }
} }
} }
function removeFromPopupLayout(index) { function removeFromPopupLayout(index) {
popupLayout.popupList.splice(index, 1) popupLayout.popupList.splice(index, 1)
} }
function showInformationPopup(title, description, isSuccess) { function showInformationPopup(title, description, isSuccess) {
if (isSuccess == undefined) isSuccess = true if (isSuccess == undefined) isSuccess = true
var infoPopup = popupComp.createObject(popupLayout, {"title": title, "description": description, "isSuccess": isSuccess}) var infoPopup = popupComp.createObject(popupLayout, {"title": title, "description": description, "isSuccess": isSuccess})
infoPopup.index = popupLayout.popupList.length infoPopup.index = popupLayout.popupList.length
popupLayout.popupList.push(infoPopup) popupLayout.popupList.push(infoPopup)
infoPopup.open() infoPopup.open()
infoPopup.closePopup.connect(removeFromPopupLayout) infoPopup.closePopup.connect(removeFromPopupLayout)
} }
function showLoadingPopup(text, cancelButtonVisible, callback) { function showLoadingPopup(text, cancelButtonVisible, callback) {
if (cancelButtonVisible == undefined) cancelButtonVisible = false if (cancelButtonVisible == undefined) cancelButtonVisible = false
loadingPopup.text = text loadingPopup.text = text
loadingPopup.callback = callback loadingPopup.callback = callback
loadingPopup.cancelButtonVisible = cancelButtonVisible loadingPopup.cancelButtonVisible = cancelButtonVisible
loadingPopup.open() loadingPopup.open()
} }
function closeLoadingPopup() { function closeLoadingPopup() {
loadingPopup.close() loadingPopup.close()
} }
function showConfirmationPopup(requestDialog){ function showConfirmationPopup(requestDialog){
console.log("Showing confirmation popup") console.log("Showing confirmation popup")
var popup = confirmPopupComp.createObject(popupLayout, {"requestDialog": requestDialog}) var popup = confirmPopupComp.createObject(popupLayout, {"requestDialog": requestDialog})
popup.open() popup.open()
popup.closePopup.connect(removeFromPopupLayout) popup.closePopup.connect(removeFromPopupLayout)
} }
function showConfirmationLambdaPopup(title,text, details, callback, firstButtonText, secondButtonText, customContent){ function showConfirmationLambdaPopup(title,text, details, callback, firstButtonText, secondButtonText, customContent){
console.log("Showing confirmation lambda popup") console.log("Showing confirmation lambda popup")
var popup = confirmPopupComp.createObject(popupLayout, {"title": title, "text": text, "details":details,"callback":callback}) var popup = confirmPopupComp.createObject(popupLayout, {"title": title, "text": text, "details":details,"callback":callback})
if (firstButtonText != undefined) popup.firstButtonText = firstButtonText if (firstButtonText != undefined) popup.firstButtonText = firstButtonText
if (secondButtonText != undefined) popup.secondButtonText = secondButtonText if (secondButtonText != undefined) popup.secondButtonText = secondButtonText
if (customContent != undefined) popup.content = customContent if (customContent != undefined) popup.content = customContent
popup.titleColor = DefaultStyle.main1_500_main popup.titleColor = DefaultStyle.main1_500_main
popup.open() popup.open()
popup.closePopup.connect(removeFromPopupLayout) popup.closePopup.connect(removeFromPopupLayout)
} }
ColumnLayout { ColumnLayout {
id: popupLayout id: popupLayout
anchors.fill: parent anchors.fill: parent
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
property int nextY: mainWindow.height property int nextY: mainWindow.height
property list<InformationPopup> popupList property list<InformationPopup> popupList
property int popupCount: popupList.length property int popupCount: popupList.length
spacing: 15 * DefaultStyle.dp spacing: 15 * DefaultStyle.dp
onPopupCountChanged: { onPopupCountChanged: {
nextY = mainWindow.height nextY = mainWindow.height
for(var i = 0; i < popupCount; ++i) { for(var i = 0; i < popupCount; ++i) {
var popupItem = popupList[i] var popupItem = popupList[i]
if( popupItem ){ if( popupItem ){
popupItem.y = nextY - popupItem.height popupItem.y = nextY - popupItem.height
popupItem.index = i popupItem.index = i
nextY = nextY - popupItem.height - 15 nextY = nextY - popupItem.height - 15
} }
} }
} }
} }
LoadingPopup { LoadingPopup {
id: loadingPopup id: loadingPopup
modal: true modal: true
closePolicy: Popup.NoAutoClose closePolicy: Popup.NoAutoClose
anchors.centerIn: parent anchors.centerIn: parent
padding: 20 * DefaultStyle.dp padding: 20 * DefaultStyle.dp
underlineColor: DefaultStyle.main1_500_main underlineColor: DefaultStyle.main1_500_main
radius: 15 * DefaultStyle.dp radius: 15 * DefaultStyle.dp
} }
FPSCounter{ FPSCounter{
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
height: 50 height: 50
width: fpsText.implicitWidth width: fpsText.implicitWidth
z: 100 z: 100
visible: !SettingsCpp.hideFps visible: !SettingsCpp.hideFps
Text{ Text{
id: fpsText id: fpsText
font.bold: true font.bold: true
font.italic: true font.italic: true
font.pixelSize: 14 * DefaultStyle.dp font.pixelSize: 14 * DefaultStyle.dp
text: parent.fps + " FPS" text: parent.fps + " FPS"
color: parent.fps < 30 ? DefaultStyle.danger_500main : DefaultStyle.main2_900 color: parent.fps < 30 ? DefaultStyle.danger_500main : DefaultStyle.main2_900
} }
} }
} }