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) {
        return(0);
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(5000));
    XScreenSaverInfo *info = XScreenSaverAllocInfo();
    XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
    uint idletime= info->idle / 1000;
    XFree(info);
    XCloseDisplay(dpy);

    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: https://stackoverflow.com/questions/68464387/how-to-calculate-system-idle-time-in-ubuntu-on-wayland

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: