PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/compositor/compositor_api/qwaylandcompositor.cpp

https://gitlab.com/qt-d/dicky98s-qtwayland
C++ | 302 lines | 203 code | 52 blank | 47 comment | 6 complexity | 6c45b42ab70f3c3af99dd62a80cafe39 MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the Qt Compositor.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. ** * Redistributions of source code must retain the above copyright
  15. ** notice, this list of conditions and the following disclaimer.
  16. ** * Redistributions in binary form must reproduce the above copyright
  17. ** notice, this list of conditions and the following disclaimer in
  18. ** the documentation and/or other materials provided with the
  19. ** distribution.
  20. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
  21. ** of its contributors may be used to endorse or promote products derived
  22. ** from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40. #include "qwaylandcompositor.h"
  41. #include "qwaylandinput.h"
  42. #include "qwaylandglobalinterface.h"
  43. #include "qwaylandsurfaceview.h"
  44. #include "wayland_wrapper/qwlcompositor_p.h"
  45. #include "wayland_wrapper/qwldatadevice_p.h"
  46. #include "wayland_wrapper/qwlsurface_p.h"
  47. #include "wayland_wrapper/qwlinputdevice_p.h"
  48. #include "wayland_wrapper/qwlinputpanel_p.h"
  49. #include "wayland_wrapper/qwlshellsurface_p.h"
  50. #include <QtCore/QCoreApplication>
  51. #include <QtCore/QStringList>
  52. #include <QtGui/QDesktopServices>
  53. #include <QDebug>
  54. QT_BEGIN_NAMESPACE
  55. QWaylandCompositor::QWaylandCompositor(QWindow *window, const char *socketName, ExtensionFlags extensions)
  56. : m_compositor(new QtWayland::Compositor(this, extensions))
  57. , m_toplevel_window(window)
  58. {
  59. m_compositor->m_socket_name = socketName;
  60. m_compositor->init();
  61. }
  62. QWaylandCompositor::QWaylandCompositor(QWindow *window, const char *socketName, QtWayland::Compositor *dptr)
  63. : m_compositor(dptr)
  64. , m_toplevel_window(window)
  65. {
  66. m_compositor->m_socket_name = socketName;
  67. m_compositor->init();
  68. }
  69. QWaylandCompositor::~QWaylandCompositor()
  70. {
  71. qDeleteAll(m_compositor->m_globals);
  72. delete m_compositor;
  73. }
  74. void QWaylandCompositor::addGlobalInterface(QWaylandGlobalInterface *interface)
  75. {
  76. wl_global_create(m_compositor->wl_display(), interface->interface(), interface->version(), interface, QtWayland::Compositor::bindGlobal);
  77. m_compositor->m_globals << interface;
  78. }
  79. void QWaylandCompositor::addDefaultShell()
  80. {
  81. addGlobalInterface(new QtWayland::Shell);
  82. }
  83. struct wl_display *QWaylandCompositor::waylandDisplay() const
  84. {
  85. return m_compositor->wl_display();
  86. }
  87. void QWaylandCompositor::sendFrameCallbacks(QList<QWaylandSurface *> visibleSurfaces)
  88. {
  89. m_compositor->sendFrameCallbacks(visibleSurfaces);
  90. }
  91. void QWaylandCompositor::frameStarted()
  92. {
  93. for (QtWayland::Surface *surf: m_compositor->surfaces())
  94. surf->frameStarted();
  95. }
  96. void QWaylandCompositor::destroyClientForSurface(QWaylandSurface *surface)
  97. {
  98. destroyClient(surface->client());
  99. }
  100. void QWaylandCompositor::destroyClient(WaylandClient *client)
  101. {
  102. m_compositor->destroyClient(client);
  103. }
  104. QList<QWaylandSurface *> QWaylandCompositor::surfacesForClient(WaylandClient* c) const
  105. {
  106. wl_client *client = static_cast<wl_client *>(c);
  107. QList<QtWayland::Surface *> surfaces = m_compositor->surfaces();
  108. QList<QWaylandSurface *> result;
  109. for (int i = 0; i < surfaces.count(); ++i) {
  110. if (surfaces.at(i)->resource()->client() == client) {
  111. result.append(surfaces.at(i)->waylandSurface());
  112. }
  113. }
  114. return result;
  115. }
  116. QList<QWaylandSurface *> QWaylandCompositor::surfaces() const
  117. {
  118. QList<QtWayland::Surface *> surfaces = m_compositor->surfaces();
  119. QList<QWaylandSurface *> surfs;
  120. foreach (QtWayland::Surface *s, surfaces)
  121. surfs << s->waylandSurface();
  122. return surfs;
  123. }
  124. QWindow * QWaylandCompositor::window() const
  125. {
  126. return m_toplevel_window;
  127. }
  128. void QWaylandCompositor::cleanupGraphicsResources()
  129. {
  130. m_compositor->cleanupGraphicsResources();
  131. }
  132. void QWaylandCompositor::surfaceAboutToBeDestroyed(QWaylandSurface *surface)
  133. {
  134. Q_UNUSED(surface);
  135. }
  136. QWaylandSurfaceView *QWaylandCompositor::pickView(const QPointF &globalPosition) const
  137. {
  138. Q_FOREACH (QtWayland::Surface *surface, m_compositor->surfaces()) {
  139. foreach (QWaylandSurfaceView *view, surface->waylandSurface()->views())
  140. if (QRectF(view->pos(), surface->size()).contains(globalPosition))
  141. return view;
  142. }
  143. return 0;
  144. }
  145. QPointF QWaylandCompositor::mapToView(QWaylandSurfaceView *surface, const QPointF &globalPosition) const
  146. {
  147. return globalPosition - surface->pos();
  148. }
  149. /*!
  150. Override this to handle QDesktopServices::openUrl() requests from the clients.
  151. The default implementation simply forwards the request to QDesktopServices::openUrl().
  152. */
  153. bool QWaylandCompositor::openUrl(WaylandClient *client, const QUrl &url)
  154. {
  155. Q_UNUSED(client);
  156. return QDesktopServices::openUrl(url);
  157. }
  158. QtWayland::Compositor * QWaylandCompositor::handle() const
  159. {
  160. return m_compositor;
  161. }
  162. void QWaylandCompositor::setRetainedSelectionEnabled(bool enabled)
  163. {
  164. m_compositor->setRetainedSelectionEnabled(enabled);
  165. }
  166. bool QWaylandCompositor::retainedSelectionEnabled() const
  167. {
  168. return m_compositor->retainedSelectionEnabled();
  169. }
  170. void QWaylandCompositor::retainedSelectionReceived(QMimeData *)
  171. {
  172. }
  173. void QWaylandCompositor::overrideSelection(const QMimeData *data)
  174. {
  175. m_compositor->overrideSelection(data);
  176. }
  177. void QWaylandCompositor::setClientFullScreenHint(bool value)
  178. {
  179. m_compositor->setClientFullScreenHint(value);
  180. }
  181. const char *QWaylandCompositor::socketName() const
  182. {
  183. if (m_compositor->m_socket_name.isEmpty())
  184. return 0;
  185. return m_compositor->m_socket_name.constData();
  186. }
  187. /*!
  188. Set the screen orientation based on accelerometer data or similar.
  189. */
  190. void QWaylandCompositor::setScreenOrientation(Qt::ScreenOrientation orientation)
  191. {
  192. m_compositor->setScreenOrientation(orientation);
  193. }
  194. void QWaylandCompositor::setOutputGeometry(const QRect &geometry)
  195. {
  196. m_compositor->setOutputGeometry(geometry);
  197. }
  198. QRect QWaylandCompositor::outputGeometry() const
  199. {
  200. return m_compositor->outputGeometry();
  201. }
  202. void QWaylandCompositor::setOutputRefreshRate(int rate)
  203. {
  204. m_compositor->setOutputRefreshRate(rate);
  205. }
  206. int QWaylandCompositor::outputRefreshRate() const
  207. {
  208. return m_compositor->outputRefreshRate();
  209. }
  210. QWaylandInputDevice *QWaylandCompositor::defaultInputDevice() const
  211. {
  212. return m_compositor->defaultInputDevice()->handle();
  213. }
  214. QWaylandInputPanel *QWaylandCompositor::inputPanel() const
  215. {
  216. return m_compositor->inputPanel()->handle();
  217. }
  218. QWaylandDrag *QWaylandCompositor::drag() const
  219. {
  220. return m_compositor->defaultInputDevice()->dragHandle();
  221. }
  222. bool QWaylandCompositor::isDragging() const
  223. {
  224. return m_compositor->isDragging();
  225. }
  226. void QWaylandCompositor::sendDragMoveEvent(const QPoint &global, const QPoint &local,
  227. QWaylandSurface *surface)
  228. {
  229. m_compositor->sendDragMoveEvent(global, local, surface ? surface->handle() : 0);
  230. }
  231. void QWaylandCompositor::sendDragEndEvent()
  232. {
  233. m_compositor->sendDragEndEvent();
  234. }
  235. void QWaylandCompositor::setCursorSurface(QWaylandSurface *surface, int hotspotX, int hotspotY)
  236. {
  237. Q_UNUSED(surface);
  238. Q_UNUSED(hotspotX);
  239. Q_UNUSED(hotspotY);
  240. }
  241. void QWaylandCompositor::configureTouchExtension(TouchExtensionFlags flags)
  242. {
  243. m_compositor->configureTouchExtension(flags);
  244. }
  245. QWaylandSurfaceView *QWaylandCompositor::createView(QWaylandSurface *surface)
  246. {
  247. return new QWaylandSurfaceView(surface);
  248. }
  249. QT_END_NAMESPACE