Skip to content

Commit 27a4fce

Browse files
committed
feat: keep_last_tab now works when clicking the close button
1 parent bb34fab commit 27a4fce

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ English | [简体中文](README_CN.md)
66
## Features
77
* Double-click to close tab.
88
* Right-click to close tab (hold Shift to show the original menu).
9-
* Preserve the last tab (prevent the browser from closing when the last tab is closed; clicking the close button will not work).
9+
* Preserve the last tab (prevent the browser from closing when the last tab is closed).
1010
* Use the mouse wheel to switch tabs when hovering over the tab bar.
1111
* Use the mouse wheel to switch tabs when holding the right mouse button.
1212
* Create new tab to opens the contents entered in address bar (can be configured to open in foreground or background).

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## 功能
77
- 双击关闭标签页。
88
- 右键关闭标签页(按住 Shift 弹出原有菜单)。
9-
- 保留最后标签页(防止关闭最后一个标签页时关闭浏览器,点关闭按钮不行)。
9+
- 保留最后标签页(防止关闭最后一个标签页时关闭浏览器)。
1010
- 鼠标悬停标签栏时使用滚轮切换标签页。
1111
- 按住右键时使用滚轮切换标签页。
1212
- 新建标签页打开地址栏输入的内容(可配置前台或后台打开)。

src/chrome++.ini

-120 Bytes
Binary file not shown.

src/tabbookmark.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,31 @@ bool HandleMiddleClick(PMOUSEHOOKSTRUCT pmouse) {
173173
return false;
174174
}
175175

176+
bool HandleCloseButton(PMOUSEHOOKSTRUCT pmouse) {
177+
if (!config.IsKeepLastTab()) {
178+
return false;
179+
}
180+
181+
POINT pt = pmouse->pt;
182+
HWND hwnd = WindowFromPoint(pt);
183+
NodePtr top_container_view = HandleFindBar(hwnd, pt);
184+
if (!top_container_view) {
185+
return false;
186+
}
187+
188+
if (!IsOnOneTab(top_container_view, pt) ||
189+
!IsOnCloseButton(top_container_view, pt)) {
190+
return false;
191+
}
192+
193+
if (!IsNeedKeep(top_container_view)) {
194+
return false;
195+
}
196+
ExecuteCommand(IDC_NEW_TAB, hwnd);
197+
ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd);
198+
return true;
199+
}
200+
176201
// Check if mouse movement is a drag operation.
177202
// Since `MouseProc` hook doesn't handle any drag-related events,
178203
// this detection can return early to avoid interference.
@@ -254,6 +279,8 @@ LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
254279
break;
255280
} else if (HandleBookmark(pmouse)) {
256281
handled = true;
282+
} else if (HandleCloseButton(pmouse)) {
283+
handled = true;
257284
}
258285
break;
259286
case WM_RBUTTONUP:

0 commit comments

Comments
 (0)