File indexing completed on 2024-11-10 04:57:36
0001 /* 0002 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "xdgdecoration_v1.h" 0008 #include "display.h" 0009 #include "xdgdecoration_v1_p.h" 0010 #include "xdgshell_p.h" 0011 0012 namespace KWin 0013 { 0014 // TODO: We need to wait for an ack_configure either here or in xdgshellclient.cpp. 0015 0016 XdgDecorationManagerV1InterfacePrivate::XdgDecorationManagerV1InterfacePrivate(XdgDecorationManagerV1Interface *manager) 0017 : q(manager) 0018 { 0019 } 0020 0021 void XdgDecorationManagerV1InterfacePrivate::zxdg_decoration_manager_v1_destroy(Resource *resource) 0022 { 0023 wl_resource_destroy(resource->handle); 0024 } 0025 0026 void XdgDecorationManagerV1InterfacePrivate::zxdg_decoration_manager_v1_get_toplevel_decoration(Resource *resource, 0027 uint32_t id, 0028 ::wl_resource *toplevelResource) 0029 { 0030 XdgToplevelInterfacePrivate *toplevelPrivate = XdgToplevelInterfacePrivate::get(toplevelResource); 0031 if (!toplevelPrivate) { 0032 wl_resource_post_error(resource->handle, QtWaylandServer::zxdg_toplevel_decoration_v1::error_orphaned, "no xdg-toplevel object"); 0033 return; 0034 } 0035 0036 if (toplevelPrivate->decoration) { 0037 wl_resource_post_error(resource->handle, 0038 QtWaylandServer::zxdg_toplevel_decoration_v1::error_already_constructed, 0039 "decoration has been already constructed"); 0040 return; 0041 } 0042 0043 wl_resource *decorationResource = wl_resource_create(resource->client(), &zxdg_toplevel_decoration_v1_interface, resource->version(), id); 0044 0045 auto decoration = new XdgToplevelDecorationV1Interface(toplevelPrivate->q, decorationResource); 0046 toplevelPrivate->decoration = decoration; 0047 0048 Q_EMIT q->decorationCreated(decoration); 0049 } 0050 0051 XdgDecorationManagerV1Interface::XdgDecorationManagerV1Interface(Display *display, QObject *parent) 0052 : QObject(parent) 0053 , d(new XdgDecorationManagerV1InterfacePrivate(this)) 0054 { 0055 d->init(*display, 1); 0056 } 0057 0058 XdgDecorationManagerV1Interface::~XdgDecorationManagerV1Interface() 0059 { 0060 } 0061 0062 XdgToplevelDecorationV1InterfacePrivate::XdgToplevelDecorationV1InterfacePrivate(XdgToplevelDecorationV1Interface *decoration) 0063 : q(decoration) 0064 { 0065 } 0066 0067 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_destroy_resource(Resource *resource) 0068 { 0069 delete q; 0070 } 0071 0072 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_destroy(Resource *resource) 0073 { 0074 wl_resource_destroy(resource->handle); 0075 } 0076 0077 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_set_mode(Resource *resource, uint32_t mode) 0078 { 0079 switch (mode) { 0080 case mode_client_side: 0081 preferredMode = XdgToplevelDecorationV1Interface::Mode::Client; 0082 break; 0083 case mode_server_side: 0084 preferredMode = XdgToplevelDecorationV1Interface::Mode::Server; 0085 break; 0086 default: 0087 preferredMode = XdgToplevelDecorationV1Interface::Mode::Undefined; 0088 break; 0089 } 0090 0091 Q_EMIT q->preferredModeChanged(preferredMode); 0092 } 0093 0094 void XdgToplevelDecorationV1InterfacePrivate::zxdg_toplevel_decoration_v1_unset_mode(Resource *resource) 0095 { 0096 preferredMode = XdgToplevelDecorationV1Interface::Mode::Undefined; 0097 Q_EMIT q->preferredModeChanged(preferredMode); 0098 } 0099 0100 XdgToplevelDecorationV1Interface::XdgToplevelDecorationV1Interface(XdgToplevelInterface *toplevel, ::wl_resource *resource) 0101 : d(new XdgToplevelDecorationV1InterfacePrivate(this)) 0102 { 0103 d->toplevel = toplevel; 0104 d->init(resource); 0105 } 0106 0107 XdgToplevelDecorationV1Interface::~XdgToplevelDecorationV1Interface() 0108 { 0109 } 0110 0111 XdgToplevelInterface *XdgToplevelDecorationV1Interface::toplevel() const 0112 { 0113 return d->toplevel; 0114 } 0115 0116 XdgToplevelDecorationV1Interface::Mode XdgToplevelDecorationV1Interface::preferredMode() const 0117 { 0118 return d->preferredMode; 0119 } 0120 0121 void XdgToplevelDecorationV1Interface::sendConfigure(Mode mode) 0122 { 0123 switch (mode) { 0124 case Mode::Client: 0125 d->send_configure(QtWaylandServer::zxdg_toplevel_decoration_v1::mode_client_side); 0126 break; 0127 case Mode::None: // Faked as server_side mode. 0128 case Mode::Server: 0129 d->send_configure(QtWaylandServer::zxdg_toplevel_decoration_v1::mode_server_side); 0130 break; 0131 case Mode::Undefined: 0132 break; 0133 } 0134 } 0135 0136 XdgToplevelDecorationV1Interface *XdgToplevelDecorationV1Interface::get(XdgToplevelInterface *toplevel) 0137 { 0138 XdgToplevelInterfacePrivate *toplevelPrivate = XdgToplevelInterfacePrivate::get(toplevel); 0139 return toplevelPrivate->decoration; 0140 } 0141 0142 } // namespace KWin 0143 0144 #include "moc_xdgdecoration_v1.cpp"