Round up workspaces on each output
This commit is contained in:
parent
e5e8094dc3
commit
3399ad9840
|
@ -30,6 +30,8 @@ struct swaybar_output {
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
struct zwlr_layer_surface_v1 *layer_surface;
|
struct zwlr_layer_surface_v1 *layer_surface;
|
||||||
|
|
||||||
|
struct wl_list workspaces;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
size_t index;
|
size_t index;
|
||||||
bool focused;
|
bool focused;
|
||||||
|
@ -39,9 +41,19 @@ struct swaybar_output {
|
||||||
struct pool_buffer *current_buffer;
|
struct pool_buffer *current_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct swaybar_workspace {
|
||||||
|
struct wl_list link;
|
||||||
|
int num;
|
||||||
|
char *name;
|
||||||
|
bool focused;
|
||||||
|
bool visible;
|
||||||
|
bool urgent;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Rename stuff to match wlroots conventions (init/create/etc)
|
||||||
void bar_setup(struct swaybar *bar,
|
void bar_setup(struct swaybar *bar,
|
||||||
const char *socket_path,
|
const char *socket_path,
|
||||||
const char *bar_id);
|
const char *bar_id);
|
||||||
void bar_run(struct swaybar *bar);
|
void bar_run(struct swaybar *bar);
|
||||||
void bar_teardown(struct swaybar *bar);
|
void bar_teardown(struct swaybar *bar);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#define _SWAYBAR_IPC_H
|
#define _SWAYBAR_IPC_H
|
||||||
#include "swaybar/bar.h"
|
#include "swaybar/bar.h"
|
||||||
|
|
||||||
void ipc_get_config(struct swaybar *bar, const char *bar_id);
|
void ipc_initialize(struct swaybar *bar, const char *bar_id);
|
||||||
void handle_ipc_event(struct swaybar *bar);
|
void handle_ipc_event(struct swaybar *bar);
|
||||||
|
void ipc_get_workspaces(struct swaybar *bar);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,6 +72,7 @@ static void handle_global(void *data, struct wl_registry *registry,
|
||||||
output->output = wl_registry_bind(registry, name,
|
output->output = wl_registry_bind(registry, name,
|
||||||
&wl_output_interface, 1);
|
&wl_output_interface, 1);
|
||||||
output->index = index++;
|
output->index = index++;
|
||||||
|
wl_list_init(&output->workspaces);
|
||||||
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(
|
||||||
|
@ -96,7 +97,7 @@ void bar_setup(struct swaybar *bar,
|
||||||
|
|
||||||
bar->ipc_socketfd = ipc_open_socket(socket_path);
|
bar->ipc_socketfd = ipc_open_socket(socket_path);
|
||||||
bar->ipc_event_socketfd = ipc_open_socket(socket_path);
|
bar->ipc_event_socketfd = ipc_open_socket(socket_path);
|
||||||
ipc_get_config(bar, bar_id);
|
ipc_initialize(bar, bar_id);
|
||||||
|
|
||||||
assert(bar->display = wl_display_connect(NULL));
|
assert(bar->display = wl_display_connect(NULL));
|
||||||
|
|
||||||
|
@ -113,6 +114,7 @@ void bar_setup(struct swaybar *bar,
|
||||||
if (coutput->index != output->index) {
|
if (coutput->index != output->index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
output->name = strdup(coutput->name);
|
||||||
assert(output->surface = wl_compositor_create_surface(
|
assert(output->surface = wl_compositor_create_surface(
|
||||||
bar->compositor));
|
bar->compositor));
|
||||||
output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
|
@ -123,10 +125,13 @@ void bar_setup(struct swaybar *bar,
|
||||||
&layer_surface_listener, output);
|
&layer_surface_listener, output);
|
||||||
zwlr_layer_surface_v1_set_anchor(output->layer_surface,
|
zwlr_layer_surface_v1_set_anchor(output->layer_surface,
|
||||||
bar->config->position);
|
bar->config->position);
|
||||||
render_frame(bar, output);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ipc_get_workspaces(bar);
|
||||||
|
wl_list_for_each(output, &bar->outputs, link) {
|
||||||
|
render_frame(bar, output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_in(int fd, short mask, void *_bar) {
|
static void display_in(int fd, short mask, void *_bar) {
|
||||||
|
|
|
@ -187,6 +187,65 @@ static void ipc_parse_config(
|
||||||
json_object_put(bar_config);
|
json_object_put(bar_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_workspaces(struct wl_list *list) {
|
||||||
|
struct swaybar_workspace *ws, *tmp;
|
||||||
|
wl_list_for_each_safe(ws, tmp, list, link) {
|
||||||
|
wl_list_remove(&ws->link);
|
||||||
|
free(ws->name);
|
||||||
|
free(ws);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ipc_get_workspaces(struct swaybar *bar) {
|
||||||
|
struct swaybar_output *output;
|
||||||
|
wl_list_for_each(output, &bar->outputs, link) {
|
||||||
|
free_workspaces(&output->workspaces);
|
||||||
|
}
|
||||||
|
uint32_t len = 0;
|
||||||
|
char *res = ipc_single_command(bar->ipc_socketfd,
|
||||||
|
IPC_GET_WORKSPACES, NULL, &len);
|
||||||
|
json_object *results = json_tokener_parse(res);
|
||||||
|
if (!results) {
|
||||||
|
free(res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t length = json_object_array_length(results);
|
||||||
|
json_object *ws_json;
|
||||||
|
json_object *num, *name, *visible, *focused, *out, *urgent;
|
||||||
|
for (size_t i = 0; i < length; ++i) {
|
||||||
|
ws_json = json_object_array_get_idx(results, i);
|
||||||
|
|
||||||
|
json_object_object_get_ex(ws_json, "num", &num);
|
||||||
|
json_object_object_get_ex(ws_json, "name", &name);
|
||||||
|
json_object_object_get_ex(ws_json, "visible", &visible);
|
||||||
|
json_object_object_get_ex(ws_json, "focused", &focused);
|
||||||
|
json_object_object_get_ex(ws_json, "output", &out);
|
||||||
|
json_object_object_get_ex(ws_json, "urgent", &urgent);
|
||||||
|
|
||||||
|
wl_list_for_each(output, &bar->outputs, link) {
|
||||||
|
const char *ws_output = json_object_get_string(out);
|
||||||
|
if (strcmp(ws_output, output->name) == 0) {
|
||||||
|
struct swaybar_workspace *ws =
|
||||||
|
calloc(1, sizeof(struct swaybar_workspace));
|
||||||
|
ws->num = json_object_get_int(num);
|
||||||
|
ws->name = strdup(json_object_get_string(name));
|
||||||
|
ws->visible = json_object_get_boolean(visible);
|
||||||
|
ws->focused = json_object_get_boolean(focused);
|
||||||
|
if (ws->focused) {
|
||||||
|
if (bar->focused_output) {
|
||||||
|
bar->focused_output->focused = false;
|
||||||
|
}
|
||||||
|
bar->focused_output = output;
|
||||||
|
output->focused = true;
|
||||||
|
}
|
||||||
|
ws->urgent = json_object_get_boolean(urgent);
|
||||||
|
wl_list_insert(&output->workspaces, &ws->link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(res);
|
||||||
|
}
|
||||||
|
|
||||||
static void ipc_get_outputs(struct swaybar *bar) {
|
static void ipc_get_outputs(struct swaybar *bar) {
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
char *res = ipc_single_command(bar->ipc_socketfd,
|
char *res = ipc_single_command(bar->ipc_socketfd,
|
||||||
|
@ -218,16 +277,18 @@ static void ipc_get_outputs(struct swaybar *bar) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
json_object_put(outputs);
|
||||||
free(res);
|
free(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipc_get_config(struct swaybar *bar, const char *bar_id) {
|
void ipc_initialize(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);
|
ipc_get_outputs(bar);
|
||||||
|
// TODO: subscribe to stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_ipc_event(struct swaybar *bar) {
|
void handle_ipc_event(struct swaybar *bar) {
|
||||||
|
|
Loading…
Reference in a new issue