diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index e02ff7fe51e..26c37d2000e 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -943,6 +943,11 @@ extern void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn); */ extern void GHOST_UseWindowFocus(bool use_focus); +/** + * Focus and raise windows on mouse hover. + */ +extern void GHOST_SetAutoFocus(bool auto_focus); + /** * If window was opened using native pixel size, it returns scaling factor. */ diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index edaeca1e159..e53026107e7 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -332,6 +332,11 @@ class GHOST_ISystem { */ virtual void useWindowFocus(const bool use_focus) = 0; + /** + * Focus and raise windows on mouse hover. + */ + virtual void setAutoFocus(const bool auto_focus) = 0; + /** * Get the Window under the cursor. * \param x: The x-coordinate of the cursor. diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index 4da9392d4d0..feba10752e2 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -918,6 +918,12 @@ void GHOST_UseWindowFocus(bool use_focus) return system->useWindowFocus(use_focus); } +void GHOST_SetAutoFocus(bool auto_focus) +{ + GHOST_ISystem *system = GHOST_ISystem::getSystem(); + system->setAutoFocus(auto_focus); +} + float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp index 670ede35989..2830c621215 100644 --- a/intern/ghost/intern/GHOST_System.cpp +++ b/intern/ghost/intern/GHOST_System.cpp @@ -23,6 +23,7 @@ GHOST_System::GHOST_System() : m_nativePixel(false), m_windowFocus(true), + m_autoFocus(true), m_displayManager(nullptr), m_timerManager(nullptr), m_windowManager(nullptr), @@ -412,6 +413,11 @@ void GHOST_System::useWindowFocus(const bool use_focus) m_windowFocus = use_focus; } +void GHOST_System::setAutoFocus(const bool auto_focus) +{ + m_autoFocus = auto_focus; +} + bool GHOST_System::supportsCursorWarp() { return true; diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index 924a4bff790..db28603c289 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -160,6 +160,12 @@ class GHOST_System : public GHOST_ISystem { bool m_windowFocus; + /** + * Focus and raise windows on mouse hover. + */ + void setAutoFocus(const bool auto_focus); + bool m_autoFocus; + /** * Get the Window under the cursor. * \param x: The x-coordinate of the cursor. diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index eb67d16d06f..b66c59038af 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -1828,10 +1828,13 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, uint msg, WPARAM wParam, if (!window->m_mousePresent) { WINTAB_PRINTF("HWND %p mouse enter\n", window->getHWND()); TRACKMOUSEEVENT tme = {sizeof(tme)}; - /* Request WM_MOUSELEAVE message when the cursor leaves the client area, and - * WM_MOUSEHOVER message after 50ms when in the client area. */ - tme.dwFlags = TME_LEAVE | TME_HOVER; - tme.dwHoverTime = 50; + /* Request WM_MOUSELEAVE message when the cursor leaves the client area. */ + tme.dwFlags = TME_LEAVE; + if (system->m_autoFocus) { + /* Request WM_MOUSEHOVER message after 100ms when in the client area. */ + tme.dwFlags |= TME_HOVER; + tme.dwHoverTime = 100; + } tme.hwndTrack = hwnd; TrackMouseEvent(&tme); window->m_mousePresent = true; diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index 5b1a17a0ac6..5ecf4c59ed8 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -20,6 +20,7 @@ set(INC ../../python ../../render ../../windowmanager + ../../../../intern/ghost ../../../../intern/guardedalloc ../../bmesh # RNA_prototypes.h diff --git a/source/blender/editors/interface/interface_handlers.cc b/source/blender/editors/interface/interface_handlers.cc index bca5095a190..093363153dc 100644 --- a/source/blender/editors/interface/interface_handlers.cc +++ b/source/blender/editors/interface/interface_handlers.cc @@ -47,6 +47,8 @@ #include "BKE_tracking.h" #include "BKE_unit.h" +#include "GHOST_C-api.h" + #include "IMB_colormanagement.h" #include "ED_screen.h" @@ -3459,6 +3461,9 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) WM_cursor_modal_set(win, WM_CURSOR_TEXT_EDIT); + /* Temporarily turn off window auto-focus on platforms that support it. */ + GHOST_SetAutoFocus(false); + #ifdef WITH_INPUT_IME if (!is_num_but) { ui_textedit_ime_begin(win, but); @@ -3514,6 +3519,9 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) WM_cursor_modal_restore(win); + /* Turn back on the auto-focusing of windows. */ + GHOST_SetAutoFocus(true); + /* Free text undo history text blocks. */ ui_textedit_undo_stack_destroy(data->undo_stack_text); data->undo_stack_text = nullptr;