KWaylandServer

xdgdecoration_v1_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "xdgdecoration_v1_interface.h"
8 #include "display.h"
9 #include "xdgdecoration_v1_interface_p.h"
10 #include "xdgshell_interface_p.h"
11 
12 namespace KWaylandServer
13 {
14 // TODO: We need to wait for an ack_configure either here or in xdgshellclient.cpp.
15 
16 XdgDecorationManagerV1InterfacePrivate::XdgDecorationManagerV1InterfacePrivate(XdgDecorationManagerV1Interface *manager)
17  : q(manager)
18 {
19 }
20 
21 void XdgDecorationManagerV1InterfacePrivate::zxdg_decoration_manager_v1_destroy(Resource *resource)
22 {
23  wl_resource_destroy(resource->handle);
24 }
25 
26 void XdgDecorationManagerV1InterfacePrivate::zxdg_decoration_manager_v1_get_toplevel_decoration(Resource *resource,
27  uint32_t id,
28  ::wl_resource *toplevelResource)
29 {
30  XdgToplevelInterfacePrivate *toplevelPrivate = XdgToplevelInterfacePrivate::get(toplevelResource);
31  if (!toplevelPrivate) {
32  wl_resource_post_error(resource->handle, QtWaylandServer::zxdg_toplevel_decoration_v1::error_orphaned, "no xdg-toplevel object");
33  return;
34  }
35 
36  if (toplevelPrivate->decoration) {
37  wl_resource_post_error(resource->handle,
38  QtWaylandServer::zxdg_toplevel_decoration_v1::error_already_constructed,
39  "decoration has been already constructed");
40  return;
41  }
42 
43  wl_resource *decorationResource = wl_resource_create(resource->client(), &zxdg_toplevel_decoration_v1_interface, resource->version(), id);
44 
45  auto decoration = new XdgToplevelDecorationV1Interface(toplevelPrivate->q, decorationResource);
46  toplevelPrivate->decoration = decoration;
47 
48  Q_EMIT q->decorationCreated(decoration);
49 }
50 
52  : QObject(parent)
53  , d(new XdgDecorationManagerV1InterfacePrivate(this))
54 {
55  d->init(*display, 1);
56 }
57 
59 {
60 }
61 
62 XdgToplevelDecorationV1InterfacePrivate::XdgToplevelDecorationV1InterfacePrivate(XdgToplevelDecorationV1Interface *decoration)
63  : q(decoration)
64 {
65 }
66 
67 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_destroy_resource(Resource *resource)
68 {
69  Q_UNUSED(resource)
70  delete q;
71 }
72 
73 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_destroy(Resource *resource)
74 {
75  wl_resource_destroy(resource->handle);
76 }
77 
78 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_set_mode(Resource *resource, uint32_t mode)
79 {
80  Q_UNUSED(resource)
81 
82  switch (mode) {
83  case mode_client_side:
84  preferredMode = XdgToplevelDecorationV1Interface::Mode::Client;
85  break;
86  case mode_server_side:
87  preferredMode = XdgToplevelDecorationV1Interface::Mode::Server;
88  break;
89  default:
90  preferredMode = XdgToplevelDecorationV1Interface::Mode::Undefined;
91  break;
92  }
93 
94  Q_EMIT q->preferredModeChanged(preferredMode);
95 }
96 
97 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_unset_mode(Resource *resource)
98 {
99  Q_UNUSED(resource)
100  preferredMode = XdgToplevelDecorationV1Interface::Mode::Undefined;
101  Q_EMIT q->preferredModeChanged(preferredMode);
102 }
103 
105  : d(new XdgToplevelDecorationV1InterfacePrivate(this))
106 {
107  d->toplevel = toplevel;
108  d->init(resource);
109 }
110 
112 {
113 }
114 
116 {
117  return d->toplevel;
118 }
119 
120 XdgToplevelDecorationV1Interface::Mode XdgToplevelDecorationV1Interface::preferredMode() const
121 {
122  return d->preferredMode;
123 }
124 
126 {
127  switch (mode) {
128  case Mode::Client:
129  d->send_configure(QtWaylandServer::zxdg_toplevel_decoration_v1::mode_client_side);
130  break;
131  case Mode::Server:
132  d->send_configure(QtWaylandServer::zxdg_toplevel_decoration_v1::mode_server_side);
133  break;
134  case Mode::Undefined:
135  break;
136  }
137 }
138 
140 {
141  XdgToplevelInterfacePrivate *toplevelPrivate = XdgToplevelInterfacePrivate::get(toplevel);
142  return toplevelPrivate->decoration;
143 }
144 
145 } // namespace KWaylandServer
XdgDecorationManagerV1Interface(Display *display, QObject *parent=nullptr)
Constructs a decoration manager with the given display and parent.
The XdgToplevelDecorationV1Interface class allows the compositor to toggle server-side window decorat...
Class holding the Wayland server display loop.
Definition: display.h:47
static XdgToplevelDecorationV1Interface * get(XdgToplevelInterface *toplevel)
Returns the XdgToplevelDecorationV1Interface for the specified toplevel.
~XdgToplevelDecorationV1Interface() override
Destructs the XdgToplevelDecorationV1Interface object.
The XdgToplevelInterface class represents a surface with window-like functionality such as maximize...
Mode preferredMode() const
Returns the decoration mode preferred by the client.
XdgToplevelInterface * toplevel() const
Returns the toplevel for this XdgToplevelDecorationV1Interface.
~XdgDecorationManagerV1Interface() override
Destructs the XdgDecorationManagerV1Interface object.
XdgToplevelDecorationV1Interface(XdgToplevelInterface *toplevel,::wl_resource *resource)
Constructs a XdgToplevelDecorationV1Interface for the given toplevel and initializes it with resource...
QObject * parent() const const
Q_EMITQ_EMIT
void sendConfigure(Mode mode)
Sends a configure event to the client.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.