pass PERCENTAGE variable on slider click

This commit is contained in:
Felix Kratz 2023-01-01 13:28:13 +01:00
parent a36350e603
commit e3f7c0e0b6
3 changed files with 28 additions and 4 deletions

View file

@ -174,7 +174,7 @@ void bar_item_needs_update(struct bar_item* bar_item) {
bar_item->needs_update = true; bar_item->needs_update = true;
} }
void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifier) { void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifier, CGPoint point) {
if (!bar_item) return; if (!bar_item) return;
env_vars_set(&bar_item->signal_args.env_vars, env_vars_set(&bar_item->signal_args.env_vars,
@ -185,6 +185,21 @@ void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifi
string_copy("MODIFIER"), string_copy("MODIFIER"),
string_copy(get_modifier_description(modifier))); string_copy(get_modifier_description(modifier)));
if (bar_item->has_slider) {
if (CGRectContainsPoint(bar_item->slider.background.bounds, point)) {
float delta = point.x - bar_item->slider.background.bounds.origin.x;
uint32_t percentage = delta
/ bar_item->slider.background.bounds.size.width
* 100.f + 0.5f;
char perc_str[8];
snprintf(perc_str, 8, "%d", percentage);
env_vars_set(&bar_item->signal_args.env_vars,
string_copy("PERCENTAGE"),
string_copy(perc_str) );
}
}
if (bar_item->click_script && strlen(bar_item->click_script) > 0) if (bar_item->click_script && strlen(bar_item->click_script) > 0)
fork_exec(bar_item->click_script, &bar_item->signal_args.env_vars); fork_exec(bar_item->click_script, &bar_item->signal_args.env_vars);
if (bar_item->update_mask & UPDATE_MOUSE_CLICKED) if (bar_item->update_mask & UPDATE_MOUSE_CLICKED)

View file

@ -105,7 +105,7 @@ bool bar_item_is_shown(struct bar_item* bar_item);
void bar_item_needs_update(struct bar_item* bar_item); void bar_item_needs_update(struct bar_item* bar_item);
bool bar_item_update(struct bar_item* bar_item, char* sender, bool forced, struct env_vars* env_vars); bool bar_item_update(struct bar_item* bar_item, char* sender, bool forced, struct env_vars* env_vars);
void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifier); void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifier, CGPoint point);
void bar_item_mouse_entered(struct bar_item* bar_item); void bar_item_mouse_entered(struct bar_item* bar_item);
void bar_item_mouse_exited(struct bar_item* bar_item); void bar_item_mouse_exited(struct bar_item* bar_item);

View file

@ -117,6 +117,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) {
debug("%s\n", __FUNCTION__); debug("%s\n", __FUNCTION__);
debug("EVENT_HANDLER_MOUSE_UP\n"); debug("EVENT_HANDLER_MOUSE_UP\n");
CGPoint point = CGEventGetLocation(context);
uint32_t wid = get_window_id_from_cg_event(context); uint32_t wid = get_window_id_from_cg_event(context);
CGEventType type = CGEventGetType(context); CGEventType type = CGEventGetType(context);
uint32_t modifier_keys = CGEventGetFlags(context); uint32_t modifier_keys = CGEventGetFlags(context);
@ -127,13 +128,21 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) {
adid ); adid );
if (!bar_item || bar_item->type == BAR_COMPONENT_GROUP) { if (!bar_item || bar_item->type == BAR_COMPONENT_GROUP) {
CGPoint point = CGEventGetLocation(context);
bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid); bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid);
} }
struct window* window = NULL;
CGPoint point_in_window_coords = CGPointZero;
if (bar_item) {
window = bar_item_get_window(bar_item, adid);
if (window) {
point_in_window_coords.x = point.x - window->origin.x;
point_in_window_coords.y = point.y - window->origin.y;
}
}
debug("item: %s\n", bar_item ? bar_item->name : "NULL"); debug("item: %s\n", bar_item ? bar_item->name : "NULL");
bar_item_on_click(bar_item, type, modifier_keys); bar_item_on_click(bar_item, type, modifier_keys, point_in_window_coords);
CFRelease(context); CFRelease(context);
return EVENT_SUCCESS; return EVENT_SUCCESS;
} }