Skip to content

Instantly share code, notes, and snippets.

@metalefty
Last active September 13, 2018 08:50
Show Gist options
  • Select an option

  • Save metalefty/6d5617eb50ec7933feff8466c5901223 to your computer and use it in GitHub Desktop.

Select an option

Save metalefty/6d5617eb50ec7933feff8466c5901223 to your computer and use it in GitHub Desktop.
/*
* Copyright 2018 HAW International, Inc.
* Copyright 2018 Koichiro Iwao <meta@vmeta.jp> a.k.a metalefty on GitHub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <X11/extensions/scrnsaver.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX_IDLE_SEC 60
int main(void)
{
Display *display;
int event_base, error_base;
XScreenSaverInfo info;
int done = 0;
unsigned long idle_msec = 0, past_idle_msec = 0;
display = XOpenDisplay("");
if (display == NULL)
{
fprintf(stderr, "Can't open display.\n");
exit(EXIT_FAILURE);
}
if (XScreenSaverQueryExtension(display, &event_base, &error_base))
{
while(1)
{
XScreenSaverQueryInfo(display, DefaultRootWindow(display), &info);
past_idle_msec = idle_msec;
idle_msec = info.idle;
if (past_idle_msec > idle_msec)
{
done = 0;
}
if (info.idle >= MAX_IDLE_SEC * 1000 && done == 0)
{
system("xrdp-dis");
done = 1;
}
sleep(1);
}
}
else
{
fprintf(stderr,"XScreenSaverQueryExtension failed.\n");
exit(EXIT_FAILURE);
}
printf("%d\n", info.idle);
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment