2016-07-06 18:30:14 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-06 18:30:14 +00:00
|
|
|
*/
|
|
|
|
#include "platform/linux/linux_gdk_helper.h"
|
|
|
|
|
2021-05-10 08:53:34 +00:00
|
|
|
#include "base/platform/linux/base_linux_gtk_integration.h"
|
2021-02-19 00:37:06 +00:00
|
|
|
#include "base/platform/linux/base_linux_gtk_integration_p.h"
|
2021-01-10 03:51:38 +00:00
|
|
|
#include "platform/linux/linux_gtk_integration_p.h"
|
2021-05-10 08:53:34 +00:00
|
|
|
#include "platform/linux/linux_wayland_integration.h"
|
|
|
|
|
|
|
|
#include <QtGui/QWindow>
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
} // extern "C"
|
2021-02-22 13:41:25 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2021-05-10 08:53:34 +00:00
|
|
|
// CentOS 7 seem to be too old for needed definitions,
|
|
|
|
// so don't include until we link to gtk directly.
|
|
|
|
#if !defined DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION && defined LINK_TO_GTK
|
|
|
|
extern "C" {
|
|
|
|
#include <gdk/gdkwayland.h>
|
|
|
|
} // extern "C"
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION && LINK_TO_GTK
|
|
|
|
|
2016-07-06 18:30:14 +00:00
|
|
|
namespace Platform {
|
|
|
|
namespace internal {
|
2021-05-10 08:53:34 +00:00
|
|
|
namespace {
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2021-05-10 08:53:34 +00:00
|
|
|
using base::Platform::GtkIntegration;
|
2021-01-10 03:51:38 +00:00
|
|
|
using namespace Platform::Gtk;
|
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
// To be able to compile with gtk-3.0 headers as well
|
|
|
|
#define GdkDrawable GdkWindow
|
|
|
|
|
|
|
|
// Gtk 2
|
2021-01-02 04:34:04 +00:00
|
|
|
using f_gdk_x11_drawable_get_xdisplay = Display*(*)(GdkDrawable*);
|
|
|
|
f_gdk_x11_drawable_get_xdisplay gdk_x11_drawable_get_xdisplay = nullptr;
|
|
|
|
|
2016-07-06 18:30:14 +00:00
|
|
|
using f_gdk_x11_drawable_get_xid = XID(*)(GdkDrawable*);
|
|
|
|
f_gdk_x11_drawable_get_xid gdk_x11_drawable_get_xid = nullptr;
|
|
|
|
|
|
|
|
// Gtk 3
|
|
|
|
using f_gdk_x11_window_get_type = GType (*)(void);
|
|
|
|
f_gdk_x11_window_get_type gdk_x11_window_get_type = nullptr;
|
|
|
|
|
2016-07-07 16:12:52 +00:00
|
|
|
// To be able to compile with gtk-2.0 headers as well
|
|
|
|
template <typename Object>
|
|
|
|
inline bool gdk_is_x11_window_check(Object *obj) {
|
2021-01-10 03:51:38 +00:00
|
|
|
return g_type_cit_helper(obj, gdk_x11_window_get_type());
|
2016-07-07 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-02 04:34:04 +00:00
|
|
|
using f_gdk_window_get_display = GdkDisplay*(*)(GdkWindow *window);
|
|
|
|
f_gdk_window_get_display gdk_window_get_display = nullptr;
|
|
|
|
|
|
|
|
using f_gdk_x11_display_get_xdisplay = Display*(*)(GdkDisplay *display);
|
|
|
|
f_gdk_x11_display_get_xdisplay gdk_x11_display_get_xdisplay = nullptr;
|
|
|
|
|
2016-07-06 18:30:14 +00:00
|
|
|
using f_gdk_x11_window_get_xid = Window(*)(GdkWindow *window);
|
|
|
|
f_gdk_x11_window_get_xid gdk_x11_window_get_xid = nullptr;
|
2021-02-22 13:41:25 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2021-05-10 08:53:34 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
|
|
|
|
using f_gdk_wayland_window_get_type = GType (*)(void);
|
|
|
|
f_gdk_wayland_window_get_type gdk_wayland_window_get_type = nullptr;
|
|
|
|
|
|
|
|
template <typename Object>
|
|
|
|
inline bool gdk_is_wayland_window_check(Object *obj) {
|
|
|
|
return g_type_cit_helper(obj, gdk_wayland_window_get_type());
|
|
|
|
}
|
|
|
|
|
|
|
|
using f_gdk_wayland_window_set_transient_for_exported = gboolean(*)(GdkWindow *window, char *parent_handle_str);
|
|
|
|
f_gdk_wayland_window_set_transient_for_exported gdk_wayland_window_set_transient_for_exported = nullptr;
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
|
|
|
|
|
|
|
|
void GdkHelperLoadGtk2(QLibrary &lib) {
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2021-05-10 08:53:34 +00:00
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_x11_drawable_get_xdisplay);
|
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_x11_drawable_get_xid);
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 08:53:34 +00:00
|
|
|
void GdkHelperLoadGtk3(QLibrary &lib) {
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2021-05-10 08:53:34 +00:00
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_x11_window_get_type);
|
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_window_get_display);
|
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_x11_display_get_xdisplay);
|
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_x11_window_get_xid);
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
|
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_wayland_window_get_type);
|
|
|
|
LOAD_GTK_SYMBOL(lib, gdk_wayland_window_set_transient_for_exported);
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 08:53:34 +00:00
|
|
|
} // namespace
|
|
|
|
|
2016-07-06 18:30:14 +00:00
|
|
|
void GdkHelperLoad(QLibrary &lib) {
|
2021-05-10 08:53:34 +00:00
|
|
|
if (const auto integration = GtkIntegration::Instance()) {
|
|
|
|
if (integration->checkVersion(3, 0, 0)) {
|
|
|
|
GdkHelperLoadGtk3(lib);
|
|
|
|
} else {
|
|
|
|
GdkHelperLoadGtk2(lib);
|
|
|
|
}
|
2016-07-06 18:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-10 08:53:34 +00:00
|
|
|
void GdkSetTransientFor(GdkWindow *window, QWindow *parent) {
|
|
|
|
#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
|
|
|
|
if (gdk_wayland_window_get_type != nullptr
|
|
|
|
&& gdk_wayland_window_set_transient_for_exported != nullptr
|
|
|
|
&& gdk_is_wayland_window_check(window)) {
|
|
|
|
if (const auto integration = WaylandIntegration::Instance()) {
|
|
|
|
if (const auto handle = integration->nativeHandle(parent)
|
|
|
|
; !handle.isEmpty()) {
|
|
|
|
auto handleUtf8 = handle.toUtf8();
|
|
|
|
gdk_wayland_window_set_transient_for_exported(
|
|
|
|
window,
|
|
|
|
handleUtf8.data());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
|
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2021-05-10 08:53:34 +00:00
|
|
|
if (gdk_x11_window_get_type != nullptr
|
|
|
|
&& gdk_x11_display_get_xdisplay != nullptr
|
|
|
|
&& gdk_x11_window_get_xid != nullptr
|
|
|
|
&& gdk_window_get_display != nullptr
|
|
|
|
&& gdk_is_x11_window_check(window)) {
|
|
|
|
XSetTransientForHint(
|
|
|
|
gdk_x11_display_get_xdisplay(gdk_window_get_display(window)),
|
|
|
|
gdk_x11_window_get_xid(window),
|
|
|
|
parent->winId());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2021-05-10 08:53:34 +00:00
|
|
|
if (gdk_x11_drawable_get_xdisplay != nullptr
|
|
|
|
&& gdk_x11_drawable_get_xid != nullptr) {
|
|
|
|
XSetTransientForHint(
|
|
|
|
gdk_x11_drawable_get_xdisplay(window),
|
|
|
|
gdk_x11_drawable_get_xid(window),
|
|
|
|
parent->winId());
|
|
|
|
return;
|
2016-07-06 18:30:14 +00:00
|
|
|
}
|
2021-02-22 13:41:25 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace Platform
|