1 /*
2  * Copyright (C) 2021, Georges Basile Stavracas Neto
3                  2020, Jan Grulich
4  *
5  * This file is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation, version 3.0 of the
8  * License.
9  *
10  * This file is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * SPDX-License-Identifier: LGPL-3.0-only
19  */
20 
21 #include "config.h"
22 #include "portal-qt5.h"
23 
24 #include "parent-private.h"
25 
26 #include <QX11Info>
27 
28 static gboolean
_xdp_parent_export_qt(XdpParent * parent,XdpParentExported callback,gpointer data)29 _xdp_parent_export_qt (XdpParent *parent,
30                        XdpParentExported callback,
31                        gpointer data)
32 {
33   if (QX11Info::isPlatformX11 ())
34     {
35       QWindow *w = (QWindow *) parent->data;
36       if (w) {
37         guint32 xid = (guint32) w->winId ();
38         g_autofree char *handle = g_strdup_printf ("x11:%x", xid);
39         callback (parent, handle, data);
40         return TRUE;
41       }
42     }
43   else
44     {
45       /* TODO: QtWayland doesn't support xdg-foreign protocol yet
46        * Upstream bugs: https://bugreports.qt.io/browse/QTBUG-73801
47        *                https://bugreports.qt.io/browse/QTBUG-76983
48        */
49       g_warning ("QtWayland doesn't support xdg-foreign protocol yet");
50       g_autofree char *handle = g_strdup ("");
51       callback (parent, handle, data);
52       return TRUE;
53     }
54 
55   g_warning ("Couldn't export handle, unsupported windowing system");
56   return FALSE;
57 }
58 
_xdp_parent_unexport_qt(XdpParent * parent)59 static inline void _xdp_parent_unexport_qt (XdpParent *parent)
60 {
61 }
62 
63 XdpParent *
xdp_parent_new_qt(QWindow * window)64 xdp_parent_new_qt (QWindow *window)
65 {
66   XdpParent *parent = g_new0 (XdpParent, 1);
67   parent->parent_export = _xdp_parent_export_qt;
68   parent->parent_unexport = _xdp_parent_unexport_qt;
69   parent->data = (gpointer) window;
70   return parent;
71 }
72