diff options
Diffstat (limited to 'mtdev/caps.c')
| -rw-r--r-- | mtdev/caps.c | 104 |
1 files changed, 49 insertions, 55 deletions
diff --git a/mtdev/caps.c b/mtdev/caps.c index 51e7f5b..069816e 100644 --- a/mtdev/caps.c +++ b/mtdev/caps.c | |||
| @@ -19,17 +19,17 @@ | |||
| 19 | * | 19 | * |
| 20 | **************************************************************************/ | 20 | **************************************************************************/ |
| 21 | 21 | ||
| 22 | #include <mtdev-caps.h> | 22 | #include "mtdev-caps.h" |
| 23 | #include "mtbit.h" | ||
| 23 | 24 | ||
| 24 | #define SETABS(c, x, map, key, fd) \ | 25 | #define SETABS(c, x, map, key, fd) \ |
| 25 | (c->has_##x = getbit(map, key) && getabs(&c->abs_##x, key, fd)) | 26 | (c->has_##x = getbit(map, key) && getabs(&c->x, key, fd)) |
| 26 | 27 | ||
| 27 | #define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") | 28 | #define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") |
| 28 | 29 | ||
| 29 | #define CLICK_AREA(c) ((c->has_ibt ? 0.20 : 0.00) * get_cap_ysize(c)) | ||
| 30 | |||
| 31 | static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */ | 30 | static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */ |
| 32 | static const int SN_WIDTH = 100; /* width signal-to-noise ratio */ | 31 | static const int SN_WIDTH = 100; /* width signal-to-noise ratio */ |
| 32 | static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */ | ||
| 33 | 33 | ||
| 34 | static const int bits_per_long = 8 * sizeof(long); | 34 | static const int bits_per_long = 8 * sizeof(long); |
| 35 | 35 | ||
| @@ -50,6 +50,11 @@ static int getabs(struct input_absinfo *abs, int key, int fd) | |||
| 50 | return rc >= 0; | 50 | return rc >= 0; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | static int has_mt_data(const struct Capabilities *cap) | ||
| 54 | { | ||
| 55 | return cap->has_abs[BIT_POSITION_X] && cap->has_abs[BIT_POSITION_Y]; | ||
| 56 | } | ||
| 57 | |||
| 53 | static int has_integrated_button(const struct Capabilities *cap) | 58 | static int has_integrated_button(const struct Capabilities *cap) |
| 54 | { | 59 | { |
| 55 | static const int bcm5974_vmask_ibt = 1; | 60 | static const int bcm5974_vmask_ibt = 1; |
| @@ -58,12 +63,20 @@ static int has_integrated_button(const struct Capabilities *cap) | |||
| 58 | return cap->devid.version & bcm5974_vmask_ibt; | 63 | return cap->devid.version & bcm5974_vmask_ibt; |
| 59 | } | 64 | } |
| 60 | 65 | ||
| 66 | static void default_fuzz(struct Capabilities *cap, unsigned int code, int sn) | ||
| 67 | { | ||
| 68 | int bit = abs2mt(code); | ||
| 69 | if (cap->has_abs[bit] && cap->abs[bit].fuzz == 0) | ||
| 70 | cap->abs[bit].fuzz = | ||
| 71 | (cap->abs[bit].maximum - cap->abs[bit].minimum) / sn; | ||
| 72 | } | ||
| 73 | |||
| 61 | int read_capabilities(struct Capabilities *cap, int fd) | 74 | int read_capabilities(struct Capabilities *cap, int fd) |
| 62 | { | 75 | { |
| 63 | unsigned long evbits[nlongs(EV_MAX)]; | 76 | unsigned long evbits[nlongs(EV_MAX)]; |
| 64 | unsigned long absbits[nlongs(ABS_MAX)]; | 77 | unsigned long absbits[nlongs(ABS_MAX)]; |
| 65 | unsigned long keybits[nlongs(KEY_MAX)]; | 78 | unsigned long keybits[nlongs(KEY_MAX)]; |
| 66 | int rc; | 79 | int rc, i; |
| 67 | 80 | ||
| 68 | memset(cap, 0, sizeof(struct Capabilities)); | 81 | memset(cap, 0, sizeof(struct Capabilities)); |
| 69 | 82 | ||
| @@ -87,95 +100,76 @@ int read_capabilities(struct Capabilities *cap, int fd) | |||
| 87 | cap->has_middle = getbit(keybits, BTN_MIDDLE); | 100 | cap->has_middle = getbit(keybits, BTN_MIDDLE); |
| 88 | cap->has_right = getbit(keybits, BTN_RIGHT); | 101 | cap->has_right = getbit(keybits, BTN_RIGHT); |
| 89 | 102 | ||
| 90 | SETABS(cap, touch_major, absbits, ABS_MT_TOUCH_MAJOR, fd); | 103 | SETABS(cap, slot, absbits, ABS_MT_SLOT, fd); |
| 91 | SETABS(cap, touch_minor, absbits, ABS_MT_TOUCH_MINOR, fd); | 104 | for (i = 0; i < MT_ABS_SIZE; i++) |
| 92 | SETABS(cap, width_major, absbits, ABS_MT_WIDTH_MAJOR, fd); | 105 | SETABS(cap, abs[i], absbits, mt2abs(i), fd); |
| 93 | SETABS(cap, width_minor, absbits, ABS_MT_WIDTH_MINOR, fd); | ||
| 94 | SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd); | ||
| 95 | SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd); | ||
| 96 | SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd); | ||
| 97 | 106 | ||
| 98 | cap->has_mtdata = cap->has_position_x && cap->has_position_y; | 107 | cap->has_mtdata = has_mt_data(cap); |
| 99 | cap->has_ibt = has_integrated_button(cap); | 108 | cap->has_ibt = has_integrated_button(cap); |
| 100 | 109 | ||
| 101 | cap->xfuzz = cap->abs_position_x.fuzz; | 110 | if (cap->has_abs[BIT_TRACKING_ID]) |
| 102 | cap->yfuzz = cap->abs_position_y.fuzz; | 111 | cap->nullid = cap->abs[BIT_TRACKING_ID].minimum - 1; |
| 103 | if (cap->xfuzz <= 0 || cap->yfuzz <= 0) { | ||
| 104 | cap->xfuzz = get_cap_xsize(cap) / SN_COORD; | ||
| 105 | cap->yfuzz = get_cap_ysize(cap) / SN_COORD; | ||
| 106 | } | ||
| 107 | cap->wfuzz = cap->abs_touch_major.fuzz; | ||
| 108 | if (cap->wfuzz <= 0) | ||
| 109 | cap->wfuzz = get_cap_wsize(cap) / SN_WIDTH; | ||
| 110 | 112 | ||
| 111 | cap->yclick = cap->abs_position_y.maximum - CLICK_AREA(cap); | 113 | default_fuzz(cap, ABS_MT_POSITION_X, SN_COORD); |
| 114 | default_fuzz(cap, ABS_MT_POSITION_Y, SN_COORD); | ||
| 115 | default_fuzz(cap, ABS_MT_TOUCH_MAJOR, SN_WIDTH); | ||
| 116 | default_fuzz(cap, ABS_MT_TOUCH_MINOR, SN_WIDTH); | ||
| 117 | default_fuzz(cap, ABS_MT_WIDTH_MAJOR, SN_WIDTH); | ||
| 118 | default_fuzz(cap, ABS_MT_WIDTH_MINOR, SN_WIDTH); | ||
| 119 | default_fuzz(cap, ABS_MT_ORIENTATION, SN_ORIENT); | ||
| 112 | 120 | ||
| 113 | return 0; | 121 | return 0; |
| 114 | } | 122 | } |
| 115 | 123 | ||
| 116 | int get_cap_xsize(const struct Capabilities *cap) | 124 | int get_cap_xsize(const struct Capabilities *cap) |
| 117 | { | 125 | { |
| 118 | return cap->abs_position_x.maximum - cap->abs_position_x.minimum; | 126 | const struct input_absinfo *x = &cap->abs[BIT_POSITION_X]; |
| 127 | return x->maximum - x->minimum; | ||
| 119 | } | 128 | } |
| 120 | 129 | ||
| 121 | int get_cap_ysize(const struct Capabilities *cap) | 130 | int get_cap_ysize(const struct Capabilities *cap) |
| 122 | { | 131 | { |
| 123 | return cap->abs_position_y.maximum - cap->abs_position_y.minimum; | 132 | const struct input_absinfo *y = &cap->abs[BIT_POSITION_Y]; |
| 133 | return y->maximum - y->minimum; | ||
| 124 | } | 134 | } |
| 125 | 135 | ||
| 126 | int get_cap_wsize(const struct Capabilities *cap) | 136 | int get_cap_wsize(const struct Capabilities *cap) |
| 127 | { | 137 | { |
| 128 | return cap->abs_touch_major.maximum - cap->abs_touch_major.minimum; | 138 | const struct input_absinfo *w = &cap->abs[BIT_TOUCH_MAJOR]; |
| 139 | return w->maximum - w->minimum; | ||
| 129 | } | 140 | } |
| 130 | 141 | ||
| 131 | int get_cap_xmid(const struct Capabilities *cap) | 142 | int get_cap_xmid(const struct Capabilities *cap) |
| 132 | { | 143 | { |
| 133 | return (cap->abs_position_x.maximum + cap->abs_position_x.minimum) >> 1; | 144 | const struct input_absinfo *x = &cap->abs[BIT_POSITION_X]; |
| 145 | return (x->maximum + x->minimum) >> 1; | ||
| 134 | } | 146 | } |
| 135 | 147 | ||
| 136 | int get_cap_ymid(const struct Capabilities *cap) | 148 | int get_cap_ymid(const struct Capabilities *cap) |
| 137 | { | 149 | { |
| 138 | return (cap->abs_position_y.maximum + cap->abs_position_y.minimum) >> 1; | 150 | const struct input_absinfo *y = &cap->abs[BIT_POSITION_Y]; |
| 151 | return (y->maximum + y->minimum) >> 1; | ||
| 139 | } | 152 | } |
| 140 | 153 | ||
| 141 | void output_capabilities(const struct Capabilities *cap) | 154 | void output_capabilities(const struct Capabilities *cap) |
| 142 | { | 155 | { |
| 143 | char line[1024]; | 156 | char line[1024]; |
| 157 | int i; | ||
| 144 | memset(line, 0, sizeof(line)); | 158 | memset(line, 0, sizeof(line)); |
| 145 | ADDCAP(line, cap, left); | 159 | ADDCAP(line, cap, left); |
| 146 | ADDCAP(line, cap, middle); | 160 | ADDCAP(line, cap, middle); |
| 147 | ADDCAP(line, cap, right); | 161 | ADDCAP(line, cap, right); |
| 148 | ADDCAP(line, cap, mtdata); | 162 | ADDCAP(line, cap, mtdata); |
| 149 | ADDCAP(line, cap, ibt); | 163 | ADDCAP(line, cap, ibt); |
| 150 | ADDCAP(line, cap, touch_major); | ||
| 151 | ADDCAP(line, cap, touch_minor); | ||
| 152 | ADDCAP(line, cap, width_major); | ||
| 153 | ADDCAP(line, cap, width_minor); | ||
| 154 | ADDCAP(line, cap, orientation); | ||
| 155 | ADDCAP(line, cap, position_x); | ||
| 156 | ADDCAP(line, cap, position_y); | ||
| 157 | xf86Msg(X_INFO, "multitouch: devname: %s\n", cap->devname); | 164 | xf86Msg(X_INFO, "multitouch: devname: %s\n", cap->devname); |
| 158 | xf86Msg(X_INFO, "multitouch: devid: %x %x %x\n", | 165 | xf86Msg(X_INFO, "multitouch: devid: %x %x %x\n", |
| 159 | cap->devid.vendor, cap->devid.product, cap->devid.version); | 166 | cap->devid.vendor, cap->devid.product, cap->devid.version); |
| 160 | xf86Msg(X_INFO, "multitouch: caps:%s\n", line); | 167 | xf86Msg(X_INFO, "multitouch: caps:%s\n", line); |
| 161 | if (cap->has_touch_major) | 168 | for (i = 0; i < MT_ABS_SIZE; i++) { |
| 162 | xf86Msg(X_INFO, "multitouch: touch: %d %d\n", | 169 | if (cap->has_abs[i]) |
| 163 | cap->abs_touch_major.minimum, | 170 | xf86Msg(X_INFO, "multitouch: %d: min: %d max: %d\n", |
| 164 | cap->abs_touch_major.maximum); | 171 | i, |
| 165 | if (cap->has_width_major) | 172 | cap->abs[i].minimum, |
| 166 | xf86Msg(X_INFO, "multitouch: width: %d %d\n", | 173 | cap->abs[i].maximum); |
| 167 | cap->abs_width_major.minimum, | 174 | } |
| 168 | cap->abs_width_major.maximum); | ||
| 169 | if (cap->has_orientation) | ||
| 170 | xf86Msg(X_INFO, "multitouch: orientation: %d %d\n", | ||
| 171 | cap->abs_orientation.minimum, | ||
| 172 | cap->abs_orientation.maximum); | ||
| 173 | if (cap->has_position_x) | ||
| 174 | xf86Msg(X_INFO, "multitouch: position_x: %d %d\n", | ||
| 175 | cap->abs_position_x.minimum, | ||
| 176 | cap->abs_position_x.maximum); | ||
| 177 | if (cap->has_position_y) | ||
| 178 | xf86Msg(X_INFO, "multitouch: position_y: %d %d\n", | ||
| 179 | cap->abs_position_y.minimum, | ||
| 180 | cap->abs_position_y.maximum); | ||
| 181 | } | 175 | } |
