Skip to content

Commit

Permalink
Implement time_threshold display
Browse files Browse the repository at this point in the history
  • Loading branch information
tesselslate committed Jun 3, 2023
1 parent 9b10354 commit c65d11e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions wayboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ render_frame(uint32_t time) {
static void
render_key(struct config_key *key, struct key_state *state) {
bool active = state->last_release < state->last_press;
uint64_t time_active = active ? 0 : state->last_release - state->last_press;

pixman_color_t foreground, text;
if (active) {
Expand All @@ -234,8 +233,10 @@ render_key(struct config_key *key, struct key_state *state) {
key->h,
});
char *text_str = NULL;
if (key->time_threshold > 0 && !active) {
// TODO
uint64_t time_active = (state->last_release - state->last_press) / 1000000;
if (key->time_threshold > 0 && time_active < key->time_threshold && !active) {
text_str = malloc(32);
snprintf(text_str, 32, "%" PRIu64 " ms", time_active);
} else if (key->text != NULL) {
text_str = strdup(key->text);
}
Expand Down Expand Up @@ -330,6 +331,9 @@ create_window() {
pixman_image_set_clip_region32(pix, &clip);
pixman_region32_fini(&clip);
render_clear_buffer();
for (int i = 0; i < config.count; i++) {
render_key(&config.keys[i], &states[i]);
}
wl_surface_attach(wl_surface, wl_buffer, 0, 0);
wl_surface_commit(wl_surface);

Expand Down Expand Up @@ -421,8 +425,8 @@ read_config(const char *path) {
config_setting_lookup_int(key, "h", &config.keys[i].h) &&
config_setting_lookup_int(key, "scancode", &scancode)) {
config.keys[i].scancode = scancode;
double time_threshold;
if (config_setting_lookup_float(key, "time_threshold", &time_threshold)) {
int time_threshold;
if (config_setting_lookup_int(key, "time_threshold", &time_threshold)) {
config.keys[i].time_threshold = time_threshold;
}
if (config_setting_lookup_string(key, "text", &str)) {
Expand Down
2 changes: 1 addition & 1 deletion wayboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct config_key {
char *text;
int x, y, w, h;
uint8_t scancode;
double time_threshold;
int time_threshold;
};

struct config {
Expand Down

0 comments on commit c65d11e

Please sign in to comment.