How to calculate system idle time in Ubuntu on Wayland?

I've implemented the below code to calculate system idle time in ubuntu on xorg which is working fine:-

#include <X11/extensions/scrnsaver.h>
#include <stdio.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xinerama.h>
#include <thread>
#include <chrono>
#include <iostream>
using namespace std;

 uint getSystemIdleTime()
    Display *dpy = XOpenDisplay(nullptr);
    if (!dpy) {
    XScreenSaverInfo *info = XScreenSaverAllocInfo();
    XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
    uint idletime= info->idle / 1000;

    return idletime;

int main()
    int ans = getSystemIdleTime();
    cout << ans << endl;

but I'm unable to find any method/API to calculate system idle in ubuntu on Wayland.

Read more here:

Content Attribution

This content was originally published by Abhishek Negi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: