Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hiro: Defer menubar updates on Windows to reduce flicker. #196

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions hiro/windows/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace hiro {

static auto Application_keyboardProc(HWND, UINT, WPARAM, LPARAM) -> bool;
static auto Application_processDeferred() -> void;
static auto Application_processDialogMessage(MSG&) -> void;
static auto CALLBACK Window_windowProc(HWND, UINT, WPARAM, LPARAM) -> LRESULT;

Expand Down Expand Up @@ -44,6 +45,14 @@ auto pApplication::processEvents() -> void {
Application_processDialogMessage(msg);
}
}
Application_processDeferred();
}

auto Application_processDeferred() -> void {
for (auto menu : pApplication::state().staleMenus) {
menu->_updateDeferred();
}
pApplication::state().staleMenus.reset();
}

auto Application_processDialogMessage(MSG& msg) -> void {
Expand Down
1 change: 1 addition & 0 deletions hiro/windows/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct pApplication {
int modalCount = 0; //number of modal loops
Timer modalTimer; //to run Application during modal events
pToolTip* toolTip = nullptr; //active toolTip
vector<pMenuBar*> staleMenus; //menubars to update
};
static auto state() -> State&;
};
Expand Down
15 changes: 15 additions & 0 deletions hiro/windows/menu-bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ auto pMenuBar::construct() -> void {
}

auto pMenuBar::destruct() -> void {
pApplication::state().staleMenus.removeByValue(this);
if(hmenu) { DestroyMenu(hmenu); hmenu = nullptr; }
if(auto parent = _parent()) {
SetMenu(parent->hwnd, nullptr);
Expand Down Expand Up @@ -44,6 +45,20 @@ auto pMenuBar::_parent() -> maybe<pWindow&> {
}

auto pMenuBar::_update() -> void {
bool updateNow = false;
if(auto parent = _parent()) {
updateNow = GetMenu(parent->hwnd) == nullptr;
}

if (updateNow) {
_updateDeferred();
} else {
pApplication::state().staleMenus.removeByValue(this);
pApplication::state().staleMenus.append(this);
}
}

auto pMenuBar::_updateDeferred() -> void {
if(hmenu) DestroyMenu(hmenu);
hmenu = CreateMenu();

Expand Down
3 changes: 2 additions & 1 deletion hiro/windows/menu-bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ struct pMenuBar : pObject {

auto _parent() -> maybe<pWindow&>;
auto _update() -> void;

auto _updateDeferred() -> void;

HMENU hmenu = 0;
vector<wObject> objects;
};
Expand Down