Skip to content

Commit

Permalink
Shell: Make reload style sheet key combination low priority so that V…
Browse files Browse the repository at this point in the history
…isualTests can do a full reload with the same shortcut key (Ctrl+R).
  • Loading branch information
mikke89 committed Jul 19, 2021
1 parent e919f10 commit 34c4ea4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
19 changes: 18 additions & 1 deletion Samples/shell/src/macosx/InputMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <macosx/InputMacOSX.h>
#include <RmlUi/Core/Context.h>
#include <RmlUi/Core/ElementDocument.h>
#include <RmlUi/Core/Input.h>
#include <RmlUi/Debugger.h>
#include <Shell.h>
Expand Down Expand Up @@ -126,12 +127,28 @@ OSStatus InputMacOSX::EventHandler(EventHandlerCallRef next_handler, EventRef ev
break;
}

bool propagates = false;

if (key_identifier != Rml::Input::KI_UNKNOWN)
context->ProcessKeyDown(key_identifier, key_modifier_state);
propagates = context->ProcessKeyDown(key_identifier, key_modifier_state);

Rml::Character character = GetCharacterCode(key_identifier, key_modifier_state);
if (character != Rml::Character::Null && !(key_modifier_state & Rml::Input::KM_CTRL))
context->ProcessTextInput(character);

// Check for low-priority key combinations that are only activated if not already consumed by the context.
if (propagates && key_identifier == Rml::Input::KI_R && key_modifier_state & Rml::Input::KM_CTRL)
{
for (int i = 0; i < context->GetNumDocuments(); i++)
{
Rml::ElementDocument* document = context->GetDocument(i);
const Rml::String& src = document->GetSourceURL();
if (src.size() > 4 && src.substr(src.size() - 4) == ".rml")
{
document->ReloadStyleSheet();
}
}
}
}
}
break;
Expand Down
29 changes: 17 additions & 12 deletions Samples/shell/src/win32/InputWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ void InputWin32::ProcessWindowsEvent(HWND window, UINT message, WPARAM w_param,
case WM_KEYDOWN:
{
Rml::Input::KeyIdentifier key_identifier = key_identifier_map[w_param];
int key_modifier_state = GetKeyModifierState();
const int key_modifier_state = GetKeyModifierState();

// Toggle debugger and set 'dp'-ratio ctrl +/-/0 keys
// Toggle debugger and set 'dp'-ratio ctrl +/-/0 keys. These global shortcuts take priority.
if (key_identifier == Rml::Input::KI_F8)
{
Rml::Debugger::SetVisible(!Rml::Debugger::IsVisible());
Expand All @@ -122,22 +122,27 @@ void InputWin32::ProcessWindowsEvent(HWND window, UINT message, WPARAM w_param,
const float new_dp_ratio = Rml::Math::Min(context->GetDensityIndependentPixelRatio() * 1.2f, 2.5f);
context->SetDensityIndependentPixelRatio(new_dp_ratio);
}
else if (key_identifier == Rml::Input::KI_R && key_modifier_state & Rml::Input::KM_CTRL)
else
{
for (int i = 0; i < context->GetNumDocuments(); i++)
// No global shortcuts detected, submit the key to the context.
if (context->ProcessKeyDown(key_identifier, key_modifier_state))
{
Rml::ElementDocument* document = context->GetDocument(i);
const Rml::String& src = document->GetSourceURL();
if (src.size() > 4 && src.substr(src.size() - 4) == ".rml")
// The key was not consumed, check for shortcuts that are of lower priority.
if (key_identifier == Rml::Input::KI_R && key_modifier_state & Rml::Input::KM_CTRL)
{
document->ReloadStyleSheet();
for (int i = 0; i < context->GetNumDocuments(); i++)
{
Rml::ElementDocument* document = context->GetDocument(i);
const Rml::String& src = document->GetSourceURL();
if (src.size() > 4 && src.substr(src.size() - 4) == ".rml")
{
document->ReloadStyleSheet();
}
}

}
}
}
else
{
context->ProcessKeyDown(key_identifier, key_modifier_state);
}
}
break;

Expand Down
32 changes: 18 additions & 14 deletions Samples/shell/src/x11/InputX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,32 +159,36 @@ void InputX11::ProcessXEvent(Display* display, const XEvent& event)

const int key_modifier_state = GetKeyModifierState(event.xkey.state);

// Check for special key combinations
// Check for special key combinations.
if (key_identifier == Rml::Input::KI_F8)
{
Rml::Debugger::SetVisible(!Rml::Debugger::IsVisible());
}
else if (key_identifier == Rml::Input::KI_R && key_modifier_state & Rml::Input::KM_CTRL)
{
for (int i = 0; i < context->GetNumDocuments(); i++)
{
Rml::ElementDocument* document = context->GetDocument(i);
const Rml::String& src = document->GetSourceURL();
if (src.size() > 4 && src.substr(src.size() - 4) == ".rml")
{
document->ReloadStyleSheet();
}
}
}
else
{
bool propagates = false;

// No special shortcut, pass the key on to the context.
if (key_identifier != Rml::Input::KI_UNKNOWN)
context->ProcessKeyDown(key_identifier, key_modifier_state);
propagates = context->ProcessKeyDown(key_identifier, key_modifier_state);

Rml::Character character = GetCharacterCode(key_identifier, key_modifier_state);
if (character != Rml::Character::Null && !(key_modifier_state & Rml::Input::KM_CTRL))
context->ProcessTextInput(character);

// Check for low-priority key combinations that are only activated if not already consumed by the context.
if (propagates && key_identifier == Rml::Input::KI_R && key_modifier_state & Rml::Input::KM_CTRL)
{
for (int i = 0; i < context->GetNumDocuments(); i++)
{
Rml::ElementDocument* document = context->GetDocument(i);
const Rml::String& src = document->GetSourceURL();
if (src.size() > 4 && src.substr(src.size() - 4) == ".rml")
{
document->ReloadStyleSheet();
}
}
}
}
}
break;
Expand Down

0 comments on commit 34c4ea4

Please sign in to comment.