Last active
November 11, 2021 18:47
-
-
Save nevinpuri/dce34f4797468387261497b3178341b0 to your computer and use it in GitHub Desktop.
My first xscreensaver module
This file contains hidden or 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
#include "screenhack.h" | |
static const char* nevinScreensaver_defaults[] = { | |
".background: black", | |
".foreground: white", | |
}; | |
static XrmOptionDescRec nevinScreensaver_options [] = { | |
{"-delay", ".delay", XrmoptionSepArg, 0 } | |
}; | |
struct state { | |
Display* dpy; | |
Window window; | |
int delay; | |
int maxCount; | |
int width, height; | |
GC gc; | |
Colormap cmap; | |
unsigned long fg, bg, pixels [512]; | |
}; | |
static void* nevinScreensaver_init(Display *dpy, Window window) { | |
struct state *st = (struct state*) calloc (1, sizeof(*st)); | |
XGCValues gcv; | |
XWindowAttributes xgwa; | |
st->dpy = dpy; | |
st->window = window; | |
st->delay = 14000; | |
st->maxCount = 0; | |
XGetWindowAttributes(st->dpy, st->window, &xgwa); | |
st->width = xgwa.width; | |
st->width = xgwa.height; | |
st->cmap = xgwa.colormap; | |
gcv.foreground = st->fg = get_pixel_resource(st->dpy, st->cmap, "foreground", "Foreground"); | |
gcv.background = st->bg = get_pixel_resource(st->dpy, st->cmap, "background", "Background"); | |
st->gc = XCreateGC(st->dpy, st->window, GCForeground, &gcv); | |
return st; | |
} | |
static unsigned long nevinScreensaver_draw (Display *dpy, Window window, void *closure) { | |
struct state *st = (struct state*) closure; | |
if (st->maxCount > 100000) { | |
XClearWindow(dpy, window); | |
st->maxCount = 0; | |
} | |
if (random() % 2 == 1){ XFillRectangle(dpy, window, st->gc, random() % st->width, random() % st->height, random() % st->width / 10, random() % st->height / 10); } | |
else { XDrawRectangle(dpy, window, st->gc, random() % st->width, random() % st->height, random() % st->width / 10, random() % st->height / 10); } | |
st->maxCount++; | |
/* XDrawLine(dpy, window, st->gc, 20, 20, 40, 40); */ | |
return st->delay; | |
} | |
static void nevinScreensaver_reshape(Display *dpy, Window window, void *closure, unsigned int w, unsigned int h) { | |
struct state *st = (struct state *) closure; | |
st->width = w; | |
st->height = h; | |
} | |
static Bool nevinScreensaver_event(Display *dpy, Window window, void *closure, XEvent *event) { | |
return False; | |
} | |
static void nevinScreensaver_free(Display *dpy, Window window, void *closure) { | |
struct state *st = (struct state *) closure; | |
XFreeGC(st->dpy, st->gc); | |
free(st); | |
} | |
XSCREENSAVER_MODULE("nevinScreensaver", nevinScreensaver) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment