File indexing completed on 2024-05-19 16:35:32

0001 /*
0002     SPDX-FileCopyrightText: 2020 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 #pragma once
0008 
0009 #include "kwin_export.h"
0010 
0011 #include <QRegion>
0012 
0013 #include <limits>
0014 #include <type_traits>
0015 
0016 struct wl_resource;
0017 
0018 namespace KWaylandServer
0019 {
0020 
0021 /**
0022  * Returns an infinite region.
0023  */
0024 inline QRegion KWIN_EXPORT infiniteRegion()
0025 {
0026     return QRegion(std::numeric_limits<int>::min() / 2, // "/ 2" is to avoid integer overflows
0027                    std::numeric_limits<int>::min() / 2,
0028                    std::numeric_limits<int>::max(),
0029                    std::numeric_limits<int>::max());
0030 }
0031 
0032 template<typename T>
0033 T resource_cast(::wl_resource *resource)
0034 {
0035     using ObjectType = std::remove_pointer_t<std::remove_cv_t<T>>;
0036     if (auto resourceContainer = ObjectType::Resource::fromResource(resource)) {
0037         return static_cast<T>(resourceContainer->object());
0038     }
0039     return T();
0040 }
0041 
0042 } // namespace KWaylandServer