Some dockapps may want to handle command line options themselves, so we
make this function optional.
Previously, if this function was skipped, then a segfault would result when
trying to access the _daContext global while first creating the dockapp
window.
Now we check if _daContext has been initialized first, and if not, we
initialize it.
---
libdockapp/src/daargs.c | 12 ++++++------
libdockapp/src/daargs.h | 2 +-
libdockapp/src/damain.c | 3 +++
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/libdockapp/src/daargs.c b/libdockapp/src/daargs.c
index 365fac6..eab61cc 100644
--- a/libdockapp/src/daargs.c
+++ b/libdockapp/src/daargs.c
@@ -58,11 +58,7 @@ DAParseArguments(
int i, j, size;
int found = 0;
- _daContext = DAContextInit();
-
- _daContext->argc = argc;
- _daContext->argv = argv;
- _daContext->programName = argv[0];
+ _daContext = DAContextInit(argc, argv);
size = (count + DEFAULT_OPTION_COUNT) * sizeof(DAProgramOption *);
_daContext->options = malloc(size);
@@ -207,12 +203,16 @@ DAGetProgramName()
*/
struct DAContext *
-DAContextInit(void)
+DAContextInit(int argc, char **argv)
{
struct DAContext *context = malloc(sizeof(struct DAContext));
memset(context, 0, sizeof(struct DAContext));
+ context->argc = argc;
+ context->argv = argv;
+ context->programName = argv[0];
+
return context;
}
diff --git a/libdockapp/src/daargs.h b/libdockapp/src/daargs.h
index 0373ffb..f3608fe 100644
--- a/libdockapp/src/daargs.h
+++ b/libdockapp/src/daargs.h
@@ -42,6 +42,6 @@ struct DAContext {
};
-struct DAContext *DAContextInit(void);
+struct DAContext *DAContextInit(int argc, char **argv);
void DAFreeContext(void);
diff --git a/libdockapp/src/damain.c b/libdockapp/src/damain.c
index e148f08..18ae291 100644
--- a/libdockapp/src/damain.c
+++ b/libdockapp/src/damain.c
@@ -134,6 +134,9 @@ DACreateIcon(char *name, unsigned width, unsigned height,
int argc, char **argv)
unsigned long valueMask;
char *resourceValue;
+ if (!_daContext)
+ _daContext = DAContextInit(argc, argv);
+
_daContext->width = width;
_daContext->height = height;
--
2.11.0
--
To unsubscribe, send mail to [email protected].