expose popup menu syntax (documentation following soon)

This commit is contained in:
Felix Kratz 2021-12-18 22:12:25 +01:00
parent 588c553f66
commit cde65125be
6 changed files with 68 additions and 6 deletions

View file

@ -21,6 +21,7 @@ bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
if (!bar_item->drawing) return false;
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << bar->adid))) return false;
if (bar_item->associated_space > 0 && !(bar_item->associated_space & (1 << bar->sid)) && (bar_item->type != BAR_COMPONENT_SPACE)) return false;
if (bar_item->position == POSITION_POPUP) return false;
return true;
}
@ -76,7 +77,8 @@ void bar_redraw(struct bar* bar) {
else if (bar_item->position == POSITION_CENTER) next_position = &bar_center_first_item_x;
else if (bar_item->position == POSITION_RIGHT) next_position = &bar_right_first_item_x, rtl = true;
else if (bar_item->position == POSITION_CENTER_RIGHT) next_position = &bar_center_right_first_item_x;
else next_position = &bar_center_left_first_item_x, rtl = true;
else if (bar_item->position == POSITION_CENTER_LEFT) next_position = &bar_center_left_first_item_x, rtl = true;
else continue;
if (bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT)
*next_position -= bar_item_display_length + bar_item->background.padding_left + bar_item->background.padding_right;

View file

@ -249,10 +249,6 @@ void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifi
fork_exec(bar_item->click_script, &bar_item->signal_args.env_vars);
if (bar_item->update_mask & UPDATE_MOUSE_CLICKED)
bar_item_update(bar_item, COMMAND_SUBSCRIBE_MOUSE_CLICKED, true, NULL);
//if (bar_item->popup.num_items == 0)
// popup_add_item(&bar_item->popup, bar_item);
//popup_set_drawing(&bar_item->popup, !bar_item->popup.drawing);
}
void bar_item_mouse_entered(struct bar_item* bar_item) {

View file

@ -131,6 +131,20 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) {
bar_item_set_type(bar_item, command.text[0]);
bar_item->position = position.text[0];
struct key_value_pair key_value_pair = get_key_value_pair(position.text, '.');
if (key_value_pair.key && key_value_pair.value) {
if (key_value_pair.key[0] == POSITION_POPUP) {
int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, key_value_pair.value);
if (item_index_for_name < 0) {
fprintf(rsp, "Name: %s not found in bar items \n", key_value_pair.value);
printf("Name: %s not found in bar items \n", key_value_pair.value);
return;
}
struct bar_item* target_item = g_bar_manager.bar_items[item_index_for_name];
popup_add_item(&target_item->popup, bar_item);
}
}
bar_item_set_name(bar_item, token_to_string(name));
if (token_equals(command, COMMAND_ADD_ITEM)) {
@ -187,6 +201,8 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
needs_update = background_parse_sub_domain(&bar_item->background, rsp, entry, message);
else if (token_equals(subdom, SUB_DOMAIN_GRAPH))
needs_update = graph_parse_sub_domain(&bar_item->graph, rsp, entry, message);
else if (token_equals(subdom, SUB_DOMAIN_POPUP))
needs_update = popup_parse_sub_domain(&bar_item->popup, rsp, entry, message);
else {
fprintf(rsp, "Invalid subdomain: %s \n", subdom.text);
printf("Invalid subdomain: %s \n", subdom.text);
@ -224,7 +240,21 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
} else if (token_equals(property, PROPERTY_UPDATE_FREQ)) {
bar_item->update_frequency = token_to_uint32t(get_token(&message));
} else if (token_equals(property, PROPERTY_POSITION)) {
bar_item->position = get_token(&message).text[0];
struct token position = get_token(&message);
bar_item->position = position.text[0];
struct key_value_pair key_value_pair = get_key_value_pair(position.text, '.');
if (key_value_pair.key && key_value_pair.value) {
if (key_value_pair.key[0] == POSITION_POPUP) {
int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, key_value_pair.value);
if (item_index_for_name < 0) {
fprintf(rsp, "Name: %s not found in bar items \n", key_value_pair.value);
printf("Name: %s not found in bar items \n", key_value_pair.value);
return;
}
struct bar_item* target_item = g_bar_manager.bar_items[item_index_for_name];
popup_add_item(&target_item->popup, bar_item);
}
}
needs_update = true;
} else if (token_equals(property, PROPERTY_ASSOCIATED_SPACE)) {
struct token token = get_token(&message);

View file

@ -31,6 +31,7 @@
#define SUB_DOMAIN_LABEL "label"
#define SUB_DOMAIN_BACKGROUND "background"
#define SUB_DOMAIN_GRAPH "graph"
#define SUB_DOMAIN_POPUP "popup"
#define PROPERTY_FONT "font"
#define PROPERTY_COLOR "color"
@ -109,6 +110,7 @@
#define POSITION_LEFT 'l'
#define POSITION_RIGHT 'r'
#define POSITION_CENTER 'c'
#define POSITION_POPUP 'p'
#define POSITION_CENTER_LEFT 'q'
#define POSITION_CENTER_RIGHT 'e'

View file

@ -11,6 +11,7 @@ void popup_init(struct popup* popup) {
popup->id = 0;
popup->frame.origin = (CGPoint){0,0};
popup->anchor = (CGPoint){100, 100};
popup->y_offset = 0;
popup->num_items = 0;
popup->cell_size = 30;
@ -81,6 +82,7 @@ void popup_add_item(struct popup* popup, struct bar_item* bar_item) {
void popup_set_anchor(struct popup* popup, CGPoint anchor) {
popup->anchor = anchor;
popup->anchor.y += popup->y_offset;
if (popup->drawing) {
//popup_close_window(popup);
@ -120,3 +122,30 @@ void popup_destroy(struct popup* popup) {
if (popup->context) free(popup->context);
}
static bool popup_parse_sub_domain(struct popup* popup, FILE* rsp, struct token property, char* message) {
if (token_equals(property, PROPERTY_YOFFSET)) {
popup->y_offset = token_to_int(get_token(&message));
return true;
} else if (token_equals(property, PROPERTY_DRAWING)) {
popup_set_drawing(popup, evaluate_boolean_state(get_token(&message), popup->drawing));
return true;
}
else {
struct key_value_pair key_value_pair = get_key_value_pair(property.text, '.');
if (key_value_pair.key && key_value_pair.value) {
struct token subdom = { key_value_pair.key, strlen(key_value_pair.key) };
struct token entry = { key_value_pair.value, strlen(key_value_pair.value) };
if (token_equals(subdom, SUB_DOMAIN_BACKGROUND))
return background_parse_sub_domain(&popup->background, rsp, entry, message);
else {
fprintf(rsp, "Invalid subdomain: %s \n", subdom.text);
printf("Invalid subdomain: %s \n", subdom.text);
}
}
else {
fprintf(rsp, "Unknown property: %s \n", property.text);
printf("Unknown property: %s \n", property.text);
}
}
return false;
}

View file

@ -6,6 +6,7 @@ struct popup {
uint32_t id;
bool drawing;
bool horizontal;
int y_offset;
uint32_t cell_size;
CGPoint anchor;
CGContextRef context;
@ -24,4 +25,6 @@ void popup_draw(struct popup* popup);
void popup_destroy(struct popup* popup);
static bool popup_parse_sub_domain(struct popup* popup, FILE* rsp, struct token property, char* message);
#endif // !POPUP_H