From 484cc189e909e6b8df42e80386e0335d6d317a6e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 27 May 2018 14:14:46 +1000 Subject: Add shell criteria token Closes #2044. --- include/sway/criteria.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/sway/criteria.h b/include/sway/criteria.h index 74da132c..bd3ca0ac 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -18,6 +18,7 @@ struct criteria { char *target; // workspace or output name for `assign` criteria pcre *title; + pcre *shell; pcre *app_id; pcre *class; pcre *instance; -- cgit v1.2.3 From d3dd7e5bae374cb890f80836d872229a37ef639f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 27 May 2018 21:59:38 +1000 Subject: Rename view_get_type to view_get_shell --- include/sway/tree/view.h | 2 +- sway/criteria.c | 4 ++-- sway/tree/view.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 0fb8f1b3..a8bf4955 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -201,7 +201,7 @@ const char *view_get_window_role(struct sway_view *view); uint32_t view_get_window_type(struct sway_view *view); -const char *view_get_type(struct sway_view *view); +const char *view_get_shell(struct sway_view *view); void view_configure(struct sway_view *view, double ox, double oy, int width, int height); diff --git a/sway/criteria.c b/sway/criteria.c index 9317a180..dec5fed7 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -56,7 +56,7 @@ static bool criteria_matches_view(struct criteria *criteria, } if (criteria->shell) { - const char *shell = view_get_type(view); + const char *shell = view_get_shell(view); if (!shell || regex_cmp(shell, criteria->shell) != 0) { return false; } @@ -284,7 +284,7 @@ static char *get_focused_prop(enum criteria_token token) { value = view_get_instance(view); break; case T_SHELL: - value = view_get_type(view); + value = view_get_shell(view); break; case T_TITLE: value = view_get_class(view); diff --git a/sway/tree/view.c b/sway/tree/view.c index d72a2235..d91182ed 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -107,7 +107,7 @@ uint32_t view_get_window_type(struct sway_view *view) { return 0; } -const char *view_get_type(struct sway_view *view) { +const char *view_get_shell(struct sway_view *view) { switch(view->type) { case SWAY_VIEW_XDG_SHELL_V6: return "xdg_shell_v6"; @@ -657,7 +657,7 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) { const char *app_id = view_get_app_id(view); const char *class = view_get_class(view); const char *instance = view_get_instance(view); - const char *shell = view_get_type(view); + const char *shell = view_get_shell(view); size_t title_len = title ? strlen(title) : 0; size_t app_id_len = app_id ? strlen(app_id) : 0; size_t class_len = class ? strlen(class) : 0; -- cgit v1.2.3 From cc10c7af6528f6006e4fccbbdc2156b957cdd5c9 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 25 May 2018 19:34:36 +0100 Subject: swaylock: implement a proper render loop --- include/swaylock/swaylock.h | 3 ++ swaylock/main.c | 56 +++++++++++++++++++++--- swaylock/password.c | 102 ++++++++++++++++++++++---------------------- swaylock/render.c | 4 ++ 4 files changed, 108 insertions(+), 57 deletions(-) (limited to 'include') diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h index dae823b8..2931fd61 100644 --- a/include/swaylock/swaylock.h +++ b/include/swaylock/swaylock.h @@ -56,6 +56,7 @@ struct swaylock_surface { struct zwlr_layer_surface_v1 *layer_surface; struct pool_buffer buffers[2]; struct pool_buffer *current_buffer; + bool frame_pending, dirty; uint32_t width, height; int32_t scale; char *output_name; @@ -74,5 +75,7 @@ void swaylock_handle_key(struct swaylock_state *state, xkb_keysym_t keysym, uint32_t codepoint); void render_frame(struct swaylock_surface *surface); void render_frames(struct swaylock_state *state); +void damage_surface(struct swaylock_surface *surface); +void damage_state(struct swaylock_state *state); #endif diff --git a/swaylock/main.c b/swaylock/main.c index f89f2849..591df7b4 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -131,14 +131,58 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { .closed = layer_surface_closed, }; -static void handle_wl_output_geometry(void *data, struct wl_output *output, int32_t x, - int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, - const char *make, const char *model, int32_t transform) { +static const struct wl_callback_listener surface_frame_listener; + +static void surface_frame_handle_done(void *data, struct wl_callback *callback, + uint32_t time) { + struct swaylock_surface *surface = data; + + wl_callback_destroy(callback); + surface->frame_pending = false; + + if (surface->dirty) { + // Schedule a frame in case the surface is damaged again + struct wl_callback *callback = wl_surface_frame(surface->surface); + wl_callback_add_listener(callback, &surface_frame_listener, surface); + surface->frame_pending = true; + + render_frame(surface); + surface->dirty = false; + } +} + +static const struct wl_callback_listener surface_frame_listener = { + .done = surface_frame_handle_done, +}; + +void damage_surface(struct swaylock_surface *surface) { + surface->dirty = true; + if (surface->frame_pending) { + return; + } + + struct wl_callback *callback = wl_surface_frame(surface->surface); + wl_callback_add_listener(callback, &surface_frame_listener, surface); + surface->frame_pending = true; + wl_surface_commit(surface->surface); +} + +void damage_state(struct swaylock_state *state) { + struct swaylock_surface *surface; + wl_list_for_each(surface, &state->surfaces, link) { + damage_surface(surface); + } +} + +static void handle_wl_output_geometry(void *data, struct wl_output *output, + int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, + int32_t subpixel, const char *make, const char *model, + int32_t transform) { // Who cares } -static void handle_wl_output_mode(void *data, struct wl_output *output, uint32_t flags, - int32_t width, int32_t height, int32_t refresh) { +static void handle_wl_output_mode(void *data, struct wl_output *output, + uint32_t flags, int32_t width, int32_t height, int32_t refresh) { // Who cares } @@ -151,7 +195,7 @@ static void handle_wl_output_scale(void *data, struct wl_output *output, struct swaylock_surface *surface = data; surface->scale = factor; if (surface->state->run_display) { - render_frames(surface->state); + damage_surface(surface); } } diff --git a/swaylock/password.c b/swaylock/password.c index 1ad5cd81..6d493309 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -93,58 +93,58 @@ static void append_ch(struct swaylock_password *pw, uint32_t codepoint) { void swaylock_handle_key(struct swaylock_state *state, xkb_keysym_t keysym, uint32_t codepoint) { switch (keysym) { - case XKB_KEY_KP_Enter: /* fallthrough */ - case XKB_KEY_Return: - state->auth_state = AUTH_STATE_VALIDATING; - render_frames(state); - wl_display_roundtrip(state->display); - if (attempt_password(&state->password)) { - state->run_display = false; - break; - } - state->auth_state = AUTH_STATE_INVALID; - render_frames(state); + case XKB_KEY_KP_Enter: /* fallthrough */ + case XKB_KEY_Return: + state->auth_state = AUTH_STATE_VALIDATING; + damage_state(state); + wl_display_roundtrip(state->display); + if (attempt_password(&state->password)) { + state->run_display = false; break; - case XKB_KEY_Delete: - case XKB_KEY_BackSpace: - if (backspace(&state->password)) { - state->auth_state = AUTH_STATE_BACKSPACE; - } else { - state->auth_state = AUTH_STATE_CLEAR; - } - render_frames(state); - break; - case XKB_KEY_Escape: - clear_password_buffer(&state->password); + } + state->auth_state = AUTH_STATE_INVALID; + damage_state(state); + break; + case XKB_KEY_Delete: + case XKB_KEY_BackSpace: + if (backspace(&state->password)) { + state->auth_state = AUTH_STATE_BACKSPACE; + } else { state->auth_state = AUTH_STATE_CLEAR; - render_frames(state); - break; - case XKB_KEY_Caps_Lock: - /* The state is getting active after this - * so we need to manually toggle it */ - state->xkb.caps_lock = !state->xkb.caps_lock; - state->auth_state = AUTH_STATE_INPUT_NOP; - render_frames(state); - break; - case XKB_KEY_Shift_L: - case XKB_KEY_Shift_R: - case XKB_KEY_Control_L: - case XKB_KEY_Control_R: - case XKB_KEY_Meta_L: - case XKB_KEY_Meta_R: - case XKB_KEY_Alt_L: - case XKB_KEY_Alt_R: - case XKB_KEY_Super_L: - case XKB_KEY_Super_R: - state->auth_state = AUTH_STATE_INPUT_NOP; - render_frames(state); - break; - default: - if (codepoint) { - append_ch(&state->password, codepoint); - state->auth_state = AUTH_STATE_INPUT; - render_frames(state); - } - break; + } + damage_state(state); + break; + case XKB_KEY_Escape: + clear_password_buffer(&state->password); + state->auth_state = AUTH_STATE_CLEAR; + damage_state(state); + break; + case XKB_KEY_Caps_Lock: + /* The state is getting active after this + * so we need to manually toggle it */ + state->xkb.caps_lock = !state->xkb.caps_lock; + state->auth_state = AUTH_STATE_INPUT_NOP; + damage_state(state); + break; + case XKB_KEY_Shift_L: + case XKB_KEY_Shift_R: + case XKB_KEY_Control_L: + case XKB_KEY_Control_R: + case XKB_KEY_Meta_L: + case XKB_KEY_Meta_R: + case XKB_KEY_Alt_L: + case XKB_KEY_Alt_R: + case XKB_KEY_Super_L: + case XKB_KEY_Super_R: + state->auth_state = AUTH_STATE_INPUT_NOP; + damage_state(state); + break; + default: + if (codepoint) { + append_ch(&state->password, codepoint); + state->auth_state = AUTH_STATE_INPUT; + damage_state(state); + } + break; } } diff --git a/swaylock/render.c b/swaylock/render.c index 05236dea..2032ddcf 100644 --- a/swaylock/render.c +++ b/swaylock/render.c @@ -23,6 +23,10 @@ void render_frame(struct swaylock_surface *surface) { surface->current_buffer = get_next_buffer(state->shm, surface->buffers, buffer_width, buffer_height); + if (surface->current_buffer == NULL) { + return; + } + cairo_t *cairo = surface->current_buffer->cairo; cairo_identity_matrix(cairo); -- cgit v1.2.3 From 36d5d4b40f5caf0b7bcccbcc3bfeec3afb23946b Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 25 May 2018 19:42:23 +0100 Subject: client/pool-buffer: munmap in destroy_buffer --- client/pool-buffer.c | 7 ++++++- include/pool-buffer.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/client/pool-buffer.c b/client/pool-buffer.c index 7610d223..52438303 100644 --- a/client/pool-buffer.c +++ b/client/pool-buffer.c @@ -72,7 +72,7 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm, struct pool_buffer *buf, int32_t width, int32_t height, uint32_t format) { uint32_t stride = width * 4; - uint32_t size = stride * height; + size_t size = stride * height; char *name; int fd = create_pool_file(size, &name); @@ -87,8 +87,10 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm, free(name); fd = -1; + buf->size = size; buf->width = width; buf->height = height; + buf->data = data; buf->surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); buf->cairo = cairo_create(buf->surface); @@ -111,6 +113,9 @@ void destroy_buffer(struct pool_buffer *buffer) { if (buffer->pango) { g_object_unref(buffer->pango); } + if (buffer->data) { + munmap(buffer->data, buffer->size); + } memset(buffer, 0, sizeof(struct pool_buffer)); } diff --git a/include/pool-buffer.h b/include/pool-buffer.h index 856f7c8c..54f5be06 100644 --- a/include/pool-buffer.h +++ b/include/pool-buffer.h @@ -12,6 +12,8 @@ struct pool_buffer { cairo_t *cairo; PangoContext *pango; uint32_t width, height; + void *data; + size_t size; bool busy; }; -- cgit v1.2.3