Skip to content

Commit

Permalink
Use auto-visibility on UI-assigned keyboards & fix active UI input wi…
Browse files Browse the repository at this point in the history
…dget tracking not clearing when keyboard window is hidden
  • Loading branch information
elvissteinjr committed Oct 3, 2022
1 parent 47bd9c6 commit f95e56e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/DesktopPlusUI/UIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ void UIManager::HandleIPCMessage(const MSG& msg, bool handle_delayed)
int overlay_id = (msg.lParam != -1) ? (int)msg.lParam : m_VRKeyboard.GetWindow().GetAssignedOverlayID();

//Only set auto-visibility if source overlay is desktop/window capture (avoid overriding browser auto-visible keyboards)
if (OverlayManager::Get().GetConfigData((unsigned int)overlay_id).ConfigInt[configid_int_overlay_capture_source] <= ovrl_capsource_winrt_capture)
if ( (overlay_id >= 0) && (OverlayManager::Get().GetConfigData((unsigned int)overlay_id).ConfigInt[configid_int_overlay_capture_source] <= ovrl_capsource_winrt_capture) )
{
m_VRKeyboard.GetWindow().SetAutoVisibility(overlay_id, (msg.lParam != -1));
}
Expand Down
10 changes: 6 additions & 4 deletions src/DesktopPlusUI/VRKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ void VRKeyboard::OnImGuiNewFrame()
if ( (!m_KeyboardHiddenLastFrame) && ( (m_InputTarget != kbdtarget_ui) || (!m_WindowKeyboard.IsVisible()) ) )
{
m_InputTarget = kbdtarget_ui;
m_WindowKeyboard.Show();

bool do_assign_to_ui = false;
int assigned_id = m_WindowKeyboard.GetAssignedOverlayID();
Expand All @@ -563,8 +562,10 @@ void VRKeyboard::OnImGuiNewFrame()

if (do_assign_to_ui)
{
m_WindowKeyboard.SetAssignedOverlayID(-2);
m_WindowKeyboard.SetAutoVisibility(-2, true);
}

m_WindowKeyboard.Show();
}
}
else if (m_WindowKeyboard.IsVisible())
Expand All @@ -580,10 +581,10 @@ void VRKeyboard::OnImGuiNewFrame()
m_WindowKeyboard.Show(); //Show() updates window title
}

//If keyboard is visible for the UI, assign to global
//If keyboard is visible for the UI, turn off auto-visibility
if (assigned_id == -2)
{
m_WindowKeyboard.SetAssignedOverlayID(-1);
m_WindowKeyboard.SetAutoVisibility(-2, false);
}

//Check if overlay target should be used
Expand Down Expand Up @@ -627,6 +628,7 @@ void VRKeyboard::OnWindowHidden()
if (io.WantTextInput)
{
ImGui::ClearActiveID();
m_ActiveInputText = 0;
io.WantTextInput = false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/DesktopPlusUI/WindowKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ void WindowKeyboard::Hide(bool skip_fade)
UIManager::Get()->GetVRKeyboard().OnWindowHidden();
}

bool WindowKeyboard::SetAutoVisibility(unsigned int overlay_id, bool show)
bool WindowKeyboard::SetAutoVisibility(int assigned_overlay_id, bool show)
{
if (show)
{
if (!IsVisible())
{
SetAssignedOverlayID(overlay_id);
SetAssignedOverlayID(assigned_overlay_id);
m_IsAutoVisible = true;

//This will not have a smooth transition if there was another auto-visible keyboard right before this, but let's skip the effort for that for now
Expand All @@ -217,7 +217,7 @@ bool WindowKeyboard::SetAutoVisibility(unsigned int overlay_id, bool show)
return true;
}
}
else if ( (m_IsAutoVisible) && (GetAssignedOverlayID() == overlay_id) )
else if ( (m_IsAutoVisible) && (GetAssignedOverlayID() == assigned_overlay_id) )
{
SetAssignedOverlayID(-1);
Hide();
Expand Down
2 changes: 1 addition & 1 deletion src/DesktopPlusUI/WindowKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WindowKeyboard : public FloatingWindow

virtual void Show(bool skip_fade = false);
virtual void Hide(bool skip_fade = false);
bool SetAutoVisibility(unsigned int overlay_id, bool show); //Returns true on success
bool SetAutoVisibility(int assigned_overlay_id, bool show); //Returns true on success
virtual vr::VROverlayHandle_t GetOverlayHandle() const;
virtual void RebaseTransform();
virtual void ResetTransform(FloatingWindowOverlayStateID state_id);
Expand Down
2 changes: 1 addition & 1 deletion src/DesktopPlusUI/WindowSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ void WindowSettings::UpdatePageMainCatInput()
//Hide currently auto-visible keyboard if it's shown for a browser overlay
int overlay_id = vr_keyboard.GetWindow().GetAssignedOverlayID();

if (OverlayManager::Get().GetConfigData((unsigned int)overlay_id).ConfigInt[configid_int_overlay_capture_source] == ovrl_capsource_browser)
if ( (overlay_id >= 0) && (OverlayManager::Get().GetConfigData((unsigned int)overlay_id).ConfigInt[configid_int_overlay_capture_source] == ovrl_capsource_browser) )
{
vr_keyboard.GetWindow().SetAutoVisibility(overlay_id, false);
}
Expand Down

0 comments on commit f95e56e

Please sign in to comment.