X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fdraw%2Fframe.c;h=45cca1052e84aee9251c2b2213642ffb8003c5f3;hb=HEAD;hp=c9e37d63c3c21c67663c980b57ca91b9ab41318f;hpb=033e32989aab05fe6174a3db4a5eca4df07d7ab8;p=fw%2Faltos diff --git a/src/draw/frame.c b/src/draw/frame.c index c9e37d63..45cca105 100644 --- a/src/draw/frame.c +++ b/src/draw/frame.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ RopNameRec ropNames[] = { { "set", GXset, }, /* 1 */ }; -int +static int RopNameToRop (char *name) { int rop; @@ -118,7 +119,7 @@ RopNameToRop (char *name) return GXcopy; } -void +static void Error (char *s, char *a) { fprintf (stderr, s, a); @@ -126,7 +127,7 @@ Error (char *s, char *a) exit (1); } -int +static int MatchCapStyle (char *s) { if (!strcmp (s, "round")) @@ -141,7 +142,7 @@ MatchCapStyle (char *s) return CapNotLast; } -int +static int MatchJoinStyle (char *s) { if (!strcmp (s, "round")) @@ -154,7 +155,7 @@ MatchJoinStyle (char *s) return JoinBevel; } -int +static int MatchFillStyle(char *s) { if (!strcmp (s, "solid")) @@ -169,7 +170,7 @@ MatchFillStyle(char *s) return FillSolid; } -int +static int MatchLineStyle(char *s) { if (!strcmp (s, "solid")) @@ -182,7 +183,17 @@ MatchLineStyle(char *s) 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; @@ -191,10 +202,16 @@ typedef struct _Position { 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; @@ -202,69 +219,53 @@ UpdatePositions (state, x, y) 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; @@ -273,10 +274,10 @@ DisplayPositions (dpy, win, gc, positions) 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++) { @@ -287,7 +288,7 @@ DisplayPositions (dpy, win, gc, positions) 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); @@ -296,27 +297,21 @@ DisplayPositions (dpy, win, gc, positions) #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); @@ -361,12 +356,18 @@ double line_width = DEFAULT_LINE_WIDTH; 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); @@ -377,10 +378,66 @@ 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 + +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; @@ -390,17 +447,18 @@ main (argc, argv) 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; @@ -411,7 +469,9 @@ main (argc, argv) 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) @@ -419,17 +479,17 @@ main (argc, argv) 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")) @@ -440,24 +500,24 @@ main (argc, argv) 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")) @@ -475,7 +535,7 @@ main (argc, argv) argv++; ndashes = 0; while (*argv && isdigit (**argv)) - dashes[ndashes++] = atoi(*argv++); + dashes[ndashes++] = (char) atoi(*argv++); argv--; } #ifdef MATCH_ARGUMENT @@ -483,15 +543,13 @@ main (argc, argv) 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", ""); @@ -603,27 +661,30 @@ main (argc, argv) 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; @@ -643,6 +704,17 @@ main (argc, argv) 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) { @@ -712,58 +784,3 @@ main (argc, argv) } } } - -#include - -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); -}