Between the parsing code seperating the two halves of set/unset and the code being confusing in general, I've rewritten this to hopefully make its operation a little clearer for the next person.
Signed-off-by: Jason Gerecke <killert...@gmail.com> --- tools/xsetwacom.c | 108 ++++++++++++++++++++++++++++++++-------------------- 1 files changed, 66 insertions(+), 42 deletions(-) diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c index 70331b5..9f88e6d 100644 --- a/tools/xsetwacom.c +++ b/tools/xsetwacom.c @@ -1116,6 +1116,24 @@ static int convert_wheel_prop(Display *dpy, XDevice *dev, Atom btnact_prop) } +/** + * Maps sub-properties (e.g. the 3rd button in WACOM_PROP_BUTTON_ACTIONS) + * to actions. This function leverages the several available parsing + * functions to convert plain-text descriptions into a list of actions + * the driver can understand. + * + * Once we have a list of actions, we can store it in the appropriate + * child property. If none exists, we must first create one and update + * the parent list. If we want no action to occur, we can delete the + * child property and have the parent point to '0' instead. + * + * @param dpy X display we want to query + * @param dev X device we want to modify + * @param btnact_prop Parent property + * @param offset Offset into the parent's list of child properties + * @param argc Number of command line arguments we've been passed + * @param argv Command line arguments we need to parse + */ static void special_map_property(Display *dpy, XDevice *dev, Atom btnact_prop, int offset, int argc, char **argv) { unsigned long *data, *btnact_data; @@ -1126,43 +1144,6 @@ static void special_map_property(Display *dpy, XDevice *dev, Atom btnact_prop, i int nwords = 0; char **words = NULL; - XGetDeviceProperty(dpy, dev, btnact_prop, 0, 100, False, - AnyPropertyType, &type, &format, &btnact_nitems, - &bytes_after, (unsigned char**)&btnact_data); - - if (offset > btnact_nitems) - return; - - /* Prop is currently 8 bit integer, i.e. plain button - * mappings. Convert to 32 bit Atom actions first. - */ - if (format == 8 && type == XA_INTEGER) - { - if (convert_wheel_prop(dpy, dev, btnact_prop)) - return; - - XGetDeviceProperty(dpy, dev, btnact_prop, 0, 100, False, - AnyPropertyType, &type, &format, - &btnact_nitems, &bytes_after, - (unsigned char**)&btnact_data); - } - - if (argc == 0) /* unset property */ - { - prop = btnact_data[offset]; - btnact_data[offset] = 0; - } else if (btnact_data[offset]) - /* some atom already assigned, modify that */ - prop = btnact_data[offset]; - else - { - char buff[64]; - sprintf(buff, "Wacom button action %d", (offset + 1)); - prop = XInternAtom(dpy, buff, False); - - btnact_data[offset] = prop; - } - data = calloc(sizeof(long), 256); nitems = 0; @@ -1197,18 +1178,61 @@ static void special_map_property(Display *dpy, XDevice *dev, Atom btnact_prop, i } } + /* obtain the button actions Atom */ + XGetDeviceProperty(dpy, dev, btnact_prop, 0, 100, False, + AnyPropertyType, &type, &format, &btnact_nitems, + &bytes_after, (unsigned char**)&btnact_data); + + if (offset > btnact_nitems) + return; + + if (format == 8 && type == XA_INTEGER) + { + /* Prop is currently 8 bit integer, i.e. plain button + * mappings. Convert to 32 bit Atom actions first. + */ + if (convert_wheel_prop(dpy, dev, btnact_prop)) + return; + + XGetDeviceProperty(dpy, dev, btnact_prop, 0, 100, False, + AnyPropertyType, &type, &format, + &btnact_nitems, &bytes_after, + (unsigned char**)&btnact_data); + } + + /* set or unset the property */ + prop = btnact_data[offset]; if (nitems > 0) + { //Setting a new or existing property + if (!prop) + { + char buff[64]; + sprintf(buff, "Wacom button action %d", (offset + 1)); + prop = XInternAtom(dpy, buff, False); + btnact_data[offset] = prop; + + XChangeDeviceProperty(dpy, dev, btnact_prop, XA_ATOM, 32, + PropModeReplace, + (unsigned char*)btnact_data, + btnact_nitems); + } + + XChangeDeviceProperty(dpy, dev, prop, XA_INTEGER, 32, PropModeReplace, (unsigned char*)data, nitems); + } + else if (prop) + { //Unsetting a property that exists + btnact_data[offset] = 0; - XChangeDeviceProperty(dpy, dev, btnact_prop, XA_ATOM, 32, - PropModeReplace, - (unsigned char*)btnact_data, - btnact_nitems); + XChangeDeviceProperty(dpy, dev, btnact_prop, XA_ATOM, 32, + PropModeReplace, + (unsigned char*)btnact_data, + btnact_nitems); - if (argc == 0 && prop) XDeleteDeviceProperty(dpy, dev, prop); + } XFlush(dpy); } -- 1.7.4.1 ------------------------------------------------------------------------------ Enable your software for Intel(R) Active Management Technology to meet the growing manageability and security demands of your customers. Businesses are taking advantage of Intel(R) vPro (TM) technology - will your software be a part of the solution? Download the Intel(R) Manageability Checker today! http://p.sf.net/sfu/intel-dev2devmar _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel