Skip to content

Commit 4b4b8c1

Browse files
authored
Merge pull request #44 from skalarproduktraum/enhancement/preparation-for-xinitthreads
Preparations for XInitThreads
2 parents 4c4ea4a + 2f60a53 commit 4b4b8c1

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

src/c/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
// For implementations, see linux.h, macos.h, posix.h, win32.h
3030
// ===========================================================
3131

32+
// used for calling XInitThreads on Linux/X11, empty on
33+
// Windows and macOS, defined in linux.h, win32.h, macos.h
34+
void initThreads();
35+
3236
// run_command implementations in posix.h, win32.h
3337
int run_command(const char *command,
3438
const char *input[], size_t numInput,

src/c/linux.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
#include <string.h>
2+
#include <dlfcn.h>
23

34
#include "common.h"
45

56
#define OS_NAME "linux"
67

8+
void (*xinit_threads_reference)();
9+
10+
void initThreads() {
11+
void *libX11Handle = dlopen("libX11.so", RTLD_LAZY);
12+
if(libX11Handle != NULL) {
13+
debug("Running XInitThreads\n");
14+
xinit_threads_reference = dlsym(libX11Handle, "XInitThreads");
15+
16+
if(xinit_threads_reference != NULL) {
17+
xinit_threads_reference();
18+
} else {
19+
error("Could not find XInitThreads in X11 library: %s\n", dlerror());
20+
}
21+
} else {
22+
error("Could not find X11 library, not running XInitThreads.\n");
23+
}
24+
}
25+
726
int is_command_available(const char *command) {
827
return access(command, X_OK) == 0;
928
}

src/c/macos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#define OS_NAME "macos"
99

10+
void initThreads() {}
11+
1012
void show_alert(const char *title, const char *message) {
1113
/* TODO: Get this objc code working.
1214
// Create an NSString from the C string

src/c/win32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define SLASH "\\"
77
#define EXE_SUFFIX ".exe"
88

9+
void initThreads() {}
10+
911
void *loadlib(const char *path) { return LoadLibrary(path); }
1012
void *dlsym(void *library, const char *symbol) { return GetProcAddress(library, symbol); }
1113
void dlclose(void *library) { FreeLibrary(library); }

0 commit comments

Comments
 (0)