Skip to content

Commit 6c4e97d

Browse files
joevtdingusdev
authored andcommitted
adbmouse: Move handler 1 check.
1 parent 8958010 commit 6c4e97d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

devices/common/adb/adbmouse.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,19 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
7575

7676
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
7777
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
78-
int total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[this->num_bits]);
78+
int num_bits, total_bits;
79+
// if the mouse is in standard protocol then only send first 2 bytes
80+
// BUGBUG: what should tablet do here?
81+
if (this->device_class == MOUSE && this->dev_handler_id == 1) {
82+
num_bits = total_bits = 7;
83+
} else {
84+
num_bits = this->num_bits;
85+
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
86+
}
7987
uint8_t buttons_state = ~this->buttons_state;
8088

8189
for (int axis = 0; axis < 2; axis++) {
82-
int bits = this->num_bits;
90+
int bits = num_bits;
8391
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
8492
: this->device_class == TABLET ? this->y_abs : this->y_rel;
8593
if (val < (-1 << (bits - 1)))
@@ -107,13 +115,6 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
107115
this->changed = false;
108116

109117
uint8_t count = (uint8_t)(p - out_buf);
110-
// should never happen, but check just in case
111-
if (((size_t)p - (size_t)out_buf) > UINT8_MAX)
112-
count = UINT8_MAX;
113-
// if the mouse is in standard protocol then only send first 2 bytes
114-
// BUGBUG: what should tablet do here?
115-
if (this->device_class == MOUSE && this->dev_handler_id == 1)
116-
count = 2;
117118
this->host_obj->set_output_count(count);
118119
return should_update;
119120
}

0 commit comments

Comments
 (0)