File indexing completed on 2024-12-22 05:09:20
0001 /* 0002 SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #include "idleinhibit.h" 0007 #include "event_queue.h" 0008 #include "surface.h" 0009 #include "wayland_pointer_p.h" 0010 0011 #include <wayland-idle-inhibit-unstable-v1-client-protocol.h> 0012 0013 namespace KWayland 0014 { 0015 namespace Client 0016 { 0017 class Q_DECL_HIDDEN IdleInhibitManager::Private 0018 { 0019 public: 0020 Private() = default; 0021 0022 void setup(zwp_idle_inhibit_manager_v1 *arg); 0023 0024 WaylandPointer<zwp_idle_inhibit_manager_v1, zwp_idle_inhibit_manager_v1_destroy> idleinhibitmanager; 0025 EventQueue *queue = nullptr; 0026 }; 0027 0028 IdleInhibitManager::IdleInhibitManager(QObject *parent) 0029 : QObject(parent) 0030 , d(new Private) 0031 { 0032 } 0033 0034 void IdleInhibitManager::Private::setup(zwp_idle_inhibit_manager_v1 *arg) 0035 { 0036 Q_ASSERT(arg); 0037 Q_ASSERT(!idleinhibitmanager); 0038 idleinhibitmanager.setup(arg); 0039 } 0040 0041 IdleInhibitManager::~IdleInhibitManager() 0042 { 0043 release(); 0044 } 0045 0046 void IdleInhibitManager::setup(zwp_idle_inhibit_manager_v1 *idleinhibitmanager) 0047 { 0048 d->setup(idleinhibitmanager); 0049 } 0050 0051 void IdleInhibitManager::release() 0052 { 0053 d->idleinhibitmanager.release(); 0054 } 0055 0056 void IdleInhibitManager::destroy() 0057 { 0058 d->idleinhibitmanager.destroy(); 0059 } 0060 0061 IdleInhibitManager::operator zwp_idle_inhibit_manager_v1 *() 0062 { 0063 return d->idleinhibitmanager; 0064 } 0065 0066 IdleInhibitManager::operator zwp_idle_inhibit_manager_v1 *() const 0067 { 0068 return d->idleinhibitmanager; 0069 } 0070 0071 bool IdleInhibitManager::isValid() const 0072 { 0073 return d->idleinhibitmanager.isValid(); 0074 } 0075 0076 void IdleInhibitManager::setEventQueue(EventQueue *queue) 0077 { 0078 d->queue = queue; 0079 } 0080 0081 EventQueue *IdleInhibitManager::eventQueue() 0082 { 0083 return d->queue; 0084 } 0085 0086 IdleInhibitor *IdleInhibitManager::createInhibitor(Surface *surface, QObject *parent) 0087 { 0088 Q_ASSERT(isValid()); 0089 auto p = new IdleInhibitor(parent); 0090 auto w = zwp_idle_inhibit_manager_v1_create_inhibitor(d->idleinhibitmanager, *surface); 0091 if (d->queue) { 0092 d->queue->addProxy(w); 0093 } 0094 p->setup(w); 0095 return p; 0096 } 0097 0098 class Q_DECL_HIDDEN IdleInhibitor::Private 0099 { 0100 public: 0101 void setup(zwp_idle_inhibitor_v1 *arg); 0102 0103 WaylandPointer<zwp_idle_inhibitor_v1, zwp_idle_inhibitor_v1_destroy> idleinhibitor; 0104 }; 0105 0106 IdleInhibitor::IdleInhibitor(QObject *parent) 0107 : QObject(parent) 0108 , d(new Private) 0109 { 0110 } 0111 0112 void IdleInhibitor::Private::setup(zwp_idle_inhibitor_v1 *arg) 0113 { 0114 Q_ASSERT(arg); 0115 Q_ASSERT(!idleinhibitor); 0116 idleinhibitor.setup(arg); 0117 } 0118 0119 IdleInhibitor::~IdleInhibitor() 0120 { 0121 release(); 0122 } 0123 0124 void IdleInhibitor::setup(zwp_idle_inhibitor_v1 *idleinhibitor) 0125 { 0126 d->setup(idleinhibitor); 0127 } 0128 0129 void IdleInhibitor::release() 0130 { 0131 d->idleinhibitor.release(); 0132 } 0133 0134 void IdleInhibitor::destroy() 0135 { 0136 d->idleinhibitor.destroy(); 0137 } 0138 0139 IdleInhibitor::operator zwp_idle_inhibitor_v1 *() 0140 { 0141 return d->idleinhibitor; 0142 } 0143 0144 IdleInhibitor::operator zwp_idle_inhibitor_v1 *() const 0145 { 0146 return d->idleinhibitor; 0147 } 0148 0149 bool IdleInhibitor::isValid() const 0150 { 0151 return d->idleinhibitor.isValid(); 0152 } 0153 0154 } 0155 } 0156 0157 #include "moc_idleinhibit.cpp"