From 8ae19258b100ee1a13c0107f709ecf1bbf767eed Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Sat, 24 Oct 2026 13:34:36 +0200 Subject: [PATCH] fix: fix Files double-click bug --- kernel/src/Api/BuildNo.hpp | 2 +- programs/src/files/dnd.cpp | 7 +++++++ programs/src/files/events.cpp | 22 +++++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/kernel/src/Api/BuildNo.hpp b/kernel/src/Api/BuildNo.hpp index feb58dc..694c0f8 100644 --- a/kernel/src/Api/BuildNo.hpp +++ b/kernel/src/Api/BuildNo.hpp @@ -12,4 +12,4 @@ #pragma once -#define MONTAUK_BUILD_NUMBER 21 +#define MONTAUK_BUILD_NUMBER 22 diff --git a/programs/src/files/dnd.cpp b/programs/src/files/dnd.cpp index c19ea88..1fb2e3d 100644 --- a/programs/src/files/dnd.cpp +++ b/programs/src/files/dnd.cpp @@ -73,6 +73,13 @@ bool filemanager_dnd_mouse(Window* win, FileManagerState* fm, const FileManagerL } if (fm->drag_serial) return true; + // A fresh press means we missed the release of the armed one (focus + // went elsewhere mid-press); drop it and let this press be handled anew. + if (ev.left_pressed()) { + fm->press_idx = -1; + return false; + } + int dx = x - fm->press_x; int dy = y - fm->press_y; if (dx * dx + dy * dy < DRAG_THRESHOLD * DRAG_THRESHOLD) return true; diff --git a/programs/src/files/events.cpp b/programs/src/files/events.cpp index 7135ebf..253628e 100644 --- a/programs/src/files/events.cpp +++ b/programs/src/files/events.cpp @@ -28,7 +28,8 @@ static bool filemanager_is_listing(const FileManagerState* fm) { // Left click on an entry. Ctrl toggles it, Shift selects the range from the // anchor (Ctrl+Shift adds that range); a plain click selects it alone, and a // second plain click within 400 ms opens it. -static void filemanager_click_entry(FileManagerState* fm, int idx) { +// True if the click opened the entry (the second click of a double-click). +static bool filemanager_click_entry(FileManagerState* fm, int idx) { DesktopState* ds = fm->desktop; bool ctrl = ds && ds->kbd_ctrl_down; bool shift = ds && ds->kbd_shift_down; @@ -38,7 +39,7 @@ static void filemanager_click_entry(FileManagerState* fm, int idx) { else filemanager_toggle_selection(fm, idx); fm->last_click_item = -1; fm->last_click_time = 0; - return; + return false; } uint64_t now = montauk::get_milliseconds(); @@ -46,11 +47,12 @@ static void filemanager_click_entry(FileManagerState* fm, int idx) { filemanager_open_entry(fm, idx); fm->last_click_item = -1; fm->last_click_time = 0; - } else { - filemanager_select_single(fm, idx); - fm->last_click_item = idx; - fm->last_click_time = now; + return true; } + filemanager_select_single(fm, idx); + fm->last_click_item = idx; + fm->last_click_time = now; + return false; } void filemanager_on_mouse(Window* win, MouseEvent& ev) { @@ -290,9 +292,11 @@ void filemanager_on_mouse(Window* win, MouseEvent& ev) { if (in_view) { int clicked_idx = entry_at(local_x, local_y); if (clicked_idx >= 0) { - filemanager_click_entry(fm, clicked_idx); - // A press on a selected entry may turn into a drag. - if (filemanager_is_entry_selected(fm, clicked_idx)) { + // A press on a selected entry may turn into a drag, unless it + // opened the entry: the opened app takes focus, so we would + // never see the release. + bool opened = filemanager_click_entry(fm, clicked_idx); + if (!opened && filemanager_is_entry_selected(fm, clicked_idx)) { fm->press_idx = clicked_idx; fm->press_x = local_x; fm->press_y = local_y;