From 9aaf6f310512d927f696ade10bb2de36182df1a7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 4 Jul 2024 23:15:33 +0200 Subject: [PATCH] web: Trigger right click when long touching area --- dist/web/source/wasm-config.js | 30 +++++++++++++++++++ plugins/builtin/source/content/ui_items.cpp | 2 +- .../content/views/view_data_processor.cpp | 2 +- .../source/content/views/view_hex_editor.cpp | 2 +- .../content/views/view_pattern_editor.cpp | 2 +- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dist/web/source/wasm-config.js b/dist/web/source/wasm-config.js index a301e847e..13908aefc 100644 --- a/dist/web/source/wasm-config.js +++ b/dist/web/source/wasm-config.js @@ -187,6 +187,36 @@ var Module = { e.preventDefault(); }, false); + // Turn long touches into right-clicks + let timer = null; + canvas.addEventListener('touchstart', event => { + timer = setTimeout(() => { + let eventArgs = { + bubbles: true, + cancelable: true, + view: window, + screenX: event.touches[0].screenX, + screenY: event.touches[0].screenY, + clientX: event.touches[0].clientX, + clientY: event.touches[0].clientY, + button: 2, + buttons: 2, + relatedTarget: event.target, + region: event.region + } + + canvas.dispatchEvent(new MouseEvent('mousedown', eventArgs)); + canvas.dispatchEvent(new MouseEvent('mouseup', eventArgs)); + }, 400); + }); + + canvas.addEventListener('touchend', event => { + if (timer) { + clearTimeout(timer); + timer = null; + } + }); + if (typeof WebGL2RenderingContext !== 'undefined') { let gl = canvas.getContext('webgl2', { stencil: true }); if (!gl) { diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index 9f8e878a7..e29b58abc 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -492,7 +492,7 @@ namespace hex::plugin::builtin { break; } - if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsItemHovered()) { + if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsItemHovered() && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { rightClickedProvider = tabProvider; RequestOpenPopup::post("ProviderMenu"); } diff --git a/plugins/builtin/source/content/views/view_data_processor.cpp b/plugins/builtin/source/content/views/view_data_processor.cpp index a97bcfb6a..f14aaa38c 100644 --- a/plugins/builtin/source/content/views/view_data_processor.cpp +++ b/plugins/builtin/source/content/views/view_data_processor.cpp @@ -597,7 +597,7 @@ namespace hex::plugin::builtin { void ViewDataProcessor::drawContextMenus(ViewDataProcessor::Workspace &workspace) { // Handle the right click context menus - if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) { + if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { // Clear selections ImNodes::ClearNodeSelection(); ImNodes::ClearLinkSelection(); diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 15631d8ff..0bbe573ea 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -629,7 +629,7 @@ namespace hex::plugin::builtin { ImGui::PopStyleVar(); // Right click menu - if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && !ImGui::IsAnyItemHovered()) + if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && !ImGui::IsAnyItemHovered() && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) RequestOpenPopup::post("hex.builtin.menu.edit"); } diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 392e1eaed..fc002d50b 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -231,7 +231,7 @@ namespace hex::plugin::builtin { m_textEditor.Render("hex.builtin.view.pattern_editor.name"_lang, textEditorSize, true); TextEditor::FindReplaceHandler *findReplaceHandler = m_textEditor.GetFindReplaceHandler(); - if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { + if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { ImGui::OpenPopup("##pattern_editor_context_menu"); }