summaryrefslogtreecommitdiff
path: root/xzoom/xzoom-0.3.shm.diff
blob: 26a15271a97dc5d53713ba3e31ba12aac5cff3d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Source: https://build.opensuse.org/source/home:Akoellh/xzoom/xzoom-0.3.shm.diff?rev=68bf54e9d06f0bce019d310ccd70d579
Date: 2021-02-16
diff -uraN xzoom-0.3.orig/xzoom.c xzoom-0.3/xzoom.c
--- xzoom-0.3.orig/xzoom.c	2017-10-12 17:53:38.446984725 +0200
+++ xzoom-0.3/xzoom.c	2017-10-12 17:54:46.094982727 +0200
@@ -28,6 +28,8 @@
                           some other minor changes/fixes
 tony mancill		2002/02/13 <tmancill@debian.org>       
 			hacked in support for WM_DELETE_WINDOW
+Egmont Koblinger          Added XSHM auto detection,
+                          -shm, -noshm and -autoshm option
 */
 
 #include <stdio.h>
@@ -87,6 +89,9 @@
 #define MAGX	MAG				/* horizontal magnification */
 #define MAGY	MAG				/* vertical magnification */
 
+int use_xshm = 1;
+int force_xshm = 0;
+
 int xgrab, ygrab;				/* where do we take the picture from */
 
 int magx = MAGX;
@@ -136,7 +141,7 @@
 
 	for(i = 0; i < 2; i++) {
 
-#ifdef XSHM
+if (use_xshm) { /*#ifdef XSHM*/
 		ximage[i] = XShmCreateImage(dpy,
 			DefaultVisualOfScreen(scr),
 			DefaultDepthOfScreen(scr),
@@ -172,11 +177,15 @@
 		ximage[i]->data = shminfo[i].shmaddr;
 		shminfo[i].readOnly = False;
 
-		XShmAttach(dpy, &shminfo[i]);
-		XSync(dpy, False);
+		if (XShmAttach(dpy, &shminfo[i]) || force_xshm) {
+			XSync(dpy, False);
 
-		shmctl(shminfo[i].shmid, IPC_RMID, 0);
-#else
+			shmctl(shminfo[i].shmid, IPC_RMID, 0);
+		} else {
+			use_xshm = 0;
+		}
+}
+if (!use_xshm) { /*#else*/
 		char *data;
 		data = malloc(BitmapUnit(dpy) / 8 * width[i] * height[i]);
 
@@ -191,7 +200,7 @@
 			exit(-1);
 		}
 
-#endif /* XSHM */
+} /*#endif*/ /* XSHM */
 	}
 	created_images = True;
 }
@@ -204,12 +213,12 @@
 		return;
 
 	for(i = 0; i < 2; i++) {
-#ifdef XSHM
+if (use_xshm) { /*#ifdef XSHM*/
 		XShmDetach(dpy, &shminfo[i]);	/* ask X11 to detach shared segment */
 		shmdt(shminfo[i].shmaddr);		/* detach it ourselves */
-#else
+} else { /*#else*/
 		free(ximage[i]->data);
-#endif
+} /*#endif*/
 		ximage[i]->data = NULL;			/* remove refrence to that address */
 		XDestroyImage(ximage[i]);		/* and destroy image */
 	}
@@ -222,6 +231,9 @@
 	fprintf(stderr, "Usage: %s [ args ]\n"
 		"Command line args:\n"
 		"-display displayname\n"
+		"-shm\n"
+		"-noshm\n"
+		"-autoshm\n"
 		"-mag magnification [ magnification ]\n"
 		"-geometry geometry\n"
 		"-source geometry\n"
@@ -351,6 +363,22 @@
 			continue;
 		}
 
+		if(!strcmp(argv[0], "-shm")) {
+			force_xshm = 1;
+			use_xshm = 1;
+			continue;
+		}
+		if(!strcmp(argv[0], "-noshm")) {
+			force_xshm = 0;
+			use_xshm = 0;
+			continue;
+		}
+		if(!strcmp(argv[0], "-autoshm")) {
+			force_xshm = 0;
+			use_xshm = 1;
+			continue;
+		}
+
 		if(!strcmp(argv[0], "-mag")) {
 			++argv; --argc;
 
@@ -818,14 +846,14 @@
 
 		}
 
-#ifdef XSHM
+if (use_xshm) { /*#ifdef XSHM*/
 		XShmGetImage(dpy, RootWindowOfScreen(scr), ximage[SRC],
 			xgrab, ygrab, AllPlanes);
-#else
+} else { /*#else*/
 		XGetSubImage(dpy, RootWindowOfScreen(scr),
 			xgrab, ygrab, width[SRC], height[SRC], AllPlanes,
 			ZPixmap, ximage[SRC], 0, 0);
-#endif
+} /*#endif*/
 #ifdef FRAME
 		if(buttonpressed) {	/* show the frame */
 			DRAW_FRAME();
@@ -840,11 +868,11 @@
 		else if (depth <= 8*sizeof(int))
 			scale32();
 
-#ifdef XSHM
+if (use_xshm) { /*#ifdef XSHM*/
 		XShmPutImage(dpy, win, gc, ximage[DST], 0, 0, 0, 0, width[DST], height[DST], False);
-#else
+} else { /*#else*/
 		XPutImage(dpy, win, gc, ximage[DST], 0, 0, 0, 0, width[DST], height[DST]);
-#endif
+} /*#endif*/
 		if(set_title) {
 			if(magx == magy && !flipx && !flipy && !flipxy)
 				sprintf(title, "%s x%d", progname, magx);
diff -uraN xzoom-0.3.orig/xzoom.man xzoom-0.3/xzoom.man
--- xzoom-0.3.orig/xzoom.man	2017-10-12 17:53:38.446984725 +0200
+++ xzoom-0.3/xzoom.man	2017-10-12 17:56:39.442979378 +0200
@@ -9,6 +9,7 @@
 [ \-display \fIdisplayname\fP ] [ \-mag \fImag\fP [ \fImag\fP ] ]
 [ \-x ] [ \-y ] [ \-xy ]
 [ \-geometry \fIgeometry\fP ] [ \-source \fIgeometry\fP ]
+[ \-shm ] [ \-noshm ] [ \-autoshm ]
 .SH OPTIONS
 .LP
 .TP 5
@@ -38,6 +39,16 @@
 The dimensions of this area are multiplied by the magnification to
 get the size of \fBxzoom\fR's window. If these dimensions are given
 separately (by use of \-geometry ) then an error is reported.
+.TP 5
+.B \-shm
+Force XSHM extension.
+.TP 5
+.B \-noshm
+Disable XSHM extension.
+.TP 5
+.B \-autoshm
+Try to autodetect if XSHM is available. This is the default. Unfortunately
+this is not perfect, sometimes you need to manually give \-noshm.
 .br
 .SH DESCRIPTION
 .IR Xzoom
@@ -148,6 +159,7 @@
 For best performance the shared memory extension for X11 is
 used. Xzoom will fail if it is compiled to use XSHM and its
 display is not on the local host.
+However, Auto detection of XSHM is far from perfect.
 .LP 5
 \(dg
 Xzoom is given with no warranty. It was tested only under
bgstack15