linux: fix potential segment faults

Fixes: #199

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2023-01-24 16:57:44 +08:00
parent a23438b02b
commit 69ef2a6ca1
4 changed files with 36 additions and 0 deletions

View File

@ -56,6 +56,18 @@
// This one is not included in any public headers. // This one is not included in any public headers.
using Display = struct _XDisplay; using Display = struct _XDisplay;
#ifndef FRAMELESSHELPER_HAS_XLIB
extern "C"
{
FRAMELESSHELPER_CORE_API int
XInitThreads(
void
);
} // extern "C"
#endif // FRAMELESSHELPER_HAS_XLIB
#if __has_include(<xcb/xcb.h>) #if __has_include(<xcb/xcb.h>)
# include <xcb/xcb.h> # include <xcb/xcb.h>
# define FRAMELESSHELPER_HAS_XCB # define FRAMELESSHELPER_HAS_XCB

View File

@ -85,6 +85,7 @@ Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader))
#endif // Q_OS_WINDOWS #endif // Q_OS_WINDOWS
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
# define API_XLIB_AVAILABLE(func) API_AVAILABLE(libX11, func)
# define API_XCB_AVAILABLE(func) API_AVAILABLE(libxcb, func) # define API_XCB_AVAILABLE(func) API_AVAILABLE(libxcb, func)
# define API_GTK_AVAILABLE(func) API_AVAILABLE(libgtk, func) # define API_GTK_AVAILABLE(func) API_AVAILABLE(libgtk, func)
#endif // Q_OS_LINUX #endif // Q_OS_LINUX

View File

@ -174,6 +174,7 @@ void initialize()
// enough, that is, before the construction of any Q(Gui)Application // enough, that is, before the construction of any Q(Gui)Application
// instances. QCoreApplication won't instantiate the platform plugin. // instances. QCoreApplication won't instantiate the platform plugin.
qputenv(QT_QPA_ENV_VAR, kxcb); qputenv(QT_QPA_ENV_VAR, kxcb);
XInitThreads();
gtk_init(nullptr, nullptr); gtk_init(nullptr, nullptr);
#endif #endif

View File

@ -25,6 +25,28 @@
#include "framelesshelper_linux.h" #include "framelesshelper_linux.h"
#include "sysapiloader_p.h" #include "sysapiloader_p.h"
//////////////////////////////////////////////
// Xlib
#ifndef FRAMELESSHELPER_HAS_XLIB
FRAMELESSHELPER_STRING_CONSTANT(libX11)
FRAMELESSHELPER_STRING_CONSTANT(XInitThreads)
extern "C" int
XInitThreads(
void
)
{
if (!API_XLIB_AVAILABLE(XInitThreads)) {
return 0;
}
return API_CALL_FUNCTION(XInitThreads);
}
#endif // FRAMELESSHELPER_HAS_XLIB
////////////////////////////////////////////// //////////////////////////////////////////////
// XCB // XCB