1 From c555a3f96836d0be562894a54e9e100b1897cfbf Mon Sep 17 00:00:00 2001
2 From: Felipe <fjfcavalcanti@gmail.com>
3 Date: Thu, 30 Jan 2014 13:43:54 -0300
4 Subject: [PATCH] Put SynapticsSHM back into the driver to be able to use
5 synclient -m once again
7 Merged and solved all conflicts
9 include/Makefile.am | 2 +-
12 src/properties.c | 1 +
15 src/synaptics.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++-
16 src/synapticsstr.h | 4 ++
18 tools/synclient.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++--
19 10 files changed, 245 insertions(+), 5 deletions(-)
21 diff --git a/include/Makefile.am b/include/Makefile.am
22 index 8234020..f078e5e 100644
23 --- a/include/Makefile.am
24 +++ b/include/Makefile.am
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.
29 -sdk_HEADERS = synaptics-properties.h
30 +sdk_HEADERS = synaptics.h synaptics-properties.h
31 diff --git a/src/alpscomm.c b/src/alpscomm.c
32 index c565636..b7f1e65 100644
38 #include <xorg-server.h>
39 +#include "synaptics.h"
41 #include "synapticsstr.h"
43 diff --git a/src/eventcomm.c b/src/eventcomm.c
44 index 9e81b86..d7de480 100644
51 +#include "synaptics.h"
52 #include "synapticsstr.h"
54 #include <libevdev/libevdev.h>
55 diff --git a/src/properties.c b/src/properties.c
56 index 718d054..dba7dbb 100644
57 --- a/src/properties.c
58 +++ b/src/properties.c
60 #include <xf86Xinput.h>
63 +#include "synaptics.h"
64 #include "synapticsstr.h"
65 #include "synaptics-properties.h"
67 diff --git a/src/ps2comm.c b/src/ps2comm.c
68 index ed2f751..74431c1 100644
73 #include <xorg-server.h>
75 +#include "synaptics.h"
76 #include "synapticsstr.h"
79 diff --git a/src/psmcomm.c b/src/psmcomm.c
80 index 4086aba..63c4536 100644
84 #include <sys/mouse.h>
87 +#include "synaptics.h"
89 #include "synapticsstr.h"
90 #include "ps2comm.h" /* ps2_print_ident() */
91 diff --git a/src/synaptics.c b/src/synaptics.c
92 index d5db457..92c57ae 100644
101 #include <xf86_OSproc.h>
102 #include <xf86Xinput.h>
103 #include <exevents.h>
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);
114 + * Allocate and initialize read-only memory for the SynapticsParameters data to hold
116 + * The function will allocate shared memory if priv->shm_config is TRUE.
119 +alloc_shm_data(InputInfoPtr pInfo)
122 + SynapticsPrivate *priv = pInfo->private;
125 + return TRUE; /* Already allocated */
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");
135 + if ((priv->synshm = (SynapticsSHM *) shmat(shmid, NULL, 0)) == NULL) {
136 + xf86IDrvMsg(pInfo, X_ERROR, "error shmat\n");
141 + priv->synshm = calloc(1, sizeof(SynapticsSHM));
150 + * Free SynapticsParameters data previously allocated by alloc_shm_data().
153 +free_shm_data(SynapticsPrivate * priv)
160 + if (priv->shm_config) {
161 + if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) != -1)
162 + shmctl(shmid, IPC_RMID, NULL);
165 + free(priv->synshm);
168 + priv->synshm = NULL;
172 calculate_edge_widths(SynapticsPrivate * priv, int *l, int *r, int *t, int *b)
174 @@ -579,6 +638,12 @@ set_default_parameters(InputInfoPtr pInfo)
175 int grab_event_device = 0;
178 + /* read the parameters */
180 + priv->synshm->version =
181 + (PACKAGE_VERSION_MAJOR * 10000 + PACKAGE_VERSION_MINOR * 100 +
182 + PACKAGE_VERSION_PATCHLEVEL);
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);
191 + /* install shared memory or normal memory for parameters */
192 + priv->shm_config = xf86SetBoolOption(pInfo->options, "SHMConfig", FALSE);
194 set_default_parameters(pInfo);
196 #ifndef NO_DRIVER_SCALING
197 CalculateScalingCoeffs(priv);
200 + if (!alloc_shm_data(pInfo))
201 + goto SetupProc_fail;
203 priv->comm.buffer = XisbNew(pInfo->fd, INPUT_BUFFER_SIZE);
205 @@ -929,6 +999,7 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
207 if (priv->comm.buffer)
208 XisbFree(priv->comm.buffer);
209 + free_shm_data(priv);
210 free(priv->proto_data);
213 @@ -1109,6 +1180,7 @@ DeviceClose(DeviceIntPtr dev)
214 RetValue = DeviceOff(dev);
215 TimerFree(priv->timer);
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)
223 priv->comm.hwState = SynapticsHwStateAlloc(priv);
225 + if (!alloc_shm_data(pInfo))
228 InitDeviceProperties(pInfo);
229 XIRegisterPropertyHandler(pInfo->dev, SetProperty, NULL, NULL);
231 @@ -1371,6 +1446,7 @@ DeviceInit(DeviceIntPtr dev)
235 + free_shm_data(priv);
236 free(priv->local_hw_state);
238 free(priv->open_slots);
239 @@ -3074,6 +3150,33 @@ reset_hw_state(struct SynapticsHwState *hw)
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.
247 +update_shm(const InputInfoPtr pInfo, const struct SynapticsHwState *hw)
250 + SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
251 + SynapticsSHM *shm = priv->synshm;
259 + shm->numFingers = hw->numFingers;
260 + shm->fingerWidth = hw->fingerWidth;
261 + shm->left = hw->left;
262 + shm->right = hw->right;
264 + shm->down = hw->down;
265 + for (i = 0; i < 8; i++)
266 + shm->multi[i] = hw->multi[i];
267 + shm->middle = hw->middle;
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;
277 + update_shm(pInfo, hw);
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);
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
288 diff --git a/src/synapticsstr.h b/src/synapticsstr.h
289 index 4bd32ac..023a7c1 100644
290 --- a/src/synapticsstr.h
291 +++ b/src/synapticsstr.h
293 #define _SYNAPTICSSTR_H_
295 #include "synproto.h"
296 +#include "synaptics.h"
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
304 + SynapticsSHM *synshm; /* Current parameter settings. Will point to
305 + shared memory if shm_config is true */
307 struct SynapticsProtocolOperations *proto_ops;
308 void *proto_data; /* protocol-specific data */
310 diff --git a/src/synproto.c b/src/synproto.c
311 index 91e20e6..409722e 100644
316 #include "synproto.h"
317 #include "synapticsstr.h"
318 +#include "synaptics.h"
321 HwStateAllocTouch(struct SynapticsHwState *hw, SynapticsPrivate * priv)
322 diff --git a/tools/synclient.c b/tools/synclient.c
323 index ac31a66..df1e6a7 100644
324 --- a/tools/synclient.c
325 +++ b/tools/synclient.c
328 #include <sys/types.h>
330 +#include <sys/shm.h>
331 #include <sys/time.h>
335 #include <X11/extensions/XI.h>
336 #include <X11/extensions/XInput.h>
337 #include "synaptics-properties.h"
338 +#include "synaptics.h"
341 #define XATOM_FLOAT "FLOAT"
342 @@ -192,6 +194,108 @@ parse_cmd(char *cmd, struct Parameter **par)
347 +is_equal(SynapticsSHM * s1, SynapticsSHM * s2)
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))
362 + for (i = 0; i < 8; i++)
363 + if (s1->multi[i] != s2->multi[i])
374 + gettimeofday(&tv, NULL);
375 + return tv.tv_sec + tv.tv_usec / 1000000.0;
379 +shm_monitor(SynapticsSHM * synshm, int delay)
383 + double t0 = get_time();
385 + memset(&old, 0, sizeof(SynapticsSHM));
386 + old.x = -1; /* Force first equality test to fail */
389 + SynapticsSHM cur = *synshm;
391 + if (!is_equal(&old, &cur)) {
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");
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],
410 + usleep(delay * 1000);
414 +/** Init and return SHM area or NULL on error */
415 +static SynapticsSHM *
418 + SynapticsSHM *synshm = NULL;
421 + if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) {
422 + if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1)
424 + "Can't access shared memory area. SHMConfig disabled?\n");
427 + "Incorrect size of shared memory area. Incompatible driver version?\n");
429 + else if ((synshm = (SynapticsSHM *) shmat(shmid, NULL, SHM_RDONLY)) == NULL)
436 +shm_process_commands(int do_monitor, int delay)
438 + SynapticsSHM *synshm = NULL;
440 + synshm = shm_init();
445 + shm_monitor(synshm, delay);
448 /** Init display connection or NULL on error */
451 @@ -469,7 +573,11 @@ dp_show_settings(Display * dpy, XDevice * dev)
455 - fprintf(stderr, "Usage: synclient [-h] [-l] [-V] [-?] [var1=value1 [var2=value2] ...]\n");
457 + "Usage: synclient [-m interval] [-h] [-l] [-V] [-?] [var1=value1 [var2=value2] ...]\n");
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[])
469 int dump_settings = 0;
470 + int do_monitor = 0;
474 @@ -491,8 +601,13 @@ main(int argc, char *argv[])
477 /* Parse command line parameters */
478 - while ((c = getopt(argc, argv, "lV?")) != -1) {
479 + while ((c = getopt(argc, argv, "m:lV?")) != -1) {
483 + if ((delay = atoi(optarg)) < 0)
489 @@ -506,9 +621,13 @@ main(int argc, char *argv[])
493 - if (!dump_settings && first_cmd == argc)
494 + if (!do_monitor && !dump_settings && first_cmd == argc)
497 + /* Connect to the shared memory area */
499 + shm_process_commands(do_monitor, delay);
502 if (!dpy || !(dev = dp_get_device(dpy)))