Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swipe to drag #96

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 65 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ This is a standard autoconf package. So:
make && make install

It is likely that you will need to change system-dependent paths such as the
xorg module directory. See `configure --help` for options.
xorg module directory. Otherwise mtrack may be not installed in xserver search
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional comment on the xorg module directory. However, I would like to keep distro specific packaging information out of the README. Please remove it.

path.
See `configure --help` for options.

To build deb package and install in system wide you will usually have to change
installation prefix to /usr like so:

./configure --prefix=/usr
dpkg-buildpackage

Configuration
-------------
Expand Down Expand Up @@ -108,7 +116,8 @@ Button emulation depends on this value being correct. Boolean value. Defaults
to true.

**ButtonMoveEmulate**
Whether or not to count the moving finger when emulating button clicks. Useful to disable if you use two hands on trackpad. Boolean value. Defaults to true.
Whether or not to count the moving finger when emulating button clicks.
Useful to disable if you use two hands on trackpad. Boolean value. Defaults to true.

**ButtonZonesEnable** -
Whether or not to enable button zones. If button zones are enabled then the
Expand Down Expand Up @@ -153,10 +162,13 @@ disables three-finger tapping. Defaults to 0.

**ClickTime** -
When tapping, how much time to hold down the emulated button. Integer value
representing milliseconds. Defaults to 50.
representing milliseconds. Not very usable because button release event will be
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrasing. "Not very usable" is subjective. It would be better to point out in what cases is it useful to change this value.

sent immediately after releasing any of fingers (touches).
Integer value representing miliseconds. Defaults to 50.

**MaxTapTime** -
The amount of time to wait for a tap to release before counting it as a move.
The amount of time to wait for incoming touches after first one before counting
it as emulated button click.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your new statement is less clear than the previous one. If you're going to rewrite it then it would be better to keep the old explanation or write one that is clearer. In both cases an example would be add much.

Integer value representing milliseconds. Defaults to 120.

**MaxTapMove** -
Expand All @@ -178,6 +190,17 @@ gestures. Integer value representing milliseconds. Defaults to 100.
For two finger scrolling. How far you must move your fingers before a button
click is triggered. Integer value. Defaults to 150.

**ScrollClickTime** -
For two finger scrolling. How long button triggered by scrolling
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar. "How long a button..." "...will hold the button..."

will be hold down. A value of 0 will hold button down till end of gesture.
Integer value representing milliseconds. Defaults to 20.

**ScrollSensitivity** -
For two finger scrolling. Sensitivity (movement speed) of pointer during two
finger scrolling. A value of 0 disables pointer movement during gesture.
Integer value expressed as parts per thousand of normal sensivity.
A value of 1000 results with normal movement speed. Defaults to 0.

**ScrollUpButton** -
For two finger scrolling. The button that is triggered by scrolling up. Integer
value. A value of 0 disables scrolling up. Defaults to 4.
Expand All @@ -198,6 +221,16 @@ Integer value. A value of 0 disables scrolling right. Defaults to 7.
For three finger swiping. How far you must move your fingers before a button
click is triggered. Integer value. Defaults to 700.

**SwipeClickTime** -
For three finger swiping. How long button triggered by swiping
will be hold down. Integer value representing milliseconds. Defaults to 300.

**SwipeSensitivity** -
For three finger scrolling. Sensitivity (movement speed) of pointer during three
finger scrolling. A value of 0 disables pointer movement during gesture.
Integer value expressed as parts per thousand of normal sensivity.
A value of 1000 results with normal movement speed. Defaults to 0.

**SwipeUpButton** -
For three finger swiping. The button that is triggered by swiping up. Integer
value. A value of 0 disables swiping up. Defaults to 8.
Expand All @@ -218,6 +251,16 @@ value. A value of 0 disables swiping right. Defaults to 11.
For four finger swiping. How far you must move your fingers before a button
click is triggered. Integer value. Defaults to 700.

**Swipe4ClickTime** -
For four finger swiping. How long button triggered by swiping
will be hold down. Integer value representing milliseconds. Defaults to 300.

**Swipe4Sensitivity** -
For four finger scrolling. Sensitivity (movement speed) of pointer during four
finger scrolling. A value of 0 disables pointer movement during gesture.
Integer value expressed as parts per thousand of normal sensivity.
A value of 1000 results with normal movement speed. Defaults to 0.

**Swipe4UpButton** -
For four finger swiping. The button that is triggered by swiping up. Integer
value. A value of 0 disables swiping up. Defaults to 8.
Expand Down Expand Up @@ -284,6 +327,24 @@ Whether or not to invert the X axis. Boolean value. Defaults to false.
**AxisYInvert**
Whether or not to invert the Y axis. Boolean value. Defaults to false.

Tips
-------------
##### Swipe to drag
To setup swipe to drag functionality you have to choose which swipe gesture (Scroll, Swipe, Swipe4)
will be used for dragging.
Example configuration for three finger drag:
```
Option "SwipeDistance" "1"
Option "SwipeLeftButton" "1"
Option "SwipeRightButton" "1"
Option "SwipeUpButton" "1"
Option "SwipeDownButton" "1"
Option "SwipeClickTime" "0"
Option "SwipeSensitivity" "1000"
```
This will enable draging with three fingers. Change sensitivity for faster/slower movements.
Scroll, and Swipe4 are also supported.

[1]: http://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt "Kernel Multitouch Protocol"
[2]: http://www.gnu.org/licenses/gpl-2.0.html "GNU General Public License, version 2"
[3]: http://bitmath.org/code/multitouch/ "xf86-input-multitouch website"
Expand Down
216 changes: 87 additions & 129 deletions driver/mprops.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ Atom atom_init_float(DeviceIntPtr dev, char* name, int nvalues, float* values, A
return atom;
}

static void init_swipe_props(DeviceIntPtr dev, struct MPropsSwipe* props_swipe,
struct MConfigSwipe* cfg_swipe, char const* settings_prop_name,
char const* buttons_prop_name){
int ivals[MAX_INT_VALUES];
ivals[0] = cfg_swipe->dist;
ivals[1] = cfg_swipe->hold;
ivals[2] = cfg_swipe->drag_sens;
props_swipe->settings = atom_init_integer(dev, (char*)settings_prop_name, 3, ivals, 32);

ivals[0] = cfg_swipe->up_btn;
ivals[1] = cfg_swipe->dn_btn;
ivals[2] = cfg_swipe->lt_btn;
ivals[3] = cfg_swipe->rt_btn;
props_swipe->buttons = atom_init_integer(dev, (char*)buttons_prop_name, 4, ivals, 8);
}

void mprops_init(struct MConfig* cfg, InputInfoPtr local) {
int ivals[MAX_INT_VALUES];
float fvals[MAX_FLOAT_VALUES];
Expand Down Expand Up @@ -142,32 +158,11 @@ void mprops_init(struct MConfig* cfg, InputInfoPtr local) {
ivals[1] = cfg->gesture_wait;
mprops.gesture_settings = atom_init_integer(local->dev, MTRACK_PROP_GESTURE_SETTINGS, 2, ivals, 16);

ivals[0] = cfg->scroll_dist;
mprops.scroll_dist = atom_init_integer(local->dev, MTRACK_PROP_SCROLL_DIST, 1, ivals, 32);

ivals[0] = cfg->scroll_up_btn;
ivals[1] = cfg->scroll_dn_btn;
ivals[2] = cfg->scroll_lt_btn;
ivals[3] = cfg->scroll_rt_btn;
mprops.scroll_buttons = atom_init_integer(local->dev, MTRACK_PROP_SCROLL_BUTTONS, 4, ivals, 8);
init_swipe_props(local->dev, &mprops.scroll, &cfg->scroll, MTRACK_PROP_SCROLL_SETTINGS, MTRACK_PROP_SCROLL_BUTTONS);

ivals[0] = cfg->swipe_dist;
mprops.swipe_dist = atom_init_integer(local->dev, MTRACK_PROP_SWIPE_DIST, 1, ivals, 32);
init_swipe_props(local->dev, &mprops.swipe3, &cfg->swipe3, MTRACK_PROP_SWIPE_SETTINGS, MTRACK_PROP_SWIPE_BUTTONS);

ivals[0] = cfg->swipe_up_btn;
ivals[1] = cfg->swipe_dn_btn;
ivals[2] = cfg->swipe_lt_btn;
ivals[3] = cfg->swipe_rt_btn;
mprops.swipe_buttons = atom_init_integer(local->dev, MTRACK_PROP_SWIPE_BUTTONS, 4, ivals, 8);

ivals[0] = cfg->swipe4_dist;
mprops.swipe4_dist = atom_init_integer(local->dev, MTRACK_PROP_SWIPE4_DIST, 1, ivals, 32);

ivals[0] = cfg->swipe4_up_btn;
ivals[1] = cfg->swipe4_dn_btn;
ivals[2] = cfg->swipe4_lt_btn;
ivals[3] = cfg->swipe4_rt_btn;
mprops.swipe4_buttons = atom_init_integer(local->dev, MTRACK_PROP_SWIPE4_BUTTONS, 4, ivals, 8);
init_swipe_props(local->dev, &mprops.swipe4, &cfg->swipe4, MTRACK_PROP_SWIPE4_SETTINGS, MTRACK_PROP_SWIPE4_BUTTONS);

ivals[0] = cfg->scale_dist;
mprops.scale_dist = atom_init_integer(local->dev, MTRACK_PROP_SCALE_DIST, 1, ivals, 32);
Expand All @@ -194,6 +189,63 @@ void mprops_init(struct MConfig* cfg, InputInfoPtr local) {
mprops.axis_invert = atom_init_integer(local->dev, MTRACK_PROP_AXIS_INVERT, 2, ivals, 8);
}

/* Return:
* 1 - property was recognized and handled with or without error, check error code for details
* 0 - property not recognized, don't trust returned error code - it's invalid
*/
static int set_swipe_properties(Atom property, BOOL checkonly, XIPropertyValuePtr prop,
struct MPropsSwipe* props_swipe,
struct MConfigSwipe* cfg_swipe, int* error_code){

uint8_t* ivals8;
uint16_t* ivals16;
uint32_t* ivals32;

*error_code = Success;

if (property == props_swipe->settings) {
if (prop->size != 3 || prop->format != 32 || prop->type != XA_INTEGER)
return *error_code = BadMatch, 1;

ivals32 = (uint32_t*)prop->data;
if (ivals32[0] < 1 || (int)(ivals32[1]) < 0)
return *error_code = BadMatch, 1;

if (!checkonly) {
cfg_swipe->dist = ivals32[0];
cfg_swipe->hold = ivals32[1];
cfg_swipe->drag_sens = ivals32[2];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set swipe settings: dist: %d hold: %d\n",
cfg_swipe->dist, cfg_swipe->hold);
#endif
}
}
else if (property == props_swipe->buttons) {
if (prop->size != 4 || prop->format != 8 || prop->type != XA_INTEGER)
return *error_code = BadMatch, 1;

ivals8 = (uint8_t*)prop->data;
if (!VALID_BUTTON(ivals8[0]) || !VALID_BUTTON(ivals8[1]) || !VALID_BUTTON(ivals8[2]) || !VALID_BUTTON(ivals8[3]))
return *error_code = BadMatch, 1;

if (!checkonly) {
cfg_swipe->up_btn = ivals8[0];
cfg_swipe->dn_btn = ivals8[1];
cfg_swipe->lt_btn = ivals8[2];
cfg_swipe->rt_btn = ivals8[3];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set swipe buttons to %d %d %d %d\n",
cfg_swipe->up_btn, cfg_swipe->dn_btn, cfg_swipe->lt_btn, cfg_swipe->rt_btn);
#endif
}
}
else{
return 0;
}
return 1;
}

int mprops_set_property(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, BOOL checkonly) {
InputInfoPtr local = dev->public.devicePrivate;
struct MConfig* cfg = &((struct MTouch*)local->private)->cfg;
Expand All @@ -203,6 +255,8 @@ int mprops_set_property(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop
uint32_t* ivals32;
float* fvals;

int error_code;

if (property == mprops.trackpad_disable) {
if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER)
return BadMatch;
Expand Down Expand Up @@ -237,7 +291,7 @@ int mprops_set_property(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop
}
}
else if (property == mprops.pressure) {
if (prop->size != 2 || prop->format != 8 || prop->type != XA_INTEGER)
if (prop->size != 2 || prop->format != 8 || prop->type != XA_INTEGER)
return BadMatch;

ivals8 = (uint8_t*)prop->data;
Expand All @@ -254,7 +308,7 @@ int mprops_set_property(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop
}
}
else if (property == mprops.button_settings) {
if (prop->size != 2 || prop->format != 8 || prop->type != XA_INTEGER)
if (prop->size != 2 || prop->format != 8 || prop->type != XA_INTEGER)
return BadMatch;

ivals8 = (uint8_t*)prop->data;
Expand Down Expand Up @@ -332,7 +386,7 @@ int mprops_set_property(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop
if (!VALID_BUTTON(ivals8[0]) || !VALID_BUTTON(ivals8[1]) || !VALID_BUTTON(ivals8[2]) || !VALID_BUTTON(ivals8[3]))
return BadMatch;

if (!checkonly) {
if (!checkonly) {
cfg->tap_1touch = ivals8[0];
cfg->tap_2touch = ivals8[1];
cfg->tap_3touch = ivals8[2];
Expand Down Expand Up @@ -427,110 +481,14 @@ int mprops_set_property(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop
#endif
}
}
else if (property == mprops.scroll_dist) {
if (prop->size != 1 || prop->format != 32 || prop->type != XA_INTEGER)
return BadMatch;

ivals32 = (uint32_t*)prop->data;
if (ivals32[0] < 1)
return BadMatch;

if (!checkonly) {
cfg->scroll_dist = ivals32[0];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set scroll distance to %d\n",
cfg->scroll_dist);
#endif
}
else if (set_swipe_properties(property, checkonly, prop, &mprops.scroll, &cfg->scroll, &error_code)) {
return error_code;
}
else if (property == mprops.scroll_buttons) {
if (prop->size != 4 || prop->format != 8 || prop->type != XA_INTEGER)
return BadMatch;

ivals8 = (uint8_t*)prop->data;
if (!VALID_BUTTON(ivals8[0]) || !VALID_BUTTON(ivals8[1]) || !VALID_BUTTON(ivals8[2]) || !VALID_BUTTON(ivals8[3]))
return BadMatch;

if (!checkonly) {
cfg->scroll_up_btn = ivals8[0];
cfg->scroll_dn_btn = ivals8[1];
cfg->scroll_lt_btn = ivals8[2];
cfg->scroll_rt_btn = ivals8[3];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set scroll buttons to %d %d %d %d\n",
cfg->scroll_up_btn, cfg->scroll_dn_btn, cfg->scroll_lt_btn, cfg->scroll_rt_btn);
#endif
}
}
else if (property == mprops.swipe_dist) {
if (prop->size != 1 || prop->format != 32 || prop->type != XA_INTEGER)
return BadMatch;

ivals32 = (uint32_t*)prop->data;
if (ivals32[0] < 1)
return BadMatch;

if (!checkonly) {
cfg->swipe_dist = ivals32[0];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set swipe distance to %d\n",
cfg->swipe_dist);
#endif
}
}
else if (property == mprops.swipe_buttons) {
if (prop->size != 4 || prop->format != 8 || prop->type != XA_INTEGER)
return BadMatch;

ivals8 = (uint8_t*)prop->data;
if (!VALID_BUTTON(ivals8[0]) || !VALID_BUTTON(ivals8[1]) || !VALID_BUTTON(ivals8[2]) || !VALID_BUTTON(ivals8[3]))
return BadMatch;

if (!checkonly) {
cfg->swipe_up_btn = ivals8[0];
cfg->swipe_dn_btn = ivals8[1];
cfg->swipe_lt_btn = ivals8[2];
cfg->swipe_rt_btn = ivals8[3];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set swipe buttons to %d %d %d %d\n",
cfg->swipe_up_btn, cfg->swipe_dn_btn, cfg->swipe_lt_btn, cfg->swipe_rt_btn);
#endif
}
else if (set_swipe_properties(property, checkonly, prop, &mprops.swipe3, &cfg->swipe3, &error_code)) {
return error_code;
}
else if (property == mprops.swipe4_dist) {
if (prop->size != 1 || prop->format != 32 || prop->type != XA_INTEGER)
return BadMatch;

ivals32 = (uint32_t*)prop->data;
if (ivals32[0] < 1)
return BadMatch;

if (!checkonly) {
cfg->swipe4_dist = ivals32[0];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set swipe4 distance to %d\n",
cfg->swipe4_dist);
#endif
}
}
else if (property == mprops.swipe4_buttons) {
if (prop->size != 4 || prop->format != 8 || prop->type != XA_INTEGER)
return BadMatch;

ivals8 = (uint8_t*)prop->data;
if (!VALID_BUTTON(ivals8[0]) || !VALID_BUTTON(ivals8[1]) || !VALID_BUTTON(ivals8[2]) || !VALID_BUTTON(ivals8[3]))
return BadMatch;

if (!checkonly) {
cfg->swipe4_up_btn = ivals8[0];
cfg->swipe4_dn_btn = ivals8[1];
cfg->swipe4_lt_btn = ivals8[2];
cfg->swipe4_rt_btn = ivals8[3];
#ifdef DEBUG_PROPS
xf86Msg(X_INFO, "mtrack: set swipe4 buttons to %d %d %d %d\n",
cfg->swipe4_up_btn, cfg->swipe4_dn_btn, cfg->swipe4_lt_btn, cfg->swipe4_rt_btn);
#endif
}
else if (set_swipe_properties(property, checkonly, prop, &mprops.swipe4, &cfg->swipe4, &error_code)) {
return error_code;
}
else if (property == mprops.scale_dist) {
if (prop->size != 1 || prop->format != 32 || prop->type != XA_INTEGER)
Expand Down
Loading