#include <stdlib.h>
#include <ctype.h>
#include <strings.h>
+#include <poll.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
return LineSolid;
}
+void
+HandleButtonPress(Display *dpy, Window win, GC gc, XEvent *ev);
+
+void
+HandleButtonRelease(Display *dpy, Window win, GC gc, XEvent *ev);
+
+void
+HandleMotionNotify(Display *dpy, Window win, GC gc, XEvent *ev);
+
#ifdef TRACK_POINTER
+
#define PASS_BUTTONS
typedef struct _Position {
int seen;
int end_x, end_y;
} PositionRec, *PositionPtr;
-PositionRec positions[5];
+void
+Draw(Display *dpy, Window win, GC gc, PositionRec positions[5]);
void
-UpdatePositions (state, x, y)
+Undraw(Display *dpy, Window win, GC gc, PositionRec positions[5]);
+
+PositionRec current_positions[5];
+
+static void
+UpdatePositions (unsigned state, int x, int y)
{
int i;
for (i = 0; i < 5; i++)
{
if (state & (1 << i)) {
- positions[i].cur_x = x;
- positions[i].cur_y = y;
+ current_positions[i].cur_x = x;
+ current_positions[i].cur_y = y;
}
}
}
void
-HandleButtonPress (dpy, win, gc, ev)
- Display *dpy;
- Window win;
- GC gc;
- XEvent *ev;
+HandleButtonPress (Display *dpy, Window win, GC gc, XEvent *ev)
{
XButtonEvent *bev = (XButtonEvent *) ev;
- Undraw (dpy, win, gc, positions);
- positions[bev->button - 1].seen = 1;
- positions[bev->button - 1].start_x = bev->x;
- positions[bev->button - 1].start_y = bev->y;
- positions[bev->button - 1].cur_x = bev->x;
- positions[bev->button - 1].cur_y = bev->y;
- positions[bev->button - 1].end_x = bev->x;
- positions[bev->button - 1].end_y = bev->y;
+ Undraw (dpy, win, gc, current_positions);
+ current_positions[bev->button - 1].seen = 1;
+ current_positions[bev->button - 1].start_x = bev->x;
+ current_positions[bev->button - 1].start_y = bev->y;
+ current_positions[bev->button - 1].cur_x = bev->x;
+ current_positions[bev->button - 1].cur_y = bev->y;
+ current_positions[bev->button - 1].end_x = bev->x;
+ current_positions[bev->button - 1].end_y = bev->y;
UpdatePositions (bev->state, bev->x, bev->y);
- Draw (dpy, win, gc, positions);
+ Draw (dpy, win, gc, current_positions);
}
void
-HandleButtonRelease (dpy, win, gc, ev)
- Display *dpy;
- Window win;
- GC gc;
- XEvent *ev;
+HandleButtonRelease (Display *dpy, Window win, GC gc, XEvent *ev)
{
XButtonEvent *bev = (XButtonEvent *) ev;
- Undraw (dpy, win, gc, positions);
+ Undraw (dpy, win, gc, current_positions);
UpdatePositions (bev->state, bev->x, bev->y);
- positions[bev->button - 1].end_x = bev->x;
- positions[bev->button - 1].end_y = bev->y;
- Draw (dpy, win, gc, positions);
+ current_positions[bev->button - 1].end_x = bev->x;
+ current_positions[bev->button - 1].end_y = bev->y;
+ Draw (dpy, win, gc, current_positions);
}
void
-HandleMotionNotify (dpy, win, gc, ev)
- Display *dpy;
- Window win;
- GC gc;
- XEvent *ev;
+HandleMotionNotify (Display *dpy, Window win, GC gc, XEvent *ev)
{
XMotionEvent *mev = (XMotionEvent *) ev;
- Undraw (dpy, win, gc, positions);
+ Undraw (dpy, win, gc, current_positions);
UpdatePositions (mev->state, mev->x, mev->y);
- Draw (dpy, win, gc, positions);
+ Draw (dpy, win, gc, current_positions);
}
-void
-DisplayPositions (dpy, win, gc, positions)
- Display *dpy;
- Window win;
- GC gc;
- PositionRec positions[5];
+static inline void
+DisplayPositions (Display *dpy, Window win, GC gc, PositionRec positions[5])
{
static char text[1024];
static int hastext;
int dir, font_ascent, font_descent;
XCharStruct overall;
- XTextExtents (default_font , text, strlen(text),
+ XTextExtents (default_font, text, (int) strlen(text),
&dir, &font_ascent, &font_descent, &overall);
if (hastext)
- XClearArea (dpy, win, 0, 0, overall.width, font_ascent + font_descent, False);
+ XClearArea (dpy, win, 0, 0, (unsigned) overall.width, (unsigned) (font_ascent + font_descent), False);
pos = 0;
for (i = 0; i < 5; i++)
{
sprintf (text + pos, "%1d: (%4d,%4d),(%4d,%4d)",
i, positions[i].start_x, positions[i].start_y,
positions[i].cur_x, positions[i].cur_y);
- pos = strlen (text);
+ pos = (int) strlen (text);
}
}
XDrawString (dpy, win, gc, 0, font_ascent, text, pos);
int depth;
Window root = 0;
int screen;
+#ifdef TIMEOUT
+int current_timeout = TIMEOUT;
+#endif
+
+void
+Setup(Display *dpy, Window win);
void
HandleExpose(Display *dpy, Window win, GC gc);
void
HandleKeyRelease(Display *dpy, Window win, GC gc, XEvent *ev);
+void
+HandleTimeout(Display *dpy, Window win, GC gc);
+
#include <X11/extensions/Xrender.h>
XRenderColor renderBlack = { 0, 0, 0, 0xffff };
int has_fg_pixel = 0, has_bg_pixel = 0;
int has_colormap = 0;
unsigned long gc_mask;
+#ifndef PASS_KEYS
+ char quit_string[10];
+#endif
unsigned long window_mask;
if (!rop_name)
XSetDashes (dpy, gc, 0, dashes, ndashes);
XMapWindow (dpy, win);
for (;;) {
+#ifdef TIMEOUT
+ while (current_timeout && !XEventsQueued(dpy, QueuedAfterFlush)) {
+ struct pollfd pollfd = {
+ .fd = ConnectionNumber(dpy),
+ .events = POLLIN
+ };
+ int r = poll(&pollfd, 1, current_timeout);
+ if (r == 0)
+ HandleTimeout(dpy, win, gc);
+ }
+#endif
XNextEvent (dpy, &ev);
#ifdef PASS_BUTTONS
if (HasMotion && ev.type != MotionNotify) {