diff options
Diffstat (limited to 'wmstatus.c')
| -rw-r--r-- | wmstatus.c | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -1,7 +1,7 @@ /* * wmstatus.c: simple PulseAudio-enabled status setter for dwm and i3/sway * - * Copyright (c) 2015 - 2024, Přemysl Eric Janouch <p@janouch.name> + * Copyright (c) 2015 - 2025, Přemysl Eric Janouch <p@janouch.name> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -798,6 +798,10 @@ backend_i3_new (void) static const struct config_schema g_config_general[] = { + { .name = "time_format", + .comment = "strftime format specification string", + .type = CONFIG_ITEM_STRING, + .default_ = "\"Week %V, %a %d %b %Y %H:%M %Z\"" }, { .name = "command", .comment = "Command to run for more info", .type = CONFIG_ITEM_STRING }, @@ -809,10 +813,10 @@ static const struct config_schema g_config_general[] = static const struct config_schema g_config_mpd[] = { + // XXX: We might want to allow config item defaults to not disable nulls. { .name = "address", .comment = "MPD host or socket", - .type = CONFIG_ITEM_STRING, - .default_ = "\"localhost\"" }, + .type = CONFIG_ITEM_STRING }, { .name = "service", .comment = "MPD service name or port", .type = CONFIG_ITEM_STRING, @@ -1375,7 +1379,7 @@ make_time_status (const char *fmt) if (local == NULL) exit_fatal ("%s: %s", "localtime", strerror (errno)); - if (!strftime (buf, sizeof buf, fmt, local)) + if (*fmt && !strftime (buf, sizeof buf, fmt, local)) exit_fatal ("strftime == 0"); return xstrdup (buf); @@ -1447,8 +1451,10 @@ refresh_status (struct app_context *ctx) for (size_t i = 0; i < ctx->command_current.len; i++) ctx->backend->add (ctx->backend, ctx->command_current.vector[i]); - char *times = make_time_status ("Week %V, %a %d %b %Y %H:%M %Z"); - ctx->backend->add (ctx->backend, times); + char *times = make_time_status + (get_config_string (ctx->config.root, "general.time_format")); + if (*times) + ctx->backend->add (ctx->backend, times); free (times); ctx->backend->flush (ctx->backend); @@ -1809,8 +1815,12 @@ mpd_on_io_hook (void *user_data, bool outgoing, const char *line) static void on_mpd_reconnect (void *user_data) { - // FIXME: the user should be able to disable MPD struct app_context *ctx = user_data; + struct config_item *root = ctx->config.root; + const char *address = get_config_string (root, "mpd.address"); + const char *service = get_config_string (root, "mpd.service"); + if (!address) + return; struct mpd_client *c = &ctx->mpd_client; c->user_data = ctx; @@ -1820,10 +1830,7 @@ on_mpd_reconnect (void *user_data) c->on_io_hook = mpd_on_io_hook; struct error *e = NULL; - struct config_item *root = ctx->config.root; - if (!mpd_client_connect (&ctx->mpd_client, - get_config_string (root, "mpd.address"), - get_config_string (root, "mpd.service"), &e)) + if (!mpd_client_connect (&ctx->mpd_client, address, service, &e)) { print_error ("%s: %s", "cannot connect to MPD", e->message); error_free (e); |
