Skip to content

Commit

Permalink
Add initThreads() function, being empty on Windows and macOS, and exe…
Browse files Browse the repository at this point in the history
…cuting XInitThreads() on Linux/X11
  • Loading branch information
skalarproduktraum committed Apr 16, 2024
1 parent 4c4ea4a commit a7773ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/c/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

#define OS_NAME "linux"

void (*xinit_threads_reference)();

void initThreads() {
void *libX11Handle = dlopen("libX11.so", RTLD_LAZY);
if(libX11Handle != NULL) {
debug("Running XInitThreads\n");
xinit_threads_reference = dlsym(libX11Handle, "XInitThreads");

if(xinit_threads_reference != NULL) {
xinit_threads_reference();
} else {
error("Could not find XInitThreads in X11 library: %s\n", dlerror());
}
} else {
error("Could not find X11 library, not running XInitThreads.\n");
}
}

int is_command_available(const char *command) {
return access(command, X_OK) == 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/c/macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#define OS_NAME "macos"

void initThreads() {}

void show_alert(const char *title, const char *message) {
/* TODO: Get this objc code working.
// Create an NSString from the C string
Expand Down
2 changes: 2 additions & 0 deletions src/c/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define SLASH "\\"
#define EXE_SUFFIX ".exe"

void initThreads() {}

void *loadlib(const char *path) { return LoadLibrary(path); }
void *dlsym(void *library, const char *symbol) { return GetProcAddress(library, symbol); }
void dlclose(void *library) { FreeLibrary(library); }
Expand Down

0 comments on commit a7773ca

Please sign in to comment.