[PATCH 18/18] Make action strings configurable via synclient
Takashi Iwai
tiwai at suse.de
Mon Oct 11 00:52:20 PDT 2010
At Sat, 09 Oct 2010 17:40:52 +0200,
walter harms wrote:
>
>
>
> Takashi Iwai schrieb:
> > Signed-off-by: Takashi Iwai <tiwai at suse.de>
> > ---
> > include/synaptics-properties.h | 10 ++++++
> > src/keymap.c | 58 ++++++++++++++++++++++++++----------
> > src/properties.c | 63 ++++++++++++++++++++++++++++++++++++++++
> > src/synaptics.c | 60 ++++++++++++++++++-------------------
> > src/synapticsstr.h | 28 +++++++++---------
> > tools/synclient.c | 49 ++++++++++++++++++++++++++++--
> > 6 files changed, 203 insertions(+), 65 deletions(-)
> >
> > diff --git a/include/synaptics-properties.h b/include/synaptics-properties.h
> > index c31c53c..7267669 100644
> > --- a/include/synaptics-properties.h
> > +++ b/include/synaptics-properties.h
> > @@ -185,4 +185,14 @@
> > /* 32 bit, 2 values */
> > #define SYNAPTICS_PROP_THREEFINGER_DELTA "Synaptics Three-Finger Delta"
> >
> > +/* STR */
> > +#define SYNAPTICS_PROP_ZOOM_IN_ACTION "Synaptics Zoom-In Action"
> > +#define SYNAPTICS_PROP_ZOOM_OUT_ACTION "Synaptics Zoom-Out Action"
> > +
> > +/* STR */
> > +#define SYNAPTICS_PROP_3FINGER_LEFT_ACTION "Synaptics 3-Finger Left Action"
> > +#define SYNAPTICS_PROP_3FINGER_RIGHT_ACTION "Synaptics 3-Finger Right Action"
> > +#define SYNAPTICS_PROP_3FINGER_UP_ACTION "Synaptics 3-Finger Up Action"
> > +#define SYNAPTICS_PROP_3FINGER_DOWN_ACTION "Synaptics 3-Finger Down Action"
> > +
> > #endif /* _SYNAPTICS_PROPERTIES_H_ */
> > diff --git a/src/keymap.c b/src/keymap.c
> > index b1e7cc6..0c365a2 100644
> > --- a/src/keymap.c
> > +++ b/src/keymap.c
> > @@ -142,15 +142,30 @@ static int string_to_keysym(const char *str)
> > }
> >
> > int SynapticsParseActionStr(LocalDevicePtr local, const char *_str,
> > - int *action, int max_actions)
> > + SynapticsAction *action)
> > {
> > char *item;
> > char *str, *next;
> > - int num_actions = 0;
> >
> > - str = xstrdup(_str);
> > + if (action->str) {
> > + if (_str && !strcmp(action->str, _str))
> > + return TRUE;
> > + free(action->str);
> > + action->str = NULL;
> > + }
> > +
> > + action->num_actions = 0;
> > + if (!_str)
> > + return TRUE;
> > +
> > + str = strdup(_str);
> > if (!str)
> > - return 0;
> > + return FALSE;
> > + action->str = strdup(_str);
> > + if (!action->str) {
> > + free(str);
> > + return FALSE;
> > + }
> > for (item = str; item && *item; item = next) {
> > int button, keysym, keycode;
> >
> > @@ -160,7 +175,8 @@ int SynapticsParseActionStr(LocalDevicePtr local, const char *_str,
> > if (!*item)
> > continue;
> > if (sscanf(item, "Button%d", &button) == 1) {
> > - action[num_actions++] = (ACTION_BUTTON << 16) | button;
> > + action->action[action->num_actions++] =
> > + (ACTION_BUTTON << 16) | button;
> > } else {
> > keysym = string_to_keysym(item);
> > if (keysym == NoSymbol) {
> > @@ -175,15 +191,17 @@ int SynapticsParseActionStr(LocalDevicePtr local, const char *_str,
> > continue;
> > }
> > if (get_modifier(keysym))
> > - action[num_actions++] = (ACTION_KEYMOD << 16) | keycode;
> > + action->action[action->num_actions++] =
> > + (ACTION_KEYMOD << 16) | keycode;
> > else
> > - action[num_actions++] = (ACTION_KEY << 16) | keycode;
> > + action->action[action->num_actions++] =
> > + (ACTION_KEY << 16) | keycode;
> > }
> > - if (num_actions >= max_actions)
> > + if (action->num_actions >= MAX_ACTIONS)
> > break;
> > }
> > free(str);
> > - return num_actions;
> > + return TRUE;
> > }
> >
> > static void
> > @@ -196,13 +214,13 @@ Bool SynapticsInitKeyboard(DeviceIntPtr dev)
> > return InitKeyboardDeviceStruct(dev, NULL, NULL, synaptics_kbdctrl);
> > }
> >
> > -void SynapticsSendAction(LocalDevicePtr local, int num_actions, int *action)
> > +void SynapticsSendAction(LocalDevicePtr local, SynapticsAction *action)
> > {
> > int n;
> >
> > - for (n = 0; n < num_actions; n++) {
> > - int val = action[n] & 0xffff;
> > - switch ((action[n] >> 16) & 0xf) {
> > + for (n = 0; n < action->num_actions; n++) {
> > + int val = action->action[n] & 0xffff;
> > + switch ((action->action[n] >> 16) & 0xf) {
> > case ACTION_KEYMOD:
> > xf86PostKeyboardEvent(local->dev, val, TRUE);
> > break;
> > @@ -216,12 +234,20 @@ void SynapticsSendAction(LocalDevicePtr local, int num_actions, int *action)
> > break;
> > }
> > }
> > - for (n = num_actions - 1; n >= 0; n--) {
> > - int val = action[n] & 0xffff;
> > - switch ((action[n] >> 16) & 0xf) {
> > + for (n = action->num_actions - 1; n >= 0; n--) {
> > + int val = action->action[n] & 0xffff;
> > + switch ((action->action[n] >> 16) & 0xf) {
> > case ACTION_KEYMOD:
> > xf86PostKeyboardEvent(local->dev, val, FALSE);
> > break;
> > }
> > }
> > }
> > +
> > +void SynapticsFreeAction(SynapticsAction *action)
> > +{
> > + if (action && action->str) {
> > + free(action->str);
> > + action->str = NULL;
> > + }
> > +}
> > diff --git a/src/properties.c b/src/properties.c
> > index 9977b28..e694189 100644
> > --- a/src/properties.c
> > +++ b/src/properties.c
> > @@ -92,6 +92,12 @@ Atom prop_multi_touch_pinch = 0;
> > Atom prop_gesture_mode_notify = 0;
> > Atom prop_gesture_mode = 0;
> > Atom prop_threefinger = 0;
> > +Atom prop_zoom_in_action = 0;
> > +Atom prop_zoom_out_action = 0;
> > +Atom prop_3finger_left_action = 0;
> > +Atom prop_3finger_right_action = 0;
> > +Atom prop_3finger_up_action = 0;
> > +Atom prop_3finger_down_action = 0;
> >
> > static Atom
> > InitAtom(DeviceIntPtr dev, char *name, int format, int nvalues, int *values)
> > @@ -141,6 +147,38 @@ InitFloatAtom(DeviceIntPtr dev, char *name, int nvalues, float *values)
> > return atom;
> > }
> >
> > +static Atom
> > +InitStringAtom(DeviceIntPtr dev, char *name, char *val)
> > +{
> > + Atom atom;
> > +
> > + if (!val)
> > + val = "";
> > + atom = MakeAtom(name, strlen(name), TRUE);
> > + XIChangeDeviceProperty(dev, atom, XA_STRING, 8, PropModeReplace,
> > + strlen(val), (unsigned char *)val, FALSE);
> > + XISetDevicePropertyDeletable(dev, atom, FALSE);
> > + return atom;
> > +}
> > +
> > +static int
> > +SetActionStr(LocalDevicePtr local, XIPropertyValuePtr prop,
> > + SynapticsAction *action)
> > +{
> > + if (prop->format != 8 || prop->type != XA_STRING)
> > + return BadMatch;
> > + if (prop->data && prop->size > 0) {
> > + char *str = calloc(1, prop->size + 1);
> > + if (!str)
> > + return BadAlloc;
> > + memcpy(str, prop->data, prop->size);
> > + SynapticsParseActionStr(local, str, action);
> > + free(str);
> > + } else
> > + SynapticsParseActionStr(local, NULL, action);
> > + return Success;
> > +}
>
> i found this more easy to understand:
>
> {
> char *str=NULL;
> if (prop->format != 8 || prop->type != XA_STRING)
> return BadMatch;
>
> if (prop->data && prop->size > 0) {
> char *str = calloc(1, prop->size + 1);
> if (!str)
> return BadAlloc;
> memcpy(str, prop->data, prop->size);
> }
>
> SynapticsParseActionStr(local, NULL, action);
> free(str);
> return Success;
> }
Two corrections needed:
> char *str = calloc(1, prop->size + 1);
The variable definition should be removed, otherwise this is local in
the scope.
> SynapticsParseActionStr(local, NULL, action);
str must be passed instead of NULL.
Takashi
More information about the xorg-devel
mailing list