aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 00:07:35 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commite5e8094dc3119584ae611c3197b38243b6c016c9 (patch)
tree6d0c6f0ff47f495f0cafc1a6d617a471330d2258 /swaybar
parentWire up basic IPC support (diff)
downloadsway-e5e8094dc3119584ae611c3197b38243b6c016c9.tar.gz
sway-e5e8094dc3119584ae611c3197b38243b6c016c9.tar.zst
sway-e5e8094dc3119584ae611c3197b38243b6c016c9.zip
Only utilize the configured outputs
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c32
-rw-r--r--swaybar/ipc.c37
2 files changed, 57 insertions, 12 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 433e2948..a6e3b780 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -65,13 +65,13 @@ static void handle_global(void *data, struct wl_registry *registry,
65 bar->shm = wl_registry_bind(registry, name, 65 bar->shm = wl_registry_bind(registry, name,
66 &wl_shm_interface, 1); 66 &wl_shm_interface, 1);
67 } else if (strcmp(interface, wl_output_interface.name) == 0) { 67 } else if (strcmp(interface, wl_output_interface.name) == 0) {
68 static int idx = 0; 68 static size_t index = 0;
69 struct swaybar_output *output = 69 struct swaybar_output *output =
70 calloc(1, sizeof(struct swaybar_output)); 70 calloc(1, sizeof(struct swaybar_output));
71 output->bar = bar; 71 output->bar = bar;
72 output->output = wl_registry_bind(registry, name, 72 output->output = wl_registry_bind(registry, name,
73 &wl_output_interface, 1); 73 &wl_output_interface, 1);
74 output->idx = idx++; 74 output->index = index++;
75 wl_list_insert(&bar->outputs, &output->link); 75 wl_list_insert(&bar->outputs, &output->link);
76 } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { 76 } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
77 bar->layer_shell = wl_registry_bind( 77 bar->layer_shell = wl_registry_bind(
@@ -108,16 +108,24 @@ void bar_setup(struct swaybar *bar,
108 // TODO: we might not necessarily be meant to do all of the outputs 108 // TODO: we might not necessarily be meant to do all of the outputs
109 struct swaybar_output *output; 109 struct swaybar_output *output;
110 wl_list_for_each(output, &bar->outputs, link) { 110 wl_list_for_each(output, &bar->outputs, link) {
111 assert(output->surface = wl_compositor_create_surface(bar->compositor)); 111 struct config_output *coutput;
112 output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( 112 wl_list_for_each(coutput, &bar->config->outputs, link) {
113 bar->layer_shell, output->surface, output->output, 113 if (coutput->index != output->index) {
114 ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); 114 continue;
115 assert(output->layer_surface); 115 }
116 zwlr_layer_surface_v1_add_listener(output->layer_surface, 116 assert(output->surface = wl_compositor_create_surface(
117 &layer_surface_listener, output); 117 bar->compositor));
118 zwlr_layer_surface_v1_set_anchor(output->layer_surface, 118 output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
119 bar->config->position); 119 bar->layer_shell, output->surface, output->output,
120 render_frame(bar, output); 120 ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
121 assert(output->layer_surface);
122 zwlr_layer_surface_v1_add_listener(output->layer_surface,
123 &layer_surface_listener, output);
124 zwlr_layer_surface_v1_set_anchor(output->layer_surface,
125 bar->config->position);
126 render_frame(bar, output);
127 break;
128 }
121 } 129 }
122} 130}
123 131
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index cef784d0..d3ee170c 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -1,4 +1,5 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 500
2#include <limits.h>
2#include <string.h> 3#include <string.h>
3#include <strings.h> 4#include <strings.h>
4#include <json-c/json.h> 5#include <json-c/json.h>
@@ -174,6 +175,7 @@ static void ipc_parse_config(
174 struct config_output *coutput = calloc( 175 struct config_output *coutput = calloc(
175 1, sizeof(struct config_output)); 176 1, sizeof(struct config_output));
176 coutput->name = strdup(name); 177 coutput->name = strdup(name);
178 coutput->index = SIZE_MAX;
177 wl_list_insert(&config->outputs, &coutput->link); 179 wl_list_insert(&config->outputs, &coutput->link);
178 } 180 }
179 } 181 }
@@ -185,12 +187,47 @@ static void ipc_parse_config(
185 json_object_put(bar_config); 187 json_object_put(bar_config);
186} 188}
187 189
190static void ipc_get_outputs(struct swaybar *bar) {
191 uint32_t len = 0;
192 char *res = ipc_single_command(bar->ipc_socketfd,
193 IPC_GET_OUTPUTS, NULL, &len);
194 json_object *outputs = json_tokener_parse(res);
195 for (size_t i = 0; i < json_object_array_length(outputs); ++i) {
196 json_object *output = json_object_array_get_idx(outputs, i);
197 json_object *output_name, *output_active;
198 json_object_object_get_ex(output, "name", &output_name);
199 json_object_object_get_ex(output, "active", &output_active);
200 const char *name = json_object_get_string(output_name);
201 bool active = json_object_get_boolean(output_active);
202 if (!active) {
203 continue;
204 }
205 if (wl_list_empty(&bar->config->outputs)) {
206 struct config_output *coutput = calloc(
207 1, sizeof(struct config_output));
208 coutput->name = strdup(name);
209 coutput->index = i;
210 wl_list_insert(&bar->config->outputs, &coutput->link);
211 } else {
212 struct config_output *coutput;
213 wl_list_for_each(coutput, &bar->config->outputs, link) {
214 if (strcmp(name, coutput->name) == 0) {
215 coutput->index = i;
216 break;
217 }
218 }
219 }
220 }
221 free(res);
222}
223
188void ipc_get_config(struct swaybar *bar, const char *bar_id) { 224void ipc_get_config(struct swaybar *bar, const char *bar_id) {
189 uint32_t len = strlen(bar_id); 225 uint32_t len = strlen(bar_id);
190 char *res = ipc_single_command(bar->ipc_socketfd, 226 char *res = ipc_single_command(bar->ipc_socketfd,
191 IPC_GET_BAR_CONFIG, bar_id, &len); 227 IPC_GET_BAR_CONFIG, bar_id, &len);
192 ipc_parse_config(bar->config, res); 228 ipc_parse_config(bar->config, res);
193 free(res); 229 free(res);
230 ipc_get_outputs(bar);
194} 231}
195 232
196void handle_ipc_event(struct swaybar *bar) { 233void handle_ipc_event(struct swaybar *bar) {