aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2026-11-22 01:26:46 +0100
committerJavier <dev.git@javispedro.com>2026-11-22 01:26:46 +0100
commit6c2ceaba02331c433fdf5db4753007ed4e597230 (patch)
tree38444c1f7bca67afb7b8aec037c8f2e9dac696c9
parent5e7e961a048fd3a4d58cecf866bc9714f35c192b (diff)
downloadvbados-6c2ceaba02331c433fdf5db4753007ed4e597230.tar.gz
vbados-6c2ceaba02331c433fdf5db4753007ed4e597230.zip
mousew16: turns out win3.x does support middle button, so pass it through in the driver
-rw-r--r--mousetsr.c2
-rw-r--r--mousew16.c73
-rw-r--r--mousew16.h48
-rw-r--r--mousmain.c2
4 files changed, 60 insertions, 65 deletions
diff --git a/mousetsr.c b/mousetsr.c
index 1e33dc2..e1fb1b9 100644
--- a/mousetsr.c
+++ b/mousetsr.c
@@ -661,7 +661,7 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch
uint16_t elapsed_ticks = cur_ticks - data.last_motion_ticks;
data.cur_speed = (data.total_motion / elapsed_ticks) * 18; // Extrapolate speed from movement in this tick
#if TRACE_EVENTS
- dprintf("mouse speed = %u / threshold = %u total_motion in last %u ticks = %u\n", data.cur_speed, data.doubleSpeedThreshold * data.doubleSpeedThreshold, elapsed_ticks, data.total_motion);
+ dprintf("mouse speed = %u / threshold = %u total_motion in last %u ticks = %u\n", data.cur_speed, data.double_speed_threshold * data.double_speed_threshold, elapsed_ticks, data.total_motion);
#endif
data.total_motion = 0;
data.last_motion_ticks = cur_ticks;
diff --git a/mousew16.c b/mousew16.c
index 5b8b0cf..ee940d1 100644
--- a/mousew16.c
+++ b/mousew16.c
@@ -39,8 +39,8 @@
/** Number of lines to scroll per (vertical) wheel event. */
#define WHEEL_SCROLL_LINES 2
-/** Windows 3.x only supports 1-2 mouse buttons anyway. */
-#define MOUSE_NUM_BUTTONS 2
+/** Max number of mouse buttons supported. */
+#define MOUSE_MAX_BUTTONS 3
/** Prefix for debug messages. */
#define DPREFIX "mousew16: "
@@ -60,6 +60,8 @@ static struct {
bool has_win386 : 1;
#endif
} flags;
+/** Current mouse number of buttons. */
+static unsigned short num_buttons;
/** Previous deltaX, deltaY from the int33 mouse callback (for relative motion) */
static short prev_delta_x, prev_delta_y;
/** Maximum X and Y coordinates expected from the int33 driver. */
@@ -73,22 +75,22 @@ static struct {
LRESULT WINAPI (*DefHookProc)( int, WPARAM, LPARAM, HOOKPROC FAR * );
HWND WINAPI (*GetActiveWindow)( void );
int WINAPI (*GetClassName)( HWND, LPSTR, int );
- void WINAPI (*GetCursorPos)( POINT FAR * );
HWND WINAPI (*GetParent)( HWND );
LONG WINAPI (*GetWindowLong)( HWND, int );
int WINAPI (*GetWindowText)( HWND, LPSTR, int );
BOOL WINAPI (*IsWindowEnabled)( HWND );
BOOL WINAPI (*PostMessage)( HWND, UINT, WPARAM, LPARAM );
UINT WINAPI (*RegisterWindowMessage)( LPCSTR );
- LRESULT WINAPI (*SendMessage)( HWND, UINT, WPARAM, LPARAM );
HOOKPROC WINAPI (*SetWindowsHook)( int, HOOKPROC );
BOOL WINAPI (*UnhookWindowsHook)( int, HOOKPROC );
HWND WINAPI (*WindowFromPoint)( POINT );
} userapi;
+/** This is the private message that we send on wheel movement and is
+ * going to be intercepted by the hook, which will translate into scroll msgs. */
static UINT wheel_msg_private;
-static UINT wheel_msg_mousewheel;
+/** The hook that comes after ours. */
static HOOKPROC wheel_hook_proc_next;
-#endif
+#endif /* USE_WHEEL */
#if USE_WIN386
/** Previous int2f handler. */
static LPFN prev_int2f_handler;
@@ -210,13 +212,13 @@ static void post_scroll_msg(HWND hWnd, UINT msg, int z, HWND hScrollBar)
/** Send wheel scrolling events to the most likely candidate window.
@param cursor the cursor position at the time the wheel event occured */
-static void simulate_scroll(POINT cursor, int z, BOOL horizontal)
+static void post_simulated_scroll_msgs(POINT cursor, int z, BOOL horizontal)
{
HWND hWnd;
#if TRACE_WHEEL
- dprintf(DPREFIX "simulate_scroll @%d,%d z=%d %s\n",
- cursor.x, cursor.y,
+ dprintf(DPREFIX "%s @%d,%d z=%d %s\n",
+ __func__, cursor.x, cursor.y,
z, horizontal ? "horiz" : "vert");
#endif
@@ -289,19 +291,10 @@ static void simulate_scroll(POINT cursor, int z, BOOL horizontal)
}
#if TRACE_WHEEL
- dprintf(DPREFIX "simulate_scroll end\n");
+ dprintf(DPREFIX "%s end\n", __func__);
#endif
}
-/** Send a MSH_MOUSEWHEEL message to hWnd. */
-static BOOL send_msg_mousewheel(HWND hWnd, POINT cursor, int z, BOOL horizontal)
-{
- WPARAM wParam = z * WHEEL_DELTA;
- LPARAM lParam = MAKELONG(cursor.x, cursor.y);
- if (horizontal) return FALSE; // TODO there is no MSH_MOUSE(H)WHEEL
- return userapi.SendMessage(hWnd, wheel_msg_mousewheel, wParam, lParam);
-}
-
/** GetMsgProc hook, called for every message before being returned by GetMessage. */
LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam)
{
@@ -313,13 +306,13 @@ LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam)
BOOL horizontal = msg->wParam;
int z = msg->lParam;
- // First try to send zmouse's MSH_MOUSEWHEEL msg,
- // which some win9x era software may handle natively
- if (!send_msg_mousewheel(msg->hwnd, msg->pt, z, horizontal)) {
- // Only if the window didn't handle the MSH_MOUSEWHEEL msg,
- // simulate scrolling events.
- simulate_scroll(msg->pt, z, horizontal);
- }
+ // TODO In theory we could try sending "native" MSH_MOUSEWHEEL msg here
+ // which some early nt/95 software supports (in addition to 98's WM_MOUSEWHEEL)
+ // but I think the fake scroll messages work well enough.
+ // To properly send MSH_MOUSEWHEEL, we'd need to thunk into 32-bit
+ // SendMessage because such win95 software will expect 32-bit WPARAM.
+
+ post_simulated_scroll_msgs(msg->pt, z, horizontal);
// Prevent us from intercepting this message if fwd'd
msg->message = WM_NULL;
@@ -349,6 +342,12 @@ static void post_wheel_msg(int z, BOOL horizontal)
userapi.PostMessage(hWnd, wheel_msg_private, horizontal, z);
}
+#else
+LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam) {
+ // Required since we export this symbol, but not use it
+ (void)code; (void) wParam; (void) lParam;
+ return 0;
+}
#endif /* USE_WHEEL */
/** Called by the int33 mouse driver. */
@@ -362,10 +361,12 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
events, buttons, x, y, delta_x, delta_y);
#endif
- if (events & INT33_EVENT_MASK_LEFT_BUTTON_PRESSED) status |= SF_B1_DOWN;
- if (events & INT33_EVENT_MASK_LEFT_BUTTON_RELEASED) status |= SF_B1_UP;
- if (events & INT33_EVENT_MASK_RIGHT_BUTTON_PRESSED) status |= SF_B2_DOWN;
- if (events & INT33_EVENT_MASK_RIGHT_BUTTON_RELEASED) status |= SF_B2_UP;
+ if (events & INT33_EVENT_MASK_LEFT_BUTTON_PRESSED) status |= SF_B1_DOWN;
+ if (events & INT33_EVENT_MASK_LEFT_BUTTON_RELEASED) status |= SF_B1_UP;
+ if (events & INT33_EVENT_MASK_RIGHT_BUTTON_PRESSED) status |= SF_B2_DOWN;
+ if (events & INT33_EVENT_MASK_RIGHT_BUTTON_RELEASED) status |= SF_B2_UP;
+ if (events & INT33_EVENT_MASK_CENTER_BUTTON_PRESSED) status |= SF_B3_DOWN;
+ if (events & INT33_EVENT_MASK_CENTER_BUTTON_RELEASED) status |= SF_B3_UP;
if (events & INT33_EVENT_MASK_MOVEMENT) {
status |= SF_MOVEMENT;
@@ -410,7 +411,7 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
}
#if TRACE_EVENTS
- dprintf(DPREFIX "post status=0x%x ", status);
+ dprintf(DPREFIX "post nb=%u status=0x%x ", num_buttons, status);
if (status & SF_ABSOLUTE) {
dprintf("x=%u y=%u\n", x, y);
} else {
@@ -418,7 +419,7 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
}
#endif
- post_event(status, x, y, MOUSE_NUM_BUTTONS, 0, 0);
+ post_event(status, x, y, num_buttons, 0, 0);
}
#if USE_WIN386
@@ -548,7 +549,7 @@ WORD FAR PASCAL Inquire(LPMOUSEINFO lpMouseInfo)
{
lpMouseInfo->msExist = TRUE;
lpMouseInfo->msRelative = 0;
- lpMouseInfo->msNumButtons = MOUSE_NUM_BUTTONS;
+ lpMouseInfo->msNumButtons = MOUSE_MAX_BUTTONS;
lpMouseInfo->msRate = 80;
return sizeof(MOUSEINFO);
}
@@ -563,7 +564,8 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc)
_enable();
if (!flags.enabled) {
- int33_reset();
+ int33_reset_get_buttons(&num_buttons);
+ num_buttons = BOUND(num_buttons, 2, MOUSE_MAX_BUTTONS);
#if USE_WIN386
// If we are running under win386, hook int2f now.
@@ -585,20 +587,17 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc)
userapi.DefHookProc = (LPVOID) GetProcAddress(userapi.hUser, "DefHookProc");
userapi.GetActiveWindow = (LPVOID) GetProcAddress(userapi.hUser, "GetActiveWindow");
userapi.GetClassName = (LPVOID) GetProcAddress(userapi.hUser, "GetClassName");
- userapi.GetCursorPos = (LPVOID) GetProcAddress(userapi.hUser, "GetCursorPos");
userapi.GetParent = (LPVOID) GetProcAddress(userapi.hUser, "GetParent");
userapi.GetWindowLong = (LPVOID) GetProcAddress(userapi.hUser, "GetWindowLong");
userapi.GetWindowText = (LPVOID) GetProcAddress(userapi.hUser, "GetWindowText");
userapi.IsWindowEnabled = (LPVOID) GetProcAddress(userapi.hUser, "IsWindowEnabled");
userapi.PostMessage = (LPVOID) GetProcAddress(userapi.hUser, "PostMessage");
userapi.RegisterWindowMessage = (LPVOID) GetProcAddress(userapi.hUser, "RegisterWindowMessage");
- userapi.SendMessage = (LPVOID) GetProcAddress(userapi.hUser, "SendMessage");
userapi.SetWindowsHook = (LPVOID) GetProcAddress(userapi.hUser, "SetWindowsHook");
userapi.UnhookWindowsHook = (LPVOID) GetProcAddress(userapi.hUser, "UnhookWindowsHook");
userapi.WindowFromPoint = (LPVOID) GetProcAddress(userapi.hUser, "WindowFromPoint");
wheel_msg_private = userapi.RegisterWindowMessage("VBMOUSE_WHEEL");
- wheel_msg_mousewheel = userapi.RegisterWindowMessage(MSH_MOUSEWHEEL);
wheel_hook_proc_next = userapi.SetWindowsHook(WH_GETMESSAGE, (HOOKPROC)WheelHookProc);
}
diff --git a/mousew16.h b/mousew16.h
index 5dbb8f8..42ecf04 100644
--- a/mousew16.h
+++ b/mousew16.h
@@ -27,18 +27,28 @@ typedef _Packed struct MOUSEINFO
} MOUSEINFO;
typedef MOUSEINFO __far *LPMOUSEINFO;
-/** Movement occurred. */
-#define SF_MOVEMENT 0x0001
-/** Button 1 changed to down. */
-#define SF_B1_DOWN 0x0002
-/** Button 1 changed to up. */
-#define SF_B1_UP 0x0004
-/** Button 2 changed to down. */
-#define SF_B2_DOWN 0x0008
-/** Button 2 changed to up. */
-#define SF_B2_UP 0x0010
-/** Event coordinates are absolute instead of relative. */
-#define SF_ABSOLUTE 0x8000
+/** Status flag when posting mouse events to Windows (mouse_event func). */
+enum MOUSESTATUSFLAGS {
+ /** Movement occurred. */
+ SF_MOVEMENT = 0x0001,
+ /** Button 1 changed to down. */
+ SF_B1_DOWN = 0x0002,
+ /** Button 1 changed to up. */
+ SF_B1_UP = 0x0004,
+ /** Button 2 changed to down. */
+ SF_B2_DOWN = 0x0008,
+ /** Button 2 changed to up. */
+ SF_B2_UP = 0x0010,
+ /** Event coordinates are absolute instead of relative. */
+ SF_ABSOLUTE = 0x8000,
+
+ // The following may only work with win95 up.
+ /** Button 3 changed to down. */
+ SF_B3_DOWN = 0x0020,
+ /** Button 3 changed to up. */
+ SF_B3_UP = 0x0040,
+};
+
/** Driver should call this callback when there are new mouse events to report.
* @param Status What happened. Combination of SF_MOVEMENT, SF_ABSOLUTE, etc.
@@ -50,18 +60,4 @@ typedef MOUSEINFO __far *LPMOUSEINFO;
typedef void (__far *LPFN_MOUSEEVENT)(unsigned short Status, short deltaX, short deltaY, short ButtonCount, short extra1, short extra2);
#pragma aux MOUSEEVENTPROC parm [ax] [bx] [cx] [dx] [di] [si]
-/* Special defines for wheel usage. */
-
-#ifndef WHEEL_DELTA
-#define WHEEL_DELTA 120
-#endif
-
-#ifndef WHEEL_PAGESCROLL
-#define WHEEL_PAGESCROLL UINT_MAX
-#endif
-
-#ifndef MSH_MOUSEWHEEL
-#define MSH_MOUSEWHEEL "MSWHEEL_ROLLMSG"
-#endif
-
#endif
diff --git a/mousmain.c b/mousmain.c
index dcc9de9..f9e31b6 100644
--- a/mousmain.c
+++ b/mousmain.c
@@ -647,7 +647,7 @@ static void uninstall_driver(LPTSRDATA data)
printf(_(1, 18, "Driver uninstalled\n"));
}
-static int driver_reset(void)
+static bool driver_reset(void)
{
printf(_(1, 19, "Reset mouse driver\n"));
return int33_reset() == INT33_MOUSE_FOUND;