skylight magic for mouse entered and exited events

This commit is contained in:
FelixKratz 2021-10-11 23:38:55 +02:00
parent 342ed8019e
commit e157482375
6 changed files with 44 additions and 3 deletions

View file

@ -127,6 +127,7 @@ void bar_redraw(struct bar* bar) {
SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, bar->id, -1, 0);
SLSRemoveAllTrackingAreas(g_connection, bar->id);
draw_rect(bar->context, bar->frame, &g_bar_manager.background.color, g_bar_manager.background.corner_radius, g_bar_manager.background.border_width, &g_bar_manager.background.border_color, true);
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
@ -199,6 +200,7 @@ void bar_redraw(struct bar* bar) {
bar_item->label.line.bounds.origin = label_position;
bar_item->icon.line.bounds.origin = icon_position;
bar_item_append_associated_bar(bar_item, (1 << (adid - 1)));
SLSAddTrackingRect(g_connection, bar->id, bar_item_construct_bounding_rect(bar_item));
bar_item_set_bounding_rect_for_display(bar_item, adid, bar->origin);
bar_draw_group(bar, bar_item, adid);
@ -242,6 +244,12 @@ void bar_resize(struct bar *bar) {
SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, bar->id, -1, 0);
SLSSetWindowShape(g_connection, bar->id, bar->origin.x, bar->origin.y, frame_region);
SLSClearActivationRegion(g_connection, bar->id);
SLSAddActivationRegion(g_connection, bar->id, frame_region);
SLSRemoveAllTrackingAreas(g_connection, bar->id);
//SLSAddTrackingRect(g_connection, bar->id, bar->frame);
bar_redraw(bar);
SLSOrderWindow(g_connection, bar->id, 1, 0);
SLSReenableUpdate(g_connection);
@ -279,6 +287,8 @@ void bar_create_window(struct bar* bar) {
bar_create_frame(bar, &frame_region);
SLSNewWindow(g_connection, 2, bar->origin.x, bar->origin.y, frame_region, &bar->id);
SLSAddActivationRegion(g_connection, bar->id, frame_region);
//SLSAddTrackingRect(g_connection, bar->id, bar->frame);
CFRelease(frame_region);
SLSSetWindowResolution(g_connection, bar->id, 2.0f);
@ -287,6 +297,7 @@ void bar_create_window(struct bar* bar) {
SLSSetWindowOpacity(g_connection, bar->id, 0);
bar_set_blur_radius(bar);
SLSSetMouseEventEnableFlags(g_connection, bar->id, false);
SLSSetWindowLevel(g_connection, bar->id, g_bar_manager.window_level);
bar->context = SLWindowContextCreate(g_connection, bar->id, 0);
CGContextSetInterpolationQuality(bar->context, kCGInterpolationNone);

View file

@ -16,6 +16,11 @@ extern CGError SLSOrderWindow(int cid, uint32_t wid, int mode, uint32_t relative
extern CGError SLSSetWindowLevel(int cid, uint32_t wid, int level);
extern CGContextRef SLWindowContextCreate(int cid, uint32_t wid, CFDictionaryRef options);
extern CGError CGSNewRegionWithRect(CGRect *rect, CFTypeRef *outRegion);
extern CGError SLSAddActivationRegion(uint32_t cid, uint32_t wid, CFTypeRef region);
extern CGError SLSAddTrackingRect(uint32_t cid, uint32_t wid, CGRect rect);
extern CGError SLSClearActivationRegion(uint32_t cid, uint32_t wid);
extern CGError SLSRemoveAllTrackingAreas(uint32_t cid, uint32_t wid);
#define kCGSDisableShadowTagBit (1 << 3)
#define kCGSHighQualityResamplingTagBit (1 << 4)

View file

@ -109,3 +109,15 @@ static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) {
CFRelease(context);
return EVENT_SUCCESS;
}
static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_MOVED) {
debug("%s\n", __FUNCTION__);
CGPoint point = CGEventGetLocation(context);
uint32_t adid = display_arrangement(display_active_display_id());
printf("EVENT_HANDLER_MOUSE_MOVED: D#%d (x: %.0f, y: %.0f) -> ", adid, point.x, point.y);
struct bar_item* bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid);
debug("item: %s\n", bar_item ? bar_item->name : "NULL");
bar_item_on_click(bar_item);
CFRelease(context);
return EVENT_SUCCESS;
}

View file

@ -18,6 +18,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_SYSTEM_WOKE);
static EVENT_CALLBACK(EVENT_HANDLER_SHELL_REFRESH);
static EVENT_CALLBACK(EVENT_HANDLER_DAEMON_MESSAGE);
static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP);
static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_MOVED);
static EVENT_CALLBACK(EVENT_HANDLER_DISTRIBUTED_NOTIFICATION);
#define EVENT_QUEUED 0x0
#define EVENT_PROCESSED 0x1
@ -43,6 +44,7 @@ enum event_type {
SHELL_REFRESH,
DAEMON_MESSAGE,
MOUSE_UP,
MOUSE_MOVED,
DISTRIBUTED_NOTIFICATION,
EVENT_TYPE_COUNT
@ -63,6 +65,7 @@ static const char *event_type_str[] = {
[SHELL_REFRESH] = "shell_refresh",
[DAEMON_MESSAGE] = "daemon_message",
[MOUSE_UP] = "mouse_up",
[MOUSE_MOVED] = "mouse_moved",
[DISTRIBUTED_NOTIFICATION] = "distributed_notification",
[EVENT_TYPE_COUNT] = "event_type_count"
@ -77,6 +80,7 @@ static event_callback *event_handler[] = {
[DISPLAY_RESIZED] = EVENT_HANDLER_DISPLAY_RESIZED,
[DISPLAY_CHANGED] = EVENT_HANDLER_DISPLAY_CHANGED,
[MOUSE_UP] = EVENT_HANDLER_MOUSE_UP,
[MOUSE_MOVED] = EVENT_HANDLER_MOUSE_MOVED,
[DISTRIBUTED_NOTIFICATION] = EVENT_HANDLER_DISTRIBUTED_NOTIFICATION,
[MENU_BAR_HIDDEN_CHANGED] = EVENT_HANDLER_MENU_BAR_HIDDEN_CHANGED,

View file

@ -7,7 +7,16 @@ static pascal OSStatus mouse_handler(EventHandlerCallRef next, EventRef e, void
event_loop_post(&g_event_loop, event);
break;
}
case kEventMouseEntered: {
printf("entered event: %d \n", GetEventKind(e));
break;
}
case kEventMouseExited: {
printf("xited event: %d \n", GetEventKind(e));
break;
}
default:
printf("event: %d \n", GetEventKind(e));
break;
}
@ -16,5 +25,5 @@ static pascal OSStatus mouse_handler(EventHandlerCallRef next, EventRef e, void
void mouse_begin(void) {
EventTargetRef target = GetEventDispatcherTarget();
InstallEventHandler(target, NewEventHandlerUPP(mouse_handler), sizeof mouse_events / sizeof *mouse_events, mouse_events, 0, 0);
InstallEventHandler(target, NewEventHandlerUPP(mouse_handler), GetEventTypeCount(mouse_events), mouse_events, 0, 0);
}

View file

@ -1,8 +1,8 @@
static const EventTypeSpec mouse_events [] = {
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp },
{ kEventClassMouse, kEventMouseMoved },
{ kEventClassMouse, kEventMouseDragged }
{ kEventClassMouse, kEventMouseEntered },
{ kEventClassMouse, kEventMouseExited }
};
void mouse_begin(void);