File indexing completed on 2024-11-10 04:57:27
0001 /* 0002 SPDX-FileCopyrightText: 2015 Martin Gräßlin <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 "display.h" 0007 #include "idle_p.h" 0008 #include "seat.h" 0009 0010 #include "idledetector.h" 0011 #include "input.h" 0012 0013 namespace KWin 0014 { 0015 0016 static const quint32 s_version = 1; 0017 0018 IdleInterfacePrivate::IdleInterfacePrivate(Display *display) 0019 : QtWaylandServer::org_kde_kwin_idle(*display, s_version) 0020 { 0021 } 0022 0023 void IdleInterfacePrivate::org_kde_kwin_idle_get_idle_timeout(Resource *resource, uint32_t id, wl_resource *seat, uint32_t timeout) 0024 { 0025 SeatInterface *s = SeatInterface::get(seat); 0026 Q_ASSERT(s); 0027 0028 wl_resource *idleTimoutResource = wl_resource_create(resource->client(), &org_kde_kwin_idle_timeout_interface, resource->version(), id); 0029 if (!idleTimoutResource) { 0030 wl_client_post_no_memory(resource->client()); 0031 return; 0032 } 0033 0034 new IdleTimeoutInterface(std::chrono::milliseconds(timeout), idleTimoutResource); 0035 } 0036 0037 IdleInterface::IdleInterface(Display *display, QObject *parent) 0038 : QObject(parent) 0039 , d(new IdleInterfacePrivate(display)) 0040 { 0041 } 0042 0043 IdleInterface::~IdleInterface() = default; 0044 0045 IdleTimeoutInterface::IdleTimeoutInterface(std::chrono::milliseconds timeout, wl_resource *resource) 0046 : QtWaylandServer::org_kde_kwin_idle_timeout(resource) 0047 { 0048 auto detector = new IdleDetector(timeout, this); 0049 connect(detector, &IdleDetector::idle, this, [this]() { 0050 send_idle(); 0051 }); 0052 connect(detector, &IdleDetector::resumed, this, [this]() { 0053 send_resumed(); 0054 }); 0055 } 0056 0057 void IdleTimeoutInterface::org_kde_kwin_idle_timeout_release(Resource *resource) 0058 { 0059 wl_resource_destroy(resource->handle); 0060 } 0061 0062 void IdleTimeoutInterface::org_kde_kwin_idle_timeout_destroy_resource(Resource *resource) 0063 { 0064 delete this; 0065 } 0066 0067 void IdleTimeoutInterface::org_kde_kwin_idle_timeout_simulate_user_activity(Resource *resource) 0068 { 0069 input()->simulateUserActivity(); 0070 } 0071 0072 } 0073 0074 #include "moc_idle.cpp" 0075 #include "moc_idle_p.cpp"