- more work to detect idle time in KDE - not tested yet

This commit is contained in:
Dmytro Bogovych 2022-05-20 10:20:41 +03:00
parent 859c1709e2
commit 8c04eb45d2
2 changed files with 91 additions and 7 deletions

View File

@ -115,15 +115,95 @@ int get_idle_time_gnome()
} }
#if defined(USE_WAYLAND) #if defined(USE_WAYLAND)
#include <wayland-client-protocol-unstable.hpp>
class kde_idle_detector
{
private:
wayland::seat_t seat;
wayland::display_t d;
wayland::org_kde_kwin_idle_t idle;
wayland::org_kde_kwin_idle_timeout_t idle_timer;
uint64_t idle_start = 0;
uint64_t idle_finish = 0;
bool active = false;
public:
kde_idle_detector()
{}
~kde_idle_detector()
{}
// Idle timeout is in msec
void start(int idle_timeout)
{
if (active)
return;
auto registry = d.get_registry();
registry.on_global() = [&] (uint32_t name, const std::string& interface, uint32_t version)
{
if (interface == wayland::seat_t::interface_name)
registry.bind(name, seat, version);
if (interface == wayland::org_kde_kwin_idle_t::interface_name)
registry.bind(name, idle, version);
};
d.roundtrip();
bool has_keyboard = false, has_pointer = false;
seat.on_capabilities() = [&] (const wayland::seat_capability& capability)
{
has_keyboard = capability & wayland::seat_capability::keyboard;
has_pointer = capability & wayland::seat_capability::pointer;
};
d.roundtrip();
idle_timer = idle.get_idle_timeout(seat, idle_timeout);
idle_timer.on_idle() = [&]()
{
idle_start = ::time(nullptr);
};
idle_timer.on_resumed() = [&]()
{
idle_finish = ::time(nullptr);
};
active = true;
}
void stop()
{
if (!active)
return;
active = false;
idle_timer.release();
seat.release();
}
// Return idle time in microseconds
int get_idle_time() const
{
if (idle_start > idle_finish)
{
return (::time(nullptr) - idle_start) * 1000;
}
return 0;
}
};
kde_idle_detector kde_idle;
int get_idle_time_kde_wayland() int get_idle_time_kde_wayland()
{ {
// Some ideas: // Ensure idle detector runs
// https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/29 kde_idle.start(1000);
// https://github.com/NilsBrause/waylandpp
// For KDE: use kde idle protocol https://wayland.app/protocols/kde-idle
return 0; return kde_idle.get_idle_time();
} }
#endif #endif
int get_idle_time_dynamically() int get_idle_time_dynamically()

View File

@ -41,13 +41,17 @@ RESOURCES = qbreak.qrc
TRANSLATIONS = strings.ts strings_en.ts strings_ru.ts TRANSLATIONS = strings.ts strings_en.ts strings_ru.ts
unix:!macx: DEFINES += TARGET_LINUX USE_WAYLAND unix:!macx: DEFINES += TARGET_LINUX # USE_WAYLAND
# Default rules for deployment. # Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target
unix:LIBS += -L/usr/X11R6/lib/ -lX11 -lXext -lXss -ldl # X11 and wayland libraries
unix:LIBS += -L/usr/X11R6/lib/ \
-L/usr/local/lib \
-lX11 -lXext -lXss -ldl \
-lwayland-client-unstable++ -lwayland-client-extra++ -lwayland-client++