mirror of
https://github.com/swaywm/sway.git
synced 2024-12-27 07:26:55 +01:00
Handle output removal on swaybar
This commit is contained in:
parent
842a3ea45c
commit
f242362e7e
7 changed files with 45 additions and 9 deletions
|
@ -79,7 +79,7 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm,
|
|||
return buf;
|
||||
}
|
||||
|
||||
static void destroy_buffer(struct pool_buffer *buffer) {
|
||||
void destroy_buffer(struct pool_buffer *buffer) {
|
||||
if (buffer->buffer) {
|
||||
wl_buffer_destroy(buffer->buffer);
|
||||
}
|
||||
|
|
|
@ -17,5 +17,6 @@ struct pool_buffer {
|
|||
|
||||
struct pool_buffer *get_next_buffer(struct wl_shm *shm,
|
||||
struct pool_buffer pool[static 2], uint32_t width, uint32_t height);
|
||||
void destroy_buffer(struct pool_buffer *buffer);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -49,6 +49,7 @@ struct swaybar_output {
|
|||
struct wl_output *output;
|
||||
struct wl_surface *surface;
|
||||
struct zwlr_layer_surface_v1 *layer_surface;
|
||||
uint32_t wl_name;
|
||||
|
||||
struct wl_list workspaces;
|
||||
struct wl_list hotspots;
|
||||
|
|
|
@ -64,7 +64,9 @@ static void container_close_notify(struct sway_container *container) {
|
|||
return;
|
||||
}
|
||||
// TODO send ipc event type based on the container type
|
||||
ipc_event_window(container, "close");
|
||||
if (container->type == C_VIEW || container->type == C_WORKSPACE) {
|
||||
ipc_event_window(container, "close");
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_container *container_create(enum sway_container_type type) {
|
||||
|
|
|
@ -34,6 +34,34 @@ static void bar_init(struct swaybar *bar) {
|
|||
wl_list_init(&bar->outputs);
|
||||
}
|
||||
|
||||
static void swaybar_output_free(struct swaybar_output *output) {
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
wlr_log(L_DEBUG, "Removing output %s", output->name);
|
||||
zwlr_layer_surface_v1_destroy(output->layer_surface);
|
||||
wl_surface_destroy(output->surface);
|
||||
wl_output_destroy(output->output);
|
||||
destroy_buffer(&output->buffers[0]);
|
||||
destroy_buffer(&output->buffers[1]);
|
||||
struct swaybar_workspace *ws, *ws_tmp;
|
||||
wl_list_for_each_safe(ws, ws_tmp, &output->workspaces, link) {
|
||||
wl_list_remove(&ws->link);
|
||||
free(ws->name);
|
||||
free(ws);
|
||||
}
|
||||
struct swaybar_hotspot *hotspot, *hotspot_tmp;
|
||||
wl_list_for_each_safe(hotspot, hotspot_tmp, &output->hotspots, link) {
|
||||
if (hotspot->destroy) {
|
||||
hotspot->destroy(hotspot->data);
|
||||
}
|
||||
free(hotspot);
|
||||
}
|
||||
wl_list_remove(&output->link);
|
||||
free(output->name);
|
||||
free(output);
|
||||
}
|
||||
|
||||
static void layer_surface_configure(void *data,
|
||||
struct zwlr_layer_surface_v1 *surface,
|
||||
uint32_t serial, uint32_t width, uint32_t height) {
|
||||
|
@ -46,10 +74,8 @@ static void layer_surface_configure(void *data,
|
|||
|
||||
static void layer_surface_closed(void *_output,
|
||||
struct zwlr_layer_surface_v1 *surface) {
|
||||
// TODO: Deal with hotplugging
|
||||
struct swaybar_output *output = _output;
|
||||
zwlr_layer_surface_v1_destroy(output->layer_surface);
|
||||
wl_surface_destroy(output->surface);
|
||||
swaybar_output_free(output);
|
||||
}
|
||||
|
||||
struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
||||
|
@ -261,6 +287,7 @@ static void handle_global(void *data, struct wl_registry *registry,
|
|||
wl_output_add_listener(output->output, &output_listener, output);
|
||||
output->scale = 1;
|
||||
output->index = index++;
|
||||
output->wl_name = name;
|
||||
wl_list_init(&output->workspaces);
|
||||
wl_list_init(&output->hotspots);
|
||||
wl_list_insert(&bar->outputs, &output->link);
|
||||
|
@ -272,7 +299,14 @@ static void handle_global(void *data, struct wl_registry *registry,
|
|||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry,
|
||||
uint32_t name) {
|
||||
// who cares
|
||||
struct swaybar *bar = data;
|
||||
struct swaybar_output *output, *tmp;
|
||||
wl_list_for_each_safe(output, tmp, &bar->outputs, link) {
|
||||
if (output->wl_name == name) {
|
||||
swaybar_output_free(output);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
|
|
|
@ -367,5 +367,5 @@ bool handle_ipc_readable(struct swaybar *bar) {
|
|||
return false;
|
||||
}
|
||||
free_ipc_response(resp);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -421,8 +421,6 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
|||
static uint32_t render_to_cairo(cairo_t *cairo,
|
||||
struct swaybar *bar, struct swaybar_output *output) {
|
||||
struct swaybar_config *config = bar->config;
|
||||
wlr_log(L_DEBUG, "output %p", output);
|
||||
|
||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||
if (output->focused) {
|
||||
cairo_set_source_u32(cairo, config->colors.focused_background);
|
||||
|
|
Loading…
Reference in a new issue