Skip to content

Commit

Permalink
fix: quick clicking on close button triggers double-click close command
Browse files Browse the repository at this point in the history
Since the close button is a child element of the page tab, quickly clicking the close button can trigger `HandleDoubleClick`, leading to incorrect command execution. The correct behavior should be to revert to the browser's original operation behavior. This commit adds a rough `IsOnCloseButton` check, which simply traverses push buttons and checks if the mouse is over it. It cannot be used alone to accurately identify the close button, so it is recommended to call it in conjunction with `IsOnOneTab`.
  • Loading branch information
Bush2021 committed Aug 2, 2024
1 parent 8a86f66 commit 085aca9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/iaccessible.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,24 @@ bool IsOnDialog(HWND hwnd, POINT pt) {
return flag;
}

// Whether the mouse is on the close button of a tab.
// Should be used together with `IsOnOneTab` to search the close button.
bool IsOnCloseButton(NodePtr top, POINT pt) {
bool flag = false;
TraversalAccessible(
top,
[&pt, &flag](NodePtr child) {
if (GetAccessibleRole(child) == ROLE_SYSTEM_PUSHBUTTON) {
GetAccessibleSize(child, [&pt, &flag](RECT rect) {
if (PtInRect(&rect, pt)) {
flag = true;
}
});
}
return flag;
},
true); // raw_traversal
return flag;
}

#endif // IACCESSIBLE_H_
20 changes: 10 additions & 10 deletions src/tabbookmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ int HandleDoubleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) {
}

bool is_on_one_tab = IsOnOneTab(top_container_view, pmouse->pt);
bool is_on_close_button = IsOnCloseButton(top_container_view, pmouse->pt);
bool is_only_one_tab = IsOnlyOneTab(top_container_view);

if (is_on_one_tab) {
if (is_only_one_tab) {
ExecuteCommand(IDC_NEW_TAB, hwnd);
ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd);
} else {
ExecuteCommand(IDC_CLOSE_TAB, hwnd);
}
return 1;
if (!is_on_one_tab || is_on_close_button) {
return 0;
}
return 0;
if (is_only_one_tab) {
ExecuteCommand(IDC_NEW_TAB, hwnd);
ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd);
} else {
ExecuteCommand(IDC_CLOSE_TAB, hwnd);
}
return 1;
}

// Right-click to close tab (Hold Shift to show the original menu).
Expand Down

0 comments on commit 085aca9

Please sign in to comment.