Skip to content

Commit

Permalink
Merge pull request #44 from skalarproduktraum/enhancement/preparation…
Browse files Browse the repository at this point in the history
…-for-xinitthreads

Preparations for XInitThreads
  • Loading branch information
ctrueden authored Apr 16, 2024
2 parents 4c4ea4a + 2f60a53 commit 4b4b8c1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
// For implementations, see linux.h, macos.h, posix.h, win32.h
// ===========================================================

// used for calling XInitThreads on Linux/X11, empty on
// Windows and macOS, defined in linux.h, win32.h, macos.h
void initThreads();

// run_command implementations in posix.h, win32.h
int run_command(const char *command,
const char *input[], size_t numInput,
Expand Down
19 changes: 19 additions & 0 deletions src/c/linux.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
#include <string.h>
#include <dlfcn.h>

#include "common.h"

#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 4b4b8c1

Please sign in to comment.