diff options
author | Nicholas Rishel <rishel.nick@gmail.com> | 2021-02-16 10:27:21 +0300 |
---|---|---|
committer | Nicholas Rishel <rishel.nick@gmail.com> | 2021-02-16 10:27:21 +0300 |
commit | dd79a715c98147dd1603b867502d3d8a0c8ca777 (patch) | |
tree | 8025b6f3fbc6449f100a32a7fc1a932c50ccfc10 /intern/ghost/intern/GHOST_SystemWin32.cpp | |
parent | 63fb53ad95dc21cc6f8647e4a157ddefa938e28f (diff) | |
parent | 2e81f2c01abd21fdbc79625f3f7a0778103fa199 (diff) |
Merge branch 'blender-v2.92-release'
# Conflicts:
# intern/ghost/intern/GHOST_SystemWin32.cpp
# intern/ghost/intern/GHOST_WindowWin32.cpp
# intern/ghost/intern/GHOST_WindowWin32.h
Diffstat (limited to 'intern/ghost/intern/GHOST_SystemWin32.cpp')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWin32.cpp | 226 |
1 files changed, 46 insertions, 180 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index fb53357bb24..1e79d9dbaaf 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -237,11 +237,6 @@ GHOST_SystemWin32::~GHOST_SystemWin32() toggleConsole(1); } -GHOST_TUns64 GHOST_SystemWin32::millisSinceStart(__int64 ms) const -{ - return (GHOST_TUns64)(ms - m_start * 1000 / m_freq); -} - GHOST_TUns64 GHOST_SystemWin32::performanceCounterToMillis(__int64 perf_ticks) const { // Calculate the time passed since system initialization. @@ -955,101 +950,25 @@ GHOST_EventButton *GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type, { GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem(); - GHOST_TabletData td = window->m_tabletInRange ? window->getLastTabletData() : - GHOST_TABLET_DATA_NONE; + GHOST_TabletData td = GHOST_TABLET_DATA_NONE; - /* Move mouse to button event position. */ - if (!window->m_tabletInRange) { - processCursorEvent(window); - } - else { - /* Tablet should be handling in between mouse moves, only move to event position. */ + if (window->m_tabletInRange) { + td = window->getTabletData(); + + /* Check if tablet cursor position is in sync with Win32 cursor position, if not then move + * cursor to position where button event occurred. */ DWORD msgPos = ::GetMessagePos(); int msgPosX = GET_X_LPARAM(msgPos); int msgPosY = GET_Y_LPARAM(msgPos); - system->pushEvent(new GHOST_EventCursor( - ::GetMessageTime(), GHOST_kEventCursorMove, window, msgPosX, msgPosY, td)); + if (msgPosX != system->m_mousePosX || msgPosY != system->m_mousePosY) { + system->pushEvent(new GHOST_EventCursor( + ::GetMessageTime(), GHOST_kEventCursorMove, window, msgPosX, msgPosY, td)); + } } - window->updateMouseCapture(type == GHOST_kEventButtonDown ? MousePressed : MouseReleased); return new GHOST_EventButton(system->getMilliSeconds(), type, window, mask, td); } -void GHOST_SystemWin32::processWintabEvent(GHOST_WindowWin32 *window) -{ - GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem(); - - std::vector<GHOST_WintabInfoWin32> wintabInfo; - if (!window->getWintabInfo(wintabInfo)) { - return; - } - - for (auto info : wintabInfo) { - switch (info.type) { - case GHOST_kEventCursorMove: { - system->pushEvent(new GHOST_EventCursor( - info.time, GHOST_kEventCursorMove, window, info.x, info.y, info.tabletData)); - break; - } - case GHOST_kEventButtonDown: { - system->pushEvent(new GHOST_EventCursor( - info.time, GHOST_kEventCursorMove, window, info.x, info.y, info.tabletData)); - - UINT message; - switch (info.button) { - case GHOST_kButtonMaskLeft: - message = WM_LBUTTONDOWN; - break; - case GHOST_kButtonMaskRight: - message = WM_RBUTTONDOWN; - break; - case GHOST_kButtonMaskMiddle: - message = WM_MBUTTONDOWN; - break; - default: - continue; - } - - MSG msg; - if (PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD) && - WM_QUIT != msg.message) { - window->updateMouseCapture(MousePressed); - system->pushEvent( - new GHOST_EventButton(info.time, info.type, window, info.button, info.tabletData)); - } - break; - } - case GHOST_kEventButtonUp: { - UINT message; - switch (info.button) { - case GHOST_kButtonMaskLeft: - message = WM_LBUTTONUP; - break; - case GHOST_kButtonMaskRight: - message = WM_RBUTTONUP; - break; - case GHOST_kButtonMaskMiddle: - message = WM_MBUTTONUP; - break; - default: - continue; - } - - MSG msg; - if (PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD) && - WM_QUIT != msg.message) { - window->updateMouseCapture(MouseReleased); - system->pushEvent( - new GHOST_EventButton(info.time, info.type, window, info.button, info.tabletData)); - } - break; - } - default: - break; - } - } -} - void GHOST_SystemWin32::processPointerEvent( UINT type, GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam, bool &eventHandled) { @@ -1129,12 +1048,15 @@ void GHOST_SystemWin32::processPointerEvent( void GHOST_SystemWin32::processCursorEvent(GHOST_WindowWin32 *window) { - /* Cursor moves handled by tablets while active. */ - if (window->m_tabletInRange) { + if (window->m_tabletInRange && window->useTabletAPI(GHOST_kTabletNative)) { + /* Tablet input handled in WM_POINTER* events. WM_MOUSEMOVE events in response to tablet + * input aren't normally generated when using WM_POINTER events, but manually moving the + * system cursor as we do in WM_POINTER handling does. */ return; } GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem(); + GHOST_TabletData td = window->getTabletData(); DWORD msgPos = ::GetMessagePos(); LONG msgTime = ::GetMessageTime(); @@ -1185,13 +1107,13 @@ void GHOST_SystemWin32::processCursorEvent(GHOST_WindowWin32 *window) window, points[i].x + x_accum, points[i].y + y_accum, - GHOST_TABLET_DATA_NONE)); + td)); } DWORD lastTimestamp = points[0].time; /* Check if we need to wrap the cursor. */ - if (window->getCursorGrabModeIsWarp()) { + if (window->getCursorGrabModeIsWarp() && !window->m_tabletInRange) { /* Wrap based on current cursor position in case Win32 mouse move queue is out of order due to * prior wrap. */ POINT point; @@ -1334,23 +1256,6 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window, RA return event; } -GHOST_Event *GHOST_SystemWin32::processWindowSizeEvent(GHOST_WindowWin32 *window) -{ - GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem(); - GHOST_Event *sizeEvent = new GHOST_Event( - system->getMilliSeconds(), GHOST_kEventWindowSize, window); - - /* We get WM_SIZE before we fully init. Do not dispatch before we are continuously resizing. */ - if (window->m_inLiveResize) { - system->pushEvent(sizeEvent); - system->dispatchEvents(); - return NULL; - } - else { - return sizeEvent; - } -} - GHOST_Event *GHOST_SystemWin32::processWindowEvent(GHOST_TEventType type, GHOST_WindowWin32 *window) { @@ -1358,6 +1263,7 @@ GHOST_Event *GHOST_SystemWin32::processWindowEvent(GHOST_TEventType type, if (type == GHOST_kEventWindowActivate) { system->getWindowManager()->setActiveWindow(window); + window->bringTabletContextToFront(); } return new GHOST_Event(system->getMilliSeconds(), type, window); @@ -1385,18 +1291,6 @@ GHOST_TSuccess GHOST_SystemWin32::pushDragDropEvent(GHOST_TEventType eventType, system->getMilliSeconds(), eventType, draggedObjectType, window, mouseX, mouseY, data)); } -void GHOST_SystemWin32::setTabletAPI(GHOST_TTabletAPI api) -{ - GHOST_System::setTabletAPI(api); - - GHOST_WindowManager *wm = getWindowManager(); - - for (GHOST_IWindow *win : wm->getWindows()) { - GHOST_WindowWin32 *windowWin32 = (GHOST_WindowWin32 *)win; - windowWin32->setWintabEnabled(windowWin32->useTabletAPI(GHOST_kTabletWintab)); - } -} - void GHOST_SystemWin32::processMinMaxInfo(MINMAXINFO *minmax) { minmax->ptMinTrackSize.x = 320; @@ -1630,30 +1524,16 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, //////////////////////////////////////////////////////////////////////// // Wintab events, processed //////////////////////////////////////////////////////////////////////// - case WT_INFOCHANGE: { + case WT_INFOCHANGE: window->processWintabInfoChangeEvent(lParam); eventHandled = true; break; - } - case WT_CSRCHANGE: - window->updateWintabCursorInfo(); - eventHandled = true; - break; - case WT_PROXIMITY: { - if (window->useTabletAPI(GHOST_kTabletWintab)) { - if (LOWORD(lParam)) { - window->m_tabletInRange = true; - } - else { - window->processWintabLeave(); - } - } - eventHandled = true; - break; - } case WT_PACKET: - processWintabEvent(window); - eventHandled = true; + window->processWin32TabletEvent(wParam, lParam); + break; + case WT_CSRCHANGE: + case WT_PROXIMITY: + window->processWin32TabletInitEvent(); break; //////////////////////////////////////////////////////////////////////// // Pointer events, processed @@ -1669,53 +1549,52 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, // Mouse events, processed //////////////////////////////////////////////////////////////////////// case WM_LBUTTONDOWN: + window->updateMouseCapture(MousePressed); event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskLeft); break; case WM_MBUTTONDOWN: + window->updateMouseCapture(MousePressed); event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskMiddle); break; case WM_RBUTTONDOWN: + window->updateMouseCapture(MousePressed); event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskRight); break; case WM_XBUTTONDOWN: if ((short)HIWORD(wParam) == XBUTTON1) { + window->updateMouseCapture(MousePressed); event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskButton4); } else if ((short)HIWORD(wParam) == XBUTTON2) { + window->updateMouseCapture(MousePressed); event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskButton5); } break; case WM_LBUTTONUP: + window->updateMouseCapture(MouseReleased); event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskLeft); break; case WM_MBUTTONUP: + window->updateMouseCapture(MouseReleased); event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskMiddle); break; case WM_RBUTTONUP: + window->updateMouseCapture(MouseReleased); event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskRight); break; case WM_XBUTTONUP: if ((short)HIWORD(wParam) == XBUTTON1) { + window->updateMouseCapture(MouseReleased); event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskButton4); } else if ((short)HIWORD(wParam) == XBUTTON2) { + window->updateMouseCapture(MouseReleased); event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskButton5); } break; case WM_MOUSEMOVE: - if (!window->m_mousePresent) { - TRACKMOUSEEVENT tme = {sizeof(tme)}; - tme.dwFlags = TME_LEAVE; - tme.hwndTrack = hwnd; - TrackMouseEvent(&tme); - window->m_mousePresent = true; - window->setWintabOverlap(true); - } - - if (!window->m_tabletInRange) { - processCursorEvent(window); - eventHandled = true; - } + processCursorEvent(window); + eventHandled = true; break; case WM_MOUSEWHEEL: { /* The WM_MOUSEWHEEL message is sent to the focus window @@ -1757,13 +1636,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, window->loadCursor(true, GHOST_kStandardCursorDefault); } break; - case WM_MOUSELEAVE: - window->m_mousePresent = false; - window->setWintabOverlap(false); - if (!window->m_tabletInRange) { - processCursorEvent(window); - } - break; + //////////////////////////////////////////////////////////////////////// // Mouse events, ignored //////////////////////////////////////////////////////////////////////// @@ -1779,6 +1652,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, * is sent to the window that has captured the mouse. */ break; + //////////////////////////////////////////////////////////////////////// // Window events, processed //////////////////////////////////////////////////////////////////////// @@ -1810,7 +1684,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, * will not be dispatched to OUR active window if we minimize one of OUR windows. */ if (LOWORD(wParam) == WA_INACTIVE) window->lostMouseCapture(); - + window->processWin32TabletActivateEvent(GET_WM_ACTIVATE_STATE(wParam, lParam)); lResult = ::DefWindowProc(hwnd, msg, wParam, lParam); break; } @@ -1852,8 +1726,6 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, /* Let DefWindowProc handle it. */ break; case WM_SIZING: - event = processWindowSizeEvent(window); - break; case WM_SIZE: /* The WM_SIZE message is sent to a window after its size has changed. * The WM_SIZE and WM_MOVE messages are not sent if an application handles the @@ -1861,15 +1733,15 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, * to perform any move or size change processing during the WM_WINDOWPOSCHANGED * message without calling DefWindowProc. */ - event = processWindowSizeEvent(window); - - if (wParam == SIZE_MINIMIZED) { - window->setWintabEnabled(false); + /* we get first WM_SIZE before we fully init. + * So, do not dispatch before we continuously resizing. */ + if (window->m_inLiveResize) { + system->pushEvent(processWindowEvent(GHOST_kEventWindowSize, window)); + system->dispatchEvents(); } - else if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED) { - window->setWintabEnabled(true); + else { + event = processWindowEvent(GHOST_kEventWindowSize, window); } - break; case WM_CAPTURECHANGED: window->lostMouseCapture(); @@ -1920,12 +1792,6 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, SWP_NOZORDER | SWP_NOACTIVATE); } break; - case WM_DISPLAYCHANGE: - for (GHOST_IWindow *iter_win : system->getWindowManager()->getWindows()) { - GHOST_WindowWin32 *iter_win32win = (GHOST_WindowWin32 *)iter_win; - iter_win32win->processWintabDisplayChangeEvent(); - } - break; //////////////////////////////////////////////////////////////////////// // Window events, ignored //////////////////////////////////////////////////////////////////////// |