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
|
|
|
*/
|
2017-08-07 11:57:34 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
2016-07-06 18:30:14 +00:00
|
|
|
#include "platform/linux/linux_gdk_helper.h"
|
|
|
|
|
|
|
|
#include "platform/linux/linux_libs.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#undef signals
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#define signals public
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
enum class GtkLoaded {
|
|
|
|
GtkNone,
|
|
|
|
Gtk2,
|
|
|
|
Gtk3,
|
|
|
|
};
|
|
|
|
|
|
|
|
GtkLoaded gdk_helper_loaded = GtkLoaded::GtkNone;
|
|
|
|
|
|
|
|
// To be able to compile with gtk-3.0 headers as well
|
|
|
|
#define GdkDrawable GdkWindow
|
|
|
|
|
|
|
|
// Gtk 2
|
|
|
|
using f_gdk_x11_drawable_get_xdisplay = Display*(*)(GdkDrawable*);
|
|
|
|
f_gdk_x11_drawable_get_xdisplay gdk_x11_drawable_get_xdisplay = nullptr;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
return Libs::g_type_cit_helper(obj, gdk_x11_window_get_type());
|
|
|
|
}
|
|
|
|
|
2016-07-06 18:30:14 +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;
|
|
|
|
|
|
|
|
using f_gdk_x11_window_get_xid = Window(*)(GdkWindow *window);
|
|
|
|
f_gdk_x11_window_get_xid gdk_x11_window_get_xid = nullptr;
|
|
|
|
|
|
|
|
bool GdkHelperLoadGtk2(QLibrary &lib) {
|
2020-06-27 02:12:12 +00:00
|
|
|
#if defined DESKTOP_APP_USE_PACKAGED && !defined DESKTOP_APP_USE_PACKAGED_LAZY
|
|
|
|
return false;
|
|
|
|
#else // DESKTOP_APP_USE_PACKAGED && !DESKTOP_APP_USE_PACKAGED_LAZY
|
|
|
|
if (!LOAD_SYMBOL(lib, "gdk_x11_drawable_get_xdisplay", gdk_x11_drawable_get_xdisplay)) return false;
|
|
|
|
if (!LOAD_SYMBOL(lib, "gdk_x11_drawable_get_xid", gdk_x11_drawable_get_xid)) return false;
|
2016-07-06 18:30:14 +00:00
|
|
|
return true;
|
2020-06-27 02:12:12 +00:00
|
|
|
#endif // !DESKTOP_APP_USE_PACKAGED || DESKTOP_APP_USE_PACKAGED_LAZY
|
2016-07-06 18:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GdkHelperLoadGtk3(QLibrary &lib) {
|
2020-06-27 02:12:12 +00:00
|
|
|
if (!LOAD_SYMBOL(lib, "gdk_x11_window_get_type", gdk_x11_window_get_type)) return false;
|
|
|
|
if (!LOAD_SYMBOL(lib, "gdk_window_get_display", gdk_window_get_display)) return false;
|
|
|
|
if (!LOAD_SYMBOL(lib, "gdk_x11_display_get_xdisplay", gdk_x11_display_get_xdisplay)) return false;
|
|
|
|
if (!LOAD_SYMBOL(lib, "gdk_x11_window_get_xid", gdk_x11_window_get_xid)) return false;
|
2016-07-06 18:30:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GdkHelperLoad(QLibrary &lib) {
|
|
|
|
gdk_helper_loaded = GtkLoaded::GtkNone;
|
2020-06-09 20:36:51 +00:00
|
|
|
if (GdkHelperLoadGtk3(lib)) {
|
2016-07-06 18:30:14 +00:00
|
|
|
gdk_helper_loaded = GtkLoaded::Gtk3;
|
2020-06-09 20:36:51 +00:00
|
|
|
} else if (GdkHelperLoadGtk2(lib)) {
|
|
|
|
gdk_helper_loaded = GtkLoaded::Gtk2;
|
2016-07-06 18:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GdkHelperLoaded() {
|
|
|
|
return gdk_helper_loaded != GtkLoaded::GtkNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XSetTransientForHint(GdkWindow *window, quintptr winId) {
|
|
|
|
if (gdk_helper_loaded == GtkLoaded::Gtk2) {
|
|
|
|
::XSetTransientForHint(gdk_x11_drawable_get_xdisplay(window),
|
|
|
|
gdk_x11_drawable_get_xid(window),
|
|
|
|
winId);
|
|
|
|
} else if (gdk_helper_loaded == GtkLoaded::Gtk3) {
|
2016-07-07 16:12:52 +00:00
|
|
|
if (gdk_is_x11_window_check(window)) {
|
2016-07-06 18:30:14 +00:00
|
|
|
::XSetTransientForHint(gdk_x11_display_get_xdisplay(gdk_window_get_display(window)),
|
|
|
|
gdk_x11_window_get_xid(window),
|
|
|
|
winId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace Platform
|
2017-08-07 11:57:34 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|