diff options
-rw-r--r-- | doc/wheelapi2.txt | 14 | ||||
-rw-r--r-- | mousetsr.c | 15 | ||||
-rw-r--r-- | mousew16.c | 120 |
3 files changed, 86 insertions, 63 deletions
diff --git a/doc/wheelapi2.txt b/doc/wheelapi2.txt index 91acd32..6f6af29 100644 --- a/doc/wheelapi2.txt +++ b/doc/wheelapi2.txt @@ -7,7 +7,7 @@ NOTE: Draft, subject to change. Changes to the wheelapi v1 functions: INT 33/0011 - Check wheel support and enable/get capabilities flags - AX = 0011h + AX = 0011h Return: AX = 574Dh ('WM' in assembly) if Wheel API is supported by driver CX = Capabilities flag Bit(s) Description @@ -28,18 +28,18 @@ Return: BL = buttons status (bits 0-4) BH = 8-bit signed counter of wheel movement since last call positive value means downward wheel movement. SI = 16-bit signed counter of 2nd wheel movement since last call - positive value means leftward wheel movement. + positive value means rightward wheel movement. Note: calling this clears the wheel counter for ALL wheels. INT 33/0005 - Get button press or wheel movement data - AX = 0005h - BX = button number, -1 for vertical wheel, -2 for 2nd/horizontal wheel + AX = 0005h + BX = button number, -1 for vertical wheel, -2 for 2nd/horizontal wheel Note: as in wheelapi v1, AH always contains (1st) wheel movement on return - independently of button number requested in BX. + independently of button number requested in BX. INT 33/0006 - Get button release or wheel movement data - AX = 0006h - BX = button number, -1 for vertical wheel, -2 for 2nd/horizontal wheel + AX = 0006h + BX = button number, -1 for vertical wheel, -2 for 2nd/horizontal wheel INT 33/000C - Define User Interrupt Routine INT 33/0014 - Exchange User Interrupt Routines @@ -764,7 +764,7 @@ static void handle_ps2_packet(void) z = sign_extend(data.ps2_packet[3], 6); } else if (data.ps2_packet[3] & PS2M_IMEX_HORIZONTAL_SCROLL) { // Horizontal scrolling, with 6 bits of precision. - z = sign_extend(data.ps2_packet[3], 6); + z = -sign_extend(data.ps2_packet[3], 6); wheeln = 1; } else { // Or 2 extra buttons (4, 5) @@ -1047,10 +1047,6 @@ static void reset_mouse_hardware() ps2m_get_device_id(&data.device_id); if (data.device_id == PS2M_DEVICE_ID_IMEX) { - dputs("ImEx detected"); - data.num_wheels = 2; - data.num_buttons = 5; - ps2m_send_imex_horz_sequence(); ps2m_get_device_id(&data.device_id); @@ -1059,7 +1055,14 @@ static void reset_mouse_hardware() // handle both protocols is the same. } } -#endif + + if (data.device_id == PS2M_DEVICE_ID_IMEX + || data.device_id == PS2M_DEVICE_ID_IMEX_HORZ) { + dputs("ImEx detected"); + data.num_wheels = 2; + data.num_buttons = 5; + } +#endif /* USE_IMEX */ dprintf("found mouse device id = 0x%hx\n", data.device_id); } else { @@ -35,7 +35,7 @@ #define TRACE_EVENTS 0 /** Verbosely trace scroll wheel code. */ #define TRACE_WHEEL 0 -/** Number of lines to scroll per wheel event. */ +/** Number of lines to scroll per (vertical) wheel event. */ #define WHEEL_SCROLL_LINES 2 /** Windows 3.x only supports 1-2 mouse buttons anyway. */ @@ -117,7 +117,7 @@ static void print_window_name(HWND hWnd) #endif /** Helper function to traverse a window hierarchy and find a candidate scrollbar. */ -static BOOL CALLBACK __loadds find_scrollbar(HWND hWnd, LPARAM lParam) +static BOOL CALLBACK __loadds find_scrollbar_enum_proc(HWND hWnd, LPARAM lParam) { LPFINDSCROLLBARDATA data = (LPFINDSCROLLBARDATA) lParam; char buffer[16]; @@ -149,6 +149,22 @@ static BOOL CALLBACK __loadds find_scrollbar(HWND hWnd, LPARAM lParam) return ENUM_CHILD_WINDOW_CONTINUE; } +/** Finds a scrollbar in the given window. */ +static HWND find_scrollbar(HWND hWnd, BOOL vertical) +{ + FINDSCROLLBARDATA data; + data.vertical = vertical; + data.scrollbar = 0; + +#if TRACE_WHEEL + dprintf(DPREFIX "find scrollbar on hWnd=0x%x...\n", hWnd); +#endif + + userapi.EnumChildWindows(hWnd, find_scrollbar_enum_proc, (LONG) (LPVOID) &data); + + return data.scrollbar; +} + /** Send scrolling messages to given window. * @param hWnd window to scroll. * @param vertical true if vertical, false if horizontal. @@ -160,7 +176,9 @@ static void post_scroll_msg(HWND hWnd, BOOL vertical, int z, HWND hScrollBar) UINT msg = vertical ? WM_VSCROLL : WM_HSCROLL; WPARAM wParam = z < 0 ? SB_LINEUP : SB_LINEDOWN; LPARAM lParam = MAKELPARAM(0, hScrollBar); - UINT i, lines = (z < 0 ? -z : z) * WHEEL_SCROLL_LINES; + UINT i, lines = (z < 0 ? -z : z); + + if (!vertical) lines *= WHEEL_SCROLL_LINES; #if TRACE_WHEEL dprintf(DPREFIX "sending scroll msg to hWnd=0x%x from=0x%x vert=%d lines=%u\n", hWnd, hScrollBar, vertical, lines); @@ -173,7 +191,7 @@ static void post_scroll_msg(HWND hWnd, BOOL vertical, int z, HWND hScrollBar) } /** Send wheel scrolling events to the most likely candidate window. */ -static void send_wheel_movement(int8_t z) +static void send_wheel_movement(int8_t z, BOOL vertical) { POINT point; HWND hWnd; @@ -202,54 +220,55 @@ static void send_wheel_movement(int8_t z) dprintf(DPREFIX "hWnd=0x%x style=0x%lx\n", hWnd, style); #endif - if (style & WS_VSCROLL) { -#if TRACE_WHEEL - dprintf(DPREFIX "found WS_VSCROLL\n"); -#endif - post_scroll_msg(hWnd, TRUE, z, 0); - break; - } else if (style & WS_HSCROLL) { -#if TRACE_WHEEL - dprintf(DPREFIX "found WS_HSCROLL\n"); -#endif - post_scroll_msg(hWnd, FALSE, z, 0); - break; - } else { - FINDSCROLLBARDATA data; - - // Let's check if we can find a vertical scroll bar in this window.. -#if TRACE_WHEEL - dprintf(DPREFIX "find vertical scrollbar...\n"); -#endif - data.vertical = TRUE; - data.scrollbar = 0; - userapi.EnumChildWindows(hWnd, find_scrollbar, (LONG) (LPVOID) &data); - if (data.scrollbar) { - post_scroll_msg(hWnd, TRUE, z, data.scrollbar); + if (vertical) { + // Check if this window is scrollable... + if (style & WS_VSCROLL) { + post_scroll_msg(hWnd, TRUE, z, 0); break; - } - - // Try a horizontal scrollbar now -#if TRACE_WHEEL - dprintf(DPREFIX "find horizontal scrollbar...\n"); -#endif - data.vertical = FALSE; - data.scrollbar = 0; - userapi.EnumChildWindows(hWnd, find_scrollbar, (LONG) (LPVOID) &data); - if (data.scrollbar) { - post_scroll_msg(hWnd, FALSE, z, data.scrollbar); + } else if (style & WS_HSCROLL) { + post_scroll_msg(hWnd, FALSE, z, 0); break; - } - - // Otherwise, try again on the parent window - if (style & WS_CHILD) { -#if TRACE_WHEEL - dprintf(DPREFIX "go into parent...\n"); -#endif - hWnd = userapi.GetParent(hWnd); } else { - // This was already a topmost window + // Otherwise, let's see if we can find a vertical scroll bar in this window.. + HWND scrollbar = find_scrollbar(hWnd, TRUE); + if (scrollbar) { + post_scroll_msg(hWnd, TRUE, z, scrollbar); + break; + } + + // Try a horizontal scrollbar second + scrollbar = find_scrollbar(hWnd, FALSE); + if (scrollbar) { + post_scroll_msg(hWnd, FALSE, z, scrollbar); + break; + } + + // Otherwise, continue search on the parent window + if (style & WS_CHILD) { + hWnd = userapi.GetParent(hWnd); + } else { + // This was already a topmost window + break; + } + } + } else { + // Similar to above except we try only horizontal scrollbars + if (style & WS_HSCROLL) { + post_scroll_msg(hWnd, FALSE, z, 0); break; + } else { + HWND scrollbar = find_scrollbar(hWnd, FALSE); + if (scrollbar) { + post_scroll_msg(hWnd, FALSE, z, scrollbar); + break; + } + + if (style & WS_CHILD) { + hWnd = userapi.GetParent(hWnd); + } else { + // This was already a topmost window + break; + } } } } @@ -281,11 +300,12 @@ static void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t } #if USE_WHEEL - if (flags.wheel && (events & INT33_EVENT_MASK_WHEEL_MOVEMENT)) { + if (flags.wheel && (events & INT33_EVENT_MASK_WHEEL_MOVEMENT|INT33_EVENT_MASK_HORIZ_WHEEL_MOVEMENT)) { // If wheel API is enabled, higher byte of buttons contains wheel movement int8_t z = (buttons & 0xFF00) >> 8; + BOOL vertical = !(events & INT33_EVENT_MASK_HORIZ_WHEEL_MOVEMENT); if (z) { - send_wheel_movement(z); + send_wheel_movement(z, vertical); } } #endif |