diff --git a/src/backends/drm/drm_gpu.cpp b/src/backends/drm/drm_gpu.cpp index 593fe15f2c..8285c1735d 100644 --- a/src/backends/drm/drm_gpu.cpp +++ b/src/backends/drm/drm_gpu.cpp @@ -77,7 +77,7 @@ DrmGpu::DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t device qCDebug(KWIN_DRM) << "drmModeAddFB2WithModifiers is" << (m_addFB2ModifiersSupported ? "supported" : "not supported") << "on GPU" << m_devNode; // find out what driver this kms device is using - DrmScopedPointer version(drmGetVersion(fd)); + DrmUniquePtr version(drmGetVersion(fd)); m_isNVidia = strstr(version->name, "nvidia-drm"); m_isVirtualMachine = strstr(version->name, "virtio") || strstr(version->name, "qxl") || strstr(version->name, "vmwgfx") || strstr(version->name, "vboxvideo"); @@ -160,13 +160,13 @@ void DrmGpu::initDrmResources() } else if (drmSetClientCap(m_fd, DRM_CLIENT_CAP_ATOMIC, 1) != 0) { qCWarning(KWIN_DRM) << "drmSetClientCap for Atomic Mode Setting failed. Using legacy mode on GPU" << m_devNode; } else { - DrmScopedPointer planeResources(drmModeGetPlaneResources(m_fd)); + DrmUniquePtr planeResources(drmModeGetPlaneResources(m_fd)); if (planeResources) { qCDebug(KWIN_DRM) << "Using Atomic Mode Setting on gpu" << m_devNode; qCDebug(KWIN_DRM) << "Number of planes on GPU" << m_devNode << ":" << planeResources->count_planes; // create the plane objects for (unsigned int i = 0; i < planeResources->count_planes; ++i) { - DrmScopedPointer kplane(drmModeGetPlane(m_fd, planeResources->planes[i])); + DrmUniquePtr kplane(drmModeGetPlane(m_fd, planeResources->planes[i])); DrmPlane *p = new DrmPlane(this, kplane->plane_id); if (p->init()) { m_planes << p; @@ -184,7 +184,7 @@ void DrmGpu::initDrmResources() } m_atomicModeSetting = !m_planes.isEmpty(); - DrmScopedPointer resources(drmModeGetResources(m_fd)); + DrmUniquePtr resources(drmModeGetResources(m_fd)); if (!resources) { qCCritical(KWIN_DRM) << "drmModeGetResources for getting CRTCs failed on GPU" << m_devNode; return; @@ -225,7 +225,7 @@ void DrmGpu::initDrmResources() bool DrmGpu::updateOutputs() { waitIdle(); - DrmScopedPointer resources(drmModeGetResources(m_fd)); + DrmUniquePtr resources(drmModeGetResources(m_fd)); if (!resources) { qCWarning(KWIN_DRM) << "drmModeGetResources failed"; return false; diff --git a/src/backends/drm/drm_object.cpp b/src/backends/drm/drm_object.cpp index 2e4ce6de3b..ebe1eaf606 100644 --- a/src/backends/drm/drm_object.cpp +++ b/src/backends/drm/drm_object.cpp @@ -134,7 +134,7 @@ bool DrmObject::needsCommit() const bool DrmObject::updateProperties() { - DrmScopedPointer properties(drmModeObjectGetProperties(m_gpu->fd(), m_id, m_objectType)); + DrmUniquePtr properties(drmModeObjectGetProperties(m_gpu->fd(), m_id, m_objectType)); if (!properties) { qCWarning(KWIN_DRM) << "Failed to get properties for object" << m_id; return false; @@ -143,7 +143,7 @@ bool DrmObject::updateProperties() const PropertyDefinition &def = m_propertyDefinitions[propIndex]; bool found = false; for (uint32_t drmPropIndex = 0; drmPropIndex < properties->count_props; drmPropIndex++) { - DrmScopedPointer prop(drmModeGetProperty(m_gpu->fd(), properties->props[drmPropIndex])); + DrmUniquePtr prop(drmModeGetProperty(m_gpu->fd(), properties->props[drmPropIndex])); if (!prop) { qCWarning(KWIN_DRM, "Getting property %d of object %d failed!", drmPropIndex, m_id); continue; @@ -152,7 +152,7 @@ bool DrmObject::updateProperties() if (m_props[propIndex]) { m_props[propIndex]->setCurrent(properties->prop_values[drmPropIndex]); } else { - m_props[propIndex] = new DrmProperty(this, prop.data(), properties->prop_values[drmPropIndex], def.enumNames); + m_props[propIndex] = new DrmProperty(this, prop.get(), properties->prop_values[drmPropIndex], def.enumNames); } found = true; break; diff --git a/src/backends/drm/drm_object_connector.cpp b/src/backends/drm/drm_object_connector.cpp index 03a5ca51e1..9bfc997b86 100644 --- a/src/backends/drm/drm_object_connector.cpp +++ b/src/backends/drm/drm_object_connector.cpp @@ -118,7 +118,7 @@ DrmConnector::DrmConnector(DrmGpu *gpu, uint32_t connectorId) { if (m_conn) { for (int i = 0; i < m_conn->count_encoders; ++i) { - DrmScopedPointer enc(drmModeGetEncoder(gpu->fd(), m_conn->encoders[i])); + DrmUniquePtr enc(drmModeGetEncoder(gpu->fd(), m_conn->encoders[i])); if (!enc) { qCWarning(KWIN_DRM) << "failed to get encoder" << m_conn->encoders[i]; continue; @@ -380,7 +380,7 @@ const Edid *DrmConnector::edid() const DrmPipeline *DrmConnector::pipeline() const { - return m_pipeline.data(); + return m_pipeline.get(); } void DrmConnector::disable() diff --git a/src/backends/drm/drm_object_connector.h b/src/backends/drm/drm_object_connector.h index aca3c7e808..b3be336a2e 100644 --- a/src/backends/drm/drm_object_connector.h +++ b/src/backends/drm/drm_object_connector.h @@ -108,8 +108,8 @@ private: QList> generateCommonModes(); std::shared_ptr generateMode(const QSize &size, uint32_t refreshRate); - QScopedPointer m_pipeline; - DrmScopedPointer m_conn; + std::unique_ptr m_pipeline; + DrmUniquePtr m_conn; Edid m_edid; QSize m_physicalSize = QSize(-1, -1); QList> m_driverModes; diff --git a/src/backends/drm/drm_object_crtc.h b/src/backends/drm/drm_object_crtc.h index 868af21ce7..8cd1127448 100644 --- a/src/backends/drm/drm_object_crtc.h +++ b/src/backends/drm/drm_object_crtc.h @@ -56,7 +56,7 @@ public: void releaseBuffers(); private: - DrmScopedPointer m_crtc; + DrmUniquePtr m_crtc; std::shared_ptr m_currentBuffer; std::shared_ptr m_nextBuffer; int m_pipeIndex; diff --git a/src/backends/drm/drm_object_plane.cpp b/src/backends/drm/drm_object_plane.cpp index 9b00932e5c..ded9d490e4 100644 --- a/src/backends/drm/drm_object_plane.cpp +++ b/src/backends/drm/drm_object_plane.cpp @@ -42,7 +42,7 @@ DrmPlane::DrmPlane(DrmGpu *gpu, uint32_t planeId) bool DrmPlane::init() { - DrmScopedPointer p(drmModeGetPlane(gpu()->fd(), id())); + DrmUniquePtr p(drmModeGetPlane(gpu()->fd(), id())); if (!p) { qCWarning(KWIN_DRM) << "Failed to get kernel plane" << id(); diff --git a/src/backends/drm/drm_pointer.h b/src/backends/drm/drm_pointer.h index 8b216bf0b3..31c02eb46b 100644 --- a/src/backends/drm/drm_pointer.h +++ b/src/backends/drm/drm_pointer.h @@ -10,8 +10,7 @@ #ifndef KWIN_DRM_POINTER_H #define KWIN_DRM_POINTER_H -#include - +#include #include #include @@ -24,7 +23,7 @@ struct DrmDeleter; template<> struct DrmDeleter { - static void cleanup(drmVersion *version) + void operator()(drmVersion *version) { drmFreeVersion(version); } @@ -33,7 +32,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeAtomicReq *req) + void operator()(drmModeAtomicReq *req) { drmModeAtomicFree(req); } @@ -42,7 +41,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeConnector *connector) + void operator()(drmModeConnector *connector) { drmModeFreeConnector(connector); } @@ -51,7 +50,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeCrtc *crtc) + void operator()(drmModeCrtc *crtc) { drmModeFreeCrtc(crtc); } @@ -60,7 +59,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeFB *fb) + void operator()(drmModeFB *fb) { drmModeFreeFB(fb); } @@ -69,7 +68,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeEncoder *encoder) + void operator()(drmModeEncoder *encoder) { drmModeFreeEncoder(encoder); } @@ -78,7 +77,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeModeInfo *info) + void operator()(drmModeModeInfo *info) { drmModeFreeModeInfo(info); } @@ -87,7 +86,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeObjectProperties *properties) + void operator()(drmModeObjectProperties *properties) { drmModeFreeObjectProperties(properties); } @@ -96,7 +95,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModePlane *plane) + void operator()(drmModePlane *plane) { drmModeFreePlane(plane); } @@ -105,7 +104,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModePlaneRes *resources) + void operator()(drmModePlaneRes *resources) { drmModeFreePlaneResources(resources); } @@ -114,7 +113,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModePropertyRes *property) + void operator()(drmModePropertyRes *property) { drmModeFreeProperty(property); } @@ -123,7 +122,7 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModePropertyBlobRes *blob) + void operator()(drmModePropertyBlobRes *blob) { drmModeFreePropertyBlob(blob); } @@ -132,15 +131,14 @@ struct DrmDeleter template<> struct DrmDeleter { - static void cleanup(drmModeRes *resources) + void operator()(drmModeRes *resources) { drmModeFreeResources(resources); } }; template -using DrmScopedPointer = QScopedPointer>; - +using DrmUniquePtr = std::unique_ptr>; } #endif diff --git a/src/backends/drm/drm_property.h b/src/backends/drm/drm_property.h index fac3a17d5a..a358dbba6c 100644 --- a/src/backends/drm/drm_property.h +++ b/src/backends/drm/drm_property.h @@ -96,7 +96,7 @@ private: uint64_t m_next = 0; // the value currently set for or by the kernel uint64_t m_current = 0; - DrmScopedPointer m_immutableBlob; + DrmUniquePtr m_immutableBlob; uint64_t m_minValue = -1; uint64_t m_maxValue = -1; diff --git a/src/backends/drm/gbm_surface.cpp b/src/backends/drm/gbm_surface.cpp index 784f9ef028..1feaa51d05 100644 --- a/src/backends/drm/gbm_surface.cpp +++ b/src/backends/drm/gbm_surface.cpp @@ -83,7 +83,7 @@ void GbmSurface::releaseBuffer(GbmBuffer *buffer) GLFramebuffer *GbmSurface::fbo() const { - return m_fbo.data(); + return m_fbo.get(); } EGLSurface GbmSurface::eglSurface() const diff --git a/src/backends/drm/gbm_surface.h b/src/backends/drm/gbm_surface.h index 607b4d12c5..b3f6a8f949 100644 --- a/src/backends/drm/gbm_surface.h +++ b/src/backends/drm/gbm_surface.h @@ -67,7 +67,7 @@ private: int m_bufferAge = 0; DamageJournal m_damageJournal; - QScopedPointer m_fbo; + std::unique_ptr m_fbo; }; } diff --git a/src/backends/drm/shadowbuffer.cpp b/src/backends/drm/shadowbuffer.cpp index 79c8f0b476..35939b69d2 100644 --- a/src/backends/drm/shadowbuffer.cpp +++ b/src/backends/drm/shadowbuffer.cpp @@ -88,7 +88,7 @@ void ShadowBuffer::render(DrmPlane::Transformations transform) GLFramebuffer *ShadowBuffer::fbo() const { - return m_fbo.data(); + return m_fbo.get(); } std::shared_ptr ShadowBuffer::texture() const diff --git a/src/backends/drm/shadowbuffer.h b/src/backends/drm/shadowbuffer.h index d62602c4d3..77cf72b3bf 100644 --- a/src/backends/drm/shadowbuffer.h +++ b/src/backends/drm/shadowbuffer.h @@ -33,8 +33,8 @@ public: private: GLint internalFormat(const GbmFormat &format) const; std::shared_ptr m_texture; - QScopedPointer m_fbo; - QScopedPointer m_vbo; + std::unique_ptr m_fbo; + std::unique_ptr m_vbo; const QSize m_size; const uint32_t m_drmFormat; }; diff --git a/src/backends/virtual/egl_gbm_backend.h b/src/backends/virtual/egl_gbm_backend.h index fdf3509c54..50e4a866b1 100644 --- a/src/backends/virtual/egl_gbm_backend.h +++ b/src/backends/virtual/egl_gbm_backend.h @@ -56,7 +56,7 @@ private: GLTexture *m_backBuffer = nullptr; GLFramebuffer *m_fbo = nullptr; int m_frameCounter = 0; - QScopedPointer m_layer; + std::unique_ptr m_layer; }; } // namespace diff --git a/src/backends/virtual/virtual_backend.cpp b/src/backends/virtual/virtual_backend.cpp index 9bd9041390..87ed75cbf4 100644 --- a/src/backends/virtual/virtual_backend.cpp +++ b/src/backends/virtual/virtual_backend.cpp @@ -34,7 +34,7 @@ VirtualBackend::VirtualBackend(QObject *parent) if (!m_screenshotDir->isValid()) { m_screenshotDir.reset(); } - if (!m_screenshotDir.isNull()) { + if (m_screenshotDir) { qDebug() << "Screenshots saved to: " << m_screenshotDir->path(); } } @@ -80,7 +80,7 @@ bool VirtualBackend::initialize() QString VirtualBackend::screenshotDirPath() const { - if (m_screenshotDir.isNull()) { + if (!m_screenshotDir) { return QString(); } return m_screenshotDir->path(); diff --git a/src/backends/virtual/virtual_backend.h b/src/backends/virtual/virtual_backend.h index c53cf0cabd..4d9932f4e7 100644 --- a/src/backends/virtual/virtual_backend.h +++ b/src/backends/virtual/virtual_backend.h @@ -38,7 +38,7 @@ public: bool saveFrames() const { - return !m_screenshotDir.isNull(); + return m_screenshotDir != nullptr; } QString screenshotDirPath() const; @@ -69,7 +69,7 @@ Q_SIGNALS: private: QVector m_outputs; QVector m_outputsEnabled; - QScopedPointer m_screenshotDir; + std::unique_ptr m_screenshotDir; Session *m_session; }; diff --git a/src/backends/wayland/egl_wayland_backend.cpp b/src/backends/wayland/egl_wayland_backend.cpp index 2d2eff310d..5648f0108e 100644 --- a/src/backends/wayland/egl_wayland_backend.cpp +++ b/src/backends/wayland/egl_wayland_backend.cpp @@ -110,7 +110,7 @@ EglWaylandOutput::~EglWaylandOutput() GLFramebuffer *EglWaylandOutput::fbo() const { - return m_fbo.data(); + return m_fbo.get(); } void EglWaylandOutput::updateSize() @@ -156,7 +156,7 @@ OutputLayerBeginFrameInfo EglWaylandOutput::beginFrame() GLFramebuffer::pushFramebuffer(m_fbo.get()); return OutputLayerBeginFrameInfo{ - .renderTarget = RenderTarget(m_fbo.data()), + .renderTarget = RenderTarget(m_fbo.get()), .repaint = repair, }; } diff --git a/src/backends/wayland/egl_wayland_backend.h b/src/backends/wayland/egl_wayland_backend.h index d4348f6b12..b8e2f5b5d3 100644 --- a/src/backends/wayland/egl_wayland_backend.h +++ b/src/backends/wayland/egl_wayland_backend.h @@ -59,7 +59,7 @@ private: EGLSurface m_eglSurface = EGL_NO_SURFACE; int m_bufferAge = 0; DamageJournal m_damageJournal; - QScopedPointer m_fbo; + std::unique_ptr m_fbo; EglWaylandBackend *const m_backend; friend class EglWaylandBackend; diff --git a/src/backends/wayland/wayland_backend.cpp b/src/backends/wayland/wayland_backend.cpp index d2374b519d..35d8993a97 100644 --- a/src/backends/wayland/wayland_backend.cpp +++ b/src/backends/wayland/wayland_backend.cpp @@ -281,36 +281,36 @@ WaylandInputDevice::WaylandInputDevice(KWayland::Client::Pointer *pointer, Wayla KWayland::Client::PointerGestures *pointerGestures = m_seat->backend()->pointerGestures(); if (pointerGestures) { - m_pinchGesture.reset(pointerGestures->createPinchGesture(m_pointer.data(), this)); - connect(m_pinchGesture.data(), &PointerPinchGesture::started, this, [this](quint32 serial, quint32 time) { + m_pinchGesture.reset(pointerGestures->createPinchGesture(m_pointer.get(), this)); + connect(m_pinchGesture.get(), &PointerPinchGesture::started, this, [this](quint32 serial, quint32 time) { Q_UNUSED(serial); Q_EMIT pinchGestureBegin(m_pinchGesture->fingerCount(), time, this); }); - connect(m_pinchGesture.data(), &PointerPinchGesture::updated, this, [this](const QSizeF &delta, qreal scale, qreal rotation, quint32 time) { + connect(m_pinchGesture.get(), &PointerPinchGesture::updated, this, [this](const QSizeF &delta, qreal scale, qreal rotation, quint32 time) { Q_EMIT pinchGestureUpdate(scale, rotation, delta, time, this); }); - connect(m_pinchGesture.data(), &PointerPinchGesture::ended, this, [this](quint32 serial, quint32 time) { + connect(m_pinchGesture.get(), &PointerPinchGesture::ended, this, [this](quint32 serial, quint32 time) { Q_UNUSED(serial) Q_EMIT pinchGestureEnd(time, this); }); - connect(m_pinchGesture.data(), &PointerPinchGesture::cancelled, this, [this](quint32 serial, quint32 time) { + connect(m_pinchGesture.get(), &PointerPinchGesture::cancelled, this, [this](quint32 serial, quint32 time) { Q_UNUSED(serial) Q_EMIT pinchGestureCancelled(time, this); }); - m_swipeGesture.reset(pointerGestures->createSwipeGesture(m_pointer.data(), this)); - connect(m_swipeGesture.data(), &PointerSwipeGesture::started, this, [this](quint32 serial, quint32 time) { + m_swipeGesture.reset(pointerGestures->createSwipeGesture(m_pointer.get(), this)); + connect(m_swipeGesture.get(), &PointerSwipeGesture::started, this, [this](quint32 serial, quint32 time) { Q_UNUSED(serial) Q_EMIT swipeGestureBegin(m_swipeGesture->fingerCount(), time, this); }); - connect(m_swipeGesture.data(), &PointerSwipeGesture::updated, this, [this](const QSizeF &delta, quint32 time) { + connect(m_swipeGesture.get(), &PointerSwipeGesture::updated, this, [this](const QSizeF &delta, quint32 time) { Q_EMIT swipeGestureUpdate(delta, time, this); }); - connect(m_swipeGesture.data(), &PointerSwipeGesture::ended, this, [this](quint32 serial, quint32 time) { + connect(m_swipeGesture.get(), &PointerSwipeGesture::ended, this, [this](quint32 serial, quint32 time) { Q_UNUSED(serial) Q_EMIT swipeGestureEnd(time, this); }); - connect(m_swipeGesture.data(), &PointerSwipeGesture::cancelled, this, [this](quint32 serial, quint32 time) { + connect(m_swipeGesture.get(), &PointerSwipeGesture::cancelled, this, [this](quint32 serial, quint32 time) { Q_UNUSED(serial) Q_EMIT swipeGestureCancelled(time, this); }); @@ -388,12 +388,12 @@ void WaylandInputDevice::setLeds(LEDs leds) bool WaylandInputDevice::isKeyboard() const { - return !m_keyboard.isNull(); + return m_keyboard != nullptr; } bool WaylandInputDevice::isAlphaNumericKeyboard() const { - return !m_keyboard.isNull(); + return m_keyboard != nullptr; } bool WaylandInputDevice::isPointer() const @@ -408,7 +408,7 @@ bool WaylandInputDevice::isTouchpad() const bool WaylandInputDevice::isTouch() const { - return !m_touch.isNull(); + return m_touch != nullptr; } bool WaylandInputDevice::isTabletTool() const @@ -433,7 +433,7 @@ bool WaylandInputDevice::isLidSwitch() const KWayland::Client::Pointer *WaylandInputDevice::nativePointer() const { - return m_pointer.data(); + return m_pointer.get(); } WaylandInputBackend::WaylandInputBackend(WaylandBackend *backend, QObject *parent) @@ -987,7 +987,7 @@ void WaylandBackend::createDpmsFilter() return; } m_dpmsFilter.reset(new DpmsInputEventFilter); - input()->prependInputEventFilter(m_dpmsFilter.data()); + input()->prependInputEventFilter(m_dpmsFilter.get()); } void WaylandBackend::clearDpmsFilter() diff --git a/src/backends/wayland/wayland_backend.h b/src/backends/wayland/wayland_backend.h index e162fdf25c..267174ab5b 100644 --- a/src/backends/wayland/wayland_backend.h +++ b/src/backends/wayland/wayland_backend.h @@ -160,12 +160,12 @@ public: private: WaylandSeat *m_seat; - QScopedPointer m_keyboard; - QScopedPointer m_touch; - QScopedPointer m_relativePointer; - QScopedPointer m_pointer; - QScopedPointer m_pinchGesture; - QScopedPointer m_swipeGesture; + std::unique_ptr m_keyboard; + std::unique_ptr m_touch; + std::unique_ptr m_relativePointer; + std::unique_ptr m_pointer; + std::unique_ptr m_pinchGesture; + std::unique_ptr m_swipeGesture; uint32_t m_enteredSerial = 0; }; @@ -353,7 +353,7 @@ private: WaylandCursor *m_waylandCursor = nullptr; - QScopedPointer m_dpmsFilter; + std::unique_ptr m_dpmsFilter; bool m_pointerLockRequested = false; KWayland::Client::ServerSideDecorationManager *m_ssdManager = nullptr; diff --git a/src/backends/x11/common/kwinxrenderutils.cpp b/src/backends/x11/common/kwinxrenderutils.cpp index 1b069e199c..f06c029e61 100644 --- a/src/backends/x11/common/kwinxrenderutils.cpp +++ b/src/backends/x11/common/kwinxrenderutils.cpp @@ -87,12 +87,12 @@ void XRenderPicture::fromImage(const QImage &img) 0, 0, 0, depth, img.sizeInBytes(), img.constBits()); xcb_free_gc(c, cid); - d = new XRenderPictureData(createPicture(xpix, depth)); + d = std::make_unique(createPicture(xpix, depth)); xcb_free_pixmap(c, xpix); } XRenderPicture::XRenderPicture(xcb_pixmap_t pix, int depth) - : d(new XRenderPictureData(createPicture(pix, depth))) + : d(std::make_unique(createPicture(pix, depth))) { } diff --git a/src/backends/x11/common/kwinxrenderutils.h b/src/backends/x11/common/kwinxrenderutils.h index 9e96d9f47c..ef5d52f93c 100644 --- a/src/backends/x11/common/kwinxrenderutils.h +++ b/src/backends/x11/common/kwinxrenderutils.h @@ -19,6 +19,8 @@ // XCB #include +#include + class QImage; /** @addtogroup kwineffects */ @@ -58,7 +60,7 @@ public: private: void fromImage(const QImage &img); - QExplicitlySharedDataPointer d; + std::unique_ptr d; }; inline XRenderPictureData::XRenderPictureData(xcb_render_picture_t pic) @@ -72,7 +74,7 @@ inline xcb_render_picture_t XRenderPictureData::value() } inline XRenderPicture::XRenderPicture(xcb_render_picture_t pic) - : d(new XRenderPictureData(pic)) + : d(std::make_unique(pic)) { } diff --git a/src/backends/x11/standalone/eglbackend.cpp b/src/backends/x11/standalone/eglbackend.cpp index 921ee446f8..7bf5eee370 100644 --- a/src/backends/x11/standalone/eglbackend.cpp +++ b/src/backends/x11/standalone/eglbackend.cpp @@ -45,7 +45,7 @@ bool EglLayer::endFrame(const QRegion &renderedRegion, const QRegion &damagedReg EglBackend::EglBackend(Display *display, X11StandalonePlatform *backend) : EglOnXBackend(display) , m_backend(backend) - , m_layer(new EglLayer(this)) + , m_layer(std::make_unique(this)) { // There is no any way to determine when a buffer swap completes with EGL. Fallback // to software vblank events. Could we use the Present extension to get notified when @@ -134,9 +134,9 @@ OutputLayerBeginFrameInfo EglBackend::beginFrame() eglWaitNative(EGL_CORE_NATIVE_ENGINE); // Push the default framebuffer to the render target stack. - GLFramebuffer::pushFramebuffer(m_fbo.data()); + GLFramebuffer::pushFramebuffer(m_fbo.get()); return OutputLayerBeginFrameInfo{ - .renderTarget = RenderTarget(m_fbo.data()), + .renderTarget = RenderTarget(m_fbo.get()), .repaint = repaint, }; } diff --git a/src/backends/x11/standalone/eglbackend.h b/src/backends/x11/standalone/eglbackend.h index 154652a594..3127c78ada 100644 --- a/src/backends/x11/standalone/eglbackend.h +++ b/src/backends/x11/standalone/eglbackend.h @@ -58,10 +58,10 @@ private: X11StandalonePlatform *m_backend; SoftwareVsyncMonitor *m_vsyncMonitor; DamageJournal m_damageJournal; - QScopedPointer m_fbo; + std::unique_ptr m_fbo; int m_bufferAge = 0; QRegion m_lastRenderedRegion; - QScopedPointer m_layer; + std::unique_ptr m_layer; }; class EglPixmapTexture : public GLTexture diff --git a/src/backends/x11/standalone/glxbackend.cpp b/src/backends/x11/standalone/glxbackend.cpp index 6c430b7eeb..207f4b6fa3 100644 --- a/src/backends/x11/standalone/glxbackend.cpp +++ b/src/backends/x11/standalone/glxbackend.cpp @@ -129,7 +129,7 @@ GlxBackend::GlxBackend(Display *display, X11StandalonePlatform *backend) , m_bufferAge(0) , m_x11Display(display) , m_backend(backend) - , m_layer(new GlxLayer(this)) + , m_layer(std::make_unique(this)) { // Force initialization of GLX integration in the Qt's xcb backend // to make it call XESetWireToEvent callbacks, which is required @@ -231,7 +231,7 @@ void GlxBackend::init() glPlatform->printResults(); initGL(&getProcAddress); - m_fbo.reset(new GLFramebuffer(0, screens()->size())); + m_fbo = std::make_unique(0, screens()->size()); bool supportsSwapEvent = false; @@ -772,7 +772,7 @@ void GlxBackend::screenGeometryChanged() // The back buffer contents are now undefined m_bufferAge = 0; - m_fbo.reset(new GLFramebuffer(0, size)); + m_fbo = std::make_unique(0, size); } SurfaceTexture *GlxBackend::createSurfaceTextureX11(SurfacePixmapX11 *pixmap) @@ -785,7 +785,7 @@ OutputLayerBeginFrameInfo GlxBackend::beginFrame() QRegion repaint; makeCurrent(); - GLFramebuffer::pushFramebuffer(m_fbo.data()); + GLFramebuffer::pushFramebuffer(m_fbo.get()); if (supportsBufferAge()) { repaint = m_damageJournal.accumulate(m_bufferAge, infiniteRegion()); } @@ -793,7 +793,7 @@ OutputLayerBeginFrameInfo GlxBackend::beginFrame() glXWaitX(); return OutputLayerBeginFrameInfo{ - .renderTarget = RenderTarget(m_fbo.data()), + .renderTarget = RenderTarget(m_fbo.get()), .repaint = repaint, }; } diff --git a/src/backends/x11/standalone/glxbackend.h b/src/backends/x11/standalone/glxbackend.h index ca62bd8060..94aa73a805 100644 --- a/src/backends/x11/standalone/glxbackend.h +++ b/src/backends/x11/standalone/glxbackend.h @@ -123,7 +123,7 @@ private: QHash m_fbconfigHash; QHash m_visualDepthHash; std::unique_ptr m_swapEventFilter; - QScopedPointer m_fbo; + std::unique_ptr m_fbo; DamageJournal m_damageJournal; QRegion m_lastRenderedRegion; int m_bufferAge; @@ -134,7 +134,7 @@ private: Display *m_x11Display; X11StandalonePlatform *m_backend; VsyncMonitor *m_vsyncMonitor = nullptr; - QScopedPointer m_layer; + std::unique_ptr m_layer; friend class GlxPixmapTexturePrivate; }; diff --git a/src/backends/x11/standalone/x11_platform.cpp b/src/backends/x11/standalone/x11_platform.cpp index 89f8e9d4ff..64282ebfdc 100644 --- a/src/backends/x11/standalone/x11_platform.cpp +++ b/src/backends/x11/standalone/x11_platform.cpp @@ -31,6 +31,7 @@ #include "overlaywindow_x11.h" #include "renderloop.h" #include "screenedges_filter.h" +#include "utils/c_ptr.h" #include "utils/xcbutils.h" #include "window.h" #include "workspace.h" @@ -180,8 +181,8 @@ OpenGLBackend *X11StandalonePlatform::createOpenGLBackend() Edge *X11StandalonePlatform::createScreenEdge(ScreenEdges *edges) { - if (m_screenEdgesFilter.isNull()) { - m_screenEdgesFilter.reset(new ScreenEdgesFilter); + if (!m_screenEdgesFilter) { + m_screenEdgesFilter = std::make_unique(); } return new WindowBasedEdge(edges); } @@ -328,15 +329,15 @@ void X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint) PlatformCursorImage X11StandalonePlatform::cursorImage() const { auto c = kwinApp()->x11Connection(); - QScopedPointer cursor( + UniqueCPtr cursor( xcb_xfixes_get_cursor_image_reply(c, xcb_xfixes_get_cursor_image_unchecked(c), nullptr)); - if (cursor.isNull()) { + if (!cursor) { return PlatformCursorImage(); } - QImage qcursorimg((uchar *)xcb_xfixes_get_cursor_image_cursor_image(cursor.data()), cursor->width, cursor->height, + QImage qcursorimg((uchar *)xcb_xfixes_get_cursor_image_cursor_image(cursor.get()), cursor->width, cursor->height, QImage::Format_ARGB32_Premultiplied); // deep copy of image as the data is going to be freed return PlatformCursorImage(qcursorimg.copy(), QPoint(cursor->xhot, cursor->yhot)); @@ -353,7 +354,7 @@ void X11StandalonePlatform::updateCursor() void X11StandalonePlatform::startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName) { - if (m_windowSelector.isNull()) { + if (!m_windowSelector) { m_windowSelector.reset(new WindowSelector); } m_windowSelector->start(callback, cursorName); @@ -361,7 +362,7 @@ void X11StandalonePlatform::startInteractiveWindowSelection(std::function callback) { - if (m_windowSelector.isNull()) { + if (!m_windowSelector) { m_windowSelector.reset(new WindowSelector); } m_windowSelector->start(callback); diff --git a/src/backends/x11/standalone/x11_platform.h b/src/backends/x11/standalone/x11_platform.h index 6a6c03c8eb..cc290a7d4e 100644 --- a/src/backends/x11/standalone/x11_platform.h +++ b/src/backends/x11/standalone/x11_platform.h @@ -93,9 +93,9 @@ private: QTimer *m_openGLFreezeProtection = nullptr; QTimer *m_updateOutputsTimer = nullptr; Display *m_x11Display; - QScopedPointer m_windowSelector; - QScopedPointer m_screenEdgesFilter; - QScopedPointer m_randrEventFilter; + std::unique_ptr m_windowSelector; + std::unique_ptr m_screenEdgesFilter; + std::unique_ptr m_randrEventFilter; RenderLoop *m_renderLoop; QVector m_outputs; }; diff --git a/src/backends/x11/standalone/xinputintegration.h b/src/backends/x11/standalone/xinputintegration.h index 6d2d88ec38..40904f4040 100644 --- a/src/backends/x11/standalone/xinputintegration.h +++ b/src/backends/x11/standalone/xinputintegration.h @@ -11,7 +11,7 @@ #include #include -#include +#include typedef struct _XDisplay Display; namespace KWin @@ -50,9 +50,9 @@ private: QPointer m_x11Cursor; Display *m_x11Display; - QScopedPointer m_xiEventFilter; - QScopedPointer m_keyPressFilter; - QScopedPointer m_keyReleaseFilter; + std::unique_ptr m_xiEventFilter; + std::unique_ptr m_keyPressFilter; + std::unique_ptr m_keyReleaseFilter; }; } diff --git a/src/backends/x11/windowed/egl_x11_backend.cpp b/src/backends/x11/windowed/egl_x11_backend.cpp index b7d5813430..6cb880263b 100644 --- a/src/backends/x11/windowed/egl_x11_backend.cpp +++ b/src/backends/x11/windowed/egl_x11_backend.cpp @@ -44,9 +44,9 @@ OutputLayerBeginFrameInfo EglX11Output::beginFrame() { eglMakeCurrent(m_backend->eglDisplay(), m_eglSurface, m_eglSurface, m_backend->context()); ensureFbo(); - GLFramebuffer::pushFramebuffer(m_fbo.data()); + GLFramebuffer::pushFramebuffer(m_fbo.get()); return OutputLayerBeginFrameInfo{ - .renderTarget = RenderTarget(m_fbo.data()), + .renderTarget = RenderTarget(m_fbo.get()), .repaint = m_output->rect(), }; } diff --git a/src/backends/x11/windowed/egl_x11_backend.h b/src/backends/x11/windowed/egl_x11_backend.h index 32dd246a54..0b33779d37 100644 --- a/src/backends/x11/windowed/egl_x11_backend.h +++ b/src/backends/x11/windowed/egl_x11_backend.h @@ -35,7 +35,7 @@ private: void ensureFbo(); EGLSurface m_eglSurface; - QScopedPointer m_fbo; + std::unique_ptr m_fbo; QRegion m_lastDamage; Output *const m_output; diff --git a/src/utils/c_ptr.h b/src/utils/c_ptr.h new file mode 100644 index 0000000000..326cc991b4 --- /dev/null +++ b/src/utils/c_ptr.h @@ -0,0 +1,30 @@ +/* + KWin - the KDE window manager + This file is part of the KDE project. + + SPDX-FileCopyrightText: 2022 Xaver Hugl + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +#pragma once + +#include + +namespace KWin +{ + +struct CDeleter +{ + template + void operator()(T *ptr) + { + if (ptr) { + free(ptr); + } + } +}; + +template +using UniqueCPtr = std::unique_ptr; + +}