File indexing completed on 2024-11-10 04:57:33

0001 /*
0002     SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #include "slide.h"
0007 #include "display.h"
0008 #include "surface_p.h"
0009 
0010 #include <qwayland-server-slide.h>
0011 
0012 namespace KWin
0013 {
0014 static const quint32 s_version = 1;
0015 
0016 class SlideManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide_manager
0017 {
0018 public:
0019     SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display);
0020 
0021     SlideManagerInterface *q;
0022 
0023 protected:
0024     void org_kde_kwin_slide_manager_destroy_global() override;
0025     void org_kde_kwin_slide_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
0026     void org_kde_kwin_slide_manager_unset(Resource *resource, wl_resource *surface) override;
0027 };
0028 
0029 void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_destroy_global()
0030 {
0031     delete q;
0032 }
0033 
0034 void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
0035 {
0036     SurfaceInterface *s = SurfaceInterface::get(surface);
0037     if (!s) {
0038         wl_resource_post_error(resource->handle, 0, "Invalid  surface");
0039         return;
0040     }
0041 
0042     wl_resource *slide_resource = wl_resource_create(resource->client(), &org_kde_kwin_slide_interface, resource->version(), id);
0043     if (!slide_resource) {
0044         wl_client_post_no_memory(resource->client());
0045         return;
0046     }
0047 
0048     auto slide = new SlideInterface(slide_resource);
0049     SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
0050     surfacePrivate->setSlide(QPointer<SlideInterface>(slide));
0051 }
0052 
0053 void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_unset(Resource *resource, wl_resource *surface)
0054 {
0055     SurfaceInterface *s = SurfaceInterface::get(surface);
0056     if (!s) {
0057         wl_resource_post_error(resource->handle, 0, "Invalid  surface");
0058         return;
0059     }
0060     SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
0061     surfacePrivate->setSlide(QPointer<SlideInterface>());
0062 }
0063 
0064 SlideManagerInterfacePrivate::SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display)
0065     : QtWaylandServer::org_kde_kwin_slide_manager(*display, s_version)
0066     , q(_q)
0067 {
0068 }
0069 
0070 SlideManagerInterface::SlideManagerInterface(Display *display, QObject *parent)
0071     : QObject(parent)
0072     , d(new SlideManagerInterfacePrivate(this, display))
0073 {
0074 }
0075 
0076 SlideManagerInterface::~SlideManagerInterface()
0077 {
0078 }
0079 
0080 void SlideManagerInterface::remove()
0081 {
0082     d->globalRemove();
0083 }
0084 
0085 class SlideInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide
0086 {
0087 public:
0088     SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource);
0089 
0090     SlideInterface::Location pendingLocation;
0091     SlideInterface::Location currentLocation;
0092     uint32_t pendingOffset;
0093     uint32_t currentOffset;
0094     SlideInterface *q;
0095 
0096 protected:
0097     void org_kde_kwin_slide_commit(Resource *resource) override;
0098     void org_kde_kwin_slide_set_location(Resource *resource, uint32_t location) override;
0099     void org_kde_kwin_slide_set_offset(Resource *resource, int32_t offset) override;
0100     void org_kde_kwin_slide_release(Resource *resource) override;
0101     void org_kde_kwin_slide_destroy_resource(Resource *resource) override;
0102 };
0103 
0104 void SlideInterfacePrivate::org_kde_kwin_slide_commit(Resource *resource)
0105 {
0106     currentLocation = pendingLocation;
0107     currentOffset = pendingOffset;
0108 }
0109 
0110 void SlideInterfacePrivate::org_kde_kwin_slide_set_location(Resource *resource, uint32_t location)
0111 {
0112     pendingLocation = (SlideInterface::Location)location;
0113 }
0114 
0115 void SlideInterfacePrivate::org_kde_kwin_slide_set_offset(Resource *resource, int32_t offset)
0116 {
0117     pendingOffset = offset;
0118 }
0119 
0120 void SlideInterfacePrivate::org_kde_kwin_slide_release(Resource *resource)
0121 {
0122     wl_resource_destroy(resource->handle);
0123 }
0124 
0125 void SlideInterfacePrivate::org_kde_kwin_slide_destroy_resource(Resource *resource)
0126 {
0127     delete q;
0128 }
0129 
0130 SlideInterfacePrivate::SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource)
0131     : QtWaylandServer::org_kde_kwin_slide(resource)
0132     , q(_q)
0133 {
0134 }
0135 
0136 SlideInterface::SlideInterface(wl_resource *resource)
0137     : d(new SlideInterfacePrivate(this, resource))
0138 {
0139 }
0140 
0141 SlideInterface::~SlideInterface() = default;
0142 
0143 SlideInterface::Location SlideInterface::location() const
0144 {
0145     return d->currentLocation;
0146 }
0147 
0148 qint32 SlideInterface::offset() const
0149 {
0150     return d->currentOffset;
0151 }
0152 
0153 }
0154 
0155 #include "moc_slide.cpp"