mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-10 05:44:16 +00:00
Scroll wheel events
This commit is contained in:
parent
cde3bc2fd4
commit
30a66a6d03
9 changed files with 140 additions and 1 deletions
|
@ -241,6 +241,38 @@ 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, uint32_t type, long scroll_delta_vert) {
|
||||
if (!bar_item) return;
|
||||
|
||||
struct env_vars env_vars;
|
||||
env_vars_init(&env_vars);
|
||||
char info_str[256];
|
||||
snprintf(info_str, 256, "{\n"
|
||||
"\t\"scroll_delta_vert\": %ld\n"
|
||||
"}\n",
|
||||
scroll_delta_vert );
|
||||
|
||||
env_vars_set(&env_vars, string_copy("INFO"), string_copy(info_str));
|
||||
|
||||
char delta_ver_str[32];
|
||||
snprintf(delta_ver_str, 32, "%ld", scroll_delta_vert);
|
||||
env_vars_set(&env_vars,
|
||||
string_copy("DELTA_VERT"),
|
||||
string_copy(delta_ver_str));
|
||||
|
||||
if (bar_item->scroll_script && strlen(bar_item->scroll_script) > 0) {
|
||||
for (int i = 0; i < bar_item->signal_args.env_vars.count; i++) {
|
||||
env_vars_set(&env_vars,
|
||||
string_copy(bar_item->signal_args.env_vars.vars[i]->key),
|
||||
string_copy(bar_item->signal_args.env_vars.vars[i]->value));
|
||||
}
|
||||
|
||||
fork_exec(bar_item->scroll_script, &env_vars);
|
||||
}
|
||||
|
||||
env_vars_destroy(&env_vars);
|
||||
}
|
||||
|
||||
void bar_item_mouse_entered(struct bar_item* bar_item) {
|
||||
if (bar_item->update_mask & UPDATE_MOUSE_ENTERED)
|
||||
bar_item_update(bar_item, COMMAND_SUBSCRIBE_MOUSE_ENTERED, true, NULL);
|
||||
|
@ -287,6 +319,21 @@ static void bar_item_set_click_script(struct bar_item* bar_item, char* script) {
|
|||
bar_item->click_script = path;
|
||||
}
|
||||
|
||||
static void bar_item_set_scroll_script(struct bar_item* bar_item, char* script) {
|
||||
if (!script) return;
|
||||
|
||||
if (bar_item->scroll_script && strcmp(bar_item->scroll_script, script) == 0) {
|
||||
free(script);
|
||||
return;
|
||||
}
|
||||
|
||||
if (script != bar_item->scroll_script && bar_item->scroll_script)
|
||||
free(bar_item->scroll_script);
|
||||
|
||||
char* path = resolve_path(script);
|
||||
bar_item->scroll_script = path;
|
||||
}
|
||||
|
||||
static bool bar_item_set_yoffset(struct bar_item* bar_item, int offset) {
|
||||
if (bar_item->y_offset == offset) return false;
|
||||
bar_item->y_offset = offset;
|
||||
|
@ -1035,6 +1082,8 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE*
|
|||
bar_item_set_script(bar_item, token_to_string(get_token(&message)));
|
||||
} else if (token_equals(property, PROPERTY_CLICK_SCRIPT)) {
|
||||
bar_item_set_click_script(bar_item, token_to_string(get_token(&message)));
|
||||
} else if (token_equals(property, PROPERTY_SCROLL_SCRIPT)) {
|
||||
bar_item_set_scroll_script(bar_item, token_to_string(get_token(&message)));
|
||||
} else if (token_equals(property, PROPERTY_UPDATE_FREQ)) {
|
||||
bar_item->update_frequency = token_to_uint32t(get_token(&message));
|
||||
} else if (token_equals(property, PROPERTY_POSITION)) {
|
||||
|
|
|
@ -50,6 +50,7 @@ struct bar_item {
|
|||
|
||||
char* script;
|
||||
char* click_script;
|
||||
char* scroll_script;
|
||||
struct signal_args signal_args;
|
||||
|
||||
// The position in the bar: l,r,c
|
||||
|
@ -106,6 +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, uint32_t type, long scroll_delta_vert);
|
||||
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);
|
||||
|
|
|
@ -781,6 +781,27 @@ void bar_manager_handle_mouse_exited_global(struct bar_manager* bar_manager) {
|
|||
NULL );
|
||||
}
|
||||
|
||||
void bar_manager_handle_mouse_scrolled_global(struct bar_manager* bar_manager, long scroll_delta_vert, uint32_t adid) {
|
||||
struct env_vars env_vars;
|
||||
env_vars_init(&env_vars);
|
||||
char delta_ver_str[32];
|
||||
snprintf(delta_ver_str, 32, "%ld", scroll_delta_vert);
|
||||
env_vars_set(&env_vars,
|
||||
string_copy("DELTA_VERT"),
|
||||
string_copy(delta_ver_str));
|
||||
|
||||
char adid_str[32];
|
||||
snprintf(adid_str, 32, "%u", adid);
|
||||
env_vars_set(&env_vars,
|
||||
string_copy("DISPLAY"),
|
||||
string_copy(adid_str));
|
||||
|
||||
bar_manager_custom_events_trigger(bar_manager,
|
||||
COMMAND_SUBSCRIBE_MOUSE_SCROLLED_GLOBAL,
|
||||
&env_vars );
|
||||
env_vars_destroy(&env_vars);
|
||||
}
|
||||
|
||||
void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct bar_item* bar_item) {
|
||||
if (!bar_item) return;
|
||||
bar_item_mouse_entered(bar_item);
|
||||
|
|
|
@ -104,6 +104,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, long scroll_delta_vert, uint32_t did);
|
||||
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);
|
||||
|
|
|
@ -26,9 +26,11 @@ void custom_events_init(struct custom_events* custom_events) {
|
|||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_CLICKED), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_SCROLLED), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WILL_SLEEP), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_SCROLLED_GLOBAL), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_VOLUME_CHANGE), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_BRIGHTNESS_CHANGE), NULL);
|
||||
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_POWER_SOURCE_CHANGE), NULL);
|
||||
|
|
49
src/event.c
49
src/event.c
|
@ -280,6 +280,55 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED) {
|
|||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
||||
EVENT_CALLBACK(EVENT_HANDLER_MOUSE_SCROLLED) {
|
||||
CGPoint point = CGEventGetLocation(context);
|
||||
uint32_t wid = get_window_id_from_cg_event(context);
|
||||
CGEventType type = CGEventGetType(context);
|
||||
long scroll_delta_vert = CGEventGetIntegerValueField(context, kCGScrollWheelEventDeltaAxis1);
|
||||
uint32_t adid = display_arrangement(display_active_display_id());
|
||||
|
||||
struct bar* bar = bar_manager_get_bar_by_wid(&g_bar_manager, wid);
|
||||
if (bar) {
|
||||
// Handle global mouse scrolled event
|
||||
if (bar->mouse_over
|
||||
&& !bar_manager_mouse_over_any_popup(&g_bar_manager)) {
|
||||
bar_manager_handle_mouse_scrolled_global(&g_bar_manager, scroll_delta_vert, bar->adid);
|
||||
}
|
||||
|
||||
CFRelease(context);
|
||||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
||||
struct popup* popup = bar_manager_get_popup_by_wid(&g_bar_manager, wid);
|
||||
if (popup) {
|
||||
// Handle global mouse scrolled event
|
||||
if (popup->mouse_over
|
||||
&& !bar_manager_mouse_over_any_bar(&g_bar_manager)) {
|
||||
bar_manager_handle_mouse_scrolled_global(&g_bar_manager, scroll_delta_vert, bar->adid);
|
||||
}
|
||||
|
||||
CFRelease(context);
|
||||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
||||
struct bar_item* bar_item = bar_manager_get_item_by_wid(&g_bar_manager,
|
||||
wid,
|
||||
adid );
|
||||
|
||||
if (!bar_item || bar_item->type == BAR_COMPONENT_GROUP) {
|
||||
bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid);
|
||||
}
|
||||
|
||||
bar_item_on_scroll(bar_item, type, scroll_delta_vert);
|
||||
|
||||
if (bar_item && bar_item->needs_update)
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
|
||||
CFRelease(context);
|
||||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EVENT_CALLBACK(EVENT_HANDLER_VOLUME_CHANGED) {
|
||||
bar_manager_handle_volume_change(&g_bar_manager, *(float*)context);
|
||||
free(context);
|
||||
|
|
|
@ -26,6 +26,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP);
|
|||
EVENT_CALLBACK(EVENT_HANDLER_MOUSE_DRAGGED);
|
||||
EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED);
|
||||
EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED);
|
||||
EVENT_CALLBACK(EVENT_HANDLER_MOUSE_SCROLLED);
|
||||
EVENT_CALLBACK(EVENT_HANDLER_VOLUME_CHANGED);
|
||||
EVENT_CALLBACK(EVENT_HANDLER_WIFI_CHANGED);
|
||||
EVENT_CALLBACK(EVENT_HANDLER_BRIGHTNESS_CHANGED);
|
||||
|
@ -62,6 +63,7 @@ enum event_type {
|
|||
MOUSE_DRAGGED,
|
||||
MOUSE_ENTERED,
|
||||
MOUSE_EXITED,
|
||||
MOUSE_SCROLLED,
|
||||
VOLUME_CHANGED,
|
||||
WIFI_CHANGED,
|
||||
BRIGHTNESS_CHANGED,
|
||||
|
@ -92,6 +94,7 @@ static const char *event_type_str[] = {
|
|||
[MOUSE_DRAGGED] = "mouse_dragged",
|
||||
[MOUSE_ENTERED] = "mouse_entered",
|
||||
[MOUSE_EXITED] = "mouse_exited",
|
||||
[MOUSE_SCROLLED] = "mouse_scrolled",
|
||||
[VOLUME_CHANGED] = "volume_changed",
|
||||
[WIFI_CHANGED] = "wifi_changed",
|
||||
[BRIGHTNESS_CHANGED] = "brightness_changed",
|
||||
|
@ -114,6 +117,7 @@ static event_callback *event_handler[] = {
|
|||
[MOUSE_DRAGGED] = EVENT_HANDLER_MOUSE_DRAGGED,
|
||||
[MOUSE_ENTERED] = EVENT_HANDLER_MOUSE_ENTERED,
|
||||
[MOUSE_EXITED] = EVENT_HANDLER_MOUSE_EXITED,
|
||||
[MOUSE_SCROLLED] = EVENT_HANDLER_MOUSE_SCROLLED,
|
||||
[VOLUME_CHANGED] = EVENT_HANDLER_VOLUME_CHANGED,
|
||||
[WIFI_CHANGED] = EVENT_HANDLER_WIFI_CHANGED,
|
||||
[BRIGHTNESS_CHANGED] = EVENT_HANDLER_BRIGHTNESS_CHANGED,
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#define PROPERTY_UPDATE_FREQ "update_freq"
|
||||
#define PROPERTY_SCRIPT "script"
|
||||
#define PROPERTY_CLICK_SCRIPT "click_script"
|
||||
#define PROPERTY_SCROLL_SCRIPT "scroll_script"
|
||||
#define PROPERTY_ICON "icon"
|
||||
#define PROPERTY_YOFFSET "y_offset"
|
||||
#define PROPERTY_WIDTH "width"
|
||||
|
@ -120,8 +121,10 @@
|
|||
#define COMMAND_SUBSCRIBE_MOUSE_ENTERED "mouse.entered"
|
||||
#define COMMAND_SUBSCRIBE_MOUSE_EXITED "mouse.exited"
|
||||
#define COMMAND_SUBSCRIBE_MOUSE_CLICKED "mouse.clicked"
|
||||
#define COMMAND_SUBSCRIBE_MOUSE_SCROLLED "mouse.scrolled"
|
||||
#define COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL "mouse.entered.global"
|
||||
#define COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL "mouse.exited.global"
|
||||
#define COMMAND_SUBSCRIBE_MOUSE_SCROLLED_GLOBAL "mouse.scrolled.global"
|
||||
|
||||
#define DOMAIN_QUERY "--query"
|
||||
#define COMMAND_QUERY_DEFAULT_ITEMS "default_menu_items"
|
||||
|
|
10
src/mouse.c
10
src/mouse.c
|
@ -8,7 +8,8 @@ static const EventTypeSpec mouse_events [] = {
|
|||
{ kEventClassMouse, kEventMouseUp },
|
||||
{ kEventClassMouse, kEventMouseDragged },
|
||||
{ kEventClassMouse, kEventMouseEntered },
|
||||
{ kEventClassMouse, kEventMouseExited }
|
||||
{ kEventClassMouse, kEventMouseExited },
|
||||
{ kEventClassMouse, kEventMouseWheelMoved }
|
||||
};
|
||||
|
||||
|
||||
|
@ -45,6 +46,13 @@ static pascal OSStatus mouse_handler(EventHandlerCallRef next, EventRef e, void
|
|||
event_loop_post(&g_event_loop, event);
|
||||
break;
|
||||
}
|
||||
case kEventMouseWheelMoved: {
|
||||
struct event *event = event_create(&g_event_loop,
|
||||
MOUSE_SCROLLED,
|
||||
(void *) CFRetain(CopyEventCGEvent(e)));
|
||||
event_loop_post(&g_event_loop, event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue