KWin
Loading...
Searching...
No Matches
resource.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include <limits>
10#include <type_traits>
11
12struct wl_resource;
13
14namespace KWin
15{
16
17template<typename T>
18T resource_cast(::wl_resource *resource)
19{
20 using ObjectType = std::remove_pointer_t<std::remove_cv_t<T>>;
21 if (auto resourceContainer = ObjectType::Resource::fromResource(resource)) {
22 return static_cast<T>(resourceContainer->object());
23 }
24 return T();
25}
26
27} // namespace KWin
T resource_cast(::wl_resource *resource)
Definition resource.h:18