From 07598f4bb2e4b91c22d831e7cd2f24fbbe8650ba Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 29 Mar 2026 18:42:05 -0600 Subject: [PATCH] [gpu] Support middle-click in WebGPU demo Map DOM button 1 (middle) to GLFW middle button so middle-click reset and middle-drag zoom work. Co-Authored-By: Claude Opus 4.6 (1M context) --- util/gpu/web/hb-gpu-web-webgpu.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/gpu/web/hb-gpu-web-webgpu.cc b/util/gpu/web/hb-gpu-web-webgpu.cc index 477bbbdae..1c35f267f 100644 --- a/util/gpu/web/hb-gpu-web-webgpu.cc +++ b/util/gpu/web/hb-gpu-web-webgpu.cc @@ -394,6 +394,7 @@ web_get_text () /* GLFW-compatible button/action constants */ #define BUTTON_LEFT 0 #define BUTTON_RIGHT 1 +#define BUTTON_MIDDLE 2 #define ACTION_RELEASE 0 #define ACTION_PRESS 1 @@ -402,7 +403,7 @@ static int active_buttons; static EM_BOOL on_mousedown (int type, const EmscriptenMouseEvent *e, void *ud) { - int button = (e->button == 2) ? BUTTON_RIGHT : BUTTON_LEFT; + int button = e->button == 2 ? BUTTON_RIGHT : e->button == 1 ? BUTTON_MIDDLE : BUTTON_LEFT; active_buttons |= (1 << button); demo_view_motion_func (vu, e->targetX, e->targetY); demo_view_mouse_func (vu, button, ACTION_PRESS, 0); @@ -412,7 +413,7 @@ on_mousedown (int type, const EmscriptenMouseEvent *e, void *ud) static EM_BOOL on_mouseup (int type, const EmscriptenMouseEvent *e, void *ud) { - int button = (e->button == 2) ? BUTTON_RIGHT : BUTTON_LEFT; + int button = e->button == 2 ? BUTTON_RIGHT : e->button == 1 ? BUTTON_MIDDLE : BUTTON_LEFT; if (!(active_buttons & (1 << button))) return EM_FALSE; /* Not our drag — ignore (e.g. UI button click) */ active_buttons &= ~(1 << button);