summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-10-15 19:02:00 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-10-15 20:28:11 (GMT)
commit039812a978a2be64108a76df292dc0fb21db2ba4 (patch)
tree3493c038e111a70313ef7cddfe1b07673b1b7920 /gui
parent3cc35a674b1eed337bba15626b55e951199042f0 (diff)
downloadeeshow-039812a978a2be64108a76df292dc0fb21db2ba4.zip
eeshow-039812a978a2be64108a76df292dc0fb21db2ba4.tar.gz
eeshow-039812a978a2be64108a76df292dc0fb21db2ba4.tar.bz2
gui/viewer.c (viewer): launch external viewer; use it in comp.c
Diffstat (limited to 'gui')
-rw-r--r--gui/comp.c3
-rw-r--r--gui/viewer.c41
-rw-r--r--gui/viewer.h18
3 files changed, 61 insertions, 1 deletions
diff --git a/gui/comp.c b/gui/comp.c
index 31d7209..453cd78 100644
--- a/gui/comp.c
+++ b/gui/comp.c
@@ -23,6 +23,7 @@
#include "gui/aoi.h"
#include "gui/over.h"
#include "gui/pop.h"
+#include "gui/viewer.h"
#include "gui/common.h"
@@ -113,7 +114,7 @@ static void comp_click(void *user)
{
const char *doc = user;
- fprintf(stderr, "%s\n", doc);
+ viewer(doc);
}
diff --git a/gui/viewer.c b/gui/viewer.c
new file mode 100644
index 0000000..9db5515
--- /dev/null
+++ b/gui/viewer.c
@@ -0,0 +1,41 @@
+/*
+ * gui/viewer.c - Document viewer
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "misc/diag.h"
+#include "gui/viewer.h"
+
+
+#define VIEWER_VAR "EESHOW_VIEWER"
+#define DEFAULT_VIEWER "xdg-open"
+
+
+void viewer(const char *url)
+{
+ const char *v;
+ pid_t pid;
+
+ v = getenv(VIEWER_VAR);
+ if (!v)
+ v = DEFAULT_VIEWER;
+ pid = fork();
+ if (pid < 0)
+ diag_perror("fork");
+ if (pid)
+ return;
+ execlp(v, v, url, NULL);
+ perror(v);
+ _exit(1);
+}
diff --git a/gui/viewer.h b/gui/viewer.h
new file mode 100644
index 0000000..4d2c321
--- /dev/null
+++ b/gui/viewer.h
@@ -0,0 +1,18 @@
+/*
+ * gui/viewer.h - Document viewer
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef GUI_VIEWER_H
+#define GUI_VIEWER_H
+
+void viewer(const char *url);
+
+#endif /* !GUI_VIEWER_H */