diff --git a/binaries/data/mods/_test.gui/gui/hotkey.js b/binaries/data/mods/_test.gui/gui/hotkey/hotkey.js similarity index 100% rename from binaries/data/mods/_test.gui/gui/hotkey.js rename to binaries/data/mods/_test.gui/gui/hotkey/hotkey.js diff --git a/binaries/data/mods/_test.gui/gui/hotkey.xml b/binaries/data/mods/_test.gui/gui/hotkey/hotkey.xml similarity index 100% rename from binaries/data/mods/_test.gui/gui/hotkey.xml rename to binaries/data/mods/_test.gui/gui/hotkey/hotkey.xml diff --git a/binaries/data/mods/_test.gui/gui/page_hotkey.xml b/binaries/data/mods/_test.gui/gui/hotkey/page_hotkey.xml similarity index 100% rename from binaries/data/mods/_test.gui/gui/page_hotkey.xml rename to binaries/data/mods/_test.gui/gui/hotkey/page_hotkey.xml diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 91fadae3c6..3d98de965e 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -73,7 +73,6 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev) if (m_GlobalHotkeys.count(hotkey) && ev->ev.type == SDL_HOTKEYDOWN) { - HotkeyInputHandler(ev); ret = IN_HANDLED; JSContext* cx = m_ScriptInterface->GetContext(); diff --git a/source/gui/tests/test_GuiManager.h b/source/gui/tests/test_GuiManager.h index edcf2c2bc5..efb789257d 100755 --- a/source/gui/tests/test_GuiManager.h +++ b/source/gui/tests/test_GuiManager.h @@ -55,17 +55,20 @@ public: void test_hotkeysState() { - // Load up a fake test hotkey when pressing 'a'. const char* test_hotkey_name = "hotkey.test"; g_ConfigDB.SetValueString(CFG_USER, test_hotkey_name, "A"); LoadHotkeys(); // Load up a test page. - JS::RootedValue val(g_GUI->GetScriptInterface()->GetContext()); - g_GUI->GetScriptInterface()->Eval("({})", &val); - std::shared_ptr data = g_GUI->GetScriptInterface()->WriteStructuredClone(JS::NullHandleValue); - g_GUI->PushPage(L"page_hotkey.xml", data, JS::UndefinedHandleValue); + const ScriptInterface& scriptInterface = *(g_GUI->GetScriptInterface()); + JSContext* cx = scriptInterface.GetContext(); + JSAutoRequest rq(cx); + JS::RootedValue val(cx); + scriptInterface.CreateObject(cx, &val); + + std::shared_ptr data = scriptInterface.WriteStructuredClone(JS::NullHandleValue); + g_GUI->PushPage(L"hotkey/page_hotkey.xml", data, JS::UndefinedHandleValue); // Press 'a'. SDL_Event_ hotkeyNotification; @@ -79,16 +82,22 @@ public: while (in_poll_event(&ev)) in_dispatch_event(&ev); + const ScriptInterface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface()); + JSContext* pcx = pageScriptInterface.GetContext(); + JSAutoRequest pagerq(pcx); + JS::RootedValue global(pcx, pageScriptInterface.GetGlobalObject()); + // Ensure that our hotkey state was synchronised with the event itself. bool hotkey_pressed_value = false; - JS::RootedValue js_hotkey_pressed_value(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext()); - g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_before", &js_hotkey_pressed_value); - g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value); + JS::RootedValue js_hotkey_pressed_value(pageScriptInterface.GetContext()); + + pageScriptInterface.GetProperty(global, "state_before", &js_hotkey_pressed_value); + ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); TS_ASSERT_EQUALS(hotkey_pressed_value, true); hotkey_pressed_value = false; - g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_after", &js_hotkey_pressed_value); - g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value); + pageScriptInterface.GetProperty(global, "state_after", &js_hotkey_pressed_value); + ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); TS_ASSERT_EQUALS(hotkey_pressed_value, true); hotkeyNotification.ev.type = SDL_KEYUP; @@ -97,13 +106,13 @@ public: in_dispatch_event(&ev); hotkey_pressed_value = true; - g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_before", &js_hotkey_pressed_value); - g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value); + pageScriptInterface.GetProperty(global, "state_before", &js_hotkey_pressed_value); + ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); TS_ASSERT_EQUALS(hotkey_pressed_value, false); hotkey_pressed_value = true; - g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_after", &js_hotkey_pressed_value); - g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value); + pageScriptInterface.GetProperty(global, "state_after", &js_hotkey_pressed_value); + ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); TS_ASSERT_EQUALS(hotkey_pressed_value, false); }