NativeEventFilter_Windows.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (result) {
  36. *result = FALSE;
  37. }
  38. QTimer::singleShot(1, main, &OBSBasic::close);
  39. return true;
  40. }
  41. return false;
  42. case WM_ENDSESSION:
  43. if (msg->wParam == TRUE) {
  44. // Session is ending, start closing the main window now with no checks or prompts.
  45. main->closeWindow();
  46. }
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. } // namespace OBS