Created
February 1, 2015 11:01
-
-
Save libbymiller/c20ff64f9bca26e4fe7d to your computer and use it in GitHub Desktop.
DPMS on and off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c++ -lX11 -L/usr/lib/arm-linux-gnueabihf/libX11.so.6 -lXext dpms_onoff.cpp -o dpms_onoff | |
// stolen pieces from http://www.karlrunge.com/x11vnc/blockdpy.c | |
// and also https://github.com/danfuzz/xscreensaver/blob/master/driver/dpms.c | |
//expected behaviour: turns the screen off then on twice, but actually only does it once | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <memory.h> | |
#include <unistd.h> | |
extern "C" { | |
#include <X11/Xlib.h> | |
#include <X11/Xproto.h> | |
#include <X11/extensions/dpms.h> | |
} | |
Display *dpy = NULL; | |
CARD16 standby, suspend, off; | |
int main(int argc, const char **argv) | |
{ | |
dpy = XOpenDisplay(NULL); | |
if (! dpy) { | |
fprintf(stderr, "XOpenDisplay failed.\n"); | |
exit(1); | |
} | |
CARD16 state; | |
BOOL onoff = False; | |
DPMSInfo(dpy, &state, &onoff); | |
fprintf(stdout, "STATE %i\n",state); | |
//turn screen off | |
CARD16 desired = DPMSModeOff; | |
DPMSForceLevel(dpy, desired); | |
usleep(1000*1000); | |
DPMSInfo(dpy, &state, &onoff); | |
fprintf(stdout, "STATE %i\n",state); | |
//turn screen on | |
desired = DPMSModeOn; | |
DPMSForceLevel(dpy, desired); | |
usleep(1000*1000); | |
DPMSInfo(dpy, &state, &onoff); | |
fprintf(stdout, "STATE %i\n",state); | |
//turn screen off | |
desired = DPMSModeOff; | |
DPMSForceLevel(dpy, desired); | |
usleep(1000*1000); | |
//XSync (dpy, False); | |
DPMSInfo(dpy, &state, &onoff); | |
fprintf(stdout, "STATE %i\n",state); | |
//turn screen on | |
desired = DPMSModeOn; | |
DPMSForceLevel(dpy, desired); | |
usleep(1000*1000); | |
DPMSInfo(dpy, &state, &onoff); | |
fprintf(stdout, "STATE %i\n",state); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment