synclient.c revision b85037db
1/* 2 * Copyright © 2002-2005,2007 Peter Osterlund 3 * 4 * Permission to use, copy, modify, distribute, and sell this software 5 * and its documentation for any purpose is hereby granted without 6 * fee, provided that the above copyright notice appear in all copies 7 * and that both that copyright notice and this permission notice 8 * appear in supporting documentation, and that the name of Red Hat 9 * not be used in advertising or publicity pertaining to distribution 10 * of the software without specific, written prior permission. Red 11 * Hat makes no representations about the suitability of this software 12 * for any purpose. It is provided "as is" without express or implied 13 * warranty. 14 * 15 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN 17 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 * 23 * Authors: 24 * Peter Osterlund (petero2@telia.com) 25 */ 26 27#ifdef HAVE_CONFIG_H 28#include "config.h" 29#endif 30 31#include <stdio.h> 32#include <stdlib.h> 33#include <sys/types.h> 34#include <sys/ipc.h> 35#include <sys/shm.h> 36#include <sys/time.h> 37#include <unistd.h> 38#include <string.h> 39#include <stddef.h> 40#include <math.h> 41 42#include <X11/Xdefs.h> 43#include <X11/Xatom.h> 44#include <X11/extensions/XI.h> 45#include <X11/extensions/XInput.h> 46#include "synaptics.h" 47#include "synaptics-properties.h" 48#include <xserver-properties.h> 49 50#ifndef XATOM_FLOAT 51#define XATOM_FLOAT "FLOAT" 52#endif 53 54union flong { /* Xlibs 64-bit property handling madness */ 55 long l; 56 float f; 57}; 58 59 60enum ParaType { 61 PT_INT, 62 PT_BOOL, 63 PT_DOUBLE 64}; 65 66struct Parameter { 67 char *name; /* Name of parameter */ 68 enum ParaType type; /* Type of parameter */ 69 double min_val; /* Minimum allowed value */ 70 double max_val; /* Maximum allowed value */ 71 char *prop_name; /* Property name */ 72 int prop_format; /* Property format (0 for floats) */ 73 int prop_offset; /* Offset inside property */ 74}; 75 76static struct Parameter params[] = { 77 {"LeftEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 0}, 78 {"RightEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 1}, 79 {"TopEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 2}, 80 {"BottomEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 3}, 81 {"FingerLow", PT_INT, 0, 255, SYNAPTICS_PROP_FINGER, 32, 0}, 82 {"FingerHigh", PT_INT, 0, 255, SYNAPTICS_PROP_FINGER, 32, 1}, 83 {"FingerPress", PT_INT, 0, 256, SYNAPTICS_PROP_FINGER, 32, 2}, 84 {"MaxTapTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_TIME, 32, 0}, 85 {"MaxTapMove", PT_INT, 0, 2000, SYNAPTICS_PROP_TAP_MOVE, 32, 0}, 86 {"MaxDoubleTapTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS,32, 1}, 87 {"SingleTapTimeout", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS,32, 0}, 88 {"ClickTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS,32, 2}, 89 {"FastTaps", PT_BOOL, 0, 1, SYNAPTICS_PROP_TAP_FAST, 8, 0}, 90 {"EmulateMidButtonTime", PT_INT, 0, 1000, SYNAPTICS_PROP_MIDDLE_TIMEOUT,32, 0}, 91 {"EmulateTwoFingerMinZ", PT_INT, 0, 1000, SYNAPTICS_PROP_TWOFINGER_PRESSURE, 32, 0}, 92 {"EmulateTwoFingerMinW", PT_INT, 0, 15, SYNAPTICS_PROP_TWOFINGER_WIDTH, 32, 0}, 93 {"VertScrollDelta", PT_INT, 0, 1000, SYNAPTICS_PROP_SCROLL_DISTANCE, 32, 0}, 94 {"HorizScrollDelta", PT_INT, 0, 1000, SYNAPTICS_PROP_SCROLL_DISTANCE, 32, 1}, 95 {"VertEdgeScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 0}, 96 {"HorizEdgeScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 1}, 97 {"CornerCoasting", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 2}, 98 {"VertTwoFingerScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_TWOFINGER, 8, 0}, 99 {"HorizTwoFingerScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_TWOFINGER, 8, 1}, 100 {"MinSpeed", PT_DOUBLE, 0, 255.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 0}, 101 {"MaxSpeed", PT_DOUBLE, 0, 255.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 1}, 102 {"AccelFactor", PT_DOUBLE, 0, 1.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 2}, 103 {"TrackstickSpeed", PT_DOUBLE, 0, 200.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 3}, 104 {"EdgeMotionMinZ", PT_INT, 1, 255, SYNAPTICS_PROP_EDGEMOTION_PRESSURE, 32, 0}, 105 {"EdgeMotionMaxZ", PT_INT, 1, 255, SYNAPTICS_PROP_EDGEMOTION_PRESSURE, 32, 1}, 106 {"EdgeMotionMinSpeed", PT_INT, 0, 1000, SYNAPTICS_PROP_EDGEMOTION_SPEED, 32, 0}, 107 {"EdgeMotionMaxSpeed", PT_INT, 0, 1000, SYNAPTICS_PROP_EDGEMOTION_SPEED, 32, 1}, 108 {"EdgeMotionUseAlways", PT_BOOL, 0, 1, SYNAPTICS_PROP_EDGEMOTION, 8, 0}, 109 {"UpDownScrolling", PT_BOOL, 0, 1, SYNAPTICS_PROP_BUTTONSCROLLING, 8, 0}, 110 {"LeftRightScrolling", PT_BOOL, 0, 1, SYNAPTICS_PROP_BUTTONSCROLLING, 8, 1}, 111 {"UpDownScrollRepeat", PT_BOOL, 0, 1, SYNAPTICS_PROP_BUTTONSCROLLING_REPEAT, 8, 0}, 112 {"LeftRightScrollRepeat", PT_BOOL, 0, 1, SYNAPTICS_PROP_BUTTONSCROLLING_REPEAT, 8, 1}, 113 {"ScrollButtonRepeat", PT_INT, SBR_MIN , SBR_MAX, SYNAPTICS_PROP_BUTTONSCROLLING_TIME, 32, 0}, 114 {"TouchpadOff", PT_INT, 0, 2, SYNAPTICS_PROP_OFF, 8, 0}, 115 {"LockedDrags", PT_BOOL, 0, 1, SYNAPTICS_PROP_LOCKED_DRAGS, 8, 0}, 116 {"LockedDragTimeout", PT_INT, 0, 30000, SYNAPTICS_PROP_LOCKED_DRAGS_TIMEOUT, 32, 0}, 117 {"RTCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 0}, 118 {"RBCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 1}, 119 {"LTCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 2}, 120 {"LBCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 3}, 121 {"TapButton1", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 4}, 122 {"TapButton2", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 5}, 123 {"TapButton3", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 6}, 124 {"ClickFinger1", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 0}, 125 {"ClickFinger2", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 1}, 126 {"ClickFinger3", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 2}, 127 {"CircularScrolling", PT_BOOL, 0, 1, SYNAPTICS_PROP_CIRCULAR_SCROLLING, 8, 0}, 128 {"CircScrollDelta", PT_DOUBLE, .01, 3, SYNAPTICS_PROP_CIRCULAR_SCROLLING_DIST, 0 /* float */, 0}, 129 {"CircScrollTrigger", PT_INT, 0, 8, SYNAPTICS_PROP_CIRCULAR_SCROLLING_TRIGGER, 8, 0}, 130 {"CircularPad", PT_BOOL, 0, 1, SYNAPTICS_PROP_CIRCULAR_PAD, 8, 0}, 131 {"PalmDetect", PT_BOOL, 0, 1, SYNAPTICS_PROP_PALM_DETECT, 8, 0}, 132 {"PalmMinWidth", PT_INT, 0, 15, SYNAPTICS_PROP_PALM_DIMENSIONS, 32, 0}, 133 {"PalmMinZ", PT_INT, 0, 255, SYNAPTICS_PROP_PALM_DIMENSIONS, 32, 1}, 134 {"CoastingSpeed", PT_DOUBLE, 0, 20, SYNAPTICS_PROP_COASTING_SPEED, 0 /* float*/, 0}, 135 {"CoastingFriction", PT_DOUBLE, 0, 255, SYNAPTICS_PROP_COASTING_SPEED, 0 /* float*/, 1}, 136 {"PressureMotionMinZ", PT_INT, 1, 255, SYNAPTICS_PROP_PRESSURE_MOTION, 32, 0}, 137 {"PressureMotionMaxZ", PT_INT, 1, 255, SYNAPTICS_PROP_PRESSURE_MOTION, 32, 1}, 138 {"PressureMotionMinFactor", PT_DOUBLE, 0, 10.0,SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 0 /*float*/, 0}, 139 {"PressureMotionMaxFactor", PT_DOUBLE, 0, 10.0,SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 0 /*float*/, 1}, 140 {"GrabEventDevice", PT_BOOL, 0, 1, SYNAPTICS_PROP_GRAB, 8, 0}, 141 {"TapAndDragGesture", PT_BOOL, 0, 1, SYNAPTICS_PROP_GESTURES, 8, 0}, 142 {"AreaLeftEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 0}, 143 {"AreaRightEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 1}, 144 {"AreaTopEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 2}, 145 {"AreaBottomEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 3}, 146 { NULL, 0, 0, 0, 0 } 147}; 148 149static double 150parse_cmd(char* cmd, struct Parameter** par) 151{ 152 char *eqp = index(cmd, '='); 153 *par = NULL; 154 155 if (eqp) { 156 int j; 157 int found = 0; 158 *eqp = 0; 159 for (j = 0; params[j].name; j++) { 160 if (strcasecmp(cmd, params[j].name) == 0) { 161 found = 1; 162 break; 163 } 164 } 165 if (found) { 166 double val = atof(&eqp[1]); 167 *par = ¶ms[j]; 168 169 if (val < (*par)->min_val) 170 val = (*par)->min_val; 171 if (val > (*par)->max_val) 172 val = (*par)->max_val; 173 174 return val; 175 } else { 176 printf("Unknown parameter %s\n", cmd); 177 } 178 } else { 179 printf("Invalid command: %s\n", cmd); 180 } 181 182 return 0; 183} 184 185static int 186is_equal(SynapticsSHM *s1, SynapticsSHM *s2) 187{ 188 int i; 189 190 if ((s1->x != s2->x) || 191 (s1->y != s2->y) || 192 (s1->z != s2->z) || 193 (s1->numFingers != s2->numFingers) || 194 (s1->fingerWidth != s2->fingerWidth) || 195 (s1->left != s2->left) || 196 (s1->right != s2->right) || 197 (s1->up != s2->up) || 198 (s1->down != s2->down) || 199 (s1->middle != s2->middle)) 200 return 0; 201 202 for (i = 0; i < 8; i++) 203 if (s1->multi[i] != s2->multi[i]) 204 return 0; 205 206 return 1; 207} 208 209static double 210get_time(void) 211{ 212 struct timeval tv; 213 gettimeofday(&tv, NULL); 214 return tv.tv_sec + tv.tv_usec / 1000000.0; 215} 216 217static void 218shm_monitor(SynapticsSHM *synshm, int delay) 219{ 220 int header = 0; 221 SynapticsSHM old; 222 double t0 = get_time(); 223 224 memset(&old, 0, sizeof(SynapticsSHM)); 225 old.x = -1; /* Force first equality test to fail */ 226 227 while (1) { 228 SynapticsSHM cur = *synshm; 229 if (!is_equal(&old, &cur)) { 230 if (!header) { 231 printf("%8s %4s %4s %3s %s %2s %2s %s %s %s %s %8s " 232 "%2s %2s %2s %3s %3s\n", 233 "time", "x", "y", "z", "f", "w", "l", "r", "u", "d", "m", 234 "multi", "gl", "gm", "gr", "gdx", "gdy"); 235 header = 20; 236 } 237 header--; 238 printf("%8.3f %4d %4d %3d %d %2d %2d %d %d %d %d %d%d%d%d%d%d%d%d\n", 239 get_time() - t0, 240 cur.x, cur.y, cur.z, cur.numFingers, cur.fingerWidth, 241 cur.left, cur.right, cur.up, cur.down, cur.middle, 242 cur.multi[0], cur.multi[1], cur.multi[2], cur.multi[3], 243 cur.multi[4], cur.multi[5], cur.multi[6], cur.multi[7]); 244 fflush(stdout); 245 old = cur; 246 } 247 usleep(delay * 1000); 248 } 249} 250 251/** Init and return SHM area or NULL on error */ 252static SynapticsSHM* 253shm_init() 254{ 255 SynapticsSHM *synshm = NULL; 256 int shmid = 0; 257 258 if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) { 259 if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1) 260 fprintf(stderr, "Can't access shared memory area. SHMConfig disabled?\n"); 261 else 262 fprintf(stderr, "Incorrect size of shared memory area. Incompatible driver version?\n"); 263 } else if ((synshm = (SynapticsSHM*) shmat(shmid, NULL, SHM_RDONLY)) == NULL) 264 perror("shmat"); 265 266 return synshm; 267} 268 269static void 270shm_process_commands(int do_monitor, int delay) 271{ 272 SynapticsSHM *synshm = NULL; 273 274 synshm = shm_init(); 275 if (!synshm) 276 return; 277 278 if (do_monitor) 279 shm_monitor(synshm, delay); 280} 281 282/** Init display connection or NULL on error */ 283static Display* 284dp_init() 285{ 286 Display *dpy = NULL; 287 XExtensionVersion *v = NULL; 288 Atom touchpad_type = 0; 289 Atom synaptics_property = 0; 290 int error = 0; 291 292 dpy = XOpenDisplay(NULL); 293 if (!dpy) { 294 fprintf(stderr, "Failed to connect to X Server.\n"); 295 error = 1; 296 goto unwind; 297 } 298 299 v = XGetExtensionVersion(dpy, INAME); 300 if (!v->present || 301 (v->major_version * 1000 + v->minor_version) < (XI_Add_DeviceProperties_Major * 1000 302 + XI_Add_DeviceProperties_Minor)) { 303 fprintf(stderr, "X server supports X Input %d.%d. I need %d.%d.\n", 304 v->major_version, v->minor_version, 305 XI_Add_DeviceProperties_Major, 306 XI_Add_DeviceProperties_Minor); 307 error = 1; 308 goto unwind; 309 } 310 311 /* We know synaptics sets XI_TOUCHPAD for all the devices. */ 312 touchpad_type = XInternAtom(dpy, XI_TOUCHPAD, True); 313 if (!touchpad_type) { 314 fprintf(stderr, "XI_TOUCHPAD not initialised.\n"); 315 error = 1; 316 goto unwind; 317 } 318 319 synaptics_property = XInternAtom(dpy, SYNAPTICS_PROP_EDGES, True); 320 if (!synaptics_property) { 321 fprintf(stderr, "Couldn't find synaptics properties. No synaptics " 322 "driver loaded?\n"); 323 error = 1; 324 goto unwind; 325 } 326 327unwind: 328 XFree(v); 329 if (error && dpy) 330 { 331 XCloseDisplay(dpy); 332 dpy = NULL; 333 } 334 return dpy; 335} 336 337static XDevice * 338dp_get_device(Display *dpy) 339{ 340 XDevice* dev = NULL; 341 XDeviceInfo *info = NULL; 342 int ndevices = 0; 343 Atom touchpad_type = 0; 344 Atom synaptics_property = 0; 345 Atom *properties = NULL; 346 int nprops = 0; 347 int error = 0; 348 349 touchpad_type = XInternAtom(dpy, XI_TOUCHPAD, True); 350 synaptics_property = XInternAtom(dpy, SYNAPTICS_PROP_EDGES, True); 351 info = XListInputDevices(dpy, &ndevices); 352 353 while(ndevices--) { 354 if (info[ndevices].type == touchpad_type) { 355 dev = XOpenDevice(dpy, info[ndevices].id); 356 if (!dev) { 357 fprintf(stderr, "Failed to open device '%s'.\n", 358 info[ndevices].name); 359 error = 1; 360 goto unwind; 361 } 362 363 properties = XListDeviceProperties(dpy, dev, &nprops); 364 if (!properties || !nprops) 365 { 366 fprintf(stderr, "No properties on device '%s'.\n", 367 info[ndevices].name); 368 error = 1; 369 goto unwind; 370 } 371 372 while(nprops--) 373 { 374 if (properties[nprops] == synaptics_property) 375 break; 376 } 377 if (!nprops) 378 { 379 fprintf(stderr, "No synaptics properties on device '%s'.\n", 380 info[ndevices].name); 381 error = 1; 382 goto unwind; 383 } 384 385 break; /* Yay, device is suitable */ 386 } 387 } 388 389unwind: 390 XFree(properties); 391 XFreeDeviceList(info); 392 if (!dev) 393 fprintf(stderr, "Unable to find a synaptics device.\n"); 394 else if (error && dev) 395 { 396 XCloseDevice(dpy, dev); 397 dev = NULL; 398 } 399 return dev; 400} 401 402static void 403dp_set_variables(Display *dpy, XDevice* dev, int argc, char *argv[], int first_cmd) 404{ 405 int i; 406 double val; 407 struct Parameter *par; 408 Atom prop, type, float_type; 409 int format; 410 unsigned char* data; 411 unsigned long nitems, bytes_after; 412 413 union flong *f; 414 long *n; 415 char *b; 416 417 float_type = XInternAtom(dpy, XATOM_FLOAT, True); 418 if (!float_type) 419 fprintf(stderr, "Float properties not available.\n"); 420 421 for (i = first_cmd; i < argc; i++) { 422 val = parse_cmd(argv[i], &par); 423 if (!par) 424 continue; 425 426 prop = XInternAtom(dpy, par->prop_name, True); 427 if (!prop) 428 { 429 fprintf(stderr, "Property for '%s' not available. Skipping.\n", 430 par->name); 431 continue; 432 433 } 434 435 XGetDeviceProperty(dpy, dev, prop, 0, 1000, False, AnyPropertyType, 436 &type, &format, &nitems, &bytes_after, &data); 437 438 switch(par->prop_format) 439 { 440 case 8: 441 if (format != par->prop_format || type != XA_INTEGER) { 442 fprintf(stderr, " %-23s = format mismatch (%d)\n", 443 par->name, format); 444 break; 445 } 446 b = (char*)data; 447 b[par->prop_offset] = rint(val); 448 break; 449 case 32: 450 if (format != par->prop_format || type != XA_INTEGER) { 451 fprintf(stderr, " %-23s = format mismatch (%d)\n", 452 par->name, format); 453 break; 454 } 455 n = (long*)data; 456 n[par->prop_offset] = rint(val); 457 break; 458 case 0: /* float */ 459 if (!float_type) 460 continue; 461 if (format != 32 || type != float_type) { 462 fprintf(stderr, " %-23s = format mismatch (%d)\n", 463 par->name, format); 464 break; 465 } 466 f = (union flong*)data; 467 f[par->prop_offset].f = val; 468 break; 469 } 470 471 XChangeDeviceProperty(dpy, dev, prop, type, format, 472 PropModeReplace, data, nitems); 473 XFlush(dpy); 474 } 475} 476 477/* FIXME: horribly inefficient. */ 478static void 479dp_show_settings(Display *dpy, XDevice *dev) 480{ 481 int j; 482 Atom a, type, float_type; 483 int format; 484 unsigned long nitems, bytes_after; 485 unsigned char* data; 486 int len; 487 488 union flong *f; 489 long *i; 490 char *b; 491 492 float_type = XInternAtom(dpy, XATOM_FLOAT, True); 493 if (!float_type) 494 fprintf(stderr, "Float properties not available.\n"); 495 496 printf("Parameter settings:\n"); 497 for (j = 0; params[j].name; j++) { 498 struct Parameter *par = ¶ms[j]; 499 a = XInternAtom(dpy, par->prop_name, True); 500 if (!a) 501 continue; 502 503 len = 1 + ((par->prop_offset * (par->prop_format ? par->prop_format : 32)/8))/4; 504 505 XGetDeviceProperty(dpy, dev, a, 0, len, False, 506 AnyPropertyType, &type, &format, 507 &nitems, &bytes_after, &data); 508 509 switch(par->prop_format) { 510 case 8: 511 if (format != par->prop_format || type != XA_INTEGER) { 512 fprintf(stderr, " %-23s = format mismatch (%d)\n", 513 par->name, format); 514 break; 515 } 516 517 b = (char*)data; 518 printf(" %-23s = %d\n", par->name, b[par->prop_offset]); 519 break; 520 case 32: 521 if (format != par->prop_format || type != XA_INTEGER) { 522 fprintf(stderr, " %-23s = format mismatch (%d)\n", 523 par->name, format); 524 break; 525 } 526 527 i = (long*)data; 528 printf(" %-23s = %ld\n", par->name, i[par->prop_offset]); 529 break; 530 case 0: /* Float */ 531 if (!float_type) 532 continue; 533 if (format != 32 || type != float_type) { 534 fprintf(stderr, " %-23s = format mismatch (%d)\n", 535 par->name, format); 536 break; 537 } 538 539 f = (union flong*)data; 540 printf(" %-23s = %g\n", par->name, f[par->prop_offset].f); 541 break; 542 } 543 544 XFree(data); 545 } 546} 547 548static void 549usage(void) 550{ 551 fprintf(stderr, "Usage: synclient [-s] [-m interval] [-h] [-l] [-V] [-?] [var1=value1 [var2=value2] ...]\n"); 552 fprintf(stderr, " -m monitor changes to the touchpad state (implies -s)\n" 553 " interval specifies how often (in ms) to poll the touchpad state\n"); 554 fprintf(stderr, " -l List current user settings\n"); 555 fprintf(stderr, " -V Print synclient version string and exit\n"); 556 fprintf(stderr, " -? Show this help message\n"); 557 fprintf(stderr, " var=value Set user parameter 'var' to 'value'.\n"); 558 exit(1); 559} 560 561int 562main(int argc, char *argv[]) 563{ 564 int c; 565 int delay = -1; 566 int do_monitor = 0; 567 int dump_settings = 0; 568 int first_cmd; 569 570 Display *dpy; 571 XDevice *dev; 572 573 if (argc == 1) 574 dump_settings = 1; 575 576 /* Parse command line parameters */ 577 while ((c = getopt(argc, argv, "sm:hlV")) != -1) { 578 switch (c) { 579 case 'm': 580 do_monitor = 1; 581 if ((delay = atoi(optarg)) < 0) 582 usage(); 583 break; 584 case 'l': 585 dump_settings = 1; 586 break; 587 case 'V': 588 printf("%s\n", VERSION); 589 exit(0); 590 default: 591 usage(); 592 } 593 } 594 595 first_cmd = optind; 596 if (!do_monitor && !dump_settings && first_cmd == argc) 597 usage(); 598 599 /* Connect to the shared memory area */ 600 if (do_monitor) 601 shm_process_commands(do_monitor, delay); 602 603 dpy = dp_init(); 604 if (!dpy || !(dev = dp_get_device(dpy))) 605 return 1; 606 607 dp_set_variables(dpy, dev, argc, argv, first_cmd); 608 if (dump_settings) 609 dp_show_settings(dpy, dev); 610 611 XCloseDevice(dpy, dev); 612 XCloseDisplay(dpy); 613 614 return 0; 615} 616