Skip to content

Commit

Permalink
added global mouse entered and exited events
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Jun 9, 2022
1 parent b41c8a9 commit 5531582
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ struct bar *bar_create(uint32_t did) {
struct bar *bar = malloc(sizeof(struct bar));
memset(bar, 0, sizeof(struct bar));
bar->hidden = false;
bar->mouse_over = false;
bar->did = did;
bar->sid = mission_control_index(display_space_id(did));
bar->shown = true;
Expand Down
1 change: 1 addition & 0 deletions src/bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
struct bar {
bool shown;
bool hidden;
bool mouse_over;

uint32_t did;
uint32_t sid;
Expand Down
12 changes: 12 additions & 0 deletions src/bar_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,18 @@ void bar_manager_display_changed(struct bar_manager* bar_manager) {
bar_manager_unfreeze(bar_manager);
}

void bar_manager_handle_mouse_entered_global(struct bar_manager* bar_manager) {
bar_manager_custom_events_trigger(bar_manager,
COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL,
NULL );
}

void bar_manager_handle_mouse_exited_global(struct bar_manager* bar_manager) {
bar_manager_custom_events_trigger(bar_manager,
COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL,
NULL );
}

void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct bar_item* bar_item) {
if (!bar_item || bar_item->mouse_over) return;
for (int i = 0; i < bar_manager->bar_item_count; i++)
Expand Down
2 changes: 2 additions & 0 deletions src/bar_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ void bar_manager_display_changed(struct bar_manager* bar_manager);
void bar_manager_refresh(struct bar_manager* bar_manager, bool forced);
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_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);
Expand Down
2 changes: 2 additions & 0 deletions src/custom_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void custom_events_init(struct custom_events* custom_events) {
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WOKE), NULL);
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_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_CLICKED), NULL);
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WILL_SLEEP), NULL);
}
Expand Down
9 changes: 0 additions & 9 deletions src/custom_events.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#pragma once
#include "misc/helpers.h"

#define UPDATE_FRONT_APP_SWITCHED 1ULL
#define UPDATE_SPACE_CHANGE 1ULL << 1
#define UPDATE_DISPLAY_CHANGE 1ULL << 2
#define UPDATE_SYSTEM_WOKE 1ULL << 3
#define UPDATE_MOUSE_ENTERED 1ULL << 4
#define UPDATE_MOUSE_EXITED 1ULL << 5
#define UPDATE_MOUSE_CLICKED 1ULL << 6
#define UPDATE_SYSTEM_WILL_SLEEP 1ULL << 7

extern void* g_workspace_context;
extern void workspace_create_custom_observer(void** context, char* name);

Expand Down
11 changes: 11 additions & 0 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) {
struct bar* bar = bar_manager_get_bar_by_wid(&g_bar_manager, wid);
if (bar) {
// Handle global mouse entered event
if (!bar->mouse_over) {
bar->mouse_over = true;
bar_manager_handle_mouse_entered_global(&g_bar_manager);
}

CFRelease(context);
return EVENT_SUCCESS;
Expand Down Expand Up @@ -173,6 +177,13 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED) {
struct bar* bar = bar_manager_get_bar_by_wid(&g_bar_manager, wid);
if (bar) {
// Handle global mouse exited event
CGPoint point = CGEventGetLocation(context);
CGRect frame = bar->window.frame;
frame.origin = bar->window.origin;
if (!CGRectContainsPoint(frame, point)) {
bar->mouse_over = false;
bar_manager_handle_mouse_exited_global(&g_bar_manager);
}

CFRelease(context);
return EVENT_SUCCESS;
Expand Down
2 changes: 2 additions & 0 deletions src/misc/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
#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_ENTERED_GLOBAL "mouse.entered.global"
#define COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL "mouse.exited.global"

#define DOMAIN_QUERY "--query"
#define COMMAND_QUERY_DEFAULT_ITEMS "default_menu_items"
Expand Down

0 comments on commit 5531582

Please sign in to comment.