mirror of https://github.com/9wm/xss.git
Add color to magic. Still having keygrab issues from time to time.
This commit is contained in:
parent
09f76a5fee
commit
db76af5ff1
71
magic.c
71
magic.c
|
@ -26,22 +26,20 @@
|
||||||
#define TRAILPCT 50
|
#define TRAILPCT 50
|
||||||
#define MAXDELTAPML 14
|
#define MAXDELTAPML 14
|
||||||
#define MINDELTAPML 2
|
#define MINDELTAPML 2
|
||||||
|
#define COLORDELTA 50
|
||||||
|
|
||||||
#define nsec (1000000000 / FPS)
|
#define nsec (1000000000 / FPS)
|
||||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
|
||||||
|
#define sum(a, b, v, m) \
|
||||||
void
|
if (b + v < 0) { \
|
||||||
sum(short *a, short b, short *v, int m)
|
a = -1 * (b + v); \
|
||||||
{
|
v *= -1; \
|
||||||
*a = b + *v;
|
} else if (b + v > m) { \
|
||||||
if (*a < 0) {
|
a = (m*2) - (b + v); \
|
||||||
*a *= -1;
|
v *= -1; \
|
||||||
*v *= -1;
|
} else { \
|
||||||
} else if (*a > m) {
|
a = b + v; \
|
||||||
*a = (m*2) - *a;
|
|
||||||
*v *= -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -49,8 +47,8 @@ main(int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
Display *display;
|
Display *display;
|
||||||
Window w = (Window)0;
|
Window w = (Window)0;
|
||||||
GC gc = (GC)0;
|
|
||||||
GC egc = (GC)0;
|
GC egc = (GC)0;
|
||||||
|
XSegment *lines = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 1; i < argc; i += 1) {
|
for (i = 1; i < argc; i += 1) {
|
||||||
|
@ -81,8 +79,10 @@ main(int argc, char * const argv[])
|
||||||
try {
|
try {
|
||||||
int screen;
|
int screen;
|
||||||
Window root;
|
Window root;
|
||||||
XSegment velocity, *lines;
|
XSegment velocity;
|
||||||
int width, height, nlines;
|
int width, height, nlines;
|
||||||
|
unsigned short red, green, blue;
|
||||||
|
int dred, dgreen, dblue;
|
||||||
|
|
||||||
if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
|
if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
|
||||||
screen = DefaultScreen(display);
|
screen = DefaultScreen(display);
|
||||||
|
@ -118,10 +118,6 @@ main(int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
XGCValues values;
|
XGCValues values;
|
||||||
|
|
||||||
gc = XCreateGC(display, w, 0, &values);
|
|
||||||
if (! XSetForeground(display, gc, WhitePixel(display, screen))) break;
|
|
||||||
if (! XSetBackground(display, gc, BlackPixel(display, screen))) break;
|
|
||||||
|
|
||||||
egc = XCreateGC(display, w, 0, &values);
|
egc = XCreateGC(display, w, 0, &values);
|
||||||
if (! XSetForeground(display, egc, BlackPixel(display, screen))) break;
|
if (! XSetForeground(display, egc, BlackPixel(display, screen))) break;
|
||||||
if (! XSetBackground(display, egc, WhitePixel(display, screen))) break;
|
if (! XSetBackground(display, egc, WhitePixel(display, screen))) break;
|
||||||
|
@ -147,12 +143,30 @@ main(int argc, char * const argv[])
|
||||||
lines[0].y1 = (short)(random() % height);
|
lines[0].y1 = (short)(random() % height);
|
||||||
lines[0].x2 = (short)(random() % width);
|
lines[0].x2 = (short)(random() % width);
|
||||||
lines[0].y2 = (short)(random() % height);
|
lines[0].y2 = (short)(random() % height);
|
||||||
|
red = (unsigned short)(random() % 65536);
|
||||||
|
green = (unsigned short)(random() % 65536);
|
||||||
|
blue = (unsigned short)(random() % 65536);
|
||||||
|
dred = dgreen = dblue = COLORDELTA;
|
||||||
|
|
||||||
i = 0;
|
for (i = 0; ;) {
|
||||||
while (1) {
|
|
||||||
XSegment segments[2];
|
XSegment segments[2];
|
||||||
struct timespec req = {0, nsec};
|
struct timespec req = {0, nsec};
|
||||||
int j = (i + 1) % nlines;
|
int j = (i + 1) % nlines;
|
||||||
|
GC gc;
|
||||||
|
XGCValues values;
|
||||||
|
XColor color;
|
||||||
|
|
||||||
|
gc = XCreateGC(display, w, 0, &values);
|
||||||
|
if (! XSetBackground(display, gc, BlackPixel(display, screen))) break;
|
||||||
|
sum(red, red, dred, 65536);
|
||||||
|
sum(green, green, dgreen, 65536);
|
||||||
|
sum(blue, blue, dblue, 65536);
|
||||||
|
color.red = red;
|
||||||
|
color.green = green;
|
||||||
|
color.blue = blue;
|
||||||
|
|
||||||
|
if (! XAllocColor(display, DefaultColormap(display, screen), &color)) break;
|
||||||
|
if (! XSetForeground(display, gc, color.pixel)) break;
|
||||||
|
|
||||||
(void)memcpy(segments + 0, lines + j, sizeof(XSegment));
|
(void)memcpy(segments + 0, lines + j, sizeof(XSegment));
|
||||||
(void)memcpy(segments + 1, lines + j, sizeof(XSegment));
|
(void)memcpy(segments + 1, lines + j, sizeof(XSegment));
|
||||||
|
@ -160,10 +174,10 @@ main(int argc, char * const argv[])
|
||||||
segments[1].x2 = width - segments[0].x2;
|
segments[1].x2 = width - segments[0].x2;
|
||||||
XDrawSegments(display, (Drawable)w, egc, segments, 2);
|
XDrawSegments(display, (Drawable)w, egc, segments, 2);
|
||||||
|
|
||||||
sum(&(lines[j].x1), lines[i].x1, &(velocity.x1), width);
|
sum(lines[j].x1, lines[i].x1, velocity.x1, width);
|
||||||
sum(&(lines[j].y1), lines[i].y1, &(velocity.y1), height);
|
sum(lines[j].y1, lines[i].y1, velocity.y1, height);
|
||||||
sum(&(lines[j].x2), lines[i].x2, &(velocity.x2), width);
|
sum(lines[j].x2, lines[i].x2, velocity.x2, width);
|
||||||
sum(&(lines[j].y2), lines[i].y2, &(velocity.y2), height);
|
sum(lines[j].y2, lines[i].y2, velocity.y2, height);
|
||||||
|
|
||||||
(void)memcpy(segments + 0, lines + j, sizeof(XSegment));
|
(void)memcpy(segments + 0, lines + j, sizeof(XSegment));
|
||||||
(void)memcpy(segments + 1, lines + j, sizeof(XSegment));
|
(void)memcpy(segments + 1, lines + j, sizeof(XSegment));
|
||||||
|
@ -171,6 +185,8 @@ main(int argc, char * const argv[])
|
||||||
segments[1].x2 = width - segments[0].x2;
|
segments[1].x2 = width - segments[0].x2;
|
||||||
XDrawSegments(display, (Drawable)w, gc, segments, 2);
|
XDrawSegments(display, (Drawable)w, gc, segments, 2);
|
||||||
|
|
||||||
|
if (! XFreeColors(display, DefaultColormap(display, screen), &(color.pixel), 1, 0)) break;
|
||||||
|
(void)XFreeGC(display, gc);
|
||||||
XSync(display, True);
|
XSync(display, True);
|
||||||
|
|
||||||
(void)nanosleep(&req, NULL);
|
(void)nanosleep(&req, NULL);
|
||||||
|
@ -179,9 +195,12 @@ main(int argc, char * const argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lines) {
|
||||||
|
free(lines);
|
||||||
|
}
|
||||||
|
|
||||||
if (display) {
|
if (display) {
|
||||||
if (gc) {
|
if (egc) {
|
||||||
(void)XFreeGC(display, gc);
|
|
||||||
(void)XFreeGC(display, egc);
|
(void)XFreeGC(display, egc);
|
||||||
}
|
}
|
||||||
(void)XCloseDisplay(display);
|
(void)XCloseDisplay(display);
|
||||||
|
|
|
@ -43,12 +43,14 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
|
if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
|
||||||
root = DefaultRootWindow(display);
|
root = DefaultRootWindow(display);
|
||||||
|
(void)XUngrabPointer(display, CurrentTime);
|
||||||
if (GrabSuccess != XGrabPointer(display, root,
|
if (GrabSuccess != XGrabPointer(display, root,
|
||||||
False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
||||||
GrabModeAsync, GrabModeAsync,
|
GrabModeAsync, GrabModeAsync,
|
||||||
None, None, CurrentTime)) {
|
None, None, CurrentTime)) {
|
||||||
raise("cannot grab pointer");
|
raise("cannot grab pointer");
|
||||||
}
|
}
|
||||||
|
(void)XUngrabKeyboard(display, CurrentTime);
|
||||||
if (GrabSuccess != XGrabKeyboard(display, root,
|
if (GrabSuccess != XGrabKeyboard(display, root,
|
||||||
True,
|
True,
|
||||||
GrabModeAsync, GrabModeAsync,
|
GrabModeAsync, GrabModeAsync,
|
||||||
|
|
Loading…
Reference in New Issue