diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ Notifications Wayland WidgetsAddons + WindowSystem ) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,7 @@ session.cpp screenshot.cpp screenshotdialog.cpp + utils.cpp ) if (SCREENCAST_ENABLED) @@ -50,6 +51,7 @@ KF5::Notifications KF5::WaylandClient KF5::WidgetsAddons + KF5::WindowSystem ) if (SCREENCAST_ENABLED) diff --git a/src/access.cpp b/src/access.cpp --- a/src/access.cpp +++ b/src/access.cpp @@ -19,6 +19,7 @@ #include "access.h" #include "accessdialog.h" +#include "utils.h" #include @@ -54,6 +55,7 @@ qCDebug(XdgDesktopPortalKdeAccess) << " options: " << options; auto accessDialog = new ::AccessDialog(); + Utils::setParentWindow(accessDialog, parent_window); accessDialog->setBody(body); accessDialog->setTitle(title); accessDialog->setSubtitle(subtitle); diff --git a/src/appchooser.cpp b/src/appchooser.cpp --- a/src/appchooser.cpp +++ b/src/appchooser.cpp @@ -19,6 +19,7 @@ #include "appchooser.h" #include "appchooserdialog.h" +#include "utils.h" #include @@ -57,6 +58,7 @@ } AppChooserDialog *appDialog = new AppChooserDialog(choices, latestChoice, options.value(QLatin1String("filename")).toString()); + Utils::setParentWindow(appDialog, parent_window); if (appDialog->exec()) { results.insert(QLatin1String("choice"), appDialog->selectedApplication()); diff --git a/src/filechooser.cpp b/src/filechooser.cpp --- a/src/filechooser.cpp +++ b/src/filechooser.cpp @@ -19,6 +19,7 @@ */ #include "filechooser.h" +#include "utils.h" #include #include @@ -153,6 +154,7 @@ } QFileDialog *fileDialog = new QFileDialog(); + Utils::setParentWindow(fileDialog, parent_window); fileDialog->setWindowTitle(title); fileDialog->setModal(modalDialog); fileDialog->setFileMode(multipleFiles ? QFileDialog::ExistingFiles : QFileDialog::ExistingFile); @@ -245,6 +247,7 @@ } QFileDialog *fileDialog = new QFileDialog(); + Utils::setParentWindow(fileDialog, parent_window); fileDialog->setWindowTitle(title); fileDialog->setModal(modalDialog); fileDialog->setAcceptMode(QFileDialog::AcceptSave); diff --git a/src/print.cpp b/src/print.cpp --- a/src/print.cpp +++ b/src/print.cpp @@ -19,6 +19,7 @@ */ #include "print.h" +#include "utils.h" #include @@ -599,6 +600,7 @@ printer->setPageMargins(pageMargins, QPageLayout::Millimeter); QPrintDialog *printDialog = new QPrintDialog(printer); + Utils::setParentWindow(printDialog, parent_window); // Process options diff --git a/src/screencast.cpp b/src/screencast.cpp --- a/src/screencast.cpp +++ b/src/screencast.cpp @@ -22,6 +22,7 @@ #include "session.h" #include "screencaststream.h" #include "screenchooserdialog.h" +#include "utils.h" #include #include @@ -407,6 +408,7 @@ } QScopedPointer screenDialog(new ScreenChooserDialog(m_outputMap, session->multipleSources())); + Utils::setParentWindow(screenDialog.data(), parent_window); if (screenDialog->exec()) { ScreenCastPortalOutput selectedOutput = m_outputMap.value(screenDialog->selectedScreens().first()); diff --git a/src/screenshot.cpp b/src/screenshot.cpp --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -20,6 +20,7 @@ #include "screenshot.h" #include "screenshotdialog.h" +#include "utils.h" #include #include @@ -99,6 +100,7 @@ qCDebug(XdgDesktopPortalKdeScreenshot) << " options: " << options; QPointer screenshotDialog = new ScreenshotDialog; + Utils::setParentWindow(screenshotDialog, parent_window); const bool modal = options.value(QLatin1String("modal"), false).toBool(); screenshotDialog->setModal(modal); diff --git a/src/utils.h b/src/utils.h new file mode 100644 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2018 Alexander Volkov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef XDG_DESKTOP_PORTAL_KDE_UTILS_H +#define XDG_DESKTOP_PORTAL_KDE_UTILS_H + +class QString; +class QWidget; + +class Utils +{ +public: + static void setParentWindow(QWidget *w, const QString &parent_window); +}; + +#endif // XDG_DESKTOP_PORTAL_KDE_UTILS_H diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,31 @@ +/* + * Copyright © 2018 Alexander Volkov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "utils.h" + +#include + +#include +#include +#include + +void Utils::setParentWindow(QWidget *w, const QString &parent_window) +{ + if (parent_window.startsWith(QLatin1String("x11:"))) { + KWindowSystem::setMainWindow(w, parent_window.midRef(4).toULongLong(nullptr, 16)); + } +}