Merge pull request #743 from parkerlamb/startup_race
Prevent race condition during emulator startup (issue #702)
This commit is contained in:
commit
d081cf5f5c
|
@ -266,6 +266,8 @@ bool EmulatorWindow::Initialize() {
|
|||
|
||||
window_->Resize(1280, 720);
|
||||
|
||||
window_->DisableMainMenu();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,9 @@ int xenia_main(const std::vector<std::wstring>& args) {
|
|||
evt->Set();
|
||||
});
|
||||
|
||||
// Enable the main menu now that the emulator is properly loaded
|
||||
emulator_window->window()->EnableMainMenu();
|
||||
|
||||
// Grab path from the flag or unnamed argument.
|
||||
std::wstring path;
|
||||
if (!FLAGS_target.empty() || args.size() >= 2) {
|
||||
|
|
|
@ -641,8 +641,8 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
|
|||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
on_launch();
|
||||
main_thread_ = main_xthread->thread();
|
||||
on_launch();
|
||||
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
class Window;
|
||||
|
||||
class MenuItem {
|
||||
public:
|
||||
typedef std::unique_ptr<MenuItem, void (*)(MenuItem*)> MenuItemPtr;
|
||||
|
@ -51,6 +53,9 @@ class MenuItem {
|
|||
void RemoveChild(MenuItem* child_item);
|
||||
MenuItem* child(size_t index);
|
||||
|
||||
virtual void EnableMenuItem(Window& window) = 0;
|
||||
virtual void DisableMenuItem(Window& window) = 0;
|
||||
|
||||
protected:
|
||||
MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
|
||||
std::function<void()> callback);
|
||||
|
|
|
@ -44,6 +44,9 @@ class Window {
|
|||
OnMainMenuChange();
|
||||
}
|
||||
|
||||
virtual void EnableMainMenu() = 0;
|
||||
virtual void DisableMainMenu() = 0;
|
||||
|
||||
const std::wstring& title() const { return title_; }
|
||||
virtual bool set_title(const std::wstring& title) {
|
||||
if (title == title_) {
|
||||
|
|
|
@ -174,6 +174,18 @@ void Win32Window::OnClose() {
|
|||
super::OnClose();
|
||||
}
|
||||
|
||||
void Win32Window::EnableMainMenu() {
|
||||
if (main_menu_) {
|
||||
main_menu_->EnableMenuItem(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void Win32Window::DisableMainMenu() {
|
||||
if (main_menu_) {
|
||||
main_menu_->DisableMenuItem(*this);
|
||||
}
|
||||
}
|
||||
|
||||
bool Win32Window::set_title(const std::wstring& title) {
|
||||
if (!super::set_title(title)) {
|
||||
return false;
|
||||
|
@ -698,6 +710,22 @@ Win32MenuItem::~Win32MenuItem() {
|
|||
}
|
||||
}
|
||||
|
||||
void Win32MenuItem::EnableMenuItem(Window& window) {
|
||||
int i = 0;
|
||||
for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) {
|
||||
::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_ENABLED);
|
||||
}
|
||||
DrawMenuBar((HWND)window.native_handle());
|
||||
}
|
||||
|
||||
void Win32MenuItem::DisableMenuItem(Window& window) {
|
||||
int i = 0;
|
||||
for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) {
|
||||
::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_GRAYED);
|
||||
}
|
||||
DrawMenuBar((HWND)window.native_handle());
|
||||
}
|
||||
|
||||
void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) {
|
||||
auto child_item = static_cast<Win32MenuItem*>(generic_child_item);
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ class Win32Window : public Window {
|
|||
NativeWindowHandle native_handle() const override { return hwnd_; }
|
||||
HWND hwnd() const { return hwnd_; }
|
||||
|
||||
void EnableMainMenu() override;
|
||||
void DisableMainMenu() override;
|
||||
|
||||
bool set_title(const std::wstring& title) override;
|
||||
|
||||
bool SetIcon(const void* buffer, size_t size) override;
|
||||
|
@ -92,6 +95,9 @@ class Win32MenuItem : public MenuItem {
|
|||
|
||||
HMENU handle() { return handle_; }
|
||||
|
||||
void EnableMenuItem(Window& window) override;
|
||||
void DisableMenuItem(Window& window) override;
|
||||
|
||||
using MenuItem::OnSelected;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue