Only utilize the configured outputs
This commit is contained in:
parent
5c9ad035db
commit
e5e8094dc3
|
@ -31,7 +31,7 @@ struct swaybar_output {
|
|||
struct zwlr_layer_surface_v1 *layer_surface;
|
||||
|
||||
char *name;
|
||||
int idx;
|
||||
size_t index;
|
||||
bool focused;
|
||||
|
||||
uint32_t width, height;
|
||||
|
|
|
@ -14,6 +14,7 @@ struct box_colors {
|
|||
struct config_output {
|
||||
struct wl_list link;
|
||||
char *name;
|
||||
size_t index;
|
||||
};
|
||||
|
||||
struct swaybar_config {
|
||||
|
|
|
@ -65,13 +65,13 @@ static void handle_global(void *data, struct wl_registry *registry,
|
|||
bar->shm = wl_registry_bind(registry, name,
|
||||
&wl_shm_interface, 1);
|
||||
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||
static int idx = 0;
|
||||
static size_t index = 0;
|
||||
struct swaybar_output *output =
|
||||
calloc(1, sizeof(struct swaybar_output));
|
||||
output->bar = bar;
|
||||
output->output = wl_registry_bind(registry, name,
|
||||
&wl_output_interface, 1);
|
||||
output->idx = idx++;
|
||||
output->index = index++;
|
||||
wl_list_insert(&bar->outputs, &output->link);
|
||||
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
||||
bar->layer_shell = wl_registry_bind(
|
||||
|
@ -108,7 +108,13 @@ void bar_setup(struct swaybar *bar,
|
|||
// TODO: we might not necessarily be meant to do all of the outputs
|
||||
struct swaybar_output *output;
|
||||
wl_list_for_each(output, &bar->outputs, link) {
|
||||
assert(output->surface = wl_compositor_create_surface(bar->compositor));
|
||||
struct config_output *coutput;
|
||||
wl_list_for_each(coutput, &bar->config->outputs, link) {
|
||||
if (coutput->index != output->index) {
|
||||
continue;
|
||||
}
|
||||
assert(output->surface = wl_compositor_create_surface(
|
||||
bar->compositor));
|
||||
output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||
bar->layer_shell, output->surface, output->output,
|
||||
ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
|
||||
|
@ -118,6 +124,8 @@ void bar_setup(struct swaybar *bar,
|
|||
zwlr_layer_surface_v1_set_anchor(output->layer_surface,
|
||||
bar->config->position);
|
||||
render_frame(bar, output);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <json-c/json.h>
|
||||
|
@ -174,6 +175,7 @@ static void ipc_parse_config(
|
|||
struct config_output *coutput = calloc(
|
||||
1, sizeof(struct config_output));
|
||||
coutput->name = strdup(name);
|
||||
coutput->index = SIZE_MAX;
|
||||
wl_list_insert(&config->outputs, &coutput->link);
|
||||
}
|
||||
}
|
||||
|
@ -185,12 +187,47 @@ static void ipc_parse_config(
|
|||
json_object_put(bar_config);
|
||||
}
|
||||
|
||||
static void ipc_get_outputs(struct swaybar *bar) {
|
||||
uint32_t len = 0;
|
||||
char *res = ipc_single_command(bar->ipc_socketfd,
|
||||
IPC_GET_OUTPUTS, NULL, &len);
|
||||
json_object *outputs = json_tokener_parse(res);
|
||||
for (size_t i = 0; i < json_object_array_length(outputs); ++i) {
|
||||
json_object *output = json_object_array_get_idx(outputs, i);
|
||||
json_object *output_name, *output_active;
|
||||
json_object_object_get_ex(output, "name", &output_name);
|
||||
json_object_object_get_ex(output, "active", &output_active);
|
||||
const char *name = json_object_get_string(output_name);
|
||||
bool active = json_object_get_boolean(output_active);
|
||||
if (!active) {
|
||||
continue;
|
||||
}
|
||||
if (wl_list_empty(&bar->config->outputs)) {
|
||||
struct config_output *coutput = calloc(
|
||||
1, sizeof(struct config_output));
|
||||
coutput->name = strdup(name);
|
||||
coutput->index = i;
|
||||
wl_list_insert(&bar->config->outputs, &coutput->link);
|
||||
} else {
|
||||
struct config_output *coutput;
|
||||
wl_list_for_each(coutput, &bar->config->outputs, link) {
|
||||
if (strcmp(name, coutput->name) == 0) {
|
||||
coutput->index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(res);
|
||||
}
|
||||
|
||||
void ipc_get_config(struct swaybar *bar, const char *bar_id) {
|
||||
uint32_t len = strlen(bar_id);
|
||||
char *res = ipc_single_command(bar->ipc_socketfd,
|
||||
IPC_GET_BAR_CONFIG, bar_id, &len);
|
||||
ipc_parse_config(bar->config, res);
|
||||
free(res);
|
||||
ipc_get_outputs(bar);
|
||||
}
|
||||
|
||||
void handle_ipc_event(struct swaybar *bar) {
|
||||
|
|
Loading…
Reference in a new issue