File indexing completed on 2024-11-10 04:57:27
0001 /* 0002 SPDX-FileCopyrightText: 2022 David Edmundson <davidedmundson@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 "fractionalscale_v1.h" 0008 0009 #include "display.h" 0010 #include "fractionalscale_v1_p.h" 0011 #include "surface_p.h" 0012 0013 #include <cmath> 0014 0015 static const int s_version = 1; 0016 0017 namespace KWin 0018 { 0019 class FractionalScaleManagerV1InterfacePrivate : public QtWaylandServer::wp_fractional_scale_manager_v1 0020 { 0021 protected: 0022 void wp_fractional_scale_manager_v1_destroy(Resource *resource) override; 0023 void wp_fractional_scale_manager_v1_get_fractional_scale(Resource *resource, uint32_t id, wl_resource *surface) override; 0024 }; 0025 0026 void FractionalScaleManagerV1InterfacePrivate::wp_fractional_scale_manager_v1_destroy(Resource *resource) 0027 { 0028 wl_resource_destroy(resource->handle); 0029 } 0030 0031 void FractionalScaleManagerV1InterfacePrivate::wp_fractional_scale_manager_v1_get_fractional_scale(Resource *resource, uint32_t id, struct ::wl_resource *surface_resource) 0032 { 0033 SurfaceInterface *surface = SurfaceInterface::get(surface_resource); 0034 0035 FractionalScaleV1Interface *scaleIface = FractionalScaleV1Interface::get(surface); 0036 if (scaleIface) { 0037 wl_resource_post_error(resource->handle, error_fractional_scale_exists, "the specified surface already has a fractional scale"); 0038 return; 0039 } 0040 0041 wl_resource *surfaceScalerResource = wl_resource_create(resource->client(), &wp_fractional_scale_v1_interface, resource->version(), id); 0042 0043 new FractionalScaleV1Interface(surface, surfaceScalerResource); 0044 } 0045 0046 FractionalScaleV1Interface::FractionalScaleV1Interface(SurfaceInterface *surface, wl_resource *resource) 0047 : QtWaylandServer::wp_fractional_scale_v1(resource) 0048 , surface(surface) 0049 { 0050 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface); 0051 surfacePrivate->fractionalScaleExtension = this; 0052 if (surfacePrivate->preferredBufferScale.has_value()) { 0053 setPreferredScale(surfacePrivate->preferredBufferScale.value()); 0054 } 0055 } 0056 0057 FractionalScaleV1Interface::~FractionalScaleV1Interface() 0058 { 0059 if (surface) { 0060 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface); 0061 surfacePrivate->fractionalScaleExtension = nullptr; 0062 } 0063 } 0064 0065 FractionalScaleV1Interface *FractionalScaleV1Interface::get(SurfaceInterface *surface) 0066 { 0067 return SurfaceInterfacePrivate::get(surface)->fractionalScaleExtension; 0068 } 0069 0070 void FractionalScaleV1Interface::setPreferredScale(qreal scale) 0071 { 0072 send_preferred_scale(std::round(scale * 120)); 0073 } 0074 0075 void FractionalScaleV1Interface::wp_fractional_scale_v1_destroy(Resource *resource) 0076 { 0077 wl_resource_destroy(resource->handle); 0078 } 0079 0080 void FractionalScaleV1Interface::wp_fractional_scale_v1_destroy_resource(Resource *) 0081 { 0082 delete this; 0083 } 0084 0085 FractionalScaleManagerV1Interface::FractionalScaleManagerV1Interface(Display *display, QObject *parent) 0086 : QObject(parent) 0087 , d(new FractionalScaleManagerV1InterfacePrivate) 0088 { 0089 d->init(*display, s_version); 0090 } 0091 0092 FractionalScaleManagerV1Interface::~FractionalScaleManagerV1Interface() 0093 { 0094 } 0095 0096 } // namespace KWin 0097 0098 #include "moc_fractionalscale_v1.cpp"