Skip to content

Commit

Permalink
chore: refine logic for tab preservation during fullscreen mode
Browse files Browse the repository at this point in the history
Co-authored-by: Bush2021 <[email protected]>
  • Loading branch information
Ritchie1108 and Bush2021 committed Apr 9, 2024
1 parent 7244c9f commit edb99af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/tabbookmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool IsNeedKeep(HWND hwnd, int32_t* ptr = nullptr) {

NodePtr top_container_view = GetTopContainerView(hwnd);
auto tab_count = GetTabCount(top_container_view);
bool is_only_one_tab = tab_count <= 1;
bool is_only_one_tab = (tab_count > 0 && tab_count <= 1);

static auto last_closing_tab_tick = GetTickCount64();
auto tick = GetTickCount64() - last_closing_tab_tick;
Expand All @@ -24,9 +24,6 @@ bool IsNeedKeep(HWND hwnd, int32_t* ptr = nullptr) {
if (tick > 0 && tick <= 250 && tab_count <= 2) {
is_only_one_tab = true;
}
if (tab_count == 0) { // 处理全屏等状态
is_only_one_tab = false;
}

keep_tab = is_only_one_tab;

Expand Down Expand Up @@ -286,6 +283,35 @@ LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
return CallNextHookEx(mouse_hook, nCode, wParam, lParam);
}

bool handleTabPreserve(WPARAM wParam) {
bool is_full_screen = false;
if (!GetTopContainerView(GetForegroundWindow())) {
is_full_screen = true;
}

bool keep_tab = false;

if (wParam == 'W' && IsPressed(VK_CONTROL) && !IsPressed(VK_SHIFT)) {
keep_tab = IsNeedKeep(GetForegroundWindow());
}
if (wParam == VK_F4 && IsPressed(VK_CONTROL)) {
keep_tab = IsNeedKeep(GetForegroundWindow());
}

if (is_full_screen) {
ExecuteCommand(IDC_FULLSCREEN);
}

if (keep_tab) {
ExecuteCommand(IDC_NEW_TAB);
ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
ExecuteCommand(IDC_CLOSE_TAB);
return 1;
}

return 0;
}

bool IsNeedOpenUrlInNewTab() {
bool open_url_ing = false;

Expand All @@ -305,21 +331,8 @@ HHOOK keyboard_hook = nullptr;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION && !(lParam & 0x80000000)) // pressed
{
bool keep_tab = false;

if (wParam == 'W' && IsPressed(VK_CONTROL) && !IsPressed(VK_SHIFT)) {
keep_tab = IsNeedKeep(GetForegroundWindow());
}
if (wParam == VK_F4 && IsPressed(VK_CONTROL)) {
keep_tab = IsNeedKeep(GetForegroundWindow());
}

if (keep_tab) {
ExecuteCommand(IDC_NEW_TAB);
ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
ExecuteCommand(IDC_CLOSE_TAB);
return 1;
}
if (handleTabPreserve(wParam)) {}

bool open_url_ing = false;

Expand Down
1 change: 1 addition & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void DebugLog(const wchar_t* format, ...) {
#define IDC_SELECT_TAB_6 34024
#define IDC_SELECT_TAB_7 34025
#define IDC_SELECT_LAST_TAB 34026
#define IDC_FULLSCREEN 34030
#define IDC_SHOW_TRANSLATE 35009

#define IDC_UPGRADE_DIALOG 40024
Expand Down

0 comments on commit edb99af

Please sign in to comment.