summaryrefslogtreecommitdiff
path: root/indra/llwindow
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2025-10-23 12:00:12 +0800
committerErik Kundiman <erik@megapahit.org>2025-10-25 20:03:33 +0800
commitab9976389fe5e4c254d3eb2c39fd2dff083d8d2d (patch)
treecf14ec0d25efd065a1471debb74080ef41763fbf /indra/llwindow
parent790a7d1ccfa5b1a20a3b5295f839670793ced950 (diff)
parent01823996196c11aea905200fe267463d520d285b (diff)
Merge tag 'Second_Life_Release#01823996-2025.08' into 2025.08
Diffstat (limited to 'indra/llwindow')
-rw-r--r--indra/llwindow/llwindow.h1
-rw-r--r--indra/llwindow/llwindowcallbacks.cpp8
-rw-r--r--indra/llwindow/llwindowcallbacks.h3
-rw-r--r--indra/llwindow/llwindowheadless.h1
-rw-r--r--indra/llwindow/llwindowmacosx.cpp2
-rw-r--r--indra/llwindow/llwindowmacosx.h1
-rw-r--r--indra/llwindow/llwindowsdl.cpp2
-rw-r--r--indra/llwindow/llwindowsdl.h2
-rw-r--r--indra/llwindow/llwindowwin32.cpp52
-rw-r--r--indra/llwindow/llwindowwin32.h2
10 files changed, 69 insertions, 5 deletions
diff --git a/indra/llwindow/llwindow.h b/indra/llwindow/llwindow.h
index 8f8ea7fdb6..d63927d23d 100644
--- a/indra/llwindow/llwindow.h
+++ b/indra/llwindow/llwindow.h
@@ -95,6 +95,7 @@ public:
#if LL_WINDOWS && !LL_SDL
virtual bool getCursorDelta(LLCoordCommon* delta) = 0;
#endif
+ virtual bool isWrapMouse() const = 0;
virtual void showCursor() = 0;
virtual void hideCursor() = 0;
virtual bool isCursorHidden() = 0;
diff --git a/indra/llwindow/llwindowcallbacks.cpp b/indra/llwindow/llwindowcallbacks.cpp
index 195f68e08b..7331f50ba0 100644
--- a/indra/llwindow/llwindowcallbacks.cpp
+++ b/indra/llwindow/llwindowcallbacks.cpp
@@ -68,7 +68,13 @@ void LLWindowCallbacks::handleMouseLeave(LLWindow *window)
return;
}
-bool LLWindowCallbacks::handleCloseRequest(LLWindow *window)
+bool LLWindowCallbacks::handleCloseRequest(LLWindow *window, bool from_user)
+{
+ //allow the window to close
+ return true;
+}
+
+bool LLWindowCallbacks::handleSessionExit(LLWindow* window)
{
//allow the window to close
return true;
diff --git a/indra/llwindow/llwindowcallbacks.h b/indra/llwindow/llwindowcallbacks.h
index d812f93524..59dcdd3ade 100644
--- a/indra/llwindow/llwindowcallbacks.h
+++ b/indra/llwindow/llwindowcallbacks.h
@@ -42,7 +42,8 @@ public:
virtual bool handleMouseUp(LLWindow *window, LLCoordGL pos, MASK mask);
virtual void handleMouseLeave(LLWindow *window);
// return true to allow window to close, which will then cause handleQuit to be called
- virtual bool handleCloseRequest(LLWindow *window);
+ virtual bool handleCloseRequest(LLWindow *window, bool from_user);
+ virtual bool handleSessionExit(LLWindow* window);
// window is about to be destroyed, clean up your business
virtual void handleQuit(LLWindow *window);
virtual bool handleRightMouseDown(LLWindow *window, LLCoordGL pos, MASK mask);
diff --git a/indra/llwindow/llwindowheadless.h b/indra/llwindow/llwindowheadless.h
index acec401133..0a1ecb05e0 100644
--- a/indra/llwindow/llwindowheadless.h
+++ b/indra/llwindow/llwindowheadless.h
@@ -63,6 +63,7 @@ public:
#if LL_WINDOWS && !LL_SDL
/*virtual*/ bool getCursorDelta(LLCoordCommon* delta) override { return false; }
#endif
+ /*virtual*/ bool isWrapMouse() const override { return true; }
/*virtual*/ void showCursor() override {}
/*virtual*/ void hideCursor() override {}
/*virtual*/ void showCursorFromMouseMove() override {}
diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp
index 4a4b2658f6..0bf1c4b057 100644
--- a/indra/llwindow/llwindowmacosx.cpp
+++ b/indra/llwindow/llwindowmacosx.cpp
@@ -613,7 +613,7 @@ void callQuitHandler()
{
if (gWindowImplementation && gWindowImplementation->getCallbacks())
{
- if(gWindowImplementation->getCallbacks()->handleCloseRequest(gWindowImplementation))
+ if(gWindowImplementation->getCallbacks()->handleCloseRequest(gWindowImplementation, true))
{
gWindowImplementation->getCallbacks()->handleQuit(gWindowImplementation);
}
diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h
index 110c5756d0..d703a84d02 100644
--- a/indra/llwindow/llwindowmacosx.h
+++ b/indra/llwindow/llwindowmacosx.h
@@ -63,6 +63,7 @@ public:
bool switchContext(bool fullscreen, const LLCoordScreen &size, bool enable_vsync, const LLCoordScreen * const posp = NULL) override;
bool setCursorPosition(LLCoordWindow position) override;
bool getCursorPosition(LLCoordWindow *position) override;
+ bool isWrapMouse() const override { return !mCursorDecoupled; };
void showCursor() override;
void hideCursor() override;
void showCursorFromMouseMove() override;
diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp
index 0a117be1fc..ad40dea0c3 100644
--- a/indra/llwindow/llwindowsdl.cpp
+++ b/indra/llwindow/llwindowsdl.cpp
@@ -1722,7 +1722,7 @@ void LLWindowSDL::gatherInput()
break;
}
case SDL_QUIT:
- if(mCallbacks->handleCloseRequest(this))
+ if(mCallbacks->handleCloseRequest(this, true))
{
// Get the app to initiate cleanup.
mCallbacks->handleQuit(this);
diff --git a/indra/llwindow/llwindowsdl.h b/indra/llwindow/llwindowsdl.h
index 076d7234bc..d9b6be5fdc 100644
--- a/indra/llwindow/llwindowsdl.h
+++ b/indra/llwindow/llwindowsdl.h
@@ -91,6 +91,8 @@ public:
bool getCursorPosition(LLCoordWindow *position) override;
+ bool isWrapMouse() const override { return true; }
+
void showCursor() override;
void hideCursor() override;
diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp
index cfc2038be9..5471e1c87a 100644
--- a/indra/llwindow/llwindowwin32.cpp
+++ b/indra/llwindow/llwindowwin32.cpp
@@ -450,6 +450,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks,
F32 max_gl_version)
:
LLWindow(callbacks, fullscreen, flags),
+ mAbsoluteCursorPosition(false),
mMaxGLVersion(max_gl_version),
mMaxCores(max_cores)
{
@@ -2466,10 +2467,13 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
case WM_CLOSE:
{
LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_CLOSE");
+ // todo: WM_CLOSE can be caused by user and by task manager,
+ // distinguish these cases.
+ // For now assume it is always user.
window_imp->post([=]()
{
// Will the app allow the window to close?
- if (window_imp->mCallbacks->handleCloseRequest(window_imp))
+ if (window_imp->mCallbacks->handleCloseRequest(window_imp, true))
{
// Get the app to initiate cleanup.
window_imp->mCallbacks->handleQuit(window_imp);
@@ -2487,6 +2491,50 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
}
return 0;
}
+ case WM_QUERYENDSESSION:
+ {
+ // Generally means that OS is going to shut down or user is going to log off.
+ // Can use ShutdownBlockReasonCreate here.
+ LL_INFOS("Window") << "Received WM_QUERYENDSESSION with wParam: " << (U32)w_param << " lParam: " << (U32)l_param << LL_ENDL;
+ return TRUE; // 1 = ok to end session. 0 no longer works by itself, use ShutdownBlockReasonCreate
+ }
+ case WM_ENDSESSION:
+ {
+ // OS session is shutting down, initiate cleanup.
+ // Comes after WM_QUERYENDSESSION
+ LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_ENDSESSION");
+ LL_INFOS("Window") << "Received WM_ENDSESSION with wParam: " << (U32)w_param << " lParam: " << (U32)l_param << LL_ENDL;
+ unsigned int end_session_flags = (U32)w_param;
+ if (end_session_flags == 0)
+ {
+ // session is not actually ending
+ return 0;
+ }
+
+ if ((end_session_flags & ENDSESSION_CLOSEAPP)
+ || (end_session_flags & ENDSESSION_CRITICAL)
+ || (end_session_flags & ENDSESSION_LOGOFF))
+ {
+ window_imp->post([=]()
+ {
+ // Check if app needs cleanup or can be closed immediately.
+ if (window_imp->mCallbacks->handleSessionExit(window_imp))
+ {
+ // Get the app to initiate cleanup.
+ window_imp->mCallbacks->handleQuit(window_imp);
+ // The app is responsible for calling destroyWindow when done with GL
+ }
+ });
+ // Give app a second to finish up. That's not enough for a clean exit,
+ // but better than nothing.
+ // Todo: sync this better, some kind of waitForResult? Can't wait forever,
+ // but can potentially use ShutdownBlockReasonCreate for a bigger delay.
+ ms_sleep(1000);
+ }
+ // Don't need to post quit or destroy window,
+ // if session is ending OS is going to take care of it.
+ return 0;
+ }
case WM_COMMAND:
{
LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_COMMAND");
@@ -3111,6 +3159,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
prev_absolute_x = absolute_x;
prev_absolute_y = absolute_y;
+ window_imp->mAbsoluteCursorPosition = true;
}
else
{
@@ -3127,6 +3176,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
window_imp->mRawMouseDelta.mX += (S32)round((F32)raw->data.mouse.lLastX * (F32)speed / DEFAULT_SPEED);
window_imp->mRawMouseDelta.mY -= (S32)round((F32)raw->data.mouse.lLastY * (F32)speed / DEFAULT_SPEED);
}
+ window_imp->mAbsoluteCursorPosition = false;
}
}
}
diff --git a/indra/llwindow/llwindowwin32.h b/indra/llwindow/llwindowwin32.h
index 7196706f87..0fc93ad0b1 100644
--- a/indra/llwindow/llwindowwin32.h
+++ b/indra/llwindow/llwindowwin32.h
@@ -70,6 +70,7 @@ public:
/*virtual*/ bool setCursorPosition(LLCoordWindow position);
/*virtual*/ bool getCursorPosition(LLCoordWindow *position);
/*virtual*/ bool getCursorDelta(LLCoordCommon* delta);
+ /*virtual*/ bool isWrapMouse() const override { return !mAbsoluteCursorPosition; };
/*virtual*/ void showCursor();
/*virtual*/ void hideCursor();
/*virtual*/ void showCursorFromMouseMove();
@@ -195,6 +196,7 @@ protected:
HCURSOR mCursor[ UI_CURSOR_COUNT ]; // Array of all mouse cursors
LLCoordWindow mCursorPosition; // mouse cursor position, should only be mutated on main thread
+ bool mAbsoluteCursorPosition; // true if last position was received in absolute coordinates.
LLMutex mRawMouseMutex;
RAWINPUTDEVICE mRawMouse;
LLCoordWindow mLastCursorPosition; // mouse cursor position from previous frame