Skip to content

Commit ec4ceb3

Browse files
committed
squashme: Review fixes
1 parent a0930bd commit ec4ceb3

File tree

9 files changed

+107
-58
lines changed

9 files changed

+107
-58
lines changed

frontend/cmake/os-freebsd.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
target_sources(
22
obs-studio
3-
PRIVATE utility/platform-x11.cpp utility/system-info-posix.cpp utility/CrashHandler_FreeBSD.cpp
3+
PRIVATE utility/NativeEventFilter.cpp utility/platform-x11.cpp utility/system-info-posix.cpp utility/CrashHandler_FreeBSD.cpp
44
)
55
target_compile_definitions(obs-studio PRIVATE OBS_INSTALL_PREFIX="${OBS_INSTALL_PREFIX}")
66
target_link_libraries(obs-studio PRIVATE Qt::GuiPrivate Qt::DBus procstat)

frontend/cmake/os-linux.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
target_sources(obs-studio PRIVATE utility/platform-x11.cpp utility/system-info-posix.cpp utility/CrashHandler_Linux.cpp)
1+
target_sources(obs-studio PRIVATE utility/NativeEventFilter.cpp utility/platform-x11.cpp utility/system-info-posix.cpp utility/CrashHandler_Linux.cpp)
22
target_compile_definitions(
33
obs-studio
44
PRIVATE OBS_INSTALL_PREFIX="${OBS_INSTALL_PREFIX}" $<$<BOOL:${ENABLE_PORTABLE_CONFIG}>:ENABLE_PORTABLE_CONFIG>

frontend/cmake/os-macos.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ target_sources(
77
dialogs/OBSPermissions.hpp
88
forms/OBSPermissions.ui
99
utility/CrashHandler_MacOS.mm
10+
utility/NativeEventFilter.cpp
1011
utility/platform-osx.mm
1112
utility/system-info-macos.mm
1213
)

frontend/cmake/os-windows.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ target_sources(
2929
utility/crypto-helpers.hpp
3030
utility/models/branches.hpp
3131
utility/models/whatsnew.hpp
32+
utility/NativeEventFilter_Windows.cpp
3233
utility/platform-windows.cpp
3334
utility/system-info-windows.cpp
3435
utility/update-helpers.cpp

frontend/cmake/ui-utility.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ target_sources(
3333
utility/MultitrackVideoError.hpp
3434
utility/MultitrackVideoOutput.cpp
3535
utility/MultitrackVideoOutput.hpp
36-
utility/NativeEventFilter.cpp
3736
utility/NativeEventFilter.hpp
3837
utility/obf.c
3938
utility/obf.h
Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,27 @@
1+
/******************************************************************************
2+
Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
13
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
28
3-
#include <utility/NativeEventFilter.hpp>
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
413
5-
#include <widgets/OBSBasic.hpp>
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
******************************************************************************/
617

7-
#ifdef _WIN32
8-
#include <sstream>
9-
#define WIN32_LEAN_AND_MEAN
10-
#include <windows.h>
11-
#else
12-
#include <unistd.h>
13-
#include <sys/socket.h>
14-
#endif
18+
#include "NativeEventFilter.hpp"
1519

1620
namespace OBS {
1721

1822
bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
1923
{
20-
if (eventType == "windows_generic_MSG") {
21-
#ifdef _WIN32
22-
MSG *msg = static_cast<MSG *>(message);
23-
24-
OBSBasic *main = OBSBasic::Get();
25-
if (!main) {
26-
return false;
27-
}
28-
29-
switch (msg->message) {
30-
case WM_QUERYENDSESSION:
31-
main->saveAll();
32-
if (msg->lParam == ENDSESSION_CRITICAL) {
33-
break;
34-
}
35-
36-
if (main->shouldPromptForClose()) {
37-
*result = FALSE;
38-
return true;
39-
}
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-
} else {
47-
/* Session is no longer ending. If OBS is still open, odds are it is what held
48-
* up the session end due to it's higher than default priority. We call the
49-
* close method to trigger the confirmation window flow. We do this after the fact
50-
* to avoid blocking the main window event loop prior to this message.
51-
* Otherwise OBS is already gone and invoking this does nothing */
52-
main->close();
53-
}
54-
55-
return true;
56-
}
57-
#else
58-
UNUSED_PARAMETER(message);
59-
UNUSED_PARAMETER(result);
60-
#endif
61-
}
62-
24+
// Stub file for operating systems that do not need nativeEventFilter
6325
return false;
6426
}
6527
} // namespace OBS

frontend/utility/NativeEventFilter.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/******************************************************************************
2+
Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
******************************************************************************/
17+
118
#pragma once
219

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

frontend/widgets/OBSBasic.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class OBSBasic : public OBSMainWindow {
217217
Q_PROPERTY(QIcon audioProcessOutputIcon READ GetAudioProcessOutputIcon WRITE SetAudioProcessOutputIcon
218218
DESIGNABLE true)
219219

220-
friend class OBS::NativeEventFilter;
221220
friend class OBSAbout;
222221
friend class OBSBasicPreview;
223222
friend class OBSBasicStatusBar;
@@ -331,11 +330,11 @@ public slots:
331330
void saveAll();
332331
bool shouldPromptForClose();
333332
inline bool isClosing() { return isClosing_; }
333+
void closeWindow();
334334

335335
protected:
336336
bool isReadyToClose();
337337
bool promptToClose();
338-
void closeWindow();
339338

340339
virtual void closeEvent(QCloseEvent *event) override;
341340
virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;

0 commit comments

Comments
 (0)