summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/gui.c21
-rw-r--r--gui/gui.h3
-rw-r--r--main.c15
3 files changed, 35 insertions, 4 deletions
diff --git a/gui/gui.c b/gui/gui.c
index 48f36d7..5f084c8 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
+#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include "version.h"
@@ -448,7 +449,8 @@ static void size_allocate_event(GtkWidget *widget, GdkRectangle *allocation,
/* ----- Initialization ---------------------------------------------------- */
-int run_gui(const struct file_names *fn, bool recurse, int limit)
+int run_gui(const struct file_names *fn, bool recurse, int limit,
+ const char **commands, unsigned n_commands)
{
GtkWidget *window;
char *title;
@@ -510,6 +512,23 @@ int run_gui(const struct file_names *fn, bool recurse, int limit)
go_to_sheet(&gui, gui.new_hist->sheets);
gtk_widget_show_all(window);
+ if (n_commands) {
+ long xid =
+ gdk_x11_window_get_xid(gtk_widget_get_window(window));
+ char *s;
+
+ if (asprintf(&s, "0x%lx", xid)) {}
+ setenv("EESHOW_WINDOW_ID", s, 1);
+
+ while (n_commands--) {
+ while (gtk_events_pending())
+ gtk_main_iteration();
+
+ system(*commands);
+ commands++;
+ }
+ }
+
/* for performance testing, use -N-depth */
if (limit >= 0)
gtk_main();
diff --git a/gui/gui.h b/gui/gui.h
index 2d71490..d3f0fab 100644
--- a/gui/gui.h
+++ b/gui/gui.h
@@ -18,6 +18,7 @@
#include "kicad/ext.h"
-int run_gui(const struct file_names *fn, bool recurse, int limit);
+int run_gui(const struct file_names *fn, bool recurse, int limit,
+ const char **commands, unsigned n_commands);
#endif /* !GUI_GUI_H */
diff --git a/main.c b/main.c
index c0f7931..0b6dc74 100644
--- a/main.c
+++ b/main.c
@@ -84,6 +84,9 @@ void usage(const char *name)
" -e show extra information (e.g., pin types)\n"
" -v increase verbosity of diagnostic output\n"
" -C 'cat' the file to standard output\n"
+" -E shell_command ...\n"
+" execute the specified shell command when the GUI is ready.\n"
+" Sets EESHOW_WINDOW_ID to the X11 window ID.\n"
" -H show history of repository on standard output\n"
" -N n limit history to n revisions (unlimited if omitted or 0)\n"
" -S parse S-expressions from stdin and dump to stdout\n"
@@ -129,6 +132,8 @@ int main(int argc, char **argv)
const char *cat = NULL;
const char *history = NULL;
const char *fmt = NULL;
+ const char **commands = NULL;
+ unsigned n_commands = 0;
struct pl_ctx *pl = NULL;
int limit = 0;
char c;
@@ -167,7 +172,7 @@ int main(int argc, char **argv)
if (!have_dashdash)
gtk_init(&argc, &argv);
- while ((c = getopt(dashdash, argv, "1evC:F:H:LN:OPSV")) != EOF)
+ while ((c = getopt(dashdash, argv, "1evC:E:F:H:LN:OPSV")) != EOF)
switch (c) {
case '1':
one_sheet = 1;
@@ -181,6 +186,11 @@ int main(int argc, char **argv)
case 'C':
cat = optarg;
break;
+ case 'E':
+ commands = realloc_type_n(commands, const char *,
+ n_commands + 1);
+ commands[n_commands++] = optarg;
+ break;
case 'F':
fmt = optarg;
break;
@@ -244,7 +254,8 @@ int main(int argc, char **argv)
if (!have_dashdash) {
optind = 0; /* reset getopt */
- return run_gui(&file_names, !one_sheet, limit);
+ return run_gui(&file_names, !one_sheet, limit,
+ commands, n_commands);
}
if (dashdash == argc) {