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

0001 /*
0002     SPDX-FileCopyrightText: 2023 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 "wayland/screenedge_v1.h"
0008 #include "wayland/display.h"
0009 #include "wayland/surface.h"
0010 
0011 #include "qwayland-server-kde-screen-edge-v1.h"
0012 
0013 #include <QPointer>
0014 
0015 namespace KWin
0016 {
0017 
0018 static const int s_version = 1;
0019 
0020 class ScreenEdgeManagerV1InterfacePrivate : public QtWaylandServer::kde_screen_edge_manager_v1
0021 {
0022 public:
0023     ScreenEdgeManagerV1InterfacePrivate(ScreenEdgeManagerV1Interface *q, Display *display);
0024 
0025     ScreenEdgeManagerV1Interface *q;
0026 
0027 protected:
0028     void kde_screen_edge_manager_v1_destroy(Resource *resource) override;
0029     void kde_screen_edge_manager_v1_get_auto_hide_screen_edge(Resource *resource, uint32_t id, uint32_t border, struct ::wl_resource *surface) override;
0030 };
0031 
0032 ScreenEdgeManagerV1InterfacePrivate::ScreenEdgeManagerV1InterfacePrivate(ScreenEdgeManagerV1Interface *q, Display *display)
0033     : QtWaylandServer::kde_screen_edge_manager_v1(*display, s_version)
0034     , q(q)
0035 {
0036 }
0037 
0038 void ScreenEdgeManagerV1InterfacePrivate::kde_screen_edge_manager_v1_destroy(Resource *resource)
0039 {
0040     wl_resource_destroy(resource->handle);
0041 }
0042 
0043 void ScreenEdgeManagerV1InterfacePrivate::kde_screen_edge_manager_v1_get_auto_hide_screen_edge(Resource *resource, uint32_t id, uint32_t border, struct ::wl_resource *surface_resource)
0044 {
0045     ElectricBorder electricBorder;
0046     switch (border) {
0047     case border_top:
0048         electricBorder = ElectricTop;
0049         break;
0050     case border_bottom:
0051         electricBorder = ElectricBottom;
0052         break;
0053     case border_left:
0054         electricBorder = ElectricLeft;
0055         break;
0056     case border_right:
0057         electricBorder = ElectricRight;
0058         break;
0059     default:
0060         wl_resource_post_error(resource->handle, error_invalid_border, "invalid border");
0061         return;
0062     }
0063 
0064     SurfaceInterface *surface = SurfaceInterface::get(surface_resource);
0065     const SurfaceRole *role = surface->role();
0066     if (!role || role->name() != "layer_surface_v1") {
0067         wl_resource_post_error(resource->handle, error_invalid_role, "surface must have layer_surface role");
0068         return;
0069     }
0070 
0071     wl_resource *edgeResource = wl_resource_create(resource->client(), &kde_auto_hide_screen_edge_v1_interface, resource->version(), id);
0072     auto edge = new AutoHideScreenEdgeV1Interface(surface, electricBorder, edgeResource);
0073     Q_EMIT q->edgeRequested(edge);
0074 }
0075 
0076 ScreenEdgeManagerV1Interface::ScreenEdgeManagerV1Interface(Display *display, QObject *parent)
0077     : d(new ScreenEdgeManagerV1InterfacePrivate(this, display))
0078 {
0079 }
0080 
0081 ScreenEdgeManagerV1Interface::~ScreenEdgeManagerV1Interface()
0082 {
0083 }
0084 
0085 class AutoHideScreenEdgeV1InterfacePrivate : public QtWaylandServer::kde_auto_hide_screen_edge_v1
0086 {
0087 public:
0088     AutoHideScreenEdgeV1InterfacePrivate(AutoHideScreenEdgeV1Interface *q, SurfaceInterface *surface, ElectricBorder border, wl_resource *resource);
0089 
0090     AutoHideScreenEdgeV1Interface *q;
0091     QPointer<SurfaceInterface> surface;
0092     ElectricBorder border;
0093 
0094 protected:
0095     void kde_auto_hide_screen_edge_v1_destroy_resource(Resource *resource) override;
0096     void kde_auto_hide_screen_edge_v1_destroy(Resource *resource) override;
0097     void kde_auto_hide_screen_edge_v1_deactivate(Resource *resource) override;
0098     void kde_auto_hide_screen_edge_v1_activate(Resource *resource) override;
0099 };
0100 
0101 AutoHideScreenEdgeV1InterfacePrivate::AutoHideScreenEdgeV1InterfacePrivate(AutoHideScreenEdgeV1Interface *q, SurfaceInterface *surface, ElectricBorder border, wl_resource *resource)
0102     : QtWaylandServer::kde_auto_hide_screen_edge_v1(resource)
0103     , q(q)
0104     , surface(surface)
0105     , border(border)
0106 {
0107 }
0108 
0109 void AutoHideScreenEdgeV1InterfacePrivate::kde_auto_hide_screen_edge_v1_destroy_resource(Resource *resource)
0110 {
0111     delete q;
0112 }
0113 
0114 void AutoHideScreenEdgeV1InterfacePrivate::kde_auto_hide_screen_edge_v1_destroy(Resource *resource)
0115 {
0116     wl_resource_destroy(resource->handle);
0117 }
0118 
0119 void AutoHideScreenEdgeV1InterfacePrivate::kde_auto_hide_screen_edge_v1_deactivate(Resource *resource)
0120 {
0121     Q_EMIT q->deactivateRequested();
0122 }
0123 
0124 void AutoHideScreenEdgeV1InterfacePrivate::kde_auto_hide_screen_edge_v1_activate(Resource *resource)
0125 {
0126     Q_EMIT q->activateRequested();
0127 }
0128 
0129 AutoHideScreenEdgeV1Interface::AutoHideScreenEdgeV1Interface(SurfaceInterface *surface, ElectricBorder border, wl_resource *resource)
0130     : d(new AutoHideScreenEdgeV1InterfacePrivate(this, surface, border, resource))
0131 {
0132 }
0133 
0134 AutoHideScreenEdgeV1Interface::~AutoHideScreenEdgeV1Interface()
0135 {
0136 }
0137 
0138 SurfaceInterface *AutoHideScreenEdgeV1Interface::surface() const
0139 {
0140     return d->surface;
0141 }
0142 
0143 ElectricBorder AutoHideScreenEdgeV1Interface::border() const
0144 {
0145     return d->border;
0146 }
0147 
0148 } // namespace KWin
0149 
0150 #include "moc_screenedge_v1.cpp"