mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
swaybar: synchronize rendering to output frames
This commit is contained in:
parent
4eb3fe4830
commit
02dfeea54c
|
@ -83,6 +83,8 @@ struct swaybar_output {
|
||||||
enum wl_output_subpixel subpixel;
|
enum wl_output_subpixel subpixel;
|
||||||
struct pool_buffer buffers[2];
|
struct pool_buffer buffers[2];
|
||||||
struct pool_buffer *current_buffer;
|
struct pool_buffer *current_buffer;
|
||||||
|
bool dirty;
|
||||||
|
bool frame_scheduled;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct swaybar_workspace {
|
struct swaybar_workspace {
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#ifndef _SWAYBAR_RENDER_H
|
#ifndef _SWAYBAR_RENDER_H
|
||||||
#define _SWAYBAR_RENDER_H
|
#define _SWAYBAR_RENDER_H
|
||||||
|
|
||||||
struct swaybar;
|
|
||||||
struct swaybar_output;
|
struct swaybar_output;
|
||||||
struct swaybar_config;
|
|
||||||
|
|
||||||
void render_frame(struct swaybar *bar, struct swaybar_output *output);
|
void render_frame(struct swaybar_output *output);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,6 +72,16 @@ static void swaybar_output_free(struct swaybar_output *output) {
|
||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_output_dirty(struct swaybar_output *output) {
|
||||||
|
if (output->frame_scheduled) {
|
||||||
|
output->dirty = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (output->surface) {
|
||||||
|
render_frame(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void layer_surface_configure(void *data,
|
static void layer_surface_configure(void *data,
|
||||||
struct zwlr_layer_surface_v1 *surface,
|
struct zwlr_layer_surface_v1 *surface,
|
||||||
uint32_t serial, uint32_t width, uint32_t height) {
|
uint32_t serial, uint32_t width, uint32_t height) {
|
||||||
|
@ -79,7 +89,7 @@ static void layer_surface_configure(void *data,
|
||||||
output->width = width;
|
output->width = width;
|
||||||
output->height = height;
|
output->height = height;
|
||||||
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
||||||
render_frame(output->bar, output);
|
set_output_dirty(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void layer_surface_closed(void *_output,
|
static void layer_surface_closed(void *_output,
|
||||||
|
@ -325,27 +335,22 @@ static void output_geometry(void *data, struct wl_output *wl_output, int32_t x,
|
||||||
const char *make, const char *model, int32_t transform) {
|
const char *make, const char *model, int32_t transform) {
|
||||||
struct swaybar_output *output = data;
|
struct swaybar_output *output = data;
|
||||||
output->subpixel = subpixel;
|
output->subpixel = subpixel;
|
||||||
if (output->surface) {
|
|
||||||
render_frame(output->bar, output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_mode(void *data, struct wl_output *output, uint32_t flags,
|
static void output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
|
||||||
int32_t width, int32_t height, int32_t refresh) {
|
int32_t width, int32_t height, int32_t refresh) {
|
||||||
// Who cares
|
// Who cares
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_done(void *data, struct wl_output *output) {
|
static void output_done(void *data, struct wl_output *wl_output) {
|
||||||
// Who cares
|
struct swaybar_output *output = data;
|
||||||
|
set_output_dirty(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_scale(void *data, struct wl_output *wl_output,
|
static void output_scale(void *data, struct wl_output *wl_output,
|
||||||
int32_t factor) {
|
int32_t factor) {
|
||||||
struct swaybar_output *output = data;
|
struct swaybar_output *output = data;
|
||||||
output->scale = factor;
|
output->scale = factor;
|
||||||
if (output->surface) {
|
|
||||||
render_frame(output->bar, output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wl_output_listener output_listener = {
|
struct wl_output_listener output_listener = {
|
||||||
|
@ -381,7 +386,7 @@ static void xdg_output_handle_done(void *data,
|
||||||
wl_list_insert(&bar->outputs, &output->link);
|
wl_list_insert(&bar->outputs, &output->link);
|
||||||
|
|
||||||
add_layer_surface(output);
|
add_layer_surface(output);
|
||||||
render_frame(bar, output);
|
set_output_dirty(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,12 +475,10 @@ static const struct wl_registry_listener registry_listener = {
|
||||||
.global_remove = handle_global_remove,
|
.global_remove = handle_global_remove,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void render_all_frames(struct swaybar *bar) {
|
static void set_bar_dirty(struct swaybar *bar) {
|
||||||
struct swaybar_output *output;
|
struct swaybar_output *output;
|
||||||
wl_list_for_each(output, &bar->outputs, link) {
|
wl_list_for_each(output, &bar->outputs, link) {
|
||||||
if (output->surface != NULL) {
|
set_output_dirty(output);
|
||||||
render_frame(bar, output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +531,7 @@ bool bar_setup(struct swaybar *bar,
|
||||||
assert(pointer->cursor_surface);
|
assert(pointer->cursor_surface);
|
||||||
|
|
||||||
ipc_get_workspaces(bar);
|
ipc_get_workspaces(bar);
|
||||||
render_all_frames(bar);
|
set_bar_dirty(bar);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,7 +546,7 @@ static void display_in(int fd, short mask, void *data) {
|
||||||
static void ipc_in(int fd, short mask, void *data) {
|
static void ipc_in(int fd, short mask, void *data) {
|
||||||
struct swaybar *bar = data;
|
struct swaybar *bar = data;
|
||||||
if (handle_ipc_readable(bar)) {
|
if (handle_ipc_readable(bar)) {
|
||||||
render_all_frames(bar);
|
set_bar_dirty(bar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,10 +554,10 @@ static void status_in(int fd, short mask, void *data) {
|
||||||
struct swaybar *bar = data;
|
struct swaybar *bar = data;
|
||||||
if (mask & (POLLHUP | POLLERR)) {
|
if (mask & (POLLHUP | POLLERR)) {
|
||||||
status_error(bar->status, "[error reading from status command]");
|
status_error(bar->status, "[error reading from status command]");
|
||||||
render_all_frames(bar);
|
set_bar_dirty(bar);
|
||||||
remove_event(fd);
|
remove_event(fd);
|
||||||
} else if (status_handle_readable(bar->status)) {
|
} else if (status_handle_readable(bar->status)) {
|
||||||
render_all_frames(bar);
|
set_bar_dirty(bar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -473,7 +473,22 @@ static uint32_t render_to_cairo(cairo_t *cairo, struct swaybar_output *output) {
|
||||||
return max_height > output->height ? max_height : output->height;
|
return max_height > output->height ? max_height : output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
static void output_frame_handle_done(void *data, struct wl_callback *callback,
|
||||||
|
uint32_t time) {
|
||||||
|
wl_callback_destroy(callback);
|
||||||
|
struct swaybar_output *output = data;
|
||||||
|
output->frame_scheduled = false;
|
||||||
|
if (output->dirty) {
|
||||||
|
render_frame(output);
|
||||||
|
output->dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_callback_listener output_frame_listener = {
|
||||||
|
.done = output_frame_handle_done
|
||||||
|
};
|
||||||
|
|
||||||
|
void render_frame(struct swaybar_output *output) {
|
||||||
assert(output->surface != NULL);
|
assert(output->surface != NULL);
|
||||||
|
|
||||||
struct swaybar_hotspot *hotspot, *tmp;
|
struct swaybar_hotspot *hotspot, *tmp;
|
||||||
|
@ -518,6 +533,8 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
||||||
output->width * output->scale,
|
output->width * output->scale,
|
||||||
output->height * output->scale);
|
output->height * output->scale);
|
||||||
if (!output->current_buffer) {
|
if (!output->current_buffer) {
|
||||||
|
cairo_surface_destroy(recorder);
|
||||||
|
cairo_destroy(cairo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cairo_t *shm = output->current_buffer->cairo;
|
cairo_t *shm = output->current_buffer->cairo;
|
||||||
|
@ -535,6 +552,11 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
||||||
output->current_buffer->buffer, 0, 0);
|
output->current_buffer->buffer, 0, 0);
|
||||||
wl_surface_damage(output->surface, 0, 0,
|
wl_surface_damage(output->surface, 0, 0,
|
||||||
output->width, output->height);
|
output->width, output->height);
|
||||||
|
|
||||||
|
struct wl_callback *frame_callback = wl_surface_frame(output->surface);
|
||||||
|
wl_callback_add_listener(frame_callback, &output_frame_listener, output);
|
||||||
|
output->frame_scheduled = true;
|
||||||
|
|
||||||
wl_surface_commit(output->surface);
|
wl_surface_commit(output->surface);
|
||||||
}
|
}
|
||||||
cairo_surface_destroy(recorder);
|
cairo_surface_destroy(recorder);
|
||||||
|
|
Loading…
Reference in a new issue