From 64a2647d8d81b5c23d22b52cc9e0dd2595270b67 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 17 Mar 2017 22:32:36 +0100 Subject: Remove X11 hackery and use Qt5 facilities to embed Gtk --- src/qt5_in_gtk2.cpp | 58 +++++------------------------------------------------ 1 file changed, 5 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/qt5_in_gtk2.cpp b/src/qt5_in_gtk2.cpp index 48704c9..0823afc 100644 --- a/src/qt5_in_gtk2.cpp +++ b/src/qt5_in_gtk2.cpp @@ -17,12 +17,9 @@ #include #include -#include #include #include #include -#include -#include #include "./suil_internal.h" @@ -34,55 +31,11 @@ extern "C" { typedef struct _SuilQtWrapper SuilQtWrapper; typedef struct _SuilQtWrapperClass SuilQtWrapperClass; -class EmbedWidget : public QWidget -{ -public: - EmbedWidget() - : QWidget() - , display(QX11Info::display()) - , wid(winId()) - {} - - WId id() const { return wid; } - -protected: - bool eventFilter(QObject*, QEvent* ev) { - if (wid == 0 || !display) { - return false; - } - - if (ev->type() == QEvent::Enter || - ev->type() == QEvent::WindowActivate) { - const Window root = XRootWindow(display, 0); - int x, y; - Window child; - XTranslateCoordinates(display, wid, root, 0, 0, &x, &y, &child); - - XWindowAttributes attrs; - XGetWindowAttributes(display, wid, &attrs); - - const QPoint p = QPoint(x - attrs.x, y - attrs.y); - if (p != pos) { - pos = p; - move(pos); - XMoveWindow(display, wid, 0, 0); - } - } - - return false; - } - -private: - Display* display; - QPoint pos; - WId wid; -}; - struct _SuilQtWrapper { GtkSocket socket; QApplication* app; - EmbedWidget* qembed; + QWidget* qembed; SuilWrapper* wrapper; SuilInstance* instance; }; @@ -136,8 +89,10 @@ suil_qt_wrapper_realize(GtkWidget* w, gpointer data) { SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(w); GtkSocket* const s = GTK_SOCKET(w); + const WId id = gtk_socket_get_id(s); - gtk_socket_add_id(s, wrap->qembed->id()); + wrap->qembed->winId(); + wrap->qembed->windowHandle()->setParent(QWindow::fromWinId(id)); wrap->qembed->show(); } @@ -146,17 +101,14 @@ wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance) { SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(wrapper->impl); - wrap->qembed = new EmbedWidget(); + wrap->qembed = new QWidget(); wrap->wrapper = wrapper; wrap->instance = instance; - wrap->qembed->setAttribute(Qt::WA_LayoutUsesWidgetRect); - QWidget* qwidget = (QWidget*)instance->ui_widget; QVBoxLayout* layout = new QVBoxLayout(wrap->qembed); layout->addWidget(qwidget); - qwidget->installEventFilter(wrap->qembed); qwidget->setParent(wrap->qembed); g_signal_connect_after(G_OBJECT(wrap), "realize", -- cgit v1.2.1