void Watcher::onTimeout() { xcb_screensaver_query_info_cookie_t cookie; xcb_screensaver_query_info_reply_t *info; cookie = xcb_screensaver_query_info (connection, screen->root); info = xcb_screensaver_query_info_reply (connection, cookie, NULL); uint32_t idle = info->ms_since_user_input; free (info); QSettings settings("qslsaver", "qslsaver"); bool enabled = settings.value("enabled", 1).toBool(); if (!enabled) return; int time = settings.value("timeout", 10).toInt() * 60000; if (idle <= time) return; stop(); emit(idling()); }
EAPI int ecore_x_screensaver_idle_time_get(void) { int ret = 0; #ifdef ECORE_XCB_SCREENSAVER xcb_screensaver_query_info_cookie_t cookie; xcb_screensaver_query_info_reply_t *reply; Ecore_X_Window root; #endif LOGFN(__FILE__, __LINE__, __FUNCTION__); CHECK_XCB_CONN; if (!_screensaver_avail) return 0; #ifdef ECORE_XCB_SCREENSAVER root = ((xcb_screen_t *)_ecore_xcb_screen)->root; cookie = xcb_screensaver_query_info_unchecked(_ecore_xcb_conn, root); reply = xcb_screensaver_query_info_reply(_ecore_xcb_conn, cookie, NULL); if (!reply) return 0; ret = (reply->ms_until_server / 1000); free(reply); #endif return ret; }
uint IdlenessWatcher::getIdleTimeMs() { xcb_screensaver_query_info_cookie_t infoCookie = xcb_screensaver_query_info_unchecked(mConn, mScreen->root); xcb_screensaver_query_info_reply_t* infoReply = xcb_screensaver_query_info_reply(mConn, infoCookie, NULL); if (!infoReply) { qWarning() << "Bad reply from X11 Screensaver"; return 0; } uint msSinceUserInput = infoReply->ms_since_user_input; free(infoReply); return msSinceUserInput; }
static void towel_window_update_working_time(towel_window_t *win, int period) { xcb_screensaver_query_info_cookie_t cookie; xcb_screensaver_query_info_reply_t *reply; cookie = xcb_screensaver_query_info_unchecked(win->conn, win->screen->root); reply = xcb_screensaver_query_info_reply(win->conn, cookie, NULL); #if DEBUG fprintf(stderr, "idle: %d sec\n", ms2sec(reply->ms_since_user_input)); #endif win->idle_time = ms2sec(reply->ms_since_user_input); if (win->idle_time < period) win->working_time += period; }
void X11IdleDetector::checkIdleness() { xcb_screensaver_query_info_cookie_t cookie; cookie = xcb_screensaver_query_info(m_connection, m_screen->root); xcb_screensaver_query_info_reply_t *info; info = xcb_screensaver_query_info_reply(m_connection, cookie, NULL); //krazy:exclude=null const int idleSecs = info->ms_since_user_input / 1000; free(info); if (idleSecs >= idlenessDuration()) maybeIdle(IdlePeriod(QDateTime::currentDateTime().addSecs(-idleSecs), QDateTime::currentDateTime())); if (m_heartbeat.secsTo(QDateTime::currentDateTime()) > idlenessDuration()) maybeIdle(IdlePeriod(m_heartbeat, QDateTime::currentDateTime())); m_heartbeat = QDateTime::currentDateTime(); }