allow enabling and disabling of items

This commit is contained in:
FelixKratz 2021-08-23 22:57:09 +02:00
parent 7cba487cd2
commit 2dc711f22f
5 changed files with 12 additions and 1 deletions

View file

@ -126,7 +126,8 @@ A list of properties is listed below:
* *script*: a script to run every *update_freq* seconds
* *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*)
* *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*)
### Changing the default values for all further items
```bash

View file

@ -175,6 +175,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) continue;
bar_item->is_shown = false;
if(bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << did))) continue;

View file

@ -7,6 +7,7 @@ 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->is_shown = false;
bar_item->nospace = false;
bar_item->counter = 0;
@ -53,6 +54,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) return;
if (strcmp(bar_item->script, "") != 0) {
bar_item->counter++;
if (bar_item->update_frequency < bar_item->counter || forced) {
@ -63,6 +65,7 @@ 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)

View file

@ -11,6 +11,7 @@
#define UPDATE_SYSTEM_WOKE 1 << 3
struct bar_item {
bool enabled;
bool is_shown;
bool nospace;
int counter;

View file

@ -28,6 +28,7 @@ extern bool g_verbose;
#define COMMAND_DEFAULT_RESET "reset"
#define DOMAIN_SET "set"
#define COMMAND_SET_ENABLED "enabled"
#define COMMAND_SET_POSITION "position"
#define COMMAND_SET_ASSOCIATED_DISPLAY "associated_display"
#define COMMAND_SET_ASSOCIATED_SPACE "associated_space"
@ -363,8 +364,12 @@ 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)) {
struct token value = get_token(&message);
bar_item->enabled = token_equals(value, ARGUMENT_COMMON_VAL_ON) ? true : false;
}
if (bar_item->is_shown)
bar_manager_refresh(&g_bar_manager);
}