summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-11-26 11:23:40 +0100
committerKim Woelders <kim@woelders.dk>2021-11-29 17:37:20 +0100
commit314fb50e922769a28431e3bdd74cb9e3cb2de45e (patch)
treeca69fe66d1633a0e8988bdaadb2defd78118f343
parent5ab0fa77f17013ac2a45fef471742529057b3d9f (diff)
x11_grab.c: Cosmetics
-rw-r--r--src/lib/x11_grab.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/lib/x11_grab.c b/src/lib/x11_grab.c
index 13e6110..185433e 100644
--- a/src/lib/x11_grab.c
+++ b/src/lib/x11_grab.c
@@ -592,30 +592,34 @@ __imlib_GrabXImageToRGBA(DATA32 * data,
592 592
593int 593int
594__imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst, 594__imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
595 int h_dst, Display * d, Drawable p, Pixmap m, 595 int h_dst, Display * d, Drawable p, Pixmap m_,
596 Visual * v, Colormap cm, int depth, int x_src, 596 Visual * v, Colormap cm, int depth, int x_src,
597 int y_src, int w_src, int h_src, char *pdomask, 597 int y_src, int w_src, int h_src, char *pdomask,
598 int grab) 598 int grab)
599{ 599{
600 XErrorHandler prev_erh = NULL; 600 XErrorHandler prev_erh = NULL;
601 XWindowAttributes xatt, ratt; 601 XWindowAttributes xatt, ratt;
602 char is_pixmap = 0, created_mask = 0, is_shm = 0, is_mshm = 0; 602 char is_pixmap = 0, is_shm = 0, is_mshm = 0;
603 char domask; 603 char domask;
604 int i; 604 int i;
605 int src_x, src_y, src_w, src_h; 605 int src_x, src_y, src_w, src_h;
606 int width, height, clipx, clipy; 606 int width, height, clipx, clipy;
607 Pixmap m = m_;
607 XShmSegmentInfo shminfo, mshminfo; 608 XShmSegmentInfo shminfo, mshminfo;
608 XImage *xim, *mxim; 609 XImage *xim, *mxim;
609 XColor cols[256]; 610 XColor cols[256];
610 611
611 domask = (pdomask) ? *pdomask : 0; 612 domask = (pdomask) ? *pdomask : 0;
613
612 /* FIXME: h_dst isn't used - i wonder if there's a bug looming... */ 614 /* FIXME: h_dst isn't used - i wonder if there's a bug looming... */
613 h_dst = 0; 615 h_dst = 0;
616
614 if (grab) 617 if (grab)
615 XGrabServer(d); 618 XGrabServer(d);
616 XSync(d, False); 619 XSync(d, False);
617 prev_erh = XSetErrorHandler(Tmp_HandleXError); 620 prev_erh = XSetErrorHandler(Tmp_HandleXError);
618 _x_err = 0; 621 _x_err = 0;
622
619 /* lets see if its a pixmap or not */ 623 /* lets see if its a pixmap or not */
620 XGetWindowAttributes(d, p, &xatt); 624 XGetWindowAttributes(d, p, &xatt);
621 XSync(d, False); 625 XSync(d, False);
@@ -623,6 +627,7 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
623 is_pixmap = 1; 627 is_pixmap = 1;
624 /* reset our error handler */ 628 /* reset our error handler */
625 XSetErrorHandler((XErrorHandler) prev_erh); 629 XSetErrorHandler((XErrorHandler) prev_erh);
630
626 if (is_pixmap) 631 if (is_pixmap)
627 { 632 {
628 Window dw; 633 Window dw;
@@ -666,18 +671,21 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
666 if ((src_y + y_src + height) > ratt.height) 671 if ((src_y + y_src + height) > ratt.height)
667 height = ratt.height - (src_y + y_src); 672 height = ratt.height - (src_y + y_src);
668 } 673 }
674
669 if (x_src < 0) 675 if (x_src < 0)
670 { 676 {
671 clipx = -x_src; 677 clipx = -x_src;
672 width += x_src; 678 width += x_src;
673 x_src = 0; 679 x_src = 0;
674 } 680 }
681
675 if (y_src < 0) 682 if (y_src < 0)
676 { 683 {
677 clipy = -y_src; 684 clipy = -y_src;
678 height += y_src; 685 height += y_src;
679 y_src = 0; 686 y_src = 0;
680 } 687 }
688
681 if (!is_pixmap) 689 if (!is_pixmap)
682 { 690 {
683 if ((src_x + x_src) < 0) 691 if ((src_x + x_src) < 0)
@@ -693,15 +701,17 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
693 y_src = -src_y; 701 y_src = -src_y;
694 } 702 }
695 } 703 }
704
696 if ((width <= 0) || (height <= 0)) 705 if ((width <= 0) || (height <= 0))
697 { 706 {
698 if (grab) 707 if (grab)
699 XUngrabServer(d); 708 XUngrabServer(d);
700 return 0; 709 return 0;
701 } 710 }
711
702 w_src = width; 712 w_src = width;
703 h_src = height; 713 h_src = height;
704 if ((!is_pixmap) && (domask) && (!m)) 714 if ((!is_pixmap) && (domask) && (m == None))
705 { 715 {
706 int ord, rect_no = 0; 716 int ord, rect_no = 0;
707 XRectangle *r = NULL; 717 XRectangle *r = NULL;
@@ -716,7 +726,6 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
716 XGCValues gcv; 726 XGCValues gcv;
717 GC gc; 727 GC gc;
718 728
719 created_mask = 1;
720 m = XCreatePixmap(d, p, w_src, h_src, 1); 729 m = XCreatePixmap(d, p, w_src, h_src, 1);
721 gcv.foreground = 0; 730 gcv.foreground = 0;
722 gc = XCreateGC(d, m, GCForeground, &gcv); 731 gc = XCreateGC(d, m, GCForeground, &gcv);
@@ -733,9 +742,8 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
733 } 742 }
734 743
735 /* Create an Ximage (shared or not) */ 744 /* Create an Ximage (shared or not) */
736 xim = 745 xim = __imlib_ShmGetXImage(d, v, p, xatt.depth, x_src, y_src, w_src, h_src,
737 __imlib_ShmGetXImage(d, v, p, xatt.depth, x_src, y_src, w_src, h_src, 746 &shminfo);
738 &shminfo);
739 is_shm = !!xim; 747 is_shm = !!xim;
740 748
741 if (!xim) 749 if (!xim)
@@ -804,6 +812,7 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
804 btab[i] = cols[i].blue >> 8; 812 btab[i] = cols[i].blue >> 8;
805 } 813 }
806 } 814 }
815
807 __imlib_GrabXImageToRGBA(data, x_dst + clipx, y_dst + clipy, w_dst, h_dst, 816 __imlib_GrabXImageToRGBA(data, x_dst + clipx, y_dst + clipy, w_dst, h_dst,
808 d, xim, mxim, v, xatt.depth, x_src, y_src, w_src, 817 d, xim, mxim, v, xatt.depth, x_src, y_src, w_src,
809 h_src, 0); 818 h_src, 0);
@@ -821,7 +830,8 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
821 else 830 else
822 XDestroyImage(mxim); 831 XDestroyImage(mxim);
823 } 832 }
824 if (created_mask) 833
834 if (m != None && m != m_)
825 XFreePixmap(d, m); 835 XFreePixmap(d, m);
826 836
827 if (pdomask) 837 if (pdomask)
@@ -829,7 +839,7 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
829 /* Set domask according to whether or not we have useful alpha data */ 839 /* Set domask according to whether or not we have useful alpha data */
830 if (xatt.depth == 32) 840 if (xatt.depth == 32)
831 *pdomask = 1; 841 *pdomask = 1;
832 else if (!m) 842 else if (m == None)
833 *pdomask = 0; 843 *pdomask = 0;
834 } 844 }
835 845
@@ -839,16 +849,16 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int x_dst, int y_dst, int w_dst,
839int 849int
840__imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst, 850__imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst,
841 int w_dst, int h_dst, 851 int w_dst, int h_dst,
842 Display * d, Drawable p, Pixmap m, 852 Display * d, Drawable p, Pixmap m_,
843 Visual * v, Colormap cm, int depth, 853 Visual * v, Colormap cm, int depth,
844 int x_src, int y_src, int w_src, int h_src, 854 int x_src, int y_src, int w_src, int h_src,
845 char *pdomask, int grab) 855 char *pdomask, int grab)
846{ 856{
847 int rc; 857 int rc;
848 int tmpmask = 0;
849 int h_tmp, i, xx; 858 int h_tmp, i, xx;
850 XGCValues gcv; 859 XGCValues gcv;
851 GC gc = 0, mgc = 0; 860 GC gc = NULL, mgc = NULL;
861 Pixmap m = m_;
852 Pixmap psc, msc; 862 Pixmap psc, msc;
853 863
854 h_tmp = h_dst > h_src ? h_dst : h_src; 864 h_tmp = h_dst > h_src ? h_dst : h_src;
@@ -859,7 +869,7 @@ __imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst,
859 gcv.graphics_exposures = False; 869 gcv.graphics_exposures = False;
860 gc = XCreateGC(d, p, GCSubwindowMode | GCGraphicsExposures, &gcv); 870 gc = XCreateGC(d, p, GCSubwindowMode | GCGraphicsExposures, &gcv);
861 871
862 if (*pdomask && !m) 872 if (*pdomask && m == None)
863 { 873 {
864 XRectangle *rect; 874 XRectangle *rect;
865 int rect_num, rect_ord; 875 int rect_num, rect_ord;
@@ -874,7 +884,6 @@ __imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst,
874 } 884 }
875 else 885 else
876 { 886 {
877 tmpmask = 1;
878 m = XCreatePixmap(d, p, w_src, h_src, 1); 887 m = XCreatePixmap(d, p, w_src, h_src, 1);
879 mgc = XCreateGC(d, m, GCForeground | GCGraphicsExposures, &gcv); 888 mgc = XCreateGC(d, m, GCForeground | GCGraphicsExposures, &gcv);
880 XFillRectangle(d, m, mgc, 0, 0, w_src, h_src); 889 XFillRectangle(d, m, mgc, 0, 0, w_src, h_src);
@@ -947,7 +956,7 @@ __imlib_GrabDrawableScaledToRGBA(DATA32 * data, int nu_x_dst, int nu_y_dst,
947 XFreeGC(d, mgc); 956 XFreeGC(d, mgc);
948 if (msc != None && msc != m) 957 if (msc != None && msc != m)
949 XFreePixmap(d, msc); 958 XFreePixmap(d, msc);
950 if (tmpmask) 959 if (m != None && m != m_)
951 XFreePixmap(d, m); 960 XFreePixmap(d, m);
952 XFreeGC(d, gc); 961 XFreeGC(d, gc);
953 XFreePixmap(d, psc); 962 XFreePixmap(d, psc);