added new toggles for drawing and scripting

This commit is contained in:
FelixKratz 2021-08-31 16:18:40 +02:00
parent 7ed2ee4ee2
commit 8559d85da2
7 changed files with 41 additions and 17 deletions

View file

@ -136,8 +136,8 @@ A list of properties is listed below:
* *update_freq*: time in seconds between script executions
* *click_script*: script to run when left clicking on item
* *cache_scripts*: If the scripts should be cached in RAM or read from disc every time (values: *on*, *off*, default: *off*)
* *enabled*: Set to *off* deactivates script updated and drawing, reactivate with *on* (values: *on*, *off*, default: *on*)
* *hidden*: Only deactivates drawing and keeps scripts running (values: *on*, *off*, default:*off*)
* *scripting*: If scripts should be executed (values: *on*, *off*, default: *on*)
* *drawing*: If the item should be drawn into the bar (values: *on*, *off*, default: *on*)
### Changing the default values for all further items
```bash
@ -155,6 +155,8 @@ this currently works for the properties:
* *icon_padding_right*
* *update_freq*
* *cache_scripts*
* *scripting*
* *drawing*
It is also possible to reset the defaults via the command
```bash

View file

@ -1,6 +1,6 @@
FRAMEWORK_PATH = -F/System/Library/PrivateFrameworks
FRAMEWORK = -framework Carbon -framework Cocoa -framework CoreServices -framework SkyLight -framework ScriptingBridge -framework IOKit
BUILD_FLAGS = -std=c99 -Wall -DDEBUG -fsanitize=address -fsanitize=undefined -g -O0 -fvisibility=hidden -mmacosx-version-min=10.13
BUILD_FLAGS = -std=c99 -Wall -DDEBUG -g -O0 -fvisibility=hidden -mmacosx-version-min=10.13
BUILD_PATH = ./bin
DOC_PATH = ./doc
SMP_PATH = ./examples

View file

@ -176,7 +176,7 @@ void bar_refresh(struct bar *bar)
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
struct bar_item* bar_item = g_bar_manager.bar_items[i];
if (!bar_item->enabled || bar_item->hidden) continue;
if (!bar_item->drawing) continue;
bar_item->is_shown = false;
if(bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << did))) continue;

View file

@ -8,8 +8,8 @@ struct bar_item* bar_item_create() {
}
void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) {
bar_item->enabled = true;
bar_item->hidden = false;
bar_item->drawing = true;
bar_item->scripting = true;
bar_item->is_shown = false;
bar_item->nospace = false;
bar_item->counter = 0;
@ -39,6 +39,8 @@ void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) {
bar_item->bounding_rects = NULL;
if (default_item) {
bar_item->scripting = default_item->scripting;
bar_item->drawing = default_item->drawing;
bar_item->icon_color = default_item->icon_color;
bar_item->icon_font_name = default_item->icon_font_name;
bar_item->label_color = default_item->label_color;
@ -59,7 +61,7 @@ void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) {
}
void bar_item_script_update(struct bar_item* bar_item, bool forced) {
if (!bar_item->enabled || (bar_item->update_frequency == 0 && !forced)) return;
if (!bar_item->scripting || (bar_item->update_frequency == 0 && !forced)) return;
if (strcmp(bar_item->script, "") != 0) {
bar_item->counter++;
if (bar_item->update_frequency < bar_item->counter || forced) {
@ -70,7 +72,6 @@ void bar_item_script_update(struct bar_item* bar_item, bool forced) {
}
void bar_item_update_component(struct bar_item* bar_item, uint32_t did, uint32_t sid) {
if (!bar_item->enabled) return;
if (bar_item->type == BAR_COMPONENT) {
if (strcmp(bar_item->identifier, BAR_COMPONENT_SPACE) == 0) {
if ((1 << sid) & bar_item->associated_space && (1 << did) & bar_item->associated_display)
@ -156,6 +157,7 @@ void bar_item_set_label_font(struct bar_item* bar_item, char *font_string) {
}
void bar_item_on_click(struct bar_item* bar_item) {
if (!bar_item->scripting) return;
if (bar_item && strlen(bar_item->on_click_script) > 0)
fork_exec(bar_item->on_click_script, NULL);
}

View file

@ -11,8 +11,8 @@
#define UPDATE_SYSTEM_WOKE 1 << 3
struct bar_item {
bool enabled;
bool hidden;
bool drawing;
bool scripting;
bool is_shown;
bool nospace;
int counter;

View file

@ -161,7 +161,7 @@ void bar_manager_check_bar_items_for_update_pattern(struct bar_manager* bar_mana
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t sid) {
for (int i = 0; i < bar_manager->bar_item_count; i++) {
struct bar_item* bar_item = bar_manager->bar_items[i];
if (!bar_item->enabled || bar_item->hidden || bar_item->num_rects < sid || bar_item->bounding_rects[sid - 1] == NULL) continue;
if (!bar_item->drawing || bar_item->num_rects < sid || bar_item->bounding_rects[sid - 1] == NULL) continue;
if (cgrect_contains_point(bar_item->bounding_rects[sid - 1], &point)) {
return bar_item;
}

View file

@ -32,8 +32,10 @@ extern bool g_verbose;
#define COMMAND_DEFAULT_RESET "reset"
#define DOMAIN_SET "set"
#define COMMAND_SET_ENABLED "enabled"
#define COMMAND_SET_HIDDEN "hidden"
#define COMMAND_SET_ENABLED "enabled" // TODO: Add deprecation notice
#define COMMAND_SET_HIDDEN "hidden" // TOD0: Add deprecation notice
#define COMMAND_SET_DRAWING "drawing"
#define COMMAND_SET_SCRIPTING "scripting"
#define COMMAND_SET_POSITION "position"
#define COMMAND_SET_ASSOCIATED_DISPLAY "associated_display"
#define COMMAND_SET_ASSOCIATED_SPACE "associated_space"
@ -241,6 +243,12 @@ static void handle_domain_default(FILE* rsp, struct token domain, char* message)
} else if (token_equals(property, COMMAND_SET_CACHE_SCRIPTS)) {
struct token value = get_token(&message);
bar_item->cache_scripts = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
} else if (token_equals(property, COMMAND_SET_SCRIPTING)) {
struct token value = get_token(&message);
bar_item->scripting = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
} else if (token_equals(property, COMMAND_SET_DRAWING)) {
struct token value = get_token(&message);
bar_item->drawing = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
} else if (token_equals(property, COMMAND_DEFAULT_RESET)) {
bar_item_init(&g_bar_manager.default_item, NULL);
}
@ -399,13 +407,25 @@ static void handle_domain_set(FILE* rsp, struct token domain, char* message) {
} else if (token_equals(property, COMMAND_SET_CACHE_SCRIPTS)) {
struct token value = get_token(&message);
bar_item->cache_scripts = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
} else if (token_equals(property, COMMAND_SET_ENABLED)) {
} else if (token_equals(property, COMMAND_SET_SCRIPTING)) {
struct token value = get_token(&message);
bar_item->enabled = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
} else if (token_equals(property, COMMAND_SET_HIDDEN)) {
bar_item->scripting = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
} else if (token_equals(property, COMMAND_SET_DRAWING)) {
struct token value = get_token(&message);
bar_item->hidden = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
bar_item->drawing = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
}
// DEPRECATED
else if (token_equals(property, COMMAND_SET_ENABLED)) {
struct token value = get_token(&message);
printf("Command: enabled soon to be deprecated: Use drawing and scripting commands \n");
bar_item->drawing = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
bar_item->scripting = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
} else if (token_equals(property, COMMAND_SET_HIDDEN)) {
printf("Command: hidden soon to be deprecated: Use drawing command \n");
struct token value = get_token(&message);
bar_item->drawing = !(token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false);
}
///////////
if (bar_item->is_shown)
bar_manager_refresh(&g_bar_manager);