diff options
| -rw-r--r-- | comet.conf | 1 | ||||
| -rw-r--r-- | src/blocks/slider.c | 25 | ||||
| -rw-r--r-- | src/layout.c | 7 |
3 files changed, 22 insertions, 11 deletions
@@ -100,5 +100,6 @@ bar-line-color = #000 bar-line-width = 2 bar-bg-color = #fff + seekable = true diff --git a/src/blocks/slider.c b/src/blocks/slider.c index ba3bb6d..82d6140 100644 --- a/src/blocks/slider.c +++ b/src/blocks/slider.c @@ -16,6 +16,7 @@ typedef struct { gradient_t bar_color; gradient_t line_color; gradient_t bg_color; + bool seekable; } block_slider_t; static void block_slider_layout(block_t *block, layout_t *layout, layout_info_t info) @@ -71,27 +72,32 @@ static void block_slider_event(layout_t *layout, event_t event) { block_slider_t *slider = (block_slider_t *)layout->block; + if (!slider->seekable) return; + int bar_y = layout->y + (layout->height - slider->height) / 2; int bar_x = layout->x + (layout->width - slider->width) / 2; if (check_capsule(event.x, event.y, bar_x, bar_y, slider->width, slider->height)) { - log_value_debug("Clicked slider", + int value = 100 * (event.x - bar_x) / (double)(slider->width - 1); + + log_value_debug("Updated slider value", + "i:event_x", event.x, "i:bar_x", bar_x, - "i:bar_y", bar_y, "i:bar_width", slider->width, - "i:bar_height", slider->height, - "i:value", slider->value); + "i:old_value", slider->value, + "i:new_value", value); + + slider->value = value; } } static void block_slider_init(block_t *block, const block_scheme_t *scheme) { block->type = BLOCK_SPEC; - - block_spec_t *spec = (block_spec_t *)block; - spec->layout_fn = block_slider_layout; - spec->render_fn = block_slider_render; - spec->event_fn = block_slider_event; + block_slider_t *slider = (block_slider_t *)block; + slider->block.layout_fn = block_slider_layout; + slider->block.render_fn = block_slider_render; + slider->block.event_fn = block_slider_event; } static void block_slider_clean(block_t *block) @@ -120,6 +126,7 @@ static const config_entry_t block_slider_entries[] = { { "bar-width", CONFIG_UINT, NULL, offsetof(block_slider_t, width) }, { "bar-line-width", CONFIG_UINT, NULL, offsetof(block_slider_t, line_width) }, { "bar-value", CONFIG_UINT, NULL, offsetof(block_slider_t, value) }, + { "seekable", CONFIG_BOOL, NULL, offsetof(block_slider_t, seekable) }, { 0 }, }; diff --git a/src/layout.c b/src/layout.c index cf19d4b..103153a 100644 --- a/src/layout.c +++ b/src/layout.c @@ -74,10 +74,13 @@ void layout_init(layout_t *layout, block_t *block, layout_info_t info) } case BLOCK_SPEC: { - block_spec_t *spec = (block_spec_t *)block; // You are on your own - // TODO: Maybe check for layout correctness + block_spec_t *spec = (block_spec_t *)block; spec->layout_fn(block, layout, info); + + // TODO: Add more checks + assert(layout->width > 0); + assert(layout->height > 0); break; } |
