diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2024-12-23 09:02:11 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2024-12-23 09:02:11 +0000 |
commit | 12af560a7c8c6be2f8421177701db35690cb1489 (patch) | |
tree | fec51f2d413619e1a131163cc0cc882bb06b7368 /app/xcompmgr/xcompmgr.c | |
parent | c52999ce2abde5e0b88fdb5e34c40150ef97efcd (diff) |
update to xcompmgr 1.1.10
Diffstat (limited to 'app/xcompmgr/xcompmgr.c')
-rw-r--r-- | app/xcompmgr/xcompmgr.c | 180 |
1 files changed, 107 insertions, 73 deletions
diff --git a/app/xcompmgr/xcompmgr.c b/app/xcompmgr/xcompmgr.c index 94ef532c6..f28e4e604 100644 --- a/app/xcompmgr/xcompmgr.c +++ b/app/xcompmgr/xcompmgr.c @@ -46,6 +46,10 @@ #include <X11/extensions/Xrender.h> #include <X11/extensions/shape.h> +#ifndef HAVE_REALLOCARRAY +#define reallocarray(old, num, size) realloc(old, (num) * (size)) +#endif + #if COMPOSITE_MAJOR > 0 || COMPOSITE_MINOR >= 2 #define HAS_NAME_WINDOW_PIXMAP 1 #endif @@ -208,11 +212,9 @@ get_time_in_milliseconds (void) } static fade * -find_fade (win *w) +find_fade (const win *w) { - fade *f; - - for (f = fades; f; f = f->next) + for (fade *f = fades; f; f = f->next) { if (f->w == w) return f; @@ -223,9 +225,8 @@ find_fade (win *w) static void dequeue_fade (Display *dpy, fade *f) { - fade **prev; - - for (prev = &fades; *prev; prev = &(*prev)->next) + for (fade **prev = &fades; *prev; prev = &(*prev)->next) + { if (*prev == f) { *prev = f->next; @@ -234,6 +235,7 @@ dequeue_fade (Display *dpy, fade *f) free (f); break; } + } } static void @@ -264,9 +266,11 @@ set_fade (Display *dpy, win *w, double start, double finish, double step, if (!f) { f = malloc (sizeof (fade)); - f->next = NULL; - f->w = w; - f->cur = start; + *f = (fade) { + .next = NULL, + .w = w, + .cur = start + }; enqueue_fade (dpy, f); } else if(!override) @@ -391,27 +395,32 @@ make_gaussian_map (Display *dpy, double r) conv *c; int size = ((int) ceil ((r * 3)) + 1) & ~1; int center = size / 2; - int x, y; double t; - double g; c = malloc (sizeof (conv) + size * size * sizeof (double)); - c->size = size; - c->data = (double *) (c + 1); + *c = (conv) { + .size = size, + .data = (double *) (c + 1) + }; t = 0.0; - for (y = 0; y < size; y++) - for (x = 0; x < size; x++) + for (int y = 0; y < size; y++) + { + for (int x = 0; x < size; x++) { - g = gaussian (r, (double) (x - center), (double) (y - center)); + double g = + gaussian (r, (double) (x - center), (double) (y - center)); t += g; c->data[y * size + x] = g; } + } /* printf ("gaussian total %f\n", t); */ - for (y = 0; y < size; y++) - for (x = 0; x < size; x++) + for (int y = 0; y < size; y++) + { + for (int x = 0; x < size; x++) { c->data[y*size + x] /= t; } + } return c; } @@ -435,7 +444,6 @@ make_gaussian_map (Display *dpy, double r) static unsigned char sum_gaussian (conv *map, double opacity, int x, int y, int width, int height) { - int fx, fy; double *g_line = map->data; int g_size = map->size; int center = g_size / 2; @@ -470,12 +478,12 @@ sum_gaussian (conv *map, double opacity, int x, int y, int width, int height) g_line = g_line + fy_start * g_size + fx_start; v = 0; - for (fy = fy_start; fy < fy_end; fy++) + for (int fy = fy_start; fy < fy_end; fy++) { double *g_data = g_line; g_line += g_size; - for (fx = fx_start; fx < fx_end; fx++) + for (int fx = fx_start; fx < fx_end; fx++) v += *g_data++; } if (v > 1) @@ -489,7 +497,6 @@ static void presum_gaussian (conv *map) { int center = map->size/2; - int opacity, x, y; Gsize = map->size; @@ -501,21 +508,23 @@ presum_gaussian (conv *map) shadowCorner = malloc ((Gsize + 1) * (Gsize + 1) * 26); shadowTop = malloc ((Gsize + 1) * 26); - for (x = 0; x <= Gsize; x++) + for (int x = 0; x <= Gsize; x++) { shadowTop[25 * (Gsize + 1) + x] = sum_gaussian (map, 1, x - center, center, Gsize * 2, Gsize * 2); - for(opacity = 0; opacity < 25; opacity++) + for (int opacity = 0; opacity < 25; opacity++) shadowTop[opacity * (Gsize + 1) + x] = shadowTop[25 * (Gsize + 1) + x] * opacity / 25; - for(y = 0; y <= x; y++) + for (int y = 0; y <= x; y++) { shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x] = sum_gaussian (map, 1, x - center, y - center, Gsize * 2, Gsize * 2); shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y] = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]; - for(opacity = 0; opacity < 25; opacity++) + for (int opacity = 0; opacity < 25; opacity++) + { shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x] = shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y] = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x] * opacity / 25; + } } } } @@ -530,7 +539,6 @@ make_shadow (Display *dpy, double opacity, int width, int height) int swidth = width + gsize; int sheight = height + gsize; int center = gsize / 2; - int x, y; unsigned char d; int x_diff; int opacity_int = (int)(opacity * 25); @@ -572,8 +580,9 @@ make_shadow (Display *dpy, double opacity, int width, int height) if (xlimit > swidth / 2) xlimit = (swidth + 1) / 2; - for (y = 0; y < ylimit; y++) - for (x = 0; x < xlimit; x++) + for (int y = 0; y < ylimit; y++) + { + for (int x = 0; x < xlimit; x++) { if (xlimit == Gsize && ylimit == Gsize) d = shadowCorner[opacity_int * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]; @@ -584,6 +593,7 @@ make_shadow (Display *dpy, double opacity, int width, int height) data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d; data[y * swidth + (swidth - x - 1)] = d; } + } /* * top/bottom @@ -591,7 +601,7 @@ make_shadow (Display *dpy, double opacity, int width, int height) x_diff = swidth - (gsize * 2); if (x_diff > 0 && ylimit > 0) { - for (y = 0; y < ylimit; y++) + for (int y = 0; y < ylimit; y++) { if (ylimit == Gsize) d = shadowTop[opacity_int * (Gsize + 1) + y]; @@ -606,13 +616,13 @@ make_shadow (Display *dpy, double opacity, int width, int height) * sides */ - for (x = 0; x < xlimit; x++) + for (int x = 0; x < xlimit; x++) { if (xlimit == Gsize) d = shadowTop[opacity_int * (Gsize + 1) + x]; else d = sum_gaussian (gaussianMap, opacity, x - center, center, width, height); - for (y = gsize; y < sheight - gsize; y++) + for (int y = gsize; y < sheight - gsize; y++) { data[y * swidth + x] = d; data[y * swidth + (swidth - x - 1)] = d; @@ -696,10 +706,12 @@ solid_picture (Display *dpy, Bool argb, double a, double r, double g, double b) return None; } - c.alpha = a * 0xffff; - c.red = r * 0xffff; - c.green = g * 0xffff; - c.blue = b * 0xffff; + c = (XRenderColor) { + .alpha = a * 0xffff, + .red = r * 0xffff, + .green = g * 0xffff, + .blue = b * 0xffff + }; XRenderFillRectangle (dpy, PictOpSrc, picture, &c, 0, 0, 1, 1); XFreePixmap (dpy, pixmap); return picture; @@ -729,8 +741,10 @@ set_ignore (Display *dpy, unsigned long sequence) ignore *i = malloc (sizeof (ignore)); if (!i) return; - i->sequence = sequence; - i->next = NULL; + *i = (ignore) { + .sequence = sequence, + .next = NULL + }; *ignore_tail = i; ignore_tail = &i->next; } @@ -745,11 +759,11 @@ should_ignore (Display *dpy, unsigned long sequence) static win * find_win (Display *dpy, Window id) { - win *w; - - for (w = list; w; w = w->next) + for (win *w = list; w; w = w->next) + { if (w->id == id) return w; + } return NULL; } @@ -771,10 +785,9 @@ root_tile (Display *dpy) unsigned char *prop; Bool fill; XRenderPictureAttributes pa; - int p; pixmap = None; - for (p = 0; backgroundProps[p]; p++) + for (int p = 0; backgroundProps[p]; p++) { if (XGetWindowProperty (dpy, root, XInternAtom (dpy, backgroundProps[p], False), 0, 4, False, AnyPropertyType, @@ -799,10 +812,12 @@ root_tile (Display *dpy) CPRepeat, &pa); if (fill) { - XRenderColor c; - - c.red = c.green = c.blue = 0x8080; - c.alpha = 0xffff; + XRenderColor c = { + .red = 0x8080, + .green = 0x8080, + .blue = 0x8080, + .alpha = 0xffff + }; XRenderFillRectangle (dpy, PictOpSrc, picture, &c, 0, 0, 1, 1); } @@ -823,12 +838,13 @@ paint_root (Display *dpy) static XserverRegion win_extents (Display *dpy, win *w) { - XRectangle r; + XRectangle r = { + .x = w->a.x, + .y = w->a.y, + .width = w->a.width + w->a.border_width * 2, + .height = w->a.height + w->a.border_width * 2 + }; - r.x = w->a.x; - r.y = w->a.y; - r.width = w->a.width + w->a.border_width * 2; - r.height = w->a.height + w->a.border_width * 2; if (compMode != CompSimple && !(w->windowType == winDockAtom && excludeDockShadows)) { if (compMode == CompServerShadows || w->mode != WINDOW_ARGB) @@ -857,10 +873,12 @@ win_extents (Display *dpy, win *w) &w->shadow_width, &w->shadow_height); } } - sr.x = w->a.x + w->shadow_dx; - sr.y = w->a.y + w->shadow_dy; - sr.width = w->shadow_width; - sr.height = w->shadow_height; + sr = (XRectangle) { + .x = w->a.x + w->shadow_dx, + .y = w->a.y + w->shadow_dy, + .width = w->shadow_width, + .height = w->shadow_height + }; if (sr.x < r.x) { r.width = (r.x + r.width) - sr.x; @@ -909,11 +927,12 @@ paint_all (Display *dpy, XserverRegion region) if (!region) { - XRectangle r; - r.x = 0; - r.y = 0; - r.width = root_width; - r.height = root_height; + XRectangle r = { + .x = 0, + .y = 0, + .width = root_width, + .height = root_height + }; region = XFixesCreateRegion (dpy, &r, 1); } #if MONITOR_REPAINT @@ -1504,8 +1523,10 @@ restack_win (Display *dpy, win *w, Window new_above) /* unhook */ for (prev = &list; *prev; prev = &(*prev)->next) + { if ((*prev) == w) break; + } *prev = w->next; /* rehook */ @@ -1617,6 +1638,7 @@ finish_destroy_win (Display *dpy, Window id, Bool gone) win **prev, *w; for (prev = &list; (w = *prev); prev = &w->next) + { if (w->id == id) { if (gone) @@ -1653,6 +1675,7 @@ finish_destroy_win (Display *dpy, Window id, Bool gone) free (w); break; } + } } #if HAS_NAME_WINDOW_PIXMAP @@ -1769,7 +1792,7 @@ shape_kind(int kind) case ShapeInput: return "ShapeInput"; default: - sprintf (buf, "Shape %d", kind); + snprintf (buf, sizeof(buf), "Shape %d", kind); return buf; } } @@ -1920,7 +1943,7 @@ ev_name (XEvent *ev) { return "Shape"; } - sprintf (buf, "Event %d", ev->type); + snprintf (buf, sizeof(buf), "Event %d", ev->type); return buf; } } @@ -2287,21 +2310,32 @@ main (int argc, char **argv) { if (expose_rects) { - expose_rects = realloc (expose_rects, - (size_expose + more) * - sizeof (XRectangle)); - size_expose += more; + XRectangle *old = expose_rects; + + expose_rects = reallocarray (old, + (size_expose + more), + sizeof (XRectangle)); + if (expose_rects == NULL) { + expose_rects = old; + expose_root (dpy, root, expose_rects, n_expose); + n_expose = 0; + } else { + size_expose += more; + } } else { - expose_rects = malloc (more * sizeof (XRectangle)); + expose_rects = reallocarray (NULL, more, + sizeof (XRectangle)); size_expose = more; } } - expose_rects[n_expose].x = ev.xexpose.x; - expose_rects[n_expose].y = ev.xexpose.y; - expose_rects[n_expose].width = ev.xexpose.width; - expose_rects[n_expose].height = ev.xexpose.height; + expose_rects[n_expose] = (XRectangle) { + .x = ev.xexpose.x, + .y = ev.xexpose.y, + .width = ev.xexpose.width, + .height = ev.xexpose.height + }; n_expose++; if (ev.xexpose.count == 0) { |