Skip to content

Commit 985d974

Browse files
committed
fix per 3e8a499
1 parent 3e8a499 commit 985d974

File tree

2 files changed

+71
-46
lines changed

2 files changed

+71
-46
lines changed

src/tabbookmark.cc

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,6 @@ bool IsNeedKeep(int tab_count, KeepTabTrigger trigger) {
4343
return keep_tab;
4444
}
4545

46-
bool IsFullScreen(HWND hwnd) {
47-
RECT window_rect;
48-
if (!GetWindowRect(hwnd, &window_rect)) {
49-
return false;
50-
}
51-
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
52-
if (!monitor) {
53-
return false;
54-
}
55-
MONITORINFO mi = {sizeof(mi)};
56-
if (!GetMonitorInfoW(monitor, &mi)) {
57-
return false;
58-
}
59-
const bool is_full_screen = (window_rect.left == mi.rcMonitor.left &&
60-
window_rect.top == mi.rcMonitor.top &&
61-
window_rect.right == mi.rcMonitor.right &&
62-
window_rect.bottom == mi.rcMonitor.bottom);
63-
return is_full_screen;
64-
}
65-
6646
// When `top_container_view` is not found, the find-in-page bar may be open
6747
// and focused. Use `IsOnFindBarPane` to check if the click occurred on the
6848
// bar. If so, return nullptr to avoid interfering with find operations
@@ -340,11 +320,16 @@ bool HandleKeepTab(WPARAM wParam) {
340320
return false;
341321
}
342322

343-
// TODO: fix pop-up cannot be closed
344323
HWND hwnd = GetForegroundWindow();
345324
const auto tab_count = FindTabCount(hwnd);
346-
if (tab_count.has_value() &&
347-
!IsNeedKeep(tab_count.value(), KeepTabTrigger::kKeyboardShortcut)) {
325+
326+
if (!tab_count.has_value()) {
327+
return false;
328+
}
329+
330+
const bool need_keep =
331+
IsNeedKeep(tab_count.value(), KeepTabTrigger::kKeyboardShortcut);
332+
if (!need_keep) {
348333
return false;
349334
}
350335

src/uia.cc

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -278,32 +278,23 @@ std::optional<int> CountClassInSubtreeRaw(
278278
return count;
279279
}
280280

281-
std::optional<TabContainer> FindTabContainerFromHwnd(
282-
const ComPtr<IUIAutomation>& automation,
283-
HWND hwnd) {
284-
auto root = GetElementFromHandle(automation, hwnd);
285-
if (!root) {
286-
return std::nullopt;
287-
}
288-
289-
if (auto c = FindFirstInSubtree(
290-
root, CreateClassCondition(automation, L"TabContainerImpl")))
291-
return TabContainer{c, L"Tab"};
292-
if (auto c = FindFirstInSubtree(
293-
root, CreateClassCondition(automation,
294-
L"VerticalUnpinnedTabContainerView"))) {
295-
return TabContainer{c, L"VerticalTabView"};
281+
bool IsWindowFullScreen(HWND hwnd) {
282+
RECT window_rect;
283+
if (!GetWindowRect(hwnd, &window_rect)) {
284+
return false;
296285
}
297-
298-
if (auto c = FindFirstInSubtreeRaw(automation, root, L"TabContainerImpl")) {
299-
return TabContainer{c, L"Tab"};
286+
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
287+
if (!monitor) {
288+
return false;
300289
}
301-
if (auto c = FindFirstInSubtreeRaw(automation, root,
302-
L"VerticalUnpinnedTabContainerView")) {
303-
return TabContainer{c, L"VerticalTabView"};
290+
MONITORINFO mi = {sizeof(mi)};
291+
if (!GetMonitorInfoW(monitor, &mi)) {
292+
return false;
304293
}
305-
306-
return std::nullopt;
294+
return window_rect.left == mi.rcMonitor.left &&
295+
window_rect.top == mi.rcMonitor.top &&
296+
window_rect.right == mi.rcMonitor.right &&
297+
window_rect.bottom == mi.rcMonitor.bottom;
307298
}
308299

309300
ComPtr<IUIAutomationElement> FindSiblingByClass(
@@ -340,6 +331,55 @@ ComPtr<IUIAutomationElement> FindSiblingByClass(
340331
return nullptr;
341332
}
342333

334+
std::optional<TabContainer> FindTabContainerFromHwnd(
335+
const ComPtr<IUIAutomation>& automation,
336+
HWND hwnd) {
337+
auto root = GetElementFromHandle(automation, hwnd);
338+
if (!root) {
339+
return std::nullopt;
340+
}
341+
342+
if (auto tab_strip = FindFirstInSubtree(
343+
root,
344+
CreateClassCondition(automation, L"TabStrip::TabDragContextImpl"))) {
345+
if (auto c =
346+
FindSiblingByClass(automation, tab_strip, L"TabContainerImpl")) {
347+
return TabContainer{c, L"Tab"};
348+
}
349+
}
350+
351+
if (auto tab_strip_region = FindFirstInSubtree(
352+
root,
353+
CreateClassCondition(automation, L"HorizontalTabStripRegionView"))) {
354+
if (auto c = FindFirstInSubtree(
355+
tab_strip_region,
356+
CreateClassCondition(automation, L"TabContainerImpl"))) {
357+
return TabContainer{c, L"Tab"};
358+
}
359+
}
360+
361+
if (auto c = FindFirstInSubtree(
362+
root, CreateClassCondition(automation,
363+
L"VerticalUnpinnedTabContainerView"))) {
364+
return TabContainer{c, L"VerticalTabView"};
365+
}
366+
367+
if (!IsWindowFullScreen(hwnd)) {
368+
return std::nullopt;
369+
}
370+
371+
if (auto c = FindFirstInSubtreeRaw(automation, root, L"TabContainerImpl")) {
372+
return TabContainer{c, L"Tab"};
373+
}
374+
375+
if (auto c = FindFirstInSubtreeRaw(automation, root,
376+
L"VerticalUnpinnedTabContainerView")) {
377+
return TabContainer{c, L"VerticalTabView"};
378+
}
379+
380+
return std::nullopt;
381+
}
382+
343383
ComPtr<IUIAutomationElement> FindParentByClass(
344384
const ComPtr<IUIAutomation>& automation,
345385
const ComPtr<IUIAutomationElement>& element,

0 commit comments

Comments
 (0)