Skip to content

Commit

Permalink
web: Trigger right click when long touching area
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jul 4, 2024
1 parent c26eccf commit 9aaf6f3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
30 changes: 30 additions & 0 deletions dist/web/source/wasm-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/builtin/source/content/ui_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion plugins/builtin/source/content/views/view_hex_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down

0 comments on commit 9aaf6f3

Please sign in to comment.