]> git.pld-linux.org Git - packages/xorg-driver-input-synaptics.git/blame - restore-shm2.patch
- updated to 1.9.2
[packages/xorg-driver-input-synaptics.git] / restore-shm2.patch
CommitLineData
f7d2631d
JR
1From c555a3f96836d0be562894a54e9e100b1897cfbf Mon Sep 17 00:00:00 2001
2From: Felipe <fjfcavalcanti@gmail.com>
3Date: Thu, 30 Jan 2014 13:43:54 -0300
4Subject: [PATCH] Put SynapticsSHM back into the driver to be able to use
5 synclient -m once again
6
7Merged and solved all conflicts
8---
9 include/Makefile.am | 2 +-
10 src/alpscomm.c | 1 +
11 src/eventcomm.c | 1 +
12 src/properties.c | 1 +
13 src/ps2comm.c | 1 +
14 src/psmcomm.c | 1 +
15 src/synaptics.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++-
16 src/synapticsstr.h | 4 ++
17 src/synproto.c | 1 +
18 tools/synclient.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++--
19 10 files changed, 245 insertions(+), 5 deletions(-)
20
21diff --git a/include/Makefile.am b/include/Makefile.am
22index 8234020..f078e5e 100644
23--- a/include/Makefile.am
24+++ b/include/Makefile.am
25@@ -18,4 +18,4 @@
26 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29-sdk_HEADERS = synaptics-properties.h
30+sdk_HEADERS = synaptics.h synaptics-properties.h
31diff --git a/src/alpscomm.c b/src/alpscomm.c
32index c565636..b7f1e65 100644
33--- a/src/alpscomm.c
34+++ b/src/alpscomm.c
35@@ -33,6 +33,7 @@
36 #endif
37
38 #include <xorg-server.h>
39+#include "synaptics.h"
40 #include "synproto.h"
41 #include "synapticsstr.h"
42 #include "ps2comm.h"
43diff --git a/src/eventcomm.c b/src/eventcomm.c
44index 9e81b86..d7de480 100644
45--- a/src/eventcomm.c
46+++ b/src/eventcomm.c
47@@ -41,6 +41,7 @@
48 #include <stdio.h>
49 #include <time.h>
50 #include "synproto.h"
51+#include "synaptics.h"
52 #include "synapticsstr.h"
53 #include <xf86.h>
54 #include <libevdev/libevdev.h>
55diff --git a/src/properties.c b/src/properties.c
56index 718d054..dba7dbb 100644
57--- a/src/properties.c
58+++ b/src/properties.c
59@@ -35,6 +35,7 @@
60 #include <xf86Xinput.h>
61 #include <exevents.h>
62
63+#include "synaptics.h"
64 #include "synapticsstr.h"
65 #include "synaptics-properties.h"
66
67diff --git a/src/ps2comm.c b/src/ps2comm.c
68index ed2f751..74431c1 100644
69--- a/src/ps2comm.c
70+++ b/src/ps2comm.c
71@@ -38,6 +38,7 @@
72
73 #include <xorg-server.h>
74 #include "synproto.h"
75+#include "synaptics.h"
76 #include "synapticsstr.h"
77 #include "ps2comm.h"
78 #include <xf86.h>
79diff --git a/src/psmcomm.c b/src/psmcomm.c
80index 4086aba..63c4536 100644
81--- a/src/psmcomm.c
82+++ b/src/psmcomm.c
83@@ -44,6 +44,7 @@
84 #include <sys/mouse.h>
85 #include <errno.h>
86 #include <string.h>
87+#include "synaptics.h"
88 #include "synproto.h"
89 #include "synapticsstr.h"
90 #include "ps2comm.h" /* ps2_print_ident() */
91diff --git a/src/synaptics.c b/src/synaptics.c
92index d5db457..92c57ae 100644
93--- a/src/synaptics.c
94+++ b/src/synaptics.c
95@@ -64,11 +64,12 @@
96 #include <misc.h>
97 #include <xf86.h>
98 #include <math.h>
99+#include <sys/shm.h>
100 #include <stdio.h>
101 #include <xf86_OSproc.h>
102 #include <xf86Xinput.h>
103 #include <exevents.h>
104-
105+#include "synaptics.h"
106 #include <X11/Xatom.h>
107 #include <X11/extensions/XI2.h>
108 #include <xserver-properties.h>
109@@ -297,6 +298,64 @@ SetDeviceAndProtocol(InputInfoPtr pInfo)
110 return (priv->proto_ops != NULL);
111 }
112
113+/*
114+ * Allocate and initialize read-only memory for the SynapticsParameters data to hold
115+ * driver settings.
116+ * The function will allocate shared memory if priv->shm_config is TRUE.
117+ */
118+static Bool
119+alloc_shm_data(InputInfoPtr pInfo)
120+{
121+ int shmid;
122+ SynapticsPrivate *priv = pInfo->private;
123+
124+ if (priv->synshm)
125+ return TRUE; /* Already allocated */
126+
127+ if (priv->shm_config) {
128+ if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) != -1)
129+ shmctl(shmid, IPC_RMID, NULL);
130+ if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM),
131+ 0774 | IPC_CREAT)) == -1) {
132+ xf86IDrvMsg(pInfo, X_ERROR, "error shmget\n");
133+ return FALSE;
134+ }
135+ if ((priv->synshm = (SynapticsSHM *) shmat(shmid, NULL, 0)) == NULL) {
136+ xf86IDrvMsg(pInfo, X_ERROR, "error shmat\n");
137+ return FALSE;
138+ }
139+ }
140+ else {
141+ priv->synshm = calloc(1, sizeof(SynapticsSHM));
142+ if (!priv->synshm)
143+ return FALSE;
144+ }
145+
146+ return TRUE;
147+}
148+
149+/*
150+ * Free SynapticsParameters data previously allocated by alloc_shm_data().
151+ */
152+static void
153+free_shm_data(SynapticsPrivate * priv)
154+{
155+ int shmid;
156+
157+ if (!priv->synshm)
158+ return;
159+
160+ if (priv->shm_config) {
161+ if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) != -1)
162+ shmctl(shmid, IPC_RMID, NULL);
163+ }
164+ else {
165+ free(priv->synshm);
166+ }
167+
168+ priv->synshm = NULL;
169+}
170+
171 static void
172 calculate_edge_widths(SynapticsPrivate * priv, int *l, int *r, int *t, int *b)
173 {
174@@ -579,6 +638,12 @@ set_default_parameters(InputInfoPtr pInfo)
175 int grab_event_device = 0;
176 const char *source;
177
178+ /* read the parameters */
179+ if (priv->synshm)
180+ priv->synshm->version =
181+ (PACKAGE_VERSION_MAJOR * 10000 + PACKAGE_VERSION_MINOR * 100 +
182+ PACKAGE_VERSION_PATCHLEVEL);
183+
184 /* The synaptics specs specify typical edge widths of 4% on x, and 5.4% on
185 * y (page 7) [Synaptics TouchPad Interfacing Guide, 510-000080 - A
186 * Second Edition, http://www.synaptics.com/support/dev_support.cfm, 8 Sep
187@@ -899,12 +964,17 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
188 /* read hardware dimensions */
189 ReadDevDimensions(pInfo);
190
191+ /* install shared memory or normal memory for parameters */
192+ priv->shm_config = xf86SetBoolOption(pInfo->options, "SHMConfig", FALSE);
193+
194 set_default_parameters(pInfo);
195
196 #ifndef NO_DRIVER_SCALING
197 CalculateScalingCoeffs(priv);
198 #endif
199
200+ if (!alloc_shm_data(pInfo))
201+ goto SetupProc_fail;
202
203 priv->comm.buffer = XisbNew(pInfo->fd, INPUT_BUFFER_SIZE);
204
205@@ -929,6 +999,7 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
206
207 if (priv->comm.buffer)
208 XisbFree(priv->comm.buffer);
209+ free_shm_data(priv);
210 free(priv->proto_data);
211 free(priv->timer);
212 free(priv);
213@@ -1109,6 +1180,7 @@ DeviceClose(DeviceIntPtr dev)
214 RetValue = DeviceOff(dev);
215 TimerFree(priv->timer);
216 priv->timer = NULL;
217+ free_shm_data(priv);
218 free(priv->touch_axes);
219 priv->touch_axes = NULL;
220 SynapticsHwStateFree(&priv->hwState);
221@@ -1363,6 +1435,9 @@ DeviceInit(DeviceIntPtr dev)
222
223 priv->comm.hwState = SynapticsHwStateAlloc(priv);
224
225+ if (!alloc_shm_data(pInfo))
226+ goto fail;
227+
228 InitDeviceProperties(pInfo);
229 XIRegisterPropertyHandler(pInfo->dev, SetProperty, NULL, NULL);
230
231@@ -1371,6 +1446,7 @@ DeviceInit(DeviceIntPtr dev)
232 return Success;
233
234 fail:
235+ free_shm_data(priv);
236 free(priv->local_hw_state);
237 free(priv->hwState);
238 free(priv->open_slots);
239@@ -3074,6 +3150,33 @@ reset_hw_state(struct SynapticsHwState *hw)
240 hw->fingerWidth = 0;
241 }
242
243+/* Update the hardware state in shared memory. This is read-only these days,
244+ * nothing in the driver reads back from SHM. SHM configuration is a thing of the past.
245+ */
246+static void
247+update_shm(const InputInfoPtr pInfo, const struct SynapticsHwState *hw)
248+{
249+ int i;
250+ SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
251+ SynapticsSHM *shm = priv->synshm;
252+
253+ if (!shm)
254+ return;
255+
256+ shm->x = hw->x;
257+ shm->y = hw->y;
258+ shm->z = hw->z;
259+ shm->numFingers = hw->numFingers;
260+ shm->fingerWidth = hw->fingerWidth;
261+ shm->left = hw->left;
262+ shm->right = hw->right;
263+ shm->up = hw->up;
264+ shm->down = hw->down;
265+ for (i = 0; i < 8; i++)
266+ shm->multi[i] = hw->multi[i];
267+ shm->middle = hw->middle;
268+}
269+
270 /*
271 * React on changes in the hardware state. This function is called every time
272 * the hardware state changes. The return value is used to specify how many
273@@ -3101,6 +3204,14 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
274 Bool using_cumulative_coords = FALSE;
275 Bool ignore_motion;
276
277+ update_shm(pInfo, hw);
278+
279+ /* If touchpad is switched off, we skip the whole thing and return delay */
280+ if (para->touchpad_off == TOUCHPAD_OFF) {
281+ UpdateTouchState(pInfo, hw);
282+ return delay;
283+ }
284+
285 /* We need both and x/y, the driver can't handle just one of the two
286 * yet. But since it's possible to hit a phys button on non-clickpads
287 * without ever getting motion data first, we must continue with 0/0 for
288diff --git a/src/synapticsstr.h b/src/synapticsstr.h
289index 4bd32ac..023a7c1 100644
290--- a/src/synapticsstr.h
291+++ b/src/synapticsstr.h
292@@ -23,6 +23,7 @@
293 #define _SYNAPTICSSTR_H_
294
295 #include "synproto.h"
296+#include "synaptics.h"
297
298 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 18
299 #define LogMessageVerbSigSafe xf86MsgVerb
300@@ -231,6 +232,9 @@ typedef struct _SynapticsParameters {
301 struct _SynapticsPrivateRec {
302 SynapticsParameters synpara; /* Default parameter settings, read from
303 the X config file */
304+ SynapticsSHM *synshm; /* Current parameter settings. Will point to
305+ shared memory if shm_config is true */
306+ Bool shm_config;
307 struct SynapticsProtocolOperations *proto_ops;
308 void *proto_data; /* protocol-specific data */
309
310diff --git a/src/synproto.c b/src/synproto.c
311index 91e20e6..409722e 100644
312--- a/src/synproto.c
313+++ b/src/synproto.c
314@@ -23,6 +23,7 @@
315
316 #include "synproto.h"
317 #include "synapticsstr.h"
318+#include "synaptics.h"
319
320 static int
321 HwStateAllocTouch(struct SynapticsHwState *hw, SynapticsPrivate * priv)
322diff --git a/tools/synclient.c b/tools/synclient.c
323index ac31a66..df1e6a7 100644
324--- a/tools/synclient.c
325+++ b/tools/synclient.c
326@@ -32,6 +32,7 @@
327 #include <stdlib.h>
328 #include <sys/types.h>
329 #include <sys/ipc.h>
330+#include <sys/shm.h>
331 #include <sys/time.h>
332 #include <unistd.h>
333 #include <string.h>
334@@ -44,6 +45,7 @@
335 #include <X11/extensions/XI.h>
336 #include <X11/extensions/XInput.h>
337 #include "synaptics-properties.h"
338+#include "synaptics.h"
339
340 #ifndef XATOM_FLOAT
341 #define XATOM_FLOAT "FLOAT"
342@@ -192,6 +194,108 @@ parse_cmd(char *cmd, struct Parameter **par)
343 return 0;
344 }
345
346+static int
347+is_equal(SynapticsSHM * s1, SynapticsSHM * s2)
348+{
349+ int i;
350+
351+ if ((s1->x != s2->x) ||
352+ (s1->y != s2->y) ||
353+ (s1->z != s2->z) ||
354+ (s1->numFingers != s2->numFingers) ||
355+ (s1->fingerWidth != s2->fingerWidth) ||
356+ (s1->left != s2->left) ||
357+ (s1->right != s2->right) ||
358+ (s1->up != s2->up) ||
359+ (s1->down != s2->down) || (s1->middle != s2->middle))
360+ return 0;
361+
362+ for (i = 0; i < 8; i++)
363+ if (s1->multi[i] != s2->multi[i])
364+ return 0;
365+
366+ return 1;
367+}
368+
369+static double
370+get_time(void)
371+{
372+ struct timeval tv;
373+
374+ gettimeofday(&tv, NULL);
375+ return tv.tv_sec + tv.tv_usec / 1000000.0;
376+}
377+
378+static void
379+shm_monitor(SynapticsSHM * synshm, int delay)
380+{
381+ int header = 0;
382+ SynapticsSHM old;
383+ double t0 = get_time();
384+
385+ memset(&old, 0, sizeof(SynapticsSHM));
386+ old.x = -1; /* Force first equality test to fail */
387+
388+ while (1) {
389+ SynapticsSHM cur = *synshm;
390+
391+ if (!is_equal(&old, &cur)) {
392+ if (!header) {
393+ printf("%8s %4s %4s %3s %s %2s %2s %s %s %s %s %8s "
394+ "%2s %2s %2s %3s %3s\n",
395+ "time", "x", "y", "z", "f", "w", "l", "r", "u", "d", "m",
396+ "multi", "gl", "gm", "gr", "gdx", "gdy");
397+ header = 20;
398+ }
399+ header--;
400+ printf
401+ ("%8.3f %4d %4d %3d %d %2d %2d %d %d %d %d %d%d%d%d%d%d%d%d\n",
402+ get_time() - t0, cur.x, cur.y, cur.z, cur.numFingers,
403+ cur.fingerWidth, cur.left, cur.right, cur.up, cur.down,
404+ cur.middle, cur.multi[0], cur.multi[1], cur.multi[2],
405+ cur.multi[3], cur.multi[4], cur.multi[5], cur.multi[6],
406+ cur.multi[7]);
407+ fflush(stdout);
408+ old = cur;
409+ }
410+ usleep(delay * 1000);
411+ }
412+}
413+
414+/** Init and return SHM area or NULL on error */
415+static SynapticsSHM *
416+shm_init()
417+{
418+ SynapticsSHM *synshm = NULL;
419+ int shmid = 0;
420+
421+ if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) {
422+ if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1)
423+ fprintf(stderr,
424+ "Can't access shared memory area. SHMConfig disabled?\n");
425+ else
426+ fprintf(stderr,
427+ "Incorrect size of shared memory area. Incompatible driver version?\n");
428+ }
429+ else if ((synshm = (SynapticsSHM *) shmat(shmid, NULL, SHM_RDONLY)) == NULL)
430+ perror("shmat");
431+
432+ return synshm;
433+}
434+
435+static void
436+shm_process_commands(int do_monitor, int delay)
437+{
438+ SynapticsSHM *synshm = NULL;
439+
440+ synshm = shm_init();
441+ if (!synshm)
442+ return;
443+
444+ if (do_monitor)
445+ shm_monitor(synshm, delay);
446+}
447+
448 /** Init display connection or NULL on error */
449 static Display *
450 dp_init()
451@@ -469,7 +573,11 @@ dp_show_settings(Display * dpy, XDevice * dev)
452 static void
453 usage(void)
454 {
455- fprintf(stderr, "Usage: synclient [-h] [-l] [-V] [-?] [var1=value1 [var2=value2] ...]\n");
456+ fprintf(stderr,
457+ "Usage: synclient [-m interval] [-h] [-l] [-V] [-?] [var1=value1 [var2=value2] ...]\n");
458+ fprintf(stderr,
459+ " -m monitor changes to the touchpad state (implies -s)\n"
460+ " interval specifies how often (in ms) to poll the touchpad state\n");
461 fprintf(stderr, " -l List current user settings\n");
462 fprintf(stderr, " -V Print synclient version string and exit\n");
463 fprintf(stderr, " -? Show this help message\n");
464@@ -481,7 +589,9 @@ int
465 main(int argc, char *argv[])
466 {
467 int c;
468+ int delay = -1;
469 int dump_settings = 0;
470+ int do_monitor = 0;
471 int first_cmd;
472
473 Display *dpy;
474@@ -491,8 +601,13 @@ main(int argc, char *argv[])
475 dump_settings = 1;
476
477 /* Parse command line parameters */
478- while ((c = getopt(argc, argv, "lV?")) != -1) {
479+ while ((c = getopt(argc, argv, "m:lV?")) != -1) {
480 switch (c) {
481+ case 'm':
482+ do_monitor = 1;
483+ if ((delay = atoi(optarg)) < 0)
484+ usage();
485+ break;
486 case 'l':
487 dump_settings = 1;
488 break;
489@@ -506,9 +621,13 @@ main(int argc, char *argv[])
490 }
491
492 first_cmd = optind;
493- if (!dump_settings && first_cmd == argc)
494+ if (!do_monitor && !dump_settings && first_cmd == argc)
495 usage();
496
497+ /* Connect to the shared memory area */
498+ if (do_monitor)
499+ shm_process_commands(do_monitor, delay);
500+
501 dpy = dp_init();
502 if (!dpy || !(dev = dp_get_device(dpy)))
503 return 1;
This page took 0.131451 seconds and 4 git commands to generate.