NativeEventFilter_Windows.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /******************************************************************************
  2. Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "NativeEventFilter.hpp"
  15. #include <widgets/OBSBasic.hpp>
  16. #include <sstream>
  17. #define WIN32_LEAN_AND_MEAN
  18. #include <windows.h>
  19. namespace OBS {
  20. bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
  21. {
  22. if (eventType == "windows_generic_MSG") {
  23. MSG *msg = static_cast<MSG *>(message);
  24. OBSBasic *main = OBSBasic::Get();
  25. if (!main) {
  26. return false;
  27. }
  28. switch (msg->message) {
  29. case WM_QUERYENDSESSION:
  30. main->saveAll();
  31. if (msg->lParam == ENDSESSION_CRITICAL) {
  32. break;
  33. }
  34. if (main->shouldPromptForClose()) {
  35. *result = FALSE;
  36. return true;
  37. }
  38. return false;
  39. case WM_ENDSESSION:
  40. if (msg->wParam == TRUE) {
  41. // Session is ending, start closing the main window now with no checks or prompts.
  42. main->closeWindow();
  43. } else {
  44. /* Session is no longer ending. If OBS is still open, odds are it is what held
  45. * up the session end due to its higher than default priority. We call the
  46. * close method to trigger the confirmation window flow. We do this after the fact
  47. * to avoid blocking the main window event loop prior to this message.
  48. * Otherwise, OBS is already gone and invoking this does nothing. */
  49. main->close();
  50. }
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56. } // namespace OBS