mirror of
https://github.com/FelixKratz/SketchyBar
synced 2025-02-16 20:48:26 +00:00
added basic structure for custom events
This commit is contained in:
parent
da2e3f844a
commit
d82d21eae5
9 changed files with 28 additions and 52 deletions
|
@ -174,6 +174,7 @@ This triggers a custom event that has been added before
|
|||
```bash
|
||||
sketchybar -m trigger <event>
|
||||
```
|
||||
This could be used to link the powerful event system of yabai to sketchybar by triggering the custom action via a yabai event.
|
||||
|
||||
### Supplying data for graphs
|
||||
```bash
|
||||
|
|
|
@ -6,11 +6,9 @@
|
|||
#define BAR_PLUGIN 'p'
|
||||
|
||||
#define UPDATE_FRONT_APP_SWITCHED 1
|
||||
#define UPDATE_WINDOW_FOCUS 1 << 1
|
||||
#define UPDATE_SPACE_CHANGE 1 << 2
|
||||
#define UPDATE_DISPLAY_CHANGE 1 << 3
|
||||
#define UPDATE_SYSTEM_WOKE 1 << 4
|
||||
#define UPDATE_TITLE_CHANGE 1 << 5
|
||||
#define UPDATE_SPACE_CHANGE 1 << 1
|
||||
#define UPDATE_DISPLAY_CHANGE 1 << 2
|
||||
#define UPDATE_SYSTEM_WOKE 1 << 3
|
||||
|
||||
struct bar_item {
|
||||
bool is_shown;
|
||||
|
|
|
@ -159,18 +159,15 @@ struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t bar_manager_get_event_flag(struct bar_manager* bar_manager, char* event) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager) {
|
||||
bar_manager_check_bar_items_for_update_pattern(bar_manager, UPDATE_FRONT_APP_SWITCHED);
|
||||
}
|
||||
|
||||
void bar_manager_handle_window_focus(struct bar_manager* bar_manager) {
|
||||
bar_manager_check_bar_items_for_update_pattern(bar_manager, UPDATE_WINDOW_FOCUS);
|
||||
}
|
||||
|
||||
void bar_manager_handle_title_change(struct bar_manager* bar_manager) {
|
||||
bar_manager_check_bar_items_for_update_pattern(bar_manager, UPDATE_TITLE_CHANGE);
|
||||
}
|
||||
|
||||
void bar_manager_handle_space_change(struct bar_manager* bar_manager) {
|
||||
bar_manager_check_bar_items_for_update_pattern(bar_manager, UPDATE_SPACE_CHANGE);
|
||||
}
|
||||
|
|
|
@ -22,9 +22,12 @@ struct bar_manager
|
|||
uint32_t padding_left;
|
||||
uint32_t padding_right;
|
||||
struct rgba_color background_color;
|
||||
struct custom_events custom_events;
|
||||
};
|
||||
|
||||
int bar_manager_get_item_index_for_name(struct bar_manager* bar_manager, char* name);
|
||||
uint32_t bar_manager_get_event_flag(struct bar_manager* bar_manager, char* event);
|
||||
|
||||
struct bar_item* bar_manager_create_item(struct bar_manager* bar_manager);
|
||||
|
||||
void bar_manager_script_update(struct bar_manager* bar_manager, bool forced);
|
||||
|
@ -45,8 +48,6 @@ void bar_manager_begin(struct bar_manager *bar_manager);
|
|||
void bar_manager_init(struct bar_manager *bar_manager);
|
||||
|
||||
void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager);
|
||||
void bar_manager_handle_window_focus(struct bar_manager* bar_manager);
|
||||
void bar_manager_handle_title_change(struct bar_manager* bar_manager);
|
||||
void bar_manager_handle_space_change(struct bar_manager* bar_manager);
|
||||
void bar_manager_handle_display_change(struct bar_manager* bar_manager);
|
||||
void bar_manager_handle_system_woke(struct bar_manager* bar_manager);
|
||||
|
|
13
src/custom_events.h
Normal file
13
src/custom_events.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef CUSTOM_EVENT_H
|
||||
#define CUSTOM_EVENT_H
|
||||
|
||||
struct custom_events {
|
||||
// How many events are reserved for system events
|
||||
uint32_t flag_offset;
|
||||
uint32_t count;
|
||||
|
||||
char** names;
|
||||
};
|
||||
|
||||
void custom_event_append(char* name);
|
||||
#endif
|
25
src/event.c
25
src/event.c
|
@ -33,10 +33,6 @@ struct event *event_create_p1(struct event_loop *event_loop, enum event_type typ
|
|||
event->context = context;
|
||||
event->param1 = param1;
|
||||
event->info = 0;
|
||||
#ifdef DEBUG
|
||||
uint64_t count = __sync_add_and_fetch(&event_loop->count, 1);
|
||||
assert(count > 0 && count < EVENT_MAX_COUNT);
|
||||
#endif
|
||||
return event;
|
||||
}
|
||||
|
||||
|
@ -49,27 +45,6 @@ static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_FRONT_SWITCHED)
|
|||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_FOCUSED)
|
||||
{
|
||||
debug("%s\n", __FUNCTION__);
|
||||
|
||||
bar_manager_handle_window_focus(&g_bar_manager);
|
||||
//bar_manager_refresh(&g_bar_manager);
|
||||
|
||||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_TITLE_CHANGED)
|
||||
{
|
||||
debug("%s\n", __FUNCTION__);
|
||||
|
||||
// TODO: we can optimize by checking if it the focused window
|
||||
bar_manager_handle_title_change(&g_bar_manager);
|
||||
//bar_manager_refresh(&g_bar_manager);
|
||||
|
||||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_SPACE_CHANGED)
|
||||
{
|
||||
debug("%s\n", __FUNCTION__);
|
||||
|
|
|
@ -7,8 +7,6 @@ extern OSStatus SLSFindWindowByGeometry(int cid, int zero, int one, int zero_aga
|
|||
typedef EVENT_CALLBACK(event_callback);
|
||||
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_FRONT_SWITCHED);
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_FOCUSED);
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_TITLE_CHANGED);
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_SPACE_CHANGED);
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_ADDED);
|
||||
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_REMOVED);
|
||||
|
@ -35,8 +33,6 @@ enum event_type
|
|||
{
|
||||
EVENT_TYPE_UNKNOWN,
|
||||
APPLICATION_FRONT_SWITCHED,
|
||||
WINDOW_FOCUSED,
|
||||
WINDOW_TITLE_CHANGED,
|
||||
SPACE_CHANGED,
|
||||
DISPLAY_ADDED,
|
||||
DISPLAY_REMOVED,
|
||||
|
@ -57,8 +53,6 @@ static const char *event_type_str[] =
|
|||
[EVENT_TYPE_UNKNOWN] = "event_type_unknown",
|
||||
|
||||
[APPLICATION_FRONT_SWITCHED] = "application_front_switched",
|
||||
[WINDOW_FOCUSED] = "window_focused",
|
||||
[WINDOW_TITLE_CHANGED] = "window_title_changed",
|
||||
[SPACE_CHANGED] = "space_changed",
|
||||
[DISPLAY_ADDED] = "display_added",
|
||||
[DISPLAY_REMOVED] = "display_removed",
|
||||
|
@ -77,8 +71,6 @@ static const char *event_type_str[] =
|
|||
static event_callback *event_handler[] =
|
||||
{
|
||||
[APPLICATION_FRONT_SWITCHED] = EVENT_HANDLER_APPLICATION_FRONT_SWITCHED,
|
||||
[WINDOW_FOCUSED] = EVENT_HANDLER_WINDOW_FOCUSED,
|
||||
[WINDOW_TITLE_CHANGED] = EVENT_HANDLER_WINDOW_TITLE_CHANGED,
|
||||
[SPACE_CHANGED] = EVENT_HANDLER_SPACE_CHANGED,
|
||||
[DISPLAY_ADDED] = EVENT_HANDLER_DISPLAY_ADDED,
|
||||
[DISPLAY_REMOVED] = EVENT_HANDLER_DISPLAY_REMOVED,
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "bar.h"
|
||||
#include "graph_data.h"
|
||||
#include "bar_item.h"
|
||||
#include "custom_events.h"
|
||||
#include "bar_manager.h"
|
||||
|
||||
#include "event_loop.c"
|
||||
|
|
|
@ -175,14 +175,12 @@ static void handle_domain_subscribe(FILE* rsp, struct token domain, char* messag
|
|||
bar_item->update_mask |= UPDATE_SYSTEM_WOKE;
|
||||
} else if (token_equals(event, COMMAND_SUBSCRIBE_SPACE_CHANGE)) {
|
||||
bar_item->update_mask |= UPDATE_SPACE_CHANGE;
|
||||
} else if (token_equals(event, COMMAND_SUBSCRIBE_TITLE_CHANGE)) {
|
||||
bar_item->update_mask |= UPDATE_TITLE_CHANGE;
|
||||
} else if (token_equals(event, COMMAND_SUBSCRIBE_DISPLAY_CHANGE)) {
|
||||
bar_item->update_mask |= UPDATE_DISPLAY_CHANGE;
|
||||
} else if (token_equals(event, COMMAND_SUBSCRIBE_FRONT_APP_SWITCHED)) {
|
||||
bar_item->update_mask |= UPDATE_FRONT_APP_SWITCHED;
|
||||
} else if (token_equals(event, COMMAND_SUBSCRIBE_WINDOW_FOCUS)) {
|
||||
bar_item->update_mask |= UPDATE_WINDOW_FOCUS;
|
||||
} else {
|
||||
bar_item->update_mask |= bar_manager_get_event_flag(&g_bar_manager, token_to_string(event));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue