aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-03-15 18:14:19 +0100
committerDavid Robillard <d@drobilla.net>2020-03-15 20:53:37 +0100
commit87351f2a8aaaad988b44e985ac5240af43d331e3 (patch)
tree3631d55d2fbf5e8a4e2fe97d4dd3845400d93ddb /pugl
parent9f1467c2173c487e35522139abc54d583a4078e9 (diff)
downloadpugl-87351f2a8aaaad988b44e985ac5240af43d331e3.tar.gz
pugl-87351f2a8aaaad988b44e985ac5240af43d331e3.tar.bz2
pugl-87351f2a8aaaad988b44e985ac5240af43d331e3.zip
Add type and flags to world
Unfortunately this is an API break, but there's no reasonable way to deprecate the old function and this is required for things to work correctly. The type will be used in following commits to tick the main loop and dispatch events correctly for either case.
Diffstat (limited to 'pugl')
-rw-r--r--pugl/detail/implementation.c4
-rw-r--r--pugl/detail/implementation.h3
-rw-r--r--pugl/detail/mac.m3
-rw-r--r--pugl/detail/win.c3
-rw-r--r--pugl/detail/x11.c6
-rw-r--r--pugl/pugl.h31
6 files changed, 42 insertions, 8 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index 17cc6fd..b2306c6 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -115,10 +115,10 @@ puglSetDefaultHints(PuglHints hints)
}
PuglWorld*
-puglNewWorld(void)
+puglNewWorld(PuglWorldType type, PuglWorldFlags flags)
{
PuglWorld* world = (PuglWorld*)calloc(1, sizeof(PuglWorld));
- if (!world || !(world->impl = puglInitWorldInternals())) {
+ if (!world || !(world->impl = puglInitWorldInternals(type, flags))) {
free(world);
return NULL;
}
diff --git a/pugl/detail/implementation.h b/pugl/detail/implementation.h
index f363a30..2ad3f65 100644
--- a/pugl/detail/implementation.h
+++ b/pugl/detail/implementation.h
@@ -36,7 +36,8 @@ void puglSetBlob(PuglBlob* dest, const void* data, size_t len);
void puglSetString(char** dest, const char* string);
/** Allocate and initialise world internals (implemented once per platform) */
-PuglWorldInternals* puglInitWorldInternals(void);
+PuglWorldInternals*
+puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags);
/** Destroy and free world internals (implemented once per platform) */
void puglFreeWorldInternals(PuglWorld* world);
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index 2920675..ab59b99 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -695,7 +695,8 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
@end
PuglWorldInternals*
-puglInitWorldInternals(void)
+puglInitWorldInternals(PuglWorldType PUGL_UNUSED(type),
+ PuglWorldFlags PUGL_UNUSED(flags))
{
PuglWorldInternals* impl = (PuglWorldInternals*)calloc(
1, sizeof(PuglWorldInternals));
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 290a658..bbaa872 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -105,7 +105,8 @@ puglRegisterWindowClass(const char* name)
}
PuglWorldInternals*
-puglInitWorldInternals(void)
+puglInitWorldInternals(PuglWorldType PUGL_UNUSED(type),
+ PuglWorldFlags PUGL_UNUSED(flags))
{
PuglWorldInternals* impl = (PuglWorldInternals*)calloc(
1, sizeof(PuglWorldInternals));
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index 10ae0bb..7edc1ed 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -66,8 +66,12 @@ static const long eventMask =
ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask);
PuglWorldInternals*
-puglInitWorldInternals(void)
+puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags)
{
+ if (type == PUGL_PROGRAM && (flags & PUGL_WORLD_THREADS)) {
+ XInitThreads();
+ }
+
Display* display = XOpenDisplay(NULL);
if (!display) {
return NULL;
diff --git a/pugl/pugl.h b/pugl/pugl.h
index c5f8969..d215749 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -491,6 +491,31 @@ typedef struct PuglWorldImpl PuglWorld;
typedef void* PuglWorldHandle;
/**
+ The type of a PuglWorld.
+*/
+typedef enum {
+ PUGL_PROGRAM, ///< Top-level application
+ PUGL_MODULE ///< Plugin or module within a larger application
+} PuglWorldType;
+
+/**
+ World flags.
+*/
+typedef enum {
+ /**
+ Set up support for threads if necessary.
+
+ - X11: Calls XInitThreads() which is required for some drivers.
+ */
+ PUGL_WORLD_THREADS = 1 << 0
+} PuglWorldFlag;
+
+/**
+ Bitwise OR of #PuglWorldFlag values.
+*/
+typedef uint32_t PuglWorldFlags;
+
+/**
A log message level, compatible with syslog.
*/
typedef enum {
@@ -514,10 +539,12 @@ typedef void (*PuglLogFunc)(PuglWorld* world,
/**
Create a new world.
+ @param type The type, which dictates what this world is responsible for.
+ @param flags Flags to control world features.
@return A new world, which must be later freed with puglFreeWorld().
*/
PUGL_API PuglWorld*
-puglNewWorld(void);
+puglNewWorld(PuglWorldType type, PuglWorldFlags flags);
/**
Free a world allocated with puglNewWorld().
@@ -1057,7 +1084,7 @@ puglInit(const int* pargc, char** argv)
(void)pargc;
(void)argv;
- return puglNewView(puglNewWorld());
+ return puglNewView(puglNewWorld(PUGL_MODULE, 0));
}
/**