[2009-03-06 07:04] Samuel Baldwin <[email protected]> > 2009/3/6 pancake <[email protected]>: > > I have been playing a bit with xgamma and I think it can be useful as a > > graphical > > notification for important alerts like low battery or so. > > > > The usage is quite simple. and we can 'flash' the screen in red for a > > fraction of a second with: > > What happens if you're not looking at the screen?
I modified `slock' some time ago to display a fullscreen red window
that closes on any button press. I use it to notify about low battery.
The code is attached.
Example usage:
$ ./redscr
< a red windows appears >
$ ./redscr 336699
< a baby blue window appears >
meillo
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details. */
/* #define _XOPEN_SOURCE 500 */
#define VERSION "0.8"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <X11/Xlib.h>
int main(int argc, char* argv[]) {
char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
int screen;
unsigned int len;
char screencolor[8] = "#660000";
Cursor invisible;
Display *dpy;
Pixmap pmap;
Window root, w;
XColor black, dummy;
XEvent ev;
XSetWindowAttributes wa;
/* printf("argc: %d\n", argc); */
if (argc > 2) {
/* invalid option */
fprintf(stderr, "usage: redscr [--version]\n"
" redscr <color> (color has to be 6 hex chars)\n");
exit(EXIT_FAILURE);
}
if ((argc == 2) && (strcmp("--version", argv[1]) == 0)) {
/* version information */
fprintf(stderr, "redscr-%s, (c) 2006-2007 Anselm R. Garbe, 2007 markus schnalke\n", VERSION);
exit(EXIT_SUCCESS);
}
if ((argc == 2)) {
/* set color */
/* printf("arg: %s", argv[1]); */
screencolor[0] = '#';
screencolor[1] = '\0';
strcat(screencolor, argv[1]);
/* printf("color is: %s", screencolor); */
}
if(!(dpy = XOpenDisplay(0))) {
fprintf(stderr, "redscr: cannot open display\n");
exit(EXIT_FAILURE);
}
/* init */
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
XColor color;
if(!XAllocNamedColor(dpy, cmap, screencolor, &color, &color)) {
fprintf(stderr,"error, cannot allocate color\n");
exit(EXIT_FAILURE);
}
wa.override_redirect = 1;
wa.background_pixel = color.pixel;
w = XCreateWindow(dpy, root, 0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixel, &wa);
XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &black, &dummy);
pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
XDefineCursor(dpy, w, invisible);
XMapRaised(dpy, w);
for(len = 1000; len; len--) {
if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
break;
usleep(1000);
}
/* main event loop */
while (ev.type != KeyPress) {
XNextEvent(dpy, &ev);
usleep(100000);
}
XFreePixmap(dpy, pmap);
XDestroyWindow(dpy, w);
XCloseDisplay(dpy);
return 0;
}
signature.asc
Description: Digital signature
