mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
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;
|
struct zwlr_layer_surface_v1 *layer_surface;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
int idx;
|
size_t index;
|
||||||
bool focused;
|
bool focused;
|
||||||
|
|
||||||
uint32_t width, height;
|
uint32_t width, height;
|
||||||
|
|
|
@ -14,6 +14,7 @@ struct box_colors {
|
||||||
struct config_output {
|
struct config_output {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
char *name;
|
char *name;
|
||||||
|
size_t index;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct swaybar_config {
|
struct swaybar_config {
|
||||||
|
|
|
@ -65,13 +65,13 @@ static void handle_global(void *data, struct wl_registry *registry,
|
||||||
bar->shm = wl_registry_bind(registry, name,
|
bar->shm = wl_registry_bind(registry, name,
|
||||||
&wl_shm_interface, 1);
|
&wl_shm_interface, 1);
|
||||||
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||||
static int idx = 0;
|
static size_t index = 0;
|
||||||
struct swaybar_output *output =
|
struct swaybar_output *output =
|
||||||
calloc(1, sizeof(struct swaybar_output));
|
calloc(1, sizeof(struct swaybar_output));
|
||||||
output->bar = bar;
|
output->bar = bar;
|
||||||
output->output = wl_registry_bind(registry, name,
|
output->output = wl_registry_bind(registry, name,
|
||||||
&wl_output_interface, 1);
|
&wl_output_interface, 1);
|
||||||
output->idx = idx++;
|
output->index = index++;
|
||||||
wl_list_insert(&bar->outputs, &output->link);
|
wl_list_insert(&bar->outputs, &output->link);
|
||||||
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
||||||
bar->layer_shell = wl_registry_bind(
|
bar->layer_shell = wl_registry_bind(
|
||||||
|
@ -108,16 +108,24 @@ void bar_setup(struct swaybar *bar,
|
||||||
// TODO: we might not necessarily be meant to do all of the outputs
|
// TODO: we might not necessarily be meant to do all of the outputs
|
||||||
struct swaybar_output *output;
|
struct swaybar_output *output;
|
||||||
wl_list_for_each(output, &bar->outputs, link) {
|
wl_list_for_each(output, &bar->outputs, link) {
|
||||||
assert(output->surface = wl_compositor_create_surface(bar->compositor));
|
struct config_output *coutput;
|
||||||
output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
wl_list_for_each(coutput, &bar->config->outputs, link) {
|
||||||
bar->layer_shell, output->surface, output->output,
|
if (coutput->index != output->index) {
|
||||||
ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
|
continue;
|
||||||
assert(output->layer_surface);
|
}
|
||||||
zwlr_layer_surface_v1_add_listener(output->layer_surface,
|
assert(output->surface = wl_compositor_create_surface(
|
||||||
&layer_surface_listener, output);
|
bar->compositor));
|
||||||
zwlr_layer_surface_v1_set_anchor(output->layer_surface,
|
output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
bar->config->position);
|
bar->layer_shell, output->surface, output->output,
|
||||||
render_frame(bar, output);
|
ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
|
||||||
|
assert(output->layer_surface);
|
||||||
|
zwlr_layer_surface_v1_add_listener(output->layer_surface,
|
||||||
|
&layer_surface_listener, output);
|
||||||
|
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
|
#define _XOPEN_SOURCE 500
|
||||||
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
|
@ -174,6 +175,7 @@ static void ipc_parse_config(
|
||||||
struct config_output *coutput = calloc(
|
struct config_output *coutput = calloc(
|
||||||
1, sizeof(struct config_output));
|
1, sizeof(struct config_output));
|
||||||
coutput->name = strdup(name);
|
coutput->name = strdup(name);
|
||||||
|
coutput->index = SIZE_MAX;
|
||||||
wl_list_insert(&config->outputs, &coutput->link);
|
wl_list_insert(&config->outputs, &coutput->link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,12 +187,47 @@ static void ipc_parse_config(
|
||||||
json_object_put(bar_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) {
|
void ipc_get_config(struct swaybar *bar, const char *bar_id) {
|
||||||
uint32_t len = strlen(bar_id);
|
uint32_t len = strlen(bar_id);
|
||||||
char *res = ipc_single_command(bar->ipc_socketfd,
|
char *res = ipc_single_command(bar->ipc_socketfd,
|
||||||
IPC_GET_BAR_CONFIG, bar_id, &len);
|
IPC_GET_BAR_CONFIG, bar_id, &len);
|
||||||
ipc_parse_config(bar->config, res);
|
ipc_parse_config(bar->config, res);
|
||||||
free(res);
|
free(res);
|
||||||
|
ipc_get_outputs(bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_ipc_event(struct swaybar *bar) {
|
void handle_ipc_event(struct swaybar *bar) {
|
||||||
|
|
Loading…
Reference in a new issue