1 | /* This file is part of the KDE libraries |
---|---|
2 | * SPDX-FileCopyrightText: 2009 Dario Freddi <drf at kde.org> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | */ |
6 | |
7 | #ifndef XSYNCBASEDPOLLER_H |
8 | #define XSYNCBASEDPOLLER_H |
9 | |
10 | #include "kabstractidletimepoller_p.h" |
11 | #include <QHash> |
12 | |
13 | #include <config-kidletime.h> |
14 | |
15 | #include <X11/Xlib.h> |
16 | #include <X11/extensions/sync.h> |
17 | #include <xcb/xcb.h> |
18 | |
19 | #include "fixx11h.h" |
20 | |
21 | class XSyncBasedPoller : public KAbstractIdleTimePoller |
22 | { |
23 | Q_OBJECT |
24 | Q_PLUGIN_METADATA(IID KAbstractIdleTimePoller_iid FILE "xcb.json") |
25 | Q_INTERFACES(KAbstractIdleTimePoller) |
26 | |
27 | public: |
28 | static XSyncBasedPoller *instance(); |
29 | |
30 | explicit XSyncBasedPoller(QObject *parent = nullptr); |
31 | ~XSyncBasedPoller() override; |
32 | |
33 | bool isAvailable() override; |
34 | bool setUpPoller() override; |
35 | void unloadPoller() override; |
36 | |
37 | bool xcbEvent(xcb_generic_event_t *event); |
38 | |
39 | QList<int> timeouts() const override; |
40 | |
41 | public Q_SLOTS: |
42 | void addTimeout(int nextTimeout) override; |
43 | void removeTimeout(int nextTimeout) override; |
44 | |
45 | int forcePollRequest() override; |
46 | void catchIdleEvent() override; |
47 | void stopCatchingIdleEvents() override; |
48 | void simulateUserActivity() override; |
49 | |
50 | private Q_SLOTS: |
51 | int poll(); |
52 | void reloadAlarms(); |
53 | |
54 | private: |
55 | void setAlarm(Display *dpy, XSyncAlarm *alarm, XSyncCounter counter, XSyncTestType test, XSyncValue value); |
56 | |
57 | private: |
58 | Display *m_display; |
59 | xcb_connection_t *m_xcb_connection; |
60 | |
61 | int m_sync_event; |
62 | XSyncCounter m_idleCounter; |
63 | QHash<int, XSyncAlarm> m_timeoutAlarm; |
64 | XSyncAlarm m_resetAlarm; |
65 | bool m_available; |
66 | }; |
67 | |
68 | #endif /* XSYNCBASEDPOLLER_H */ |
69 |