diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-07-13 21:36:00 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-07-13 21:47:56 -0700 |
commit | 1446525ac78b25932db12e4e690184b137fc6aa8 (patch) | |
tree | 46434c9363d4acf7610abaa7f863f660ecaa35b4 /src | |
parent | 2f4011b4c5ec416d78d6da304315708a42e39798 (diff) |
til_args,*_fb: introduce --title= and wire up to til_fb_t
For meta-demo use cases like alphazed is experimenting with, it's
desirable to change the window title from "rototiller" to
"alphazed" or whatever if in windowed mode.
This adds a way to do that in the obvious fashion...
--title="alphazed" etc.
Diffstat (limited to 'src')
-rw-r--r-- | src/drm_fb.c | 2 | ||||
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/mem_fb.c | 2 | ||||
-rw-r--r-- | src/sdl_fb.c | 12 | ||||
-rw-r--r-- | src/til_args.c | 3 | ||||
-rw-r--r-- | src/til_args.h | 1 | ||||
-rw-r--r-- | src/til_fb.c | 4 | ||||
-rw-r--r-- | src/til_fb.h | 4 |
8 files changed, 28 insertions, 10 deletions
diff --git a/src/drm_fb.c b/src/drm_fb.c index 4996252..d10891b 100644 --- a/src/drm_fb.c +++ b/src/drm_fb.c @@ -354,7 +354,7 @@ static drmModeModeInfo * lookup_mode(drmModeConnector *connector, const char *mo /* prepare the drm context for use with the supplied settings */ -static int drm_fb_init(const til_setup_t *setup, void **res_context) +static int drm_fb_init(const char *title, const til_setup_t *setup, void **res_context) { drm_fb_setup_t *s = (drm_fb_setup_t *)setup; drm_fb_t *c; @@ -70,6 +70,7 @@ typedef struct setup_t { til_settings_t *video_settings; til_setup_t *video_setup; unsigned seed; + const char *title; } setup_t; /* FIXME: this is unnecessarily copy-pasta, i think modules should just be made @@ -207,6 +208,10 @@ static int setup_from_args(til_args_t *args, setup_t *res_setup, const char **re assert(args); assert(res_setup); + setup.title = strdup(args->title ? : "rototiller"); + if (!setup.title) + goto _err; + if (args->seed) { r = parse_seed(args->seed, &setup.seed); if (r < 0) @@ -245,6 +250,7 @@ static int setup_from_args(til_args_t *args, setup_t *res_setup, const char **re return changes; _err: + free((void *)setup.title); til_settings_free(setup.module_settings); til_settings_free(setup.video_settings); @@ -308,7 +314,7 @@ _out: static int print_help(void) { - printf("Run without any flags or partial settings for interactive mode.\n" + printf("\nRun without any flags or partial settings for interactive mode.\n" "\n" "Supported flags:\n"); @@ -387,7 +393,7 @@ int main(int argc, const char *argv[]) exit_if(!(rototiller.module = til_lookup_module(til_settings_get_value_by_idx(setup.module_settings, 0, NULL))), "unable to lookup module from settings \"%s\"", til_settings_get_value_by_idx(setup.module_settings, 0, NULL)); - exit_if((r = til_fb_new(fb_ops, setup.video_setup, NUM_FB_PAGES, &rototiller.fb)) < 0, + exit_if((r = til_fb_new(fb_ops, setup.title, setup.video_setup, NUM_FB_PAGES, &rototiller.fb)) < 0, "unable to create fb: %s", strerror(-r)); exit_if(!(rototiller.stream = til_stream_new()), diff --git a/src/mem_fb.c b/src/mem_fb.c index fc9406b..ee736c7 100644 --- a/src/mem_fb.c +++ b/src/mem_fb.c @@ -63,7 +63,7 @@ static int mem_fb_setup(const til_settings_t *settings, til_setting_t **res_sett } -static int mem_fb_init(const til_setup_t *setup, void **res_context) +static int mem_fb_init(const char *title, const til_setup_t *setup, void **res_context) { mem_fb_t *c; int r; diff --git a/src/sdl_fb.c b/src/sdl_fb.c index 6a67411..6221a83 100644 --- a/src/sdl_fb.c +++ b/src/sdl_fb.c @@ -24,6 +24,7 @@ struct sdl_fb_page_t { }; typedef struct sdl_fb_t { + const char *title; unsigned width, height; Uint32 flags; @@ -137,12 +138,13 @@ static int sdl_err_to_errno(int err) } } -static int sdl_fb_init(const til_setup_t *setup, void **res_context) +static int sdl_fb_init(const char *title, const til_setup_t *setup, void **res_context) { sdl_fb_setup_t *s = (sdl_fb_setup_t *)setup; sdl_fb_t *c; int r; + assert(title); assert(setup); assert(res_context); @@ -157,6 +159,12 @@ static int sdl_fb_init(const til_setup_t *setup, void **res_context) c->flags = SDL_WINDOW_FULLSCREEN_DESKTOP; } + c->title = strdup(title); + if (!c->title) { + free(c); + return -ENOMEM; + } + c->width = s->width; c->height = s->height; @@ -208,7 +216,7 @@ static int sdl_fb_acquire(til_fb_t *fb, void *context, void *page) { sdl_fb_t *c = context; - c->window = SDL_CreateWindow("rototiller", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, c->width, c->height, c->flags); + c->window = SDL_CreateWindow(c->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, c->width, c->height, c->flags); if (!c->window) return -1; diff --git a/src/til_args.c b/src/til_args.c index 7e4c7e6..b51f81b 100644 --- a/src/til_args.c +++ b/src/til_args.c @@ -60,6 +60,8 @@ static int args_parse(int argc, const char *argv[], til_args_t *res_args, int *r res_args->print_module_contexts = 1; } else if (!strcasecmp("--print-pipes", argv[i])) { res_args->print_pipes = 1; + } else if (!strncasecmp("--title=", argv[i], 8)) { + res_args->title = &argv[i][8]; } else { if (!res_argv) return -EINVAL; @@ -97,6 +99,7 @@ int til_args_help(FILE *out) " --print-module-contexts print active contexts on-stream to stdout\n" " --print-pipes print active pipes on-stream to stdout\n" " --seed= seed to use for all PRNG in hexadecimal (e.g. 0xdeadbeef)\n" + " --title= title to use where applicable (e.g. window title)\n" " --video= video settings\n" ); } diff --git a/src/til_args.h b/src/til_args.h index 7c21668..d49211e 100644 --- a/src/til_args.h +++ b/src/til_args.h @@ -7,6 +7,7 @@ typedef struct til_args_t { const char *module; const char *video; const char *seed; + const char *title; unsigned use_defaults:1; unsigned help:1; diff --git a/src/til_fb.c b/src/til_fb.c index fd008ca..aa20fd9 100644 --- a/src/til_fb.c +++ b/src/til_fb.c @@ -486,7 +486,7 @@ til_fb_t * til_fb_free(til_fb_t *fb) /* create a new fb instance */ -int til_fb_new(const til_fb_ops_t *ops, const til_setup_t *setup, int n_pages, til_fb_t **res_fb) +int til_fb_new(const til_fb_ops_t *ops, const char *title, const til_setup_t *setup, int n_pages, til_fb_t **res_fb) { _til_fb_page_t *page; til_fb_t *fb; @@ -509,7 +509,7 @@ int til_fb_new(const til_fb_ops_t *ops, const til_setup_t *setup, int n_pages, t fb->ops = ops; if (ops->init) { - r = ops->init(setup, &fb->ops_context); + r = ops->init(title, setup, &fb->ops_context); if (r < 0) goto fail; } diff --git a/src/til_fb.h b/src/til_fb.h index 21699c2..1f100dd 100644 --- a/src/til_fb.h +++ b/src/til_fb.h @@ -38,7 +38,7 @@ typedef struct til_fb_t til_fb_t; /* Supply this struct to fb_new() with the appropriate context */ typedef struct til_fb_ops_t { int (*setup)(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup); - int (*init)(const til_setup_t *setup, void **res_context); + int (*init)(const char *title, const til_setup_t *setup, void **res_context); void (*shutdown)(til_fb_t *fb, void *context); int (*acquire)(til_fb_t *fb, void *context, void *page); void (*release)(til_fb_t *fb, void *context); @@ -53,7 +53,7 @@ til_fb_fragment_t * til_fb_fragment_snapshot(til_fb_fragment_t **fragment_ptr, i til_fb_fragment_t * til_fb_fragment_reclaim(til_fb_fragment_t *fragment); til_fb_t * til_fb_free(til_fb_t *fb); void til_fb_get_put_pages_count(til_fb_t *fb, unsigned *count); -int til_fb_new(const til_fb_ops_t *ops, const til_setup_t *setup, int n_pages, til_fb_t **res_fb); +int til_fb_new(const til_fb_ops_t *ops, const char *title, const til_setup_t *setup, int n_pages, til_fb_t **res_fb); void til_fb_rebuild(til_fb_t *fb); void * til_fb_context(til_fb_t *fb); int til_fb_flip(til_fb_t *fb); |