diff options
Diffstat (limited to 'taro')
| -rw-r--r-- | taro/config.h | 8 | ||||
| -rw-r--r-- | taro/daemon.c | 42 | ||||
| -rw-r--r-- | taro/db.c | 8 | ||||
| -rw-r--r-- | taro/file_ext.c | 2 | ||||
| -rw-r--r-- | taro/ui.c | 60 |
5 files changed, 73 insertions, 47 deletions
diff --git a/taro/config.h b/taro/config.h index 16fad79..cca7807 100644 --- a/taro/config.h +++ b/taro/config.h @@ -57,7 +57,7 @@ static void parse_config_json(struct config *conf, char *envhome, json_t *root) json_t *assets = json_object_get(directories, "assets"); if (!assets || !json_is_string(assets) || al_strlen(json_string_value(assets)) == 0) { - error("asset directory not set or invalid"); + log_error("asset directory not set or invalid"); conf->valid = false; goto out; } @@ -71,13 +71,13 @@ static void parse_config_json(struct config *conf, char *envhome, json_t *root) json_t *value; json_array_foreach(wallpapers, index, value) { if (!json_is_string(value) || al_strlen(json_string_value(value)) == 0) { - error("invalid wallpaper directory (index: %zu)", index); + log_error("invalid wallpaper directory (index: %zu)", index); continue; } str path; maybe_replace_home_in_path(&path, envhome, json_string_value(value)); if (!nn_dir_exists(&path)) { - warn("directory does not exist %.*s", al_str_x(&path)); + log_warn("directory does not exist %.*s", al_str_x(&path)); al_str_free(&path); continue; } @@ -85,7 +85,7 @@ static void parse_config_json(struct config *conf, char *envhome, json_t *root) } if (conf->wallpaper_dirs.count == 0) { - error("no valid wallpaper directories"); + log_error("no valid wallpaper directories"); conf->valid = false; goto out; } diff --git a/taro/daemon.c b/taro/daemon.c index 92e6388..a26de8b 100644 --- a/taro/daemon.c +++ b/taro/daemon.c @@ -83,7 +83,7 @@ static s32 parse_and_set_props(str *selection, str *wallpaper_id, bool *is_packa static bool send_signal_to_pid(pid_t pid, s32 signal) { if (kill(pid, signal) != 0) { - error("kill(%d) failed (%s)", pid, nn_strerror(errno)); + log_error("kill(%d) failed (%s)", pid, nn_strerror(errno)); return false; } return true; @@ -103,11 +103,11 @@ static pid_t exec_or_exit(char *args[]) { pid_t pid = fork(); if (pid == -1) { - error("fatal: failed to fork process, exiting..."); + log_error("fatal: failed to fork process, exiting..."); exit(EXIT_FAILURE); } else if (pid == 0) { if (execvp(args[0], args) == -1) { - error("fatal: failed to run '%s', exiting...", args[0]); + log_error("fatal: failed to run '%s', exiting...", args[0]); // This should return the pid of init if the parent process has already exited. pid_t ppid = getppid(); if (ppid != 1) send_signal_to_pid(ppid, SIGINT); @@ -132,21 +132,21 @@ static void maybe_kill_wallpaper(struct monitor *monitor) static bool search_wallpaper_dirs(struct daemon *dmon, str *id, str *path) { bool found = false; - debug("searching for wallpaper of id %.*s", al_str_x(id)); + log_debug("searching for wallpaper of id %.*s", al_str_x(id)); str *dir; al_array_foreach_ptr(dmon->conf.wallpaper_dirs, i, dir) { - debug("checking dir %.*s", al_str_x(dir)); + log_debug("checking dir %.*s", al_str_x(dir)); al_str_clone(path, dir); if (al_str_at(path, 1) != '/') al_str_cat(path, &al_str_c("/")); al_str_cat(path, id); if (nn_dir_exists(path)) { - debug("found wallpaper"); + log_debug("found wallpaper"); found = true; break; } al_str_free(path); } - if (!found) error("failed to find wallpaper of id %.*s", al_str_x(id)); + if (!found) log_error("failed to find wallpaper of id %.*s", al_str_x(id)); al_str_free(id); return found; } @@ -156,7 +156,7 @@ static bool run_wallpaper(struct daemon *dmon, struct monitor *monitor) maybe_kill_wallpaper(monitor); if (!dmon->conf.valid) { - error("config invalid, not setting wallpaper on %s", monitor->os->name); + log_error("config invalid, not setting wallpaper on %s", monitor->os->name); return false; } @@ -168,7 +168,7 @@ static bool run_wallpaper(struct daemon *dmon, struct monitor *monitor) } if (selection.length == 0) { - error("config for %s is empty", monitor->os->name); + log_error("config for %s is empty", monitor->os->name); al_str_free(&selection); return false; } @@ -179,7 +179,7 @@ static bool run_wallpaper(struct daemon *dmon, struct monitor *monitor) al_str_free(&selection); if (ret != 0) { if (ret == -1) { - error("failed to set properties for wallpaper on %s", monitor->os->name); + log_error("failed to set properties for wallpaper on %s", monitor->os->name); } al_str_free(&wallpaper_id); return false; @@ -195,14 +195,14 @@ static bool run_wallpaper(struct daemon *dmon, struct monitor *monitor) if (!nn_file_exists(&wallpaper_path)) { al_str_insert(&wallpaper_path, wallpaper_path.length - 9, &al_str_c("gif")); if (!nn_file_exists(&wallpaper_path)) { - error("wallpaper at %.*s has no package file", al_str_x(&wallpaper_path)); + log_error("wallpaper at %.*s has no package file", al_str_x(&wallpaper_path)); al_str_free(&wallpaper_path); return false; } } } - info("setting wallpaper %.*s on %s", al_str_x(&wallpaper_path), monitor->os->name); + log_info("setting wallpaper %.*s on %s", al_str_x(&wallpaper_path), monitor->os->name); char width[8], height[8]; al_snprintf(width, sizeof(width), "%d", monitor->os->width / monitor->os->scale); @@ -212,10 +212,10 @@ static bool run_wallpaper(struct daemon *dmon, struct monitor *monitor) char *c_str1 = al_str_to_c_str(&dmon->conf.asset_dir); if (is_package) { monitor->pid = exec_or_exit((char *[]){ - "mauri", "-p", c_str0, "-a", c_str1, "-m", monitor->os->name, "-w", width, "-h", height, NULL}); + "mauri", "-p", c_str0, "-a", c_str1, "-m", monitor->os->name, "-w", width, "-h", height, NULL }); } else { monitor->pid = exec_or_exit((char *[]){ - "mauri", "-d", c_str0, "-a", c_str1, "-m", monitor->os->name, "-w", width, "-h", height, NULL}); + "mauri", "-d", c_str0, "-a", c_str1, "-m", monitor->os->name, "-w", width, "-h", height, NULL }); } al_str_free(&wallpaper_path); al_free(c_str0); @@ -301,7 +301,7 @@ static void conf_fs_event_callback(void *userdata, struct inotify_event *event) (void)event; close_config(&dmon->conf); if (!open_config(&dmon->conf, false)) { - error("config became unavailable, exiting..."); + log_error("config became unavailable, exiting..."); exit(EXIT_FAILURE); } struct monitor *monitor; @@ -320,20 +320,20 @@ static void close_monitor(struct monitor *monitor) static void ipc_handle_subscribe_success(json_t *root) { if (json_boolean_value(root)) { - info("successfully subscribed to sway background covered events"); + log_info("successfully subscribed to sway background covered events"); } else { - info("failed to subscribe to sway background covered events"); + log_info("failed to subscribe to sway background covered events"); } } static void ipc_handle_response(struct daemon *dmon, u8 *buf, u32 size) { - debug("IN: %.*s", size, (char *)buf); + log_debug("IN: %.*s", size, (char *)buf); json_error_t error; json_t *root = json_loadb((char *)buf, size, 0, &error); if (!root) { - error("failed to parse sway-ipc json payload (%s)", error.text); + log_error("failed to parse sway-ipc json payload (%s)", error.text); goto done; } @@ -398,7 +398,7 @@ static void ipc_poll_callback(void *userdata, s32 revents) if (revents & NNWT_POLL_WRITE) { al_assert(!dmon->ipc_connected); if (!dmon->ipc_connected) { - info("connected to sway ipc socket"); + log_info("connected to sway ipc socket"); dmon->ipc_connected = true; } ssize_t ret = nn_socket_write(&dmon->ipc_socket, dmon->out.buf + dmon->out.index, dmon->out.size - dmon->out.index); @@ -542,7 +542,7 @@ s32 main(void) nn_poll_start(&dmon.ipc_poll, &dmon.loop); } else { dmon.ipc_errored = true; - warn("couldn't connect to sway ipc socket"); + log_warn("couldn't connect to sway ipc socket"); } nn_fs_event_init(&dmon.conf_event, &dmon.conf.config_path, NNWT_CLOSE_WRITE, conf_fs_event_callback, &dmon); @@ -76,7 +76,7 @@ static bool load_entry(struct entry *e) type = json_object_get(iter_obj, "type"); if (!type) { // Silently ignore for now. Is "Notes" a special case? see 1918273588. - //warn("improperly handled prop (%.*s)", al_str_x(&e->id)); + //log_warn("improperly handled prop (%.*s)", al_str_x(&e->id)); iter = json_object_iter_next(properties, iter); continue; } @@ -85,7 +85,7 @@ static bool load_entry(struct entry *e) if (al_str_eq(&type_str, &al_str_c("bool"))) { json_t *value = json_object_get(iter_obj, "value"); if (!value) { - warn("improperly handled bool (%.*s)", al_str_x(&e->id)); + log_warn("improperly handled bool (%.*s)", al_str_x(&e->id)); iter = json_object_iter_next(properties, iter); continue; } @@ -97,7 +97,7 @@ static bool load_entry(struct entry *e) json_t *min = json_object_get(iter_obj, "min"); json_t *max = json_object_get(iter_obj, "max"); if (!value || !min || !max) { - warn("improperly handled slider (%.*s)", al_str_x(&e->id)); + log_warn("improperly handled slider (%.*s)", al_str_x(&e->id)); iter = json_object_iter_next(properties, iter); continue; } @@ -115,7 +115,7 @@ static bool load_entry(struct entry *e) } p.type = PROP_TYPE_SLIDER; } else { - //warn("unhandled type. (%.*s)", al_str_x(type_str)); + //log_warn("unhandled type. (%.*s)", al_str_x(type_str)); } al_array_push(e->props, p); diff --git a/taro/file_ext.c b/taro/file_ext.c index 78fdba8..b419981 100644 --- a/taro/file_ext.c +++ b/taro/file_ext.c @@ -34,7 +34,7 @@ json_t *nn_file_open_as_json(str *path) json_error_t error; json_t *root = json_loadb(s.data, s.length, 0, &error); if (!root) { - error("json_loadb(%.*s, %u) failed (%s)", al_str_x(path), s.length, error.text); + log_error("json_loadb(%.*s, %u) failed (%s)", al_str_x(path), s.length, error.text); } al_str_free(&s); return root; @@ -100,6 +100,7 @@ struct info_prop { struct info { struct ncplane *ip; struct entry *e; + f32 flash; bool blitted; struct scrolling_text text; u32 max_props; @@ -169,6 +170,9 @@ static void select_monitor(struct ui *u) al_str_cat(&u->m.selection_path, &al_str_cr(monitor)); al_str_cat(&u->m.selection_path, &al_str_c("/selection")); u->g.set_index = get_entry_from_config(u); + if (u->g.set_index >= 0) { + u->g.selected_index = u->g.set_index; + } } static void write_selected_entry_to_config(struct ui *u) @@ -242,7 +246,7 @@ static bool init_monitors(struct ui *u, struct monitors *m) bool ret = nn_file_open_and_read_wholly(&monitors_path, &monitors, false); al_str_free(&monitors_path); if (!ret) { - error("failed to open monitor list, has `tarod` run?"); + log_error("failed to open monitor list, has `tarod` run?"); return false; } str monitor_dir; @@ -291,7 +295,7 @@ static bool init_ui(struct ui *u) if (!init_image_pool(&u->pool)) return false; if (!init_info(&u->n)) return false; if (!(u->nc = notcurses_init(NULL, stdin))) { - error("failed to initialize notcurses"); + log_error("failed to initialize notcurses"); return false; } al_set_print(void_print_callback, NULL); @@ -777,6 +781,7 @@ void draw_info(struct ui *u, struct info *n, bool update_text) ncplane_erase(u->ip); + struct ncvisual_options vopts = { 0 }; vopts.scaling = PIXEL_BLIT ? NCSCALE_SCALE_HIRES : NCSCALE_STRETCH; vopts.blitter = PIXEL_BLIT ? NCBLIT_PIXEL : NCBLIT_2x1; @@ -811,9 +816,17 @@ void draw_info(struct ui *u, struct info *n, bool update_text) } ip = &al_array_at(n->props, index); if (u->selected_menu == MENU_INFO && index == (u32)n->selected_prop) { - ncplane_set_fg_palindex(u->ip, 8); + if (n->flash > 0.f) { + ncplane_set_fg_palindex(u->ip, 0); + ncplane_set_bg_palindex(u->ip, 7); + n->flash -= MAX(TIMER_UPDATE_BASE * (u->delay / 1000000.f), 0.001f); + } else { + ncplane_set_fg_palindex(u->ip, 8); + ncplane_set_bg_default(u->ip); + } } else { ncplane_set_fg_default(u->ip); + ncplane_set_bg_default(u->ip); } draw_scrolling_text(u->ip, &ip->text, update_text); switch (ip->p->type) { @@ -898,21 +911,23 @@ static bool handle_input_monitors(struct ui *u, struct monitors *m, struct ncinp bool should_redraw_info = false; switch (input->id) { case NCKEY_LEFT: - case 'h': + case 'h': { if (m->selected_monitor - 1 < 0) { return false; } m->selected_monitor--; should_redraw_monitors = true; break; + } case NCKEY_RIGHT: - case 'l': + case 'l': { if ((u32)(m->selected_monitor + 1) >= m->monitors.count) { return false; } m->selected_monitor++; should_redraw_monitors = true; break; + } case NCKEY_RETURN: case NCKEY_SPACE: { select_monitor(u); @@ -942,21 +957,23 @@ static bool handle_input_info(struct ui *u, struct info *n, struct ncinput *inpu bool should_redraw_info = false; switch (input->id) { case NCKEY_UP: - case 'k': + case 'k': { if (n->selected_prop - 1 < 0) { return false; } n->selected_prop--; should_redraw_info = true; break; + } case NCKEY_DOWN: - case 'j': + case 'j': { if ((u32)(n->selected_prop + 1) >= n->props.count) { return false; } n->selected_prop++; should_redraw_info = true; break; + } case NCKEY_RETURN: case NCKEY_SPACE: { if (!n->props.count) return false; @@ -971,7 +988,7 @@ static bool handle_input_info(struct ui *u, struct info *n, struct ncinput *inpu case NCKEY_LEFT: case 'h': case NCKEY_RIGHT: - case 'l': + case 'l': { if (!n->props.count) return false; struct prop *p = &al_array_at(n->e->props, n->selected_prop); if (p->type == PROP_TYPE_SLIDER) { @@ -1000,6 +1017,7 @@ static bool handle_input_info(struct ui *u, struct info *n, struct ncinput *inpu } break; } + } if (should_redraw_info) draw_info(u, n, false); return should_redraw_info; } @@ -1039,7 +1057,7 @@ static bool handle_input_grid(struct ui *u, struct grid *g, struct ncinput *inpu bool should_redraw_info = false; switch (input->id) { case NCKEY_LEFT: - case 'h': + case 'h': { if (g->selected_index - 1 < 0) { return false; } @@ -1051,8 +1069,9 @@ static bool handle_input_grid(struct ui *u, struct grid *g, struct ncinput *inpu should_redraw_info = true; should_redraw_grid = true; break; + } case NCKEY_RIGHT: - case 'l': + case 'l': { if (g->selected_index + 1 >= (s32)u->db.entries.count) { return false; } @@ -1064,8 +1083,9 @@ static bool handle_input_grid(struct ui *u, struct grid *g, struct ncinput *inpu should_redraw_info = true; should_redraw_grid = true; break; + } case NCKEY_UP: - case 'k': + case 'k': { if (g->selected_index - g->tiles_x < g->min_index) { return false; } @@ -1073,8 +1093,9 @@ static bool handle_input_grid(struct ui *u, struct grid *g, struct ncinput *inpu should_redraw_info = true; should_redraw_grid = true; break; + } case NCKEY_DOWN: - case 'j': + case 'j': { if (g->selected_index + g->tiles_x > g->max_index) { return false; } @@ -1082,26 +1103,30 @@ static bool handle_input_grid(struct ui *u, struct grid *g, struct ncinput *inpu should_redraw_info = true; should_redraw_grid = true; break; - case 'f': + } + case 'f': { if (grid_next_page(u, &u->g, 0)) { should_update_grid = true; should_redraw_info = true; should_redraw_grid = true; } break; - case 'b': + } + case 'b': { if (grid_previous_page(&u->g, 0)) { should_update_grid = true; should_redraw_info = true; should_redraw_grid = true; } break; - case 'r': + } + case 'r': { g->set_index = -1; write_selected_entry_to_config(u); should_redraw_grid = true; should_redraw_info = true; break; + } case 's': { if (!u->db.entries.count) { return false; @@ -1156,6 +1181,7 @@ static void input_poll_callback(void *userdata, s32 revents) case MENU_GRID: if (u->n.props.count > 0) { u->selected_menu = MENU_INFO; + u->n.flash = FLASH_DURATION; } else { u->selected_menu = MENU_MONITORS; } @@ -1225,7 +1251,7 @@ s32 main(void) if (!nn_common_init()) return EXIT_FAILURE; if (!open_config(&u.conf, false)) { - error("failed to open config, run `tarod` at least once to generate needed config"); + log_error("failed to open config, run `tarod` at least once to generate needed config"); return EXIT_FAILURE; } @@ -1249,7 +1275,7 @@ s32 main(void) if (!layout_ui(&u)) { notcurses_stop(u.nc); - error("failed to layout ui, your terminal window is probably too small"); + log_error("failed to layout ui, your terminal window is probably too small"); goto out; } u.layed_out = true; |