aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/imv.1.txt6
-rw-r--r--src/imv.c16
-rw-r--r--src/list.c6
3 files changed, 25 insertions, 3 deletions
diff --git a/doc/imv.1.txt b/doc/imv.1.txt
index 0d6a2b3..5d4ec2b 100644
--- a/doc/imv.1.txt
+++ b/doc/imv.1.txt
@@ -35,6 +35,12 @@ Options
Set the background colour. Can either be a 6-digit hexadecimal colour code
or 'checks' to show a chequered background.
+*-c* <command>::
+ Specify a command to be run on launch, after the configuration has been
+ loaded. Can be used to configure custom keys with the bind command. This
+ option can be used multiple times. Commands are run in the order that they
+ have been passed to imv.
+
*-d*::
Start with overlay visible.
diff --git a/src/imv.c b/src/imv.c
index d657862..035f9d3 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -155,6 +155,9 @@ struct imv {
/* if specified by user, the path of the first image to display */
char *starting_path;
+ /* list of startup commands to be run on launch, after loading the config */
+ struct list *startup_commands;
+
/* the user-specified format strings for the overlay and window title */
char *title_text;
char *overlay_text;
@@ -524,6 +527,7 @@ struct imv *imv_create(void)
" [${imv_width}x${imv_height}] [${imv_scale}%]"
" $imv_current_file [$imv_scaling_mode]"
);
+ imv->startup_commands = list_create();
imv_command_register(imv->commands, "quit", &command_quit);
imv_command_register(imv->commands, "pan", &command_pan);
@@ -624,6 +628,8 @@ void imv_free(struct imv *imv)
backend = next;
}
+ list_free(imv->startup_commands);
+
free(imv);
}
@@ -762,7 +768,7 @@ bool imv_parse_args(struct imv *imv, int argc, char **argv)
int o;
/* TODO getopt_long */
- while ((o = getopt(argc, argv, "frdxhvlu:s:n:b:t:")) != -1) {
+ while ((o = getopt(argc, argv, "frdxhvlu:s:n:b:t:c:")) != -1) {
switch(o) {
case 'f': imv->start_fullscreen = true; break;
case 'r': imv->recursive_load = true; break;
@@ -802,6 +808,7 @@ bool imv_parse_args(struct imv *imv, int argc, char **argv)
return false;
}
break;
+ case 'c': list_append(imv->startup_commands, optarg); break;
case '?':
imv_log(IMV_ERROR, "Unknown argument '%c'. Aborting.\n", optopt);
return false;
@@ -878,6 +885,13 @@ int imv_run(struct imv *imv)
}
}
+ /* Push any startup commands into the event queue */
+ for (size_t i = 0; i < imv->startup_commands->len; ++i) {
+ command_callback(imv->startup_commands->items[i], imv);
+ }
+ list_free(imv->startup_commands);
+ imv->startup_commands = NULL;
+
/* time keeping */
double last_time = cur_time();
double current_time;
diff --git a/src/list.c b/src/list.c
index 21f2f74..69fc0e3 100644
--- a/src/list.c
+++ b/src/list.c
@@ -13,8 +13,10 @@ struct list *list_create(void)
void list_free(struct list *list)
{
- free(list->items);
- free(list);
+ if (list) {
+ free(list->items);
+ free(list);
+ }
}
void list_deep_free(struct list *list)