mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-24 04:13:17 +00:00
much snappier space scripting
This commit is contained in:
parent
a884801bc0
commit
48abe65ddc
7 changed files with 16 additions and 27 deletions
|
@ -170,7 +170,6 @@ void bar_item_set_label_font(struct bar_item* bar_item, char *font_string) {
|
||||||
|
|
||||||
void bar_item_on_click(struct bar_item* bar_item) {
|
void bar_item_on_click(struct bar_item* bar_item) {
|
||||||
if (!bar_item) return;
|
if (!bar_item) return;
|
||||||
if (!bar_item->scripting) return;
|
|
||||||
if (bar_item && strlen(bar_item->click_script) > 0)
|
if (bar_item && strlen(bar_item->click_script) > 0)
|
||||||
fork_exec(bar_item->click_script, &bar_item->signal_args);
|
fork_exec(bar_item->click_script, &bar_item->signal_args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define UPDATE_SYSTEM_WOKE 1 << 3
|
#define UPDATE_SYSTEM_WOKE 1 << 3
|
||||||
|
|
||||||
struct bar_item {
|
struct bar_item {
|
||||||
|
bool needs_update;
|
||||||
bool drawing;
|
bool drawing;
|
||||||
bool scripting;
|
bool scripting;
|
||||||
bool is_shown;
|
bool is_shown;
|
||||||
|
|
|
@ -135,25 +135,31 @@ void bar_manager_init(struct bar_manager *bar_manager) {
|
||||||
CFRunLoopAddTimer(CFRunLoopGetMain(), bar_manager->shell_refresh_timer, kCFRunLoopCommonModes);
|
CFRunLoopAddTimer(CFRunLoopGetMain(), bar_manager->shell_refresh_timer, kCFRunLoopCommonModes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_manager_update_components(struct bar_manager* bar_manager) {
|
void bar_manager_update_components(struct bar_manager* bar_manager, bool forced) {
|
||||||
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
|
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
|
||||||
struct bar_item* bar_item = g_bar_manager.bar_items[i];
|
struct bar_item* bar_item = g_bar_manager.bar_items[i];
|
||||||
|
if (!bar_item->is_shown && !forced) continue;
|
||||||
|
|
||||||
for (int j = 0; j < bar_manager->bar_count; j++) {
|
for (int j = 0; j < bar_manager->bar_count; j++) {
|
||||||
struct bar* bar = bar_manager->bars[j];
|
struct bar* bar = bar_manager->bars[j];
|
||||||
uint32_t did = display_arrangement(bar->did);
|
uint32_t did = display_arrangement(bar->did);
|
||||||
uint32_t sid = mission_control_index(display_space_id(bar->did));
|
|
||||||
if (sid == 0) continue;
|
|
||||||
|
|
||||||
if (((1 << did) & bar_item->associated_display) && strcmp(bar_item->identifier, BAR_COMPONENT_SPACE)== 0) {
|
if (((1 << did) & bar_item->associated_display) && strcmp(bar_item->identifier, BAR_COMPONENT_SPACE)== 0) {
|
||||||
if (!bar_item->selected && bar_item->associated_space & (1 << sid)) {
|
uint32_t sid = mission_control_index(display_space_id(bar->did));
|
||||||
|
if (sid == 0) continue;
|
||||||
|
if ((!bar_item->selected || forced) && bar_item->associated_space & (1 << sid)) {
|
||||||
bar_item->selected = true;
|
bar_item->selected = true;
|
||||||
|
bar_item->scripting = true;
|
||||||
strncpy(&bar_item->signal_args.value[1][0], "true", 255);
|
strncpy(&bar_item->signal_args.value[1][0], "true", 255);
|
||||||
}
|
}
|
||||||
else if (bar_item->selected && !(bar_item->associated_space & (1 << sid))) {
|
else if ((bar_item->selected || forced) && !(bar_item->associated_space & (1 << sid))) {
|
||||||
bar_item->selected = false;
|
bar_item->selected = false;
|
||||||
|
bar_item->scripting = true;
|
||||||
strncpy(&bar_item->signal_args.value[1][0], "false", 255);
|
strncpy(&bar_item->signal_args.value[1][0], "false", 255);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
bar_item->scripting = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +220,7 @@ void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_manager_handle_space_change(struct bar_manager* bar_manager) {
|
void bar_manager_handle_space_change(struct bar_manager* bar_manager) {
|
||||||
bar_manager_update_components(bar_manager);
|
bar_manager_update_components(bar_manager, false);
|
||||||
bar_manager_check_bar_items_for_update_pattern(bar_manager, UPDATE_SPACE_CHANGE);
|
bar_manager_check_bar_items_for_update_pattern(bar_manager, UPDATE_SPACE_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void bar_manager_destroy_item(struct bar_manager* bar_manager, struct bar_item*
|
||||||
void bar_manager_handle_notification(struct bar_manager* bar_manager, char* context);
|
void bar_manager_handle_notification(struct bar_manager* bar_manager, char* context);
|
||||||
|
|
||||||
void bar_manager_script_update(struct bar_manager* bar_manager, bool forced);
|
void bar_manager_script_update(struct bar_manager* bar_manager, bool forced);
|
||||||
void bar_manager_update_components(struct bar_manager* bar_manager);
|
void bar_manager_update_components(struct bar_manager* bar_manager, bool forced);
|
||||||
void bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t radius);
|
void bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t radius);
|
||||||
void bar_manager_set_background_color(struct bar_manager *bar_manager, uint32_t color);
|
void bar_manager_set_background_color(struct bar_manager *bar_manager, uint32_t color);
|
||||||
void bar_manager_set_position(struct bar_manager *bar_manager, char *pos);
|
void bar_manager_set_position(struct bar_manager *bar_manager, char *pos);
|
||||||
|
|
|
@ -341,7 +341,6 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bar_item_set_name(bar_item, token_to_string(name));
|
bar_item_set_name(bar_item, token_to_string(name));
|
||||||
bar_manager_update_components(&g_bar_manager);
|
|
||||||
bar_manager_refresh(&g_bar_manager);
|
bar_manager_refresh(&g_bar_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,6 +600,7 @@ void handle_message(FILE *rsp, char *message) {
|
||||||
} else if (token_equals(domain, DOMAIN_REMOVE)){
|
} else if (token_equals(domain, DOMAIN_REMOVE)){
|
||||||
handle_domain_remove(rsp, domain, message);
|
handle_domain_remove(rsp, domain, message);
|
||||||
} else if (token_equals(domain, DOMAIN_UPDATE)) {
|
} else if (token_equals(domain, DOMAIN_UPDATE)) {
|
||||||
|
bar_manager_update_components(&g_bar_manager, true);
|
||||||
bar_manager_script_update(&g_bar_manager, true);
|
bar_manager_script_update(&g_bar_manager, true);
|
||||||
} else if (token_equals(domain, DOMAIN_SUBSCRIBE)) {
|
} else if (token_equals(domain, DOMAIN_SUBSCRIBE)) {
|
||||||
handle_domain_subscribe(rsp, domain, message);
|
handle_domain_subscribe(rsp, domain, message);
|
||||||
|
|
|
@ -74,23 +74,6 @@ bool socket_connect_un(int *sockfd, char *socket_path) {
|
||||||
return connect(*sockfd, (struct sockaddr *) &socket_address, sizeof(socket_address)) != -1;
|
return connect(*sockfd, (struct sockaddr *) &socket_address, sizeof(socket_address)) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void socket_wait(int sockfd) {
|
|
||||||
struct pollfd fds[] = {
|
|
||||||
{ sockfd, POLLIN, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
char dummy[1];
|
|
||||||
int bytes = 0;
|
|
||||||
|
|
||||||
while (poll(fds, 1, -1) > 0) {
|
|
||||||
if (fds[0].revents & POLLIN) {
|
|
||||||
if ((bytes = recv(sockfd, dummy, 0, 0)) <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void socket_close(int sockfd) {
|
void socket_close(int sockfd) {
|
||||||
shutdown(sockfd, SHUT_RDWR);
|
shutdown(sockfd, SHUT_RDWR);
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
|
|
@ -35,7 +35,7 @@ bool g_verbose;
|
||||||
|
|
||||||
static int client_send_message(int argc, char **argv) {
|
static int client_send_message(int argc, char **argv) {
|
||||||
if (argc <= 1) {
|
if (argc <= 1) {
|
||||||
error("sketchybar-msg: no arguments given! abort..\n");
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *user = getenv("USER");
|
char *user = getenv("USER");
|
||||||
|
|
Loading…
Reference in a new issue