Use xcb to set transient parent for gtk file dialog

This commit is contained in:
Ilya Fedin 2020-12-14 14:38:03 +04:00 committed by John Preston
parent e9e4c7a8cc
commit cd3b989e70

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/linux/linux_gdk_helper.h" #include "platform/linux/linux_gdk_helper.h"
#include "platform/linux/linux_libs.h" #include "platform/linux/linux_libs.h"
#include "base/platform/linux/base_xcb_utilities_linux.h"
extern "C" { extern "C" {
#undef signals #undef signals
@ -31,9 +32,6 @@ GtkLoaded gdk_helper_loaded = GtkLoaded::GtkNone;
#define GdkDrawable GdkWindow #define GdkDrawable GdkWindow
// Gtk 2 // 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*); using f_gdk_x11_drawable_get_xid = XID(*)(GdkDrawable*);
f_gdk_x11_drawable_get_xid gdk_x11_drawable_get_xid = nullptr; f_gdk_x11_drawable_get_xid gdk_x11_drawable_get_xid = nullptr;
@ -47,12 +45,6 @@ inline bool gdk_is_x11_window_check(Object *obj) {
return Libs::g_type_cit_helper(obj, gdk_x11_window_get_type()); return Libs::g_type_cit_helper(obj, gdk_x11_window_get_type());
} }
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); using f_gdk_x11_window_get_xid = Window(*)(GdkWindow *window);
f_gdk_x11_window_get_xid gdk_x11_window_get_xid = nullptr; f_gdk_x11_window_get_xid gdk_x11_window_get_xid = nullptr;
@ -60,7 +52,6 @@ bool GdkHelperLoadGtk2(QLibrary &lib) {
#if defined DESKTOP_APP_USE_PACKAGED && !defined DESKTOP_APP_USE_PACKAGED_LAZY #if defined DESKTOP_APP_USE_PACKAGED && !defined DESKTOP_APP_USE_PACKAGED_LAZY
return false; return false;
#else // DESKTOP_APP_USE_PACKAGED && !DESKTOP_APP_USE_PACKAGED_LAZY #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; if (!LOAD_SYMBOL(lib, "gdk_x11_drawable_get_xid", gdk_x11_drawable_get_xid)) return false;
return true; return true;
#endif // !DESKTOP_APP_USE_PACKAGED || DESKTOP_APP_USE_PACKAGED_LAZY #endif // !DESKTOP_APP_USE_PACKAGED || DESKTOP_APP_USE_PACKAGED_LAZY
@ -68,8 +59,6 @@ bool GdkHelperLoadGtk2(QLibrary &lib) {
bool GdkHelperLoadGtk3(QLibrary &lib) { bool GdkHelperLoadGtk3(QLibrary &lib) {
if (!LOAD_SYMBOL(lib, "gdk_x11_window_get_type", gdk_x11_window_get_type)) return false; 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; if (!LOAD_SYMBOL(lib, "gdk_x11_window_get_xid", gdk_x11_window_get_xid)) return false;
return true; return true;
} }
@ -89,14 +78,26 @@ bool GdkHelperLoaded() {
void XSetTransientForHint(GdkWindow *window, quintptr winId) { void XSetTransientForHint(GdkWindow *window, quintptr winId) {
if (gdk_helper_loaded == GtkLoaded::Gtk2) { if (gdk_helper_loaded == GtkLoaded::Gtk2) {
::XSetTransientForHint(gdk_x11_drawable_get_xdisplay(window), xcb_change_property(
gdk_x11_drawable_get_xid(window), base::Platform::XCB::GetConnectionFromQt(),
winId); XCB_PROP_MODE_REPLACE,
gdk_x11_drawable_get_xid(window),
XCB_ATOM_WM_TRANSIENT_FOR,
XCB_ATOM_WINDOW,
32,
1,
&winId);
} else if (gdk_helper_loaded == GtkLoaded::Gtk3) { } else if (gdk_helper_loaded == GtkLoaded::Gtk3) {
if (gdk_is_x11_window_check(window)) { if (gdk_is_x11_window_check(window)) {
::XSetTransientForHint(gdk_x11_display_get_xdisplay(gdk_window_get_display(window)), xcb_change_property(
gdk_x11_window_get_xid(window), base::Platform::XCB::GetConnectionFromQt(),
winId); XCB_PROP_MODE_REPLACE,
gdk_x11_window_get_xid(window),
XCB_ATOM_WM_TRANSIENT_FOR,
XCB_ATOM_WINDOW,
32,
1,
&winId);
} }
} }
} }