Skip to content

Instantly share code, notes, and snippets.

@crashdump
Created October 9, 2013 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crashdump/6897740 to your computer and use it in GitHub Desktop.
Save crashdump/6897740 to your computer and use it in GitHub Desktop.
I use this on a monitoring screen to get my attention: It make the screen flash multiples times (X11)
#include <unistd.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <strings.h>
#include <memory.h>
#include <stdlib.h>
#include <stdio.h>
/*
* 2013/10/09. Adrien Pujol.
*
* Build me: `gcc -std=gnu99 -Wall epilepsy.c -lX11 -o epilepsy`
*
*/
const long INTERVAL_MS = 500000;
int main ()
{
Display* dis = XOpenDisplay(NULL);
Atom wm_state = XInternAtom(dis, "_NET_WM_STATE", False);
Atom fullscreen = XInternAtom(dis, "_NET_WM_STATE_FULLSCREEN", False);
// White Screen Event
Window whiteWin = XCreateSimpleWindow(dis, RootWindow(dis, 0), 0, 0, 10, 10,
0, WhitePixel (dis, 0), WhitePixel(dis, 0));
XEvent whiteXev;
memset(&whiteXev, 0, sizeof(whiteXev));
whiteXev.type = ClientMessage;
whiteXev.xclient.window = whiteWin;
whiteXev.xclient.message_type = wm_state;
whiteXev.xclient.format = 32;
whiteXev.xclient.data.l[0] = 1;
whiteXev.xclient.data.l[1] = fullscreen;
whiteXev.xclient.data.l[2] = 0;
Window blackWin = XCreateSimpleWindow(dis, RootWindow(dis, 0), 0, 0, 10, 10,
0, BlackPixel (dis, 0), BlackPixel(dis, 0));
XEvent blackXev;
memset(&blackXev, 0, sizeof(blackXev));
blackXev.type = ClientMessage;
blackXev.xclient.window = blackWin;
blackXev.xclient.message_type = wm_state;
blackXev.xclient.format = 32;
blackXev.xclient.data.l[0] = 1;
blackXev.xclient.data.l[1] = fullscreen;
blackXev.xclient.data.l[2] = 0;
for (int i = 0; i < 5; i++){
// White flash
XMapWindow(dis, whiteWin);
XSendEvent (dis, DefaultRootWindow(dis), False,
SubstructureRedirectMask | SubstructureNotifyMask, &whiteXev);
usleep(INTERVAL_MS);
XFlush(dis);
XMapWindow(dis, blackWin);
XSendEvent (dis, DefaultRootWindow(dis), False,
SubstructureRedirectMask | SubstructureNotifyMask, &blackXev);
usleep(INTERVAL_MS);
XFlush(dis);
}
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment