allow setting default values for a lot of properties

This commit is contained in:
FelixKratz 2021-08-22 14:37:30 +02:00
parent 026b2eda0a
commit 2b3e59dadb
8 changed files with 149 additions and 98 deletions

View file

@ -127,6 +127,28 @@ A list of properties is listed below:
* *click_script*: script to run when left clicking on item * *click_script*: script to run when left clicking on item
### Changing the default values for all further items
```bash
sketchybar -m default <property> <value>
```
this currently works for the properties:
* *label_font*
* *label_color*
* *label_padding_left*
* *label_padding_right*
* *icon_font*
* *icon_color*
* *icon_padding_left*
* *icon_padding_right*
* *update_freq*
It is also possible to reset the defaults via the command
```bash
sketchybar -m default reset
```
### Subscribing items to system events for their script execution ### Subscribing items to system events for their script execution
```bash ```bash
sketchybar -m subscribe <name> <event> sketchybar -m subscribe <name> <event>

View file

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

View file

@ -2,86 +2,68 @@
# TODO: Create a enable disable command to hide items and unsubscribe them from updates # TODO: Create a enable disable command to hide items and unsubscribe them from updates
# TODO: Implement the plugin system for easier setup of preconfigured items # TODO: Implement the plugin system for easier setup of preconfigured items
############## BAR ##################
sketchybar -m config height 25 sketchybar -m config height 25
sketchybar -m config position top sketchybar -m config position top
sketchybar -m config padding_left 10 sketchybar -m config padding_left 10
sketchybar -m config padding_right 10 sketchybar -m config padding_right 10
sketchybar -m config bar_color 0x44000000 #0xaf202020 sketchybar -m config bar_color 0x44000000 #0xaf202020
############## SPACES ###############
sketchybar -m default icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m default icon_color 0xffffffff
sketchybar -m default label_font "Hack Nerd Font:Bold:14.0"
sketchybar -m default label_color 0xffffffff
sketchybar -m default label_padding_left 4
sketchybar -m default icon_padding_left 16
sketchybar -m add component space code left sketchybar -m add component space code left
sketchybar -m set code associated_display 1 sketchybar -m set code associated_display 1
sketchybar -m set code associated_space 1 sketchybar -m set code associated_space 1
sketchybar -m set code icon_font "Hack Nerd Font:Bold:20.0" sketchybar -m set code icon_font "Hack Nerd Font:Bold:20.0"
sketchybar -m set code icon  # # sketchybar -m set code icon 
sketchybar -m set code icon_color 0xffffffff
sketchybar -m set code icon_highlight_color 0xff48aa2a sketchybar -m set code icon_highlight_color 0xff48aa2a
sketchybar -m set code label_padding_left 4 sketchybar -m set code icon_padding_left 0
sketchybar -m set code label code sketchybar -m set code label code
sketchybar -m set code click_script "yabai -m space --focus 1" sketchybar -m set code click_script "yabai -m space --focus 1"
sketchybar -m add item spaceSep left
sketchybar -m set spaceSep associated_display 1
sketchybar -m set spaceSep icon_font "Hack Nerd Font:Bold:15.0"
#sketchybar -m set spaceSep icon 
sketchybar -m set spaceSep icon_padding_right 8
sketchybar -m set spaceSep icon_padding_left 8
sketchybar -m add component space writing left sketchybar -m add component space writing left
sketchybar -m set writing associated_display 1 sketchybar -m set writing associated_display 1
sketchybar -m set writing associated_space 2 sketchybar -m set writing associated_space 2
sketchybar -m set writing icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set writing icon_highlight_color 0xfffab402 sketchybar -m set writing icon_highlight_color 0xfffab402
sketchybar -m set writing icon  # sketchybar -m set writing icon 
sketchybar -m set writing label_padding_left 4
sketchybar -m set writing label tex sketchybar -m set writing label tex
sketchybar -m set writing click_script "yabai -m space --focus 2" sketchybar -m set writing click_script "yabai -m space --focus 2"
sketchybar -m add item spaceSep2 left
sketchybar -m set spaceSep2 associated_display 1
sketchybar -m set spaceSep2 icon_font "Hack Nerd Font:Bold:15.0"
#sketchybar -m set spaceSep2 icon 
sketchybar -m set spaceSep2 icon_padding_right 8
sketchybar -m set spaceSep2 icon_padding_left 8
sketchybar -m add component space reading left sketchybar -m add component space reading left
sketchybar -m set reading associated_display 1 sketchybar -m set reading associated_display 1
sketchybar -m set reading associated_space 3 sketchybar -m set reading associated_space 3
sketchybar -m set reading icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set reading icon_highlight_color 0xff7fe5f0 sketchybar -m set reading icon_highlight_color 0xff7fe5f0
sketchybar -m set reading icon  sketchybar -m set reading icon 
sketchybar -m set reading label_padding_left 4
sketchybar -m set reading label web sketchybar -m set reading label web
sketchybar -m set reading click_script "yabai -m space --focus 3" sketchybar -m set reading click_script "yabai -m space --focus 3"
sketchybar -m add item spaceSep3 left
sketchybar -m set spaceSep3 associated_display 1
sketchybar -m set spaceSep3 icon_font "Hack Nerd Font:Bold:15.0"
#sketchybar -m set spaceSep3 icon 
sketchybar -m set spaceSep3 icon_padding_right 8
sketchybar -m set spaceSep3 icon_padding_left 8
sketchybar -m add component space entertainment left sketchybar -m add component space entertainment left
sketchybar -m set entertainment associated_display 1 sketchybar -m set entertainment associated_display 1
sketchybar -m set entertainment associated_space 4 sketchybar -m set entertainment associated_space 4
sketchybar -m set entertainment icon_font "Hack Nerd Font:Bold:19.0" sketchybar -m set entertainment icon_font "Hack Nerd Font:Bold:19.0"
sketchybar -m set entertainment icon_highlight_color 0xfffff68f sketchybar -m set entertainment icon_highlight_color 0xfffff68f
sketchybar -m set entertainment icon  #鈴 sketchybar -m set entertainment icon 
sketchybar -m set entertainment label_padding_left 4
sketchybar -m set entertainment label idle sketchybar -m set entertainment label idle
sketchybar -m set entertainment click_script "yabai -m space --focus 4" sketchybar -m set entertainment click_script "yabai -m space --focus 4"
sketchybar -m add component space zoom left sketchybar -m add component space zoom left
sketchybar -m set zoom associated_display 2 sketchybar -m set zoom associated_display 2
sketchybar -m set zoom associated_space 5 sketchybar -m set zoom associated_space 5
sketchybar -m set zoom icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set zoom icon V sketchybar -m set zoom icon V
sketchybar -m set zoom label_padding_left 4 sketchybar -m set zoom icon_padding_left 0
################## LEFT ITEMS ##################
sketchybar -m default label_padding_left 0
sketchybar -m default icon_padding_left 0
sketchybar -m add item vimSeparator left sketchybar -m add item vimSeparator left
sketchybar -m set vimSeparator icon_font "Hack Nerd Font:Bold:15.0" sketchybar -m set vimSeparator icon_font "Hack Nerd Font:Bold:15.0"
# You can change each individual color
#sketchybar -m set vimSeparator icon_color 0xff48aa2a
#sketchybar -m set vimSeparator label_color 0xaf202020
sketchybar -m set vimSeparator icon  sketchybar -m set vimSeparator icon 
sketchybar -m set vimSeparator associated_space 1 sketchybar -m set vimSeparator associated_space 1
sketchybar -m set vimSeparator associated_space 2 sketchybar -m set vimSeparator associated_space 2
@ -96,14 +78,22 @@ sketchybar -m set vimIndicator icon ""
sketchybar -m set vimIndicator icon_padding_right 4 sketchybar -m set vimIndicator icon_padding_right 4
sketchybar -m set vimIndicator label "normal" sketchybar -m set vimIndicator label "normal"
sketchybar -m set vimIndicator label_padding_right 10 sketchybar -m set vimIndicator label_padding_right 10
sketchybar -m set vimIndicator click_script "gvim"
sketchybar -m add item topmem left
sketchybar -m set topmem associated_space 1
sketchybar -m set topmem script "~/.config/sketchybar/plugins/topmem.sh"
sketchybar -m set topmem update_freq 15
################# RIGHT ITEMS ####################
sketchybar -m add item clock right sketchybar -m add item clock right
sketchybar -m set clock update_freq 10 sketchybar -m set clock update_freq 10
sketchybar -m set clock script "~/.config/sketchybar/plugins/clock.sh" sketchybar -m set clock script "~/.config/sketchybar/plugins/clock.sh"
sketchybar -m set clock icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set clock label_padding_left 15 sketchybar -m set clock label_padding_left 15
sketchybar -m default label_padding_left 4
sketchybar -m default icon_padding_left 15
sketchybar -m add item mailIndicator right sketchybar -m add item mailIndicator right
# Items can be associated to multiple spaces / displays # Items can be associated to multiple spaces / displays
sketchybar -m set mailIndicator associated_space 1 sketchybar -m set mailIndicator associated_space 1
@ -113,8 +103,6 @@ sketchybar -m set mailIndicator update_freq 15
sketchybar -m set mailIndicator script "~/.config/sketchybar/plugins/mailIndicator.sh" sketchybar -m set mailIndicator script "~/.config/sketchybar/plugins/mailIndicator.sh"
sketchybar -m set mailIndicator icon_font "Hack Nerd Font:Bold:20.0" sketchybar -m set mailIndicator icon_font "Hack Nerd Font:Bold:20.0"
sketchybar -m set mailIndicator icon  sketchybar -m set mailIndicator icon 
sketchybar -m set mailIndicator label_padding_left 4
sketchybar -m set mailIndicator icon_padding_left 15
sketchybar -m set mailIndicator click_script "osascript -e 'tell application \"Mail\" to activate'" sketchybar -m set mailIndicator click_script "osascript -e 'tell application \"Mail\" to activate'"
sketchybar -m add item githubIndicator right sketchybar -m add item githubIndicator right
@ -122,59 +110,25 @@ sketchybar -m set githubIndicator associated_space 1
sketchybar -m set githubIndicator script "~/.config/sketchybar/plugins/githubIndicator.sh" sketchybar -m set githubIndicator script "~/.config/sketchybar/plugins/githubIndicator.sh"
sketchybar -m set githubIndicator update_freq 1000 sketchybar -m set githubIndicator update_freq 1000
sketchybar -m set githubIndicator icon_font "Hack Nerd Font:Bold:18.0" sketchybar -m set githubIndicator icon_font "Hack Nerd Font:Bold:18.0"
sketchybar -m set githubIndicator icon  # sketchybar -m set githubIndicator icon 
sketchybar -m set githubIndicator label_padding_left 4
sketchybar -m set githubIndicator icon_padding_left 15
sketchybar -m set githubIndicator click_script "open https://github.com" sketchybar -m set githubIndicator click_script "open https://github.com"
sketchybar -m subscribe githubIndicator system_woke sketchybar -m subscribe githubIndicator system_woke
sketchybar -m default icon_padding_left 4
sketchybar -m add component graph cpu_user right 200 nospace sketchybar -m add component graph cpu_user right 200 nospace
sketchybar -m set cpu_user script "~/.config/sketchybar/plugins/cpu_graph.sh" sketchybar -m set cpu_user script "~/.config/sketchybar/plugins/cpu_graph.sh"
sketchybar -m set cpu_user graph_color 0xffffffff sketchybar -m set cpu_user graph_color 0xffffffff
sketchybar -m set cpu_user update_freq 1 sketchybar -m set cpu_user update_freq 1
sketchybar -m set cpu_user associated_space 1 sketchybar -m set cpu_user associated_space 1
sketchybar -m set cpu_user icon_font "Hack Nerd Font:Bold:17.0" sketchybar -m set cpu_user label_padding_left 0
sketchybar -m set cpu_user icon  sketchybar -m set cpu_user icon 
sketchybar -m set cpu_user icon_padding_left 4
sketchybar -m add component graph cpu_sys right 200 sketchybar -m add component graph cpu_sys right 200
sketchybar -m set cpu_sys graph_color 0xff48aa2a sketchybar -m set cpu_sys graph_color 0xff48aa2a
sketchybar -m set cpu_sys label_padding_left 0
sketchybar -m set cpu_sys associated_space 1 sketchybar -m set cpu_sys associated_space 1
sketchybar -m set cpu_sys icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set cpu_sys icon  sketchybar -m set cpu_sys icon 
sketchybar -m set cpu_sys icon_padding_left 4
sketchybar -m add component graph network_down right 200 nospace
sketchybar -m set network_down associated_space 3
sketchybar -m set network_down icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set network_down icon 
sketchybar -m set network_down icon_padding_left 4
sketchybar -m set network_down update_freq 1
sketchybar -m set network_down graph_color 0xffffffff
sketchybar -m set network_down script "~/.config/sketchybar/plugins/network_graph.sh"
sketchybar -m add component graph network_up right 200
sketchybar -m set network_up icon_font "Hack Nerd Font:Bold:17.0"
sketchybar -m set network_up icon 
sketchybar -m set network_up icon_padding_left 4
sketchybar -m set network_up associated_space 3
sketchybar -m set network_up graph_color 0xff48aa2a
sketchybar -m add item topmem left
sketchybar -m set topmem associated_space 1
sketchybar -m set topmem script "~/.config/sketchybar/plugins/topmem.sh"
sketchybar -m set topmem update_freq 15
sketchybar -m add item spotifyIndicator center
sketchybar -m set spotifyIndicator update_freq 10
sketchybar -m set spotifyIndicator script "~/.config/sketchybar/plugins/spotifyIndicator.sh"
sketchybar -m set spotifyIndicator click_script "osascript -e 'tell application \"Spotify\" to pause'"
#sketchybar -m add item windowTitle center
#sketchybar -m set windowTitle script "~/.config/sketchybar/plugins/windowTitle.sh"
#sketchybar -m subscribe windowTitle window_focus
#sketchybar -m subscribe windowTitle front_app_switched
#sketchybar -m subscribe windowTitle space_change
sketchybar -m add item topproc right sketchybar -m add item topproc right
sketchybar -m set topproc associated_space 1 sketchybar -m set topproc associated_space 1
@ -183,18 +137,29 @@ sketchybar -m set topproc label_padding_right 5
sketchybar -m set topproc script "~/.config/sketchybar/plugins/topproc.sh" sketchybar -m set topproc script "~/.config/sketchybar/plugins/topproc.sh"
sketchybar -m set topproc update_freq 15 sketchybar -m set topproc update_freq 15
# This is how to subscribe an item/component to a certain system event sketchybar -m add component graph network_down right 200 nospace
# It is possible to subscribe to more than one event sketchybar -m set network_down associated_space 3
#sketchybar -m add item random center sketchybar -m set network_down label_padding_left 0
#sketchybar -m set random label test sketchybar -m set network_down icon 
#sketchybar -m set random click_script "~/.config/sketchybar/plugins/random.sh" sketchybar -m set network_down update_freq 1
#sketchybar -m set random script "~/.config/sketchybar/plugins/random.sh" sketchybar -m set network_down graph_color 0xffffffff
#sketchybar -m subscribe random front_app_switched sketchybar -m set network_down script "~/.config/sketchybar/plugins/network_graph.sh"
#sketchybar -m subscribe random title_change
#sketchybar -m subscribe random space_change sketchybar -m add component graph network_up right 200
#sketchybar -m subscribe random window_focus sketchybar -m set network_up icon 
#sketchybar -m subscribe random display_change sketchybar -m set network_up label_padding_left 0
#sketchybar -m subscribe random system_woke sketchybar -m set network_up associated_space 3
sketchybar -m set network_up graph_color 0xff48aa2a
###################### CENTER ITEMS ###################
sketchybar -m default label_padding_right 15
sketchybar -m default icon_padding_right 4
sketchybar -m add item spotifyIndicator center
sketchybar -m set spotifyIndicator update_freq 10
sketchybar -m set spotifyIndicator script "~/.config/sketchybar/plugins/spotifyIndicator.sh"
sketchybar -m set spotifyIndicator click_script "osascript -e 'tell application \"Spotify\" to pause'"
sketchybar -m update sketchybar -m update

View file

@ -6,17 +6,19 @@ struct bar_item* bar_item_create() {
return bar_item; return bar_item;
} }
void bar_item_init(struct bar_item* bar_item) { void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) {
bar_item->nospace = false; bar_item->nospace = false;
bar_item->counter = 0; bar_item->counter = 0;
bar_item->name = ""; bar_item->name = "";
bar_item->type = BAR_ITEM; bar_item->type = BAR_ITEM;
bar_item->update_frequency = 1000; bar_item->update_frequency = 1000;
bar_item->script = ""; bar_item->script = "";
bar_item->on_click_script = "~/.config/sketchybar/plugins/random.sh"; bar_item->on_click_script = "";
bar_item->position = BAR_POSITION_RIGHT; bar_item->position = BAR_POSITION_RIGHT;
bar_item->associated_display = 0; bar_item->associated_display = 0;
bar_item->associated_space = 0; bar_item->associated_space = 0;
bar_item->icon_font_name = "Hack Nerd Font:Bold:14.0";
bar_item->label_font_name = "Hack Nerd Font:Bold:14.0";
bar_item->icon_spacing_left = 0; bar_item->icon_spacing_left = 0;
bar_item->icon_spacing_right = 0; bar_item->icon_spacing_right = 0;
bar_item->icon_color = rgba_color_from_hex(0xffffffff); bar_item->icon_color = rgba_color_from_hex(0xffffffff);
@ -28,10 +30,23 @@ void bar_item_init(struct bar_item* bar_item) {
bar_item->num_rects = 0; bar_item->num_rects = 0;
bar_item->bounding_rects = NULL; bar_item->bounding_rects = NULL;
if (default_item) {
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;
bar_item->label_font_name = default_item->label_font_name;
bar_item->icon_spacing_left = default_item->icon_spacing_left;
bar_item->icon_spacing_right = default_item->icon_spacing_right;
bar_item->label_spacing_left = default_item->label_spacing_left;
bar_item->label_spacing_right = default_item->label_spacing_right;
bar_item->update_frequency = default_item->update_frequency;
}
bar_item_set_icon(bar_item, string_copy(""), bar_item->icon_color); bar_item_set_icon(bar_item, string_copy(""), bar_item->icon_color);
bar_item_set_icon_font(bar_item, string_copy("Hack Nerd Font:Bold:14.0")); bar_item_set_icon_font(bar_item, string_copy(bar_item->icon_font_name));
bar_item_set_label_font(bar_item, string_copy("Hack Nerd Font:Bold:14.0")); bar_item_set_label_font(bar_item, string_copy(bar_item->label_font_name));
bar_item_set_label(bar_item, string_copy("")); bar_item_set_label(bar_item, string_copy(""));
} }
void bar_item_script_update(struct bar_item* bar_item, bool forced) { void bar_item_script_update(struct bar_item* bar_item, bool forced) {
@ -123,6 +138,7 @@ void bar_item_set_icon_font(struct bar_item* bar_item, char *font_string) {
} }
bar_item->icon_font = bar_create_font(font_string); bar_item->icon_font = bar_create_font(font_string);
bar_item->icon_font_name = font_string;
} }
void bar_item_set_label_font(struct bar_item* bar_item, char *font_string) { void bar_item_set_label_font(struct bar_item* bar_item, char *font_string) {
@ -131,6 +147,7 @@ void bar_item_set_label_font(struct bar_item* bar_item, char *font_string) {
} }
bar_item->label_font = bar_create_font(font_string); bar_item->label_font = bar_create_font(font_string);
bar_item->label_font_name = font_string;
} }
void bar_item_on_click(struct bar_item* bar_item) { void bar_item_on_click(struct bar_item* bar_item) {

View file

@ -38,6 +38,7 @@ struct bar_item {
// Icon properties // Icon properties
struct bar_line icon_line; struct bar_line icon_line;
char* icon; char* icon;
char* icon_font_name;
CTFontRef icon_font; CTFontRef icon_font;
uint32_t icon_spacing_left; uint32_t icon_spacing_left;
uint32_t icon_spacing_right; uint32_t icon_spacing_right;
@ -47,6 +48,7 @@ struct bar_item {
// Label properties // Label properties
struct bar_line label_line; struct bar_line label_line;
char* label; char* label;
char* label_font_name;
CTFontRef label_font; CTFontRef label_font;
uint32_t label_spacing_left; uint32_t label_spacing_left;
uint32_t label_spacing_right; uint32_t label_spacing_right;
@ -68,7 +70,7 @@ struct bar_item {
struct bar_item* bar_item_create(); struct bar_item* bar_item_create();
void bar_item_script_update(struct bar_item* bar_item, bool forced); 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); void bar_item_update_component(struct bar_item* bar_item, uint32_t did, uint32_t sid);
void bar_item_init(struct bar_item* bar_item); void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item);
void bar_item_set_name(struct bar_item* bar_item, char* name); void bar_item_set_name(struct bar_item* bar_item, char* name);
void bar_item_set_script(struct bar_item* bar_item, char* script); void bar_item_set_script(struct bar_item* bar_item, char* script);
void bar_item_set_click_script(struct bar_item* bar_item, char* script); void bar_item_set_click_script(struct bar_item* bar_item, char* script);

View file

@ -1,4 +1,5 @@
#include "bar_manager.h" #include "bar_manager.h"
#include "bar_item.h"
extern struct event_loop g_event_loop; extern struct event_loop g_event_loop;
@ -87,7 +88,7 @@ struct bar_item* bar_manager_create_item(struct bar_manager* bar_manager) {
bar_manager->bar_items = (struct bar_item**) realloc(bar_manager->bar_items, sizeof(struct bar_item*) * (bar_manager->bar_item_count + 1)); bar_manager->bar_items = (struct bar_item**) realloc(bar_manager->bar_items, sizeof(struct bar_item*) * (bar_manager->bar_item_count + 1));
bar_manager->bar_item_count += 1; bar_manager->bar_item_count += 1;
struct bar_item* bar_item = bar_item_create(); struct bar_item* bar_item = bar_item_create();
bar_item_init(bar_item); bar_item_init(bar_item, &bar_manager->default_item);
bar_manager->bar_items[bar_manager->bar_item_count - 1] = bar_item; bar_manager->bar_items[bar_manager->bar_item_count - 1] = bar_item;
return bar_item; return bar_item;
} }
@ -103,6 +104,8 @@ void bar_manager_init(struct bar_manager *bar_manager)
bar_manager->padding_left = 20; bar_manager->padding_left = 20;
bar_manager->padding_right = 20; bar_manager->padding_right = 20;
bar_item_init(&bar_manager->default_item, NULL);
int refresh_frequency = 1; int refresh_frequency = 1;
int shell_refresh_frequency = 1; int shell_refresh_frequency = 1;

View file

@ -14,6 +14,7 @@ struct bar_manager
struct bar **bars; struct bar **bars;
int bar_count; int bar_count;
struct bar_item **bar_items; struct bar_item **bar_items;
struct bar_item default_item;
int bar_item_count; int bar_item_count;
char *position; char *position;
char *display; char *display;

View file

@ -1,4 +1,5 @@
#include "message.h" #include "message.h"
#include "bar_item.h"
extern struct event_loop g_event_loop; extern struct event_loop g_event_loop;
extern struct display_manager g_display_manager; extern struct display_manager g_display_manager;
@ -21,6 +22,9 @@ extern bool g_verbose;
#define DOMAIN_CLEAR "clear" #define DOMAIN_CLEAR "clear"
#define DOMAIN_DEFAULT "default"
#define COMMAND_DEFAULT_RESET "reset"
#define DOMAIN_SET "set" #define DOMAIN_SET "set"
#define COMMAND_SET_POSITION "position" #define COMMAND_SET_POSITION "position"
#define COMMAND_SET_ASSOCIATED_DISPLAY "associated_display" #define COMMAND_SET_ASSOCIATED_DISPLAY "associated_display"
@ -58,6 +62,7 @@ extern bool g_verbose;
#define COMMAND_CONFIG_BAR_PADDING_RIGHT "padding_right" #define COMMAND_CONFIG_BAR_PADDING_RIGHT "padding_right"
#define COMMAND_CONFIG_BAR_DISPLAY "display" #define COMMAND_CONFIG_BAR_DISPLAY "display"
#define ARGUMENT_COMMON_VAL_ON "on" #define ARGUMENT_COMMON_VAL_ON "on"
#define ARGUMENT_COMMON_VAL_OFF "off" #define ARGUMENT_COMMON_VAL_OFF "off"
#define ARGUMENT_COMMON_NO_SPACE "nospace" #define ARGUMENT_COMMON_NO_SPACE "nospace"
@ -185,6 +190,40 @@ static void handle_domain_subscribe(FILE* rsp, struct token domain, char* messag
static void handle_domain_clear(FILE* rsp, struct token domain, char* message) { static void handle_domain_clear(FILE* rsp, struct token domain, char* message) {
} }
// Syntax: sketchybar -m default <property> <value>
static void handle_domain_default(FILE* rsp, struct token domain, char* message) {
struct token property = get_token(&message);
struct bar_item* bar_item = &g_bar_manager.default_item;
if (token_equals(property, COMMAND_SET_ICON_FONT)) {
bar_item_set_icon_font(bar_item, string_copy(message));
} else if (token_equals(property, COMMAND_SET_LABEL_FONT)) {
bar_item_set_label_font(bar_item, string_copy(message));
} else if (token_equals(property, COMMAND_SET_UPDATE_FREQ)) {
struct token value = get_token(&message);
bar_item->update_frequency = token_to_uint32t(value);
} else if (token_equals(property, COMMAND_SET_LABEL_COLOR)) {
struct token value = get_token(&message);
bar_item_set_label_color(bar_item, token_to_uint32t(value));
} else if (token_equals(property, COMMAND_SET_ICON_COLOR)) {
struct token value = get_token(&message);
bar_item_set_icon_color(bar_item, token_to_uint32t(value));
} else if (token_equals(property, COMMAND_SET_ICON_PADDING_LEFT)) {
struct token value = get_token(&message);
bar_item->icon_spacing_left = token_to_uint32t(value);
} else if (token_equals(property, COMMAND_SET_ICON_PADDING_RIGHT)) {
struct token value = get_token(&message);
bar_item->icon_spacing_right = token_to_uint32t(value);
} else if (token_equals(property, COMMAND_SET_LABEL_PADDING_LEFT)) {
struct token value = get_token(&message);
bar_item->label_spacing_left = token_to_uint32t(value);
} else if (token_equals(property, COMMAND_SET_LABEL_PADDING_RIGHT)) {
struct token value = get_token(&message);
bar_item->label_spacing_right = token_to_uint32t(value);
} else if (token_equals(property, COMMAND_DEFAULT_RESET)) {
bar_item_init(&g_bar_manager.default_item, NULL);
}
}
// Syntax: sketchybar -m push <name> <y> // Syntax: sketchybar -m push <name> <y>
static void handle_domain_push(FILE* rsp, struct token domain, char* message) { static void handle_domain_push(FILE* rsp, struct token domain, char* message) {
struct token name = get_token(&message); struct token name = get_token(&message);
@ -417,6 +456,8 @@ void handle_message(FILE *rsp, char *message)
handle_domain_clear(rsp, domain, message); handle_domain_clear(rsp, domain, message);
} 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);
} else if (token_equals(domain, DOMAIN_DEFAULT)) {
handle_domain_default(rsp, domain, message);
} else { } else {
daemon_fail(rsp, "unknown domain '%.*s'\n", domain.length, domain.text); daemon_fail(rsp, "unknown domain '%.*s'\n", domain.length, domain.text);
} }