Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DPMS on and off
// 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
You can’t perform that action at this time.