summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2018-01-14 17:59:37 +0100
committerKim Woelders <kim@woelders.dk>2021-11-29 17:37:20 +0100
commitb2d7af466e6864f2b4ea7d4df52cc132c96c1dfd (patch)
treea0310f04726e48db8793267b1b2ac7aadcba3fcd
parent314fb50e922769a28431e3bdd74cb9e3cb2de45e (diff)
downloadimlib2-b2d7af466e6864f2b4ea7d4df52cc132c96c1dfd.tar.gz
x11_grab.c: Introduce function to get shape mask
Avoiding some code duplication.
-rw-r--r--src/lib/x11_grab.c108
1 files changed, 51 insertions, 57 deletions
diff --git a/src/lib/x11_grab.c b/src/lib/x11_grab.c
index 185433e..e57179f 100644
--- a/src/lib/x11_grab.c
+++ b/src/lib/x11_grab.c
@@ -590,6 +590,49 @@ __imlib_GrabXImageToRGBA(DATA32 * data,
XUngrabServer(d);
}
+static Pixmap
+_WindowGetShapeMask(Display * d, Window p,
+ int x, int y, int w, int h, int ww, int wh)
+{
+ Pixmap mask;
+ XRectangle *rect;
+ int rect_num, rect_ord, i;
+ XGCValues gcv;
+ GC mgc;
+
+ mask = None;
+
+ rect = XShapeGetRectangles(d, p, ShapeBounding, &rect_num, &rect_ord);
+ if (!rect)
+ return mask;
+
+ if (rect_num == 1 &&
+ rect[0].x == 0 && rect[0].y == 0 &&
+ rect[0].width == ww && rect[0].height == wh)
+ goto done;
+
+ mask = XCreatePixmap(d, p, w, h, 1);
+
+ gcv.foreground = 0;
+ gcv.graphics_exposures = False;
+ mgc = XCreateGC(d, mask, GCForeground | GCGraphicsExposures, &gcv);
+
+ XFillRectangle(d, mask, mgc, 0, 0, w, h);
+
+ XSetForeground(d, mgc, 1);
+ for (i = 0; i < rect_num; i++)
+ XFillRectangle(d, mask, mgc, rect[i].x - x, rect[i].y - y,
+ rect[i].width, rect[i].height);
+
+ if (mgc)
+ XFreeGC(d, mgc);
+
+ done:
+ XFree(rect);
+
+ return mask;
+}
+
int
__imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
int h_dst, Display * d, Drawable p, Pixmap m_,
@@ -711,35 +754,10 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
w_src = width;
h_src = height;
- if ((!is_pixmap) && (domask) && (m == None))
- {
- int ord, rect_no = 0;
- XRectangle *r = NULL;
- r = XShapeGetRectangles(d, p, ShapeBounding, &rect_no, &ord);
- if (r)
- {
- if (!((rect_no == 1) &&
- (r[0].x == 0) && (r[0].y == 0) &&
- (r[0].width == xatt.width) && (r[0].height == xatt.height)))
- {
- XGCValues gcv;
- GC gc;
-
- m = XCreatePixmap(d, p, w_src, h_src, 1);
- gcv.foreground = 0;
- gc = XCreateGC(d, m, GCForeground, &gcv);
- XFillRectangle(d, m, gc, 0, 0, w_src, h_src);
- XSetForeground(d, gc, 1);
- for (i = 0; i < rect_no; i++)
- XFillRectangle(d, m, gc,
- r[i].x - x_src, r[i].y - y_src,
- r[i].width, r[i].height);
- XFreeGC(d, gc);
- }
- XFree(r);
- }
- }
+ if ((!is_pixmap) && (domask) && (m == None))
+ m = _WindowGetShapeMask(d, p, x_src, y_src, w_src, h_src,
+ xatt.width, xatt.height);
/* Create an Ximage (shared or not) */
xim = __imlib_ShmGetXImage(d, v, p, xatt.depth, x_src, y_src, w_src, h_src,
@@ -857,7 +875,7 @@ __imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst,
int rc;
int h_tmp, i, xx;
XGCValues gcv;
- GC gc = NULL, mgc = NULL;
+ GC gc, mgc = NULL;
Pixmap m = m_;
Pixmap psc, msc;
@@ -871,31 +889,9 @@ __imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst,
if (*pdomask && m == None)
{
- XRectangle *rect;
- int rect_num, rect_ord;
-
- rect = XShapeGetRectangles(d, p, ShapeBounding, &rect_num, &rect_ord);
-
- if (rect && (rect_num == 1 && rect[0].x == 0 && rect[0].y == 0 &&
- rect[0].width == w_src && rect[0].height == h_src))
- {
- *pdomask = 0;
- XFree(rect);
- }
- else
- {
- m = XCreatePixmap(d, p, w_src, h_src, 1);
- mgc = XCreateGC(d, m, GCForeground | GCGraphicsExposures, &gcv);
- XFillRectangle(d, m, mgc, 0, 0, w_src, h_src);
- if (rect)
- {
- XSetForeground(d, mgc, 1);
- for (i = 0; i < rect_num; i++)
- XFillRectangle(d, m, mgc, rect[i].x, rect[i].y,
- rect[i].width, rect[i].height);
- XFree(rect);
- }
- }
+ m = _WindowGetShapeMask(d, p, 0, 0, w_src, h_src, w_src, h_src);
+ if (m == None)
+ *pdomask = 0;
}
if (w_dst == w_src && h_dst == h_src)
@@ -908,9 +904,7 @@ __imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst,
if (*pdomask)
{
msc = XCreatePixmap(d, p, w_dst, h_tmp, 1);
- if (!mgc)
- mgc =
- XCreateGC(d, msc, GCForeground | GCGraphicsExposures, &gcv);
+ mgc = XCreateGC(d, msc, GCForeground | GCGraphicsExposures, &gcv);
}
else
msc = None;