From ca5cc4ae6370ffdb9347a233fe2287f5e2cb2346 Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Wed, 16 Oct 2019 15:24:01 +0200 Subject: [PATCH] #119 include label in space queries --- src/space_manager.c | 12 ++++++++++++ src/space_manager.h | 1 + src/view.c | 3 +++ 3 files changed, 16 insertions(+) diff --git a/src/space_manager.c b/src/space_manager.c index 16ed6b1d..3712df1e 100644 --- a/src/space_manager.c +++ b/src/space_manager.c @@ -158,6 +158,18 @@ void space_manager_untile_window(struct space_manager *sm, struct view *view, st } } +struct space_label *space_manager_get_label_for_space(struct space_manager *sm, uint64_t sid) +{ + for (int i = 0; i < buf_len(sm->labels); ++i) { + struct space_label *space_label = &sm->labels[i]; + if (space_label->sid == sid) { + return space_label; + } + } + + return NULL; +} + struct space_label *space_manager_get_space_for_label(struct space_manager *sm, struct token label) { for (int i = 0; i < buf_len(sm->labels); ++i) { diff --git a/src/space_manager.h b/src/space_manager.h index 8ac4e5d1..57936e19 100644 --- a/src/space_manager.h +++ b/src/space_manager.h @@ -66,6 +66,7 @@ uint64_t space_manager_next_space(uint64_t sid); uint64_t space_manager_first_space(void); uint64_t space_manager_last_space(void); uint64_t space_manager_active_space(void); +struct space_label *space_manager_get_label_for_space(struct space_manager *sm, uint64_t sid); struct space_label *space_manager_get_space_for_label(struct space_manager *sm, struct token label); void space_manager_set_label_for_space(struct space_manager *sm, uint64_t sid, char *label); void space_manager_set_layout_for_space(struct space_manager *sm, uint64_t sid, enum view_type type); diff --git a/src/view.c b/src/view.c index cbeb59a8..6056a0ec 100644 --- a/src/view.c +++ b/src/view.c @@ -475,12 +475,14 @@ void view_serialize(FILE *rsp, struct view *view) if (buffer_size <= 0) break; } + struct space_label *space_label = space_manager_get_label_for_space(&g_space_manager, view->sid); struct window_node *first_leaf = window_node_find_first_leaf(view->root); struct window_node *last_leaf = window_node_find_last_leaf(view->root); fprintf(rsp, "{\n" "\t\"id\":%lld,\n" + "\t\"label\":\"%s\",\n" "\t\"index\":%d,\n" "\t\"display\":%d,\n" "\t\"windows\":[%s],\n" @@ -492,6 +494,7 @@ void view_serialize(FILE *rsp, struct view *view) "\t\"last-window\":%d\n" "}", view->sid, + space_label ? space_label->label : "", space_manager_mission_control_index(view->sid), display_arrangement(space_display_id(view->sid)), buffer,