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

fix(nui): hide mouse cursor when the css cursor property is set to none #2753

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions code/components/nui-core/include/CefOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ namespace nui
bool OVERLAY_DECL HasCursor();
bool OVERLAY_DECL HasFocus();
bool OVERLAY_DECL HasFocusKeepInput();
void OVERLAY_DECL SetCursorHidden(bool isHidden);
bool OVERLAY_DECL IsCursorHidden();
void OVERLAY_DECL GiveFocus(const std::string& frameName, bool hasFocus, bool hasCursor = false);
void OVERLAY_DECL OverrideFocus(bool hasFocus);
void OVERLAY_DECL KeepInput(bool keepInput);
Expand Down
12 changes: 12 additions & 0 deletions code/components/nui-core/src/CefInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern nui::GameInterface* g_nuiGi;

static bool g_hasFocus = false;
static bool g_hasCursor = false;
static bool g_isCursorHidden = false;
bool g_keepInput = false;
static bool g_hasOverriddenFocus = false;
extern bool g_mainUIFlag;
Expand Down Expand Up @@ -139,6 +140,16 @@ namespace nui
return g_keepInput;
}

void SetCursorHidden(bool isHidden)
{
g_isCursorHidden = isHidden;
}

bool IsCursorHidden()
{
return g_isCursorHidden;
}

void GiveFocus(const std::string& frameName, bool hasFocus, bool hasCursor)
{
if (!HasFocus() && hasFocus)
Expand All @@ -152,6 +163,7 @@ namespace nui

g_hasFocus = hasFocus;
g_hasCursor = hasCursor;
g_isCursorHidden = false;
}

void OverrideFocus(bool hasFocus)
Expand Down
8 changes: 7 additions & 1 deletion code/components/nui-core/src/NUIClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,18 @@ extern HCURSOR g_defaultCursor;

bool NUIClient::OnCursorChange(CefRefPtr<CefBrowser> browser, CefCursorHandle cursor, cef_cursor_type_t type, const CefCursorInfo& custom_cursor_info)
{
if (!cursor || type == CT_POINTER)
if (type == CT_NONE)
{
nui::SetCursorHidden(true);
}
else if (!cursor || type == CT_POINTER)
{
nui::SetCursorHidden(false);
g_nuiGi->SetHostCursor(g_defaultCursor);
}
else
{
nui::SetCursorHidden(false);
g_nuiGi->SetHostCursor(cursor);
}

Expand Down
2 changes: 1 addition & 1 deletion code/components/nui-core/src/NUIRenderCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static HookFunction initFunction([] ()
}

// are we in any situation where we need a cursor?
bool needsNuiCursor = (nui::HasCursor()) && !g_shouldHideCursor;
bool needsNuiCursor = (nui::HasCursor()) && !(nui::IsCursorHidden()) && !g_shouldHideCursor;
g_nuiGi->SetHostCursorEnabled(needsNuiCursor);

// we set the host cursor above unconditionally- this is for cases where the host cursor isn't sufficient
Expand Down
Loading