[fix] support selective mouse button release across desktop platforms

This commit is contained in:
dijunkun
2026-10-22 16:10:34 +08:00
parent f6a2637540
commit 5e494bfa3b
10 changed files with 115 additions and 21 deletions
@@ -40,11 +40,14 @@ void PlatformMouseController::UpdateDisplayInfoList(
display_info_list_.size());
}
int PlatformMouseController::Destroy() { return ReleasePressedButtons(); }
int PlatformMouseController::Destroy() {
return ReleasePressedButtons() == 7 ? 0 : -1;
}
int PlatformMouseController::ReleasePressedButtons() {
const unsigned pressed = pressed_buttons_.load();
if (!pressed) return 0;
unsigned PlatformMouseController::ReleasePressedButtons(unsigned mask) {
mask &= 7;
const unsigned pressed = pressed_buttons_.load() & mask;
if (!pressed) return mask;
INPUT input{};
input.type = INPUT_MOUSE;
input.mi.dwExtraInfo = kInjectedMouseInputMarker;
@@ -53,10 +56,10 @@ int PlatformMouseController::ReleasePressedButtons() {
if (pressed & 4) input.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
if (SendInputOnUserDesktop(input) != 1) {
LOG_WARN("Release remote mouse buttons failed, error={}", GetLastError());
return -1;
return mask & ~pressed;
}
pressed_buttons_.fetch_and(~pressed);
return 0;
return mask;
}
int PlatformMouseController::SendMouseCommand(RemoteAction remote_action,
@@ -29,7 +29,7 @@ class PlatformMouseController final : public MouseController {
virtual int SendMouseCommand(RemoteAction remote_action, int display_index);
void UpdateDisplayInfoList(
const std::vector<DisplayInfo>& display_info_list) override;
int ReleasePressedButtons();
unsigned ReleasePressedButtons(unsigned mask = 7) override;
private:
std::vector<DisplayInfo> display_info_list_;