mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-10 05:44:16 +00:00
send modifier keys held while scrolling to scripts
This commit is contained in:
parent
4194da0bd2
commit
dd8b7cd124
5 changed files with 33 additions and 11 deletions
|
@ -256,16 +256,20 @@ void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t mouse_
|
|||
env_vars_destroy(&env_vars);
|
||||
}
|
||||
|
||||
void bar_item_on_scroll(struct bar_item* bar_item, int scroll_delta) {
|
||||
void bar_item_on_scroll(struct bar_item* bar_item, int scroll_delta, uint32_t modifier) {
|
||||
if (!bar_item) return;
|
||||
|
||||
struct env_vars env_vars;
|
||||
env_vars_init(&env_vars);
|
||||
char info_str[256];
|
||||
snprintf(info_str, 256, "{\n"
|
||||
"\t\"delta\": %d\n"
|
||||
"\t\"delta\": %d,\n"
|
||||
"\t\"modifier\": \"%s\",\n"
|
||||
"\t\"modfier_code\": %u\n"
|
||||
"}\n",
|
||||
scroll_delta );
|
||||
scroll_delta,
|
||||
get_modifier_description(modifier),
|
||||
modifier );
|
||||
|
||||
env_vars_set(&env_vars, string_copy("INFO"), string_copy(info_str));
|
||||
|
||||
|
@ -275,6 +279,11 @@ void bar_item_on_scroll(struct bar_item* bar_item, int scroll_delta) {
|
|||
string_copy("SCROLL_DELTA"),
|
||||
string_copy(delta_ver_str));
|
||||
|
||||
env_vars_set(&env_vars,
|
||||
string_copy("MODIFIER"),
|
||||
string_copy(get_modifier_description(modifier)));
|
||||
|
||||
|
||||
if (bar_item->update_mask & UPDATE_MOUSE_SCROLLED)
|
||||
bar_item_update(bar_item,
|
||||
COMMAND_SUBSCRIBE_MOUSE_SCROLLED,
|
||||
|
|
|
@ -107,7 +107,7 @@ 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);
|
||||
|
||||
void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t mouse_button_code, uint32_t modifier, CGPoint point);
|
||||
void bar_item_on_scroll(struct bar_item* bar_item, int scroll_delta);
|
||||
void bar_item_on_scroll(struct bar_item* bar_item, int scroll_delta, uint32_t modifier);
|
||||
void bar_item_on_drag(struct bar_item* bar_item, CGPoint point);
|
||||
void bar_item_mouse_entered(struct bar_item* bar_item);
|
||||
void bar_item_mouse_exited(struct bar_item* bar_item);
|
||||
|
|
|
@ -802,7 +802,7 @@ void bar_manager_handle_mouse_exited_global(struct bar_manager* bar_manager) {
|
|||
bar_manager_handle_mouse_exited(bar_manager, NULL);
|
||||
}
|
||||
|
||||
void bar_manager_handle_mouse_scrolled_global(struct bar_manager* bar_manager, int scroll_delta, uint32_t adid) {
|
||||
void bar_manager_handle_mouse_scrolled_global(struct bar_manager* bar_manager, int scroll_delta, uint32_t adid, uint32_t modifier) {
|
||||
struct env_vars env_vars;
|
||||
env_vars_init(&env_vars);
|
||||
char delta_ver_str[32];
|
||||
|
@ -813,9 +813,13 @@ void bar_manager_handle_mouse_scrolled_global(struct bar_manager* bar_manager, i
|
|||
|
||||
char info_str[256];
|
||||
snprintf(info_str, 256, "{\n"
|
||||
"\t\"delta\": %d\n"
|
||||
"\t\"delta\": %d,\n"
|
||||
"\t\"modifier\": \"%s\",\n"
|
||||
"\t\"modfier_code\": %u\n"
|
||||
"}\n",
|
||||
scroll_delta );
|
||||
scroll_delta,
|
||||
get_modifier_description(modifier),
|
||||
modifier );
|
||||
|
||||
env_vars_set(&env_vars, string_copy("INFO"), string_copy(info_str));
|
||||
|
||||
|
@ -825,6 +829,10 @@ void bar_manager_handle_mouse_scrolled_global(struct bar_manager* bar_manager, i
|
|||
string_copy("DID"),
|
||||
string_copy(adid_str));
|
||||
|
||||
env_vars_set(&env_vars,
|
||||
string_copy("MODIFIER"),
|
||||
string_copy(get_modifier_description(modifier)));
|
||||
|
||||
bar_manager_custom_events_trigger(bar_manager,
|
||||
COMMAND_SUBSCRIBE_MOUSE_SCROLLED_GLOBAL,
|
||||
&env_vars );
|
||||
|
|
|
@ -105,7 +105,7 @@ void bar_manager_resize(struct bar_manager* bar_manager);
|
|||
|
||||
void bar_manager_handle_mouse_entered_global(struct bar_manager* bar_manager);
|
||||
void bar_manager_handle_mouse_exited_global(struct bar_manager* bar_manager);
|
||||
void bar_manager_handle_mouse_scrolled_global(struct bar_manager* bar_manager, int scroll_delta, uint32_t did);
|
||||
void bar_manager_handle_mouse_scrolled_global(struct bar_manager* bar_manager, int scroll_delta, uint32_t did, uint32_t modifier);
|
||||
void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct bar_item* bar_item);
|
||||
void bar_manager_handle_mouse_exited(struct bar_manager* bar_manager, struct bar_item* bar_item);
|
||||
void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager, char* info);
|
||||
|
|
11
src/event.c
11
src/event.c
|
@ -242,6 +242,7 @@ static void event_mouse_scrolled(void* context) {
|
|||
int scroll_delta
|
||||
= CGEventGetIntegerValueField(context,
|
||||
kCGScrollWheelEventDeltaAxis1);
|
||||
uint32_t modifier_keys = CGEventGetFlags(context);
|
||||
|
||||
uint64_t event_time = clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW_APPROX);
|
||||
if (g_scroll_info.timestamp + SCROLL_TIMEOUT > event_time) {
|
||||
|
@ -263,7 +264,8 @@ static void event_mouse_scrolled(void* context) {
|
|||
bar_manager_handle_mouse_scrolled_global(&g_bar_manager,
|
||||
scroll_delta
|
||||
+ g_scroll_info.delta_y,
|
||||
bar->adid );
|
||||
bar->adid,
|
||||
modifier_keys );
|
||||
}
|
||||
|
||||
g_scroll_info.delta_y = 0;
|
||||
|
@ -278,7 +280,8 @@ static void event_mouse_scrolled(void* context) {
|
|||
bar_manager_handle_mouse_scrolled_global(&g_bar_manager,
|
||||
scroll_delta
|
||||
+ g_scroll_info.delta_y,
|
||||
bar->adid );
|
||||
bar->adid,
|
||||
modifier_keys );
|
||||
}
|
||||
|
||||
g_scroll_info.delta_y = 0;
|
||||
|
@ -293,7 +296,9 @@ static void event_mouse_scrolled(void* context) {
|
|||
bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, NULL);
|
||||
}
|
||||
|
||||
bar_item_on_scroll(bar_item, scroll_delta + g_scroll_info.delta_y);
|
||||
bar_item_on_scroll(bar_item,
|
||||
scroll_delta + g_scroll_info.delta_y,
|
||||
modifier_keys );
|
||||
|
||||
if (bar_item && bar_item->needs_update)
|
||||
bar_manager_refresh(&g_bar_manager, false, false);
|
||||
|
|
Loading…
Reference in a new issue