Skip to content

Commit

Permalink
Don't update selection when folder window in background; fix #79
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jun 19, 2022
1 parent f7bf37c commit 5a5be0f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
14 changes: 11 additions & 3 deletions src/FolderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ void FolderWindow::onActivate(WORD state, HWND prevWindow) {
activateOnShiftRelease = GetKeyState(VK_SHIFT) < 0;
checkHR(shellView->UIActivate(SVUIA_ACTIVATE_FOCUS));
}
if (updateSelectionOnActivate) {
selectionChanged();
updateSelectionOnActivate = false;
}
}
}

Expand Down Expand Up @@ -301,9 +305,13 @@ STDMETHODIMP FolderWindow::OnDefaultCommand(IShellView *) {
STDMETHODIMP FolderWindow::OnStateChange(IShellView *, ULONG change) {
if (change == CDBOSC_SELCHANGE) {
if (!ignoreNextSelection) {
// TODO this can hang the browser and should really be done asynchronously with a message
// but that adds other complication
selectionChanged();
if (GetActiveWindow() != hwnd) {
// this could happen when dragging a file. don't try to create any windows yet
updateSelectionOnActivate = true;
} else {
selectionChanged();
updateSelectionOnActivate = false;
}
}
ignoreNextSelection = false;
}
Expand Down
1 change: 1 addition & 0 deletions src/FolderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class FolderWindow : public ItemWindow, public IServiceProvider, public ICommDlg

// jank flags
bool ignoreNextSelection = false;
bool updateSelectionOnActivate = false;
bool activateOnShiftRelease = false;
};

Expand Down
8 changes: 4 additions & 4 deletions src/ItemWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ bool ItemWindow::create(RECT rect, int showCommand) {
else if (child)
owner = GetWindowOwner(child->hwnd);
else
owner = createChainOwner();
owner = createChainOwner(showCommand);

HWND createHwnd = CreateWindow(
className(), title,
Expand All @@ -191,10 +191,10 @@ bool ItemWindow::create(RECT rect, int showCommand) {
return true;
}

HWND ItemWindow::createChainOwner() {
HWND ItemWindow::createChainOwner(int showCommand) {
HWND window = CreateWindow(CHAIN_OWNER_CLASS, nullptr, WS_POPUP, 0, 0, 0, 0,
nullptr, nullptr, GetModuleHandle(nullptr), 0); // user data stores num owned windows
ShowWindow(window, SW_SHOWNORMAL); // show in taskbar
ShowWindow(window, showCommand); // show in taskbar
return window;
}

Expand Down Expand Up @@ -724,7 +724,7 @@ void ItemWindow::detachFromParent() {
clearParent();
ShowWindow(parentButton, SW_SHOW);
HWND prevOwner = GetWindowOwner(hwnd);
HWND owner = createChainOwner();
HWND owner = createChainOwner(SW_SHOWNORMAL);
int numChildren = 0;
for (ItemWindow *next = this; next != nullptr; next = next->child) {
SetWindowLongPtr(next->hwnd, GWLP_HWNDPARENT, (LONG_PTR)owner);
Expand Down
2 changes: 1 addition & 1 deletion src/ItemWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ItemWindow : public IUnknownImpl, public IDropSource, public IDropTarget {
private:
virtual const wchar_t * className() = 0;

HWND createChainOwner();
HWND createChainOwner(int showCommand);

void windowRectChanged();
void bringGroupToFront();
Expand Down

0 comments on commit 5a5be0f

Please sign in to comment.