/* SPDX-FileCopyrightText: 2020 Vlad Zahorodnii SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include #include #include struct wl_resource; namespace KWaylandServer { template struct SafeGlobalDeleter { static inline void cleanup(T *global) { if (global) { global->remove(); } } }; template using ScopedGlobalPointer = QScopedPointer>; /** * Returns an infinite region. */ inline QRegion KWAYLANDSERVER_EXPORT infiniteRegion() { return QRegion(std::numeric_limits::min() / 2, // "/ 2" is to avoid integer overflows std::numeric_limits::min() / 2, std::numeric_limits::max(), std::numeric_limits::max()); } template T resource_cast(::wl_resource *resource) { using ObjectType = std::remove_pointer_t>; if (auto resourceContainer = ObjectType::Resource::fromResource(resource)) { return static_cast(resourceContainer->object()); } return T(); } } // namespace KWaylandServer