#include <stdlib.h>
#include <ctype.h>
#include <strings.h>
+#include <poll.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
{ "set", GXset, }, /* 1 */
};
-int
+static int
RopNameToRop (char *name)
{
int rop;
return GXcopy;
}
-void
+static void
Error (char *s, char *a)
{
fprintf (stderr, s, a);
exit (1);
}
-int
+static int
MatchCapStyle (char *s)
{
if (!strcmp (s, "round"))
return CapNotLast;
}
-int
+static int
MatchJoinStyle (char *s)
{
if (!strcmp (s, "round"))
return JoinBevel;
}
-int
+static int
MatchFillStyle(char *s)
{
if (!strcmp (s, "solid"))
return FillSolid;
}
-int
+static int
MatchLineStyle(char *s)
{
if (!strcmp (s, "solid"))
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);
#endif
-void
-SetToFg (dpy, gc)
- Display *dpy;
- GC gc;
+static inline void
+SetToFg (Display *dpy, GC gc)
{
XSetForeground (dpy, gc, fg_pixel);
XSetFunction (dpy, gc, default_rop);
}
-void
-SetToBg (dpy, gc)
- Display *dpy;
- GC gc;
+static inline void
+SetToBg (Display *dpy, GC gc)
{
XSetForeground (dpy, gc, bg_pixel);
XSetFunction (dpy, gc, GXcopy);
}
-
-void
-Usage (program)
- char *program;
+static void
+Usage (char *program)
{
int i;
fprintf (stderr, "Usage: %s\n", program);
char dashes[256] = { DEFAULT_DASHES };
int ndashes = DEFAULT_NUM_DASHES;
VisualID vid = DEFAULT_VISUAL;
-unsigned long planemask = ~0;
+unsigned long planemask = ~0UL;
Colormap colormap;
Visual *visual;
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
+HandleKeyPress(Display *dpy, Window win, GC gc, XEvent *ev);
+
+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 };
+XRenderColor renderWhite = { 0xffff, 0xffff, 0xffff, 0xffff };
+XRenderColor renderRed = { 0xffff, 0, 0, 0xffff };
+XRenderColor renderGreen = { 0, 0xffff, 0, 0xffff };
+XRenderColor renderBlue = { 0, 0, 0xffff, 0xffff };
+
+XRenderColor renderClearRed = { 0x8000, 0, 0, 0x8000 };
+XRenderColor renderClearGreen = { 0, 0x8000, 0, 0x8000 };
+XRenderColor renderClearBlue = { 0, 0, 0x8000, 0x8000 };
+
+static inline Picture
+GetPicture (Display *dpy, Window w)
+{
+ static Picture p;
+
+ if (!p)
+ p = XRenderCreatePicture (dpy, w,
+ XRenderFindVisualFormat (dpy, visual),
+ 0, 0);
+ return p;
+}
+
+static inline Picture
+GetSrc (Display *dpy, XRenderColor *color)
+{
+ static Picture p;
+ static Pixmap pix;
+ static XRenderColor lastColor;
+ XRenderPictFormat *f;
+ XRenderPictureAttributes attr;
+
+ if (p && !memcmp (color, &lastColor, sizeof (XRenderColor)))
+ return p;
+ if (!p)
+ {
+ f = XRenderFindStandardFormat (dpy, PictStandardARGB32);
+ pix = XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
+ 1, 1, (unsigned) f->depth);
+ attr.repeat = True;
+ p = XRenderCreatePicture (dpy, pix, f, CPRepeat, &attr);
+ XFreePixmap (dpy, pix);
+ }
+ XRenderFillRectangle (dpy, PictOpSrc, p, color, 0, 0, 1, 1);
+ lastColor = *color;
+ return p;
+}
+
+static inline XRenderPictFormat *
+GetMask (Display *dpy)
+{
+ return XRenderFindStandardFormat (dpy, PictStandardA8);
+}
+
int
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
Display *dpy;
Window win;
XColor hard, exact;
int x = 0, y = 0;
unsigned int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT;
- int geometryMask;
- int border_width = 1;
+ unsigned int border_width = 1u;
XSizeHints sizeHints;
XWMHints wmHints;
- XClassHint classHints;
- XEvent ev, mev;
+ XEvent ev;
XGCValues gcv;
#ifdef MATCH_ARGUMENT
int i;
#endif
+#ifdef PASS_BUTTONS
int HasMotion = 0;
+ XEvent mev;
+#endif
#ifdef COMPRESS_EXPOSE
XEvent eev;
int HasExpose = 0;
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)
wm_name.value = (unsigned char *) argv[0];
wm_name.encoding = XA_STRING;
wm_name.format = 8;
- wm_name.nitems = strlen (wm_name.value) + 1;
+ wm_name.nitems = strlen ((const char *) wm_name.value) + 1;
icon_name = wm_name;
gc_mask = 0;
while (*++argv) {
if (!strcmp (*argv, "-display"))
dpy_name = *++argv;
else if (!strcmp (*argv, "-visual"))
- vid = strtol(*++argv, NULL, 0);
+ vid = strtoul(*++argv, NULL, 0);
else if (!strcmp (*argv, "-cmap"))
{
- colormap = strtol(*++argv, NULL, 0);
+ colormap = strtoul(*++argv, NULL, 0);
has_colormap = 1;
}
else if (!strcmp (*argv, "-rop"))
bg = *++argv;
else if (!strcmp (*argv, "-fg_pixel"))
{
- fg_pixel = strtol(*++argv, NULL, 0);
+ fg_pixel = strtoul(*++argv, NULL, 0);
has_fg_pixel = 1;
}
else if (!strcmp (*argv, "-bg_pixel"))
{
- bg_pixel = strtol(*++argv, NULL, 0);
+ bg_pixel = strtoul(*++argv, NULL, 0);
has_bg_pixel = 1;
}
else if (!strcmp (*argv, "-fn"))
font_name = *++argv;
else if (!strcmp (*argv, "-pm"))
- planemask = strtol(*++argv, NULL, 0);
+ planemask = strtoul(*++argv, NULL, 0);
else if (!strcmp (*argv, "-geometry"))
- geometryMask = XParseGeometry (*++argv, &x, &y, &width, &height);
+ XParseGeometry (*++argv, &x, &y, &width, &height);
else if (!strcmp (*argv, "-sync"))
sync = 1;
else if (!strcmp (*argv, "-bw"))
- border_width = strtol(*++argv, NULL, 0);
+ border_width = (unsigned int) strtoul(*++argv, NULL, 0);
else if (!strcmp (*argv, "-lw"))
line_width = strtod(*++argv, NULL);
else if (!strcmp (*argv, "-cap"))
argv++;
ndashes = 0;
while (*argv && isdigit (**argv))
- dashes[ndashes++] = atoi(*argv++);
+ dashes[ndashes++] = (char) atoi(*argv++);
argv--;
}
#ifdef MATCH_ARGUMENT
argv += i - 1;
#endif
else if (!strcmp (*argv, "-root"))
- root = strtol (*++argv, NULL, 0);
+ root = strtoul (*++argv, NULL, 0);
else
Usage (*init_argv);
}
sizeHints.flags = 0;
wmHints.flags = InputHint;
wmHints.input = True;
- classHints.res_name = init_argv[0];
- classHints.res_class = init_argv[0];
dpy = XOpenDisplay (dpy_name);
if (!dpy)
Error ("Can't open display", "");
gc_mask |= GCFunction|GCForeground|GCBackground|GCPlaneMask;
if (bitmap_file)
{
- unsigned int width, height;
+ unsigned int b_width, b_height;
int ret;
Pixmap bitmap, pixmap;
- ret = XReadBitmapFile (dpy, win, bitmap_file, &width, &height,
+ ret = XReadBitmapFile (dpy, win, bitmap_file, &b_width, &b_height,
&bitmap, (int *) 0, (int *) 0);
switch (ret) {
case BitmapOpenFailed:
Error ("Can't open bitmap file %s", bitmap_file);
+ break;
case BitmapFileInvalid:
Error ("Bitmap file %s invalid", bitmap_file);
+ break;
case BitmapNoMemory:
Error ("Out of memory reading bitmap file %s", bitmap_file);
+ break;
case BitmapSuccess:
break;
}
switch (gcv.fill_style) {
case FillTiled:
- pixmap = XCreatePixmap (dpy, win, width, height, DefaultDepth (dpy, screen));
+ pixmap = XCreatePixmap (dpy, win, b_width, b_height, (unsigned) DefaultDepth (dpy, screen));
gc = XCreateGC (dpy, pixmap, GCForeground|GCBackground, &gcv);
- XCopyPlane (dpy, bitmap, pixmap, gc, 0, 0, width, height, 0, 0, 1);
+ XCopyPlane (dpy, bitmap, pixmap, gc, 0, 0, b_width, b_height, 0, 0, 1);
XFreeGC (dpy, gc);
XFreePixmap (dpy, bitmap);
gcv.tile = pixmap;
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) {
}
}
}
-
-#include <X11/extensions/Xrender.h>
-
-XRenderColor renderBlack = { 0, 0, 0, 0xffff };
-XRenderColor renderWhite = { 0xffff, 0xffff, 0xffff, 0xffff };
-XRenderColor renderRed = { 0xffff, 0, 0, 0xffff };
-XRenderColor renderGreen = { 0, 0xffff, 0, 0xffff };
-XRenderColor renderBlue = { 0, 0, 0xffff, 0xffff };
-
-XRenderColor renderClearRed = { 0x8000, 0, 0, 0x8000 };
-XRenderColor renderClearGreen = { 0, 0x8000, 0, 0x8000 };
-XRenderColor renderClearBlue = { 0, 0, 0x8000, 0x8000 };
-
-Picture
-GetPicture (Display *dpy, Window w)
-{
- static Picture p;
-
- if (!p)
- p = XRenderCreatePicture (dpy, w,
- XRenderFindVisualFormat (dpy, visual),
- 0, 0);
- return p;
-}
-
-Picture
-GetSrc (Display *dpy, XRenderColor *color)
-{
- static Picture p;
- static Pixmap pix;
- static XRenderColor lastColor;
- XRenderPictFormat *f;
- XRenderPictureAttributes attr;
-
- if (p && !memcmp (color, &lastColor, sizeof (XRenderColor)))
- return p;
- if (!p)
- {
- f = XRenderFindStandardFormat (dpy, PictStandardARGB32);
- pix = XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
- 1, 1, f->depth);
- attr.repeat = True;
- p = XRenderCreatePicture (dpy, pix, f, CPRepeat, &attr);
- XFreePixmap (dpy, pix);
- }
- XRenderFillRectangle (dpy, PictOpSrc, p, color, 0, 0, 1, 1);
- lastColor = *color;
- return p;
-}
-
-XRenderPictFormat *
-GetMask (Display *dpy)
-{
- return XRenderFindStandardFormat (dpy, PictStandardA8);
-}