2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-07 18:15:15 +00:00

Implement parent setting for portal and gtk dialogs on Wayland via xdg-foreign-v2

This commit is contained in:
Ilya Fedin
2021-05-10 12:53:34 +04:00
committed by John Preston
parent 7de8d6f9ac
commit 680a9a7ca7
10 changed files with 204 additions and 90 deletions

View File

@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/platform_file_utilities.h"
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "platform/linux/linux_wayland_integration.h"
#include "storage/localstorage.h"
#include "base/openssl_help.h"
#include "base/qt_adapters.h"
@@ -20,6 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <glibmm.h>
#include <giomm.h>
using Platform::internal::WaylandIntegration;
namespace Platform {
namespace FileDialog {
namespace XDP {
@@ -207,7 +210,7 @@ private:
uint _requestSignalId = 0;
// Options
WId _winId = 0;
QWindow *_parent = nullptr;
QFileDialog::Options _options;
QFileDialog::AcceptMode _acceptMode = QFileDialog::AcceptOpen;
QFileDialog::FileMode _fileMode = QFileDialog::ExistingFile;
@@ -266,8 +269,13 @@ XDPFileDialog::~XDPFileDialog() {
void XDPFileDialog::openPortal() {
std::stringstream parentWindowId;
if (IsX11()) {
parentWindowId << "x11:" << std::hex << _winId;
if (const auto integration = WaylandIntegration::Instance()) {
if (const auto handle = integration->nativeHandle(_parent)
; !handle.isEmpty()) {
parentWindowId << "wayland:" << handle.toStdString();
}
} else if (IsX11() && _parent) {
parentWindowId << "x11:" << std::hex << _parent->winId();
}
std::map<Glib::ustring, Glib::VariantBase> options;
@@ -408,7 +416,7 @@ void XDPFileDialog::openPortal() {
+ uniqueName
+ '/'
+ handleToken;
const auto responseCallback = crl::guard(this, [=](
const Glib::RefPtr<Gio::DBus::Connection> &connection,
const Glib::ustring &sender_name,
@@ -629,7 +637,7 @@ void XDPFileDialog::showHelper(
Qt::WindowModality windowModality,
QWindow *parent) {
_modal = windowModality != Qt::NonModal;
_winId = parent ? parent->winId() : 0;
_parent = parent;
openPortal();
}