summaryrefslogtreecommitdiffstats
path: root/swaylock
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-05-25 19:34:36 +0100
committerLibravatar emersion <contact@emersion.fr>2018-05-27 13:39:38 +0100
commitcc10c7af6528f6006e4fccbbdc2156b957cdd5c9 (patch)
tree5e1ebce0a9a71954679ade0676e3b7db01b018f2 /swaylock
parentMerge pull request #2049 from RyanDwyer/criteria-shell (diff)
downloadsway-cc10c7af6528f6006e4fccbbdc2156b957cdd5c9.tar.gz
sway-cc10c7af6528f6006e4fccbbdc2156b957cdd5c9.tar.zst
sway-cc10c7af6528f6006e4fccbbdc2156b957cdd5c9.zip
swaylock: implement a proper render loop
Diffstat (limited to 'swaylock')
-rw-r--r--swaylock/main.c56
-rw-r--r--swaylock/password.c102
-rw-r--r--swaylock/render.c4
3 files changed, 105 insertions, 57 deletions
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 = {
131 .closed = layer_surface_closed, 131 .closed = layer_surface_closed,
132}; 132};
133 133
134static void handle_wl_output_geometry(void *data, struct wl_output *output, int32_t x, 134static const struct wl_callback_listener surface_frame_listener;
135 int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, 135
136 const char *make, const char *model, int32_t transform) { 136static void surface_frame_handle_done(void *data, struct wl_callback *callback,
137 uint32_t time) {
138 struct swaylock_surface *surface = data;
139
140 wl_callback_destroy(callback);
141 surface->frame_pending = false;
142
143 if (surface->dirty) {
144 // Schedule a frame in case the surface is damaged again
145 struct wl_callback *callback = wl_surface_frame(surface->surface);
146 wl_callback_add_listener(callback, &surface_frame_listener, surface);
147 surface->frame_pending = true;
148
149 render_frame(surface);
150 surface->dirty = false;
151 }
152}
153
154static const struct wl_callback_listener surface_frame_listener = {
155 .done = surface_frame_handle_done,
156};
157
158void damage_surface(struct swaylock_surface *surface) {
159 surface->dirty = true;
160 if (surface->frame_pending) {
161 return;
162 }
163
164 struct wl_callback *callback = wl_surface_frame(surface->surface);
165 wl_callback_add_listener(callback, &surface_frame_listener, surface);
166 surface->frame_pending = true;
167 wl_surface_commit(surface->surface);
168}
169
170void damage_state(struct swaylock_state *state) {
171 struct swaylock_surface *surface;
172 wl_list_for_each(surface, &state->surfaces, link) {
173 damage_surface(surface);
174 }
175}
176
177static void handle_wl_output_geometry(void *data, struct wl_output *output,
178 int32_t x, int32_t y, int32_t width_mm, int32_t height_mm,
179 int32_t subpixel, const char *make, const char *model,
180 int32_t transform) {
137 // Who cares 181 // Who cares
138} 182}
139 183
140static void handle_wl_output_mode(void *data, struct wl_output *output, uint32_t flags, 184static void handle_wl_output_mode(void *data, struct wl_output *output,
141 int32_t width, int32_t height, int32_t refresh) { 185 uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
142 // Who cares 186 // Who cares
143} 187}
144 188
@@ -151,7 +195,7 @@ static void handle_wl_output_scale(void *data, struct wl_output *output,
151 struct swaylock_surface *surface = data; 195 struct swaylock_surface *surface = data;
152 surface->scale = factor; 196 surface->scale = factor;
153 if (surface->state->run_display) { 197 if (surface->state->run_display) {
154 render_frames(surface->state); 198 damage_surface(surface);
155 } 199 }
156} 200}
157 201
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) {
93void swaylock_handle_key(struct swaylock_state *state, 93void swaylock_handle_key(struct swaylock_state *state,
94 xkb_keysym_t keysym, uint32_t codepoint) { 94 xkb_keysym_t keysym, uint32_t codepoint) {
95 switch (keysym) { 95 switch (keysym) {
96 case XKB_KEY_KP_Enter: /* fallthrough */ 96 case XKB_KEY_KP_Enter: /* fallthrough */
97 case XKB_KEY_Return: 97 case XKB_KEY_Return:
98 state->auth_state = AUTH_STATE_VALIDATING; 98 state->auth_state = AUTH_STATE_VALIDATING;
99 render_frames(state); 99 damage_state(state);
100 wl_display_roundtrip(state->display); 100 wl_display_roundtrip(state->display);
101 if (attempt_password(&state->password)) { 101 if (attempt_password(&state->password)) {
102 state->run_display = false; 102 state->run_display = false;
103 break;
104 }
105 state->auth_state = AUTH_STATE_INVALID;
106 render_frames(state);
107 break; 103 break;
108 case XKB_KEY_Delete: 104 }
109 case XKB_KEY_BackSpace: 105 state->auth_state = AUTH_STATE_INVALID;
110 if (backspace(&state->password)) { 106 damage_state(state);
111 state->auth_state = AUTH_STATE_BACKSPACE; 107 break;
112 } else { 108 case XKB_KEY_Delete:
113 state->auth_state = AUTH_STATE_CLEAR; 109 case XKB_KEY_BackSpace:
114 } 110 if (backspace(&state->password)) {
115 render_frames(state); 111 state->auth_state = AUTH_STATE_BACKSPACE;
116 break; 112 } else {
117 case XKB_KEY_Escape:
118 clear_password_buffer(&state->password);
119 state->auth_state = AUTH_STATE_CLEAR; 113 state->auth_state = AUTH_STATE_CLEAR;
120 render_frames(state); 114 }
121 break; 115 damage_state(state);
122 case XKB_KEY_Caps_Lock: 116 break;
123 /* The state is getting active after this 117 case XKB_KEY_Escape:
124 * so we need to manually toggle it */ 118 clear_password_buffer(&state->password);
125 state->xkb.caps_lock = !state->xkb.caps_lock; 119 state->auth_state = AUTH_STATE_CLEAR;
126 state->auth_state = AUTH_STATE_INPUT_NOP; 120 damage_state(state);
127 render_frames(state); 121 break;
128 break; 122 case XKB_KEY_Caps_Lock:
129 case XKB_KEY_Shift_L: 123 /* The state is getting active after this
130 case XKB_KEY_Shift_R: 124 * so we need to manually toggle it */
131 case XKB_KEY_Control_L: 125 state->xkb.caps_lock = !state->xkb.caps_lock;
132 case XKB_KEY_Control_R: 126 state->auth_state = AUTH_STATE_INPUT_NOP;
133 case XKB_KEY_Meta_L: 127 damage_state(state);
134 case XKB_KEY_Meta_R: 128 break;
135 case XKB_KEY_Alt_L: 129 case XKB_KEY_Shift_L:
136 case XKB_KEY_Alt_R: 130 case XKB_KEY_Shift_R:
137 case XKB_KEY_Super_L: 131 case XKB_KEY_Control_L:
138 case XKB_KEY_Super_R: 132 case XKB_KEY_Control_R:
139 state->auth_state = AUTH_STATE_INPUT_NOP; 133 case XKB_KEY_Meta_L:
140 render_frames(state); 134 case XKB_KEY_Meta_R:
141 break; 135 case XKB_KEY_Alt_L:
142 default: 136 case XKB_KEY_Alt_R:
143 if (codepoint) { 137 case XKB_KEY_Super_L:
144 append_ch(&state->password, codepoint); 138 case XKB_KEY_Super_R:
145 state->auth_state = AUTH_STATE_INPUT; 139 state->auth_state = AUTH_STATE_INPUT_NOP;
146 render_frames(state); 140 damage_state(state);
147 } 141 break;
148 break; 142 default:
143 if (codepoint) {
144 append_ch(&state->password, codepoint);
145 state->auth_state = AUTH_STATE_INPUT;
146 damage_state(state);
147 }
148 break;
149 } 149 }
150} 150}
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) {
23 23
24 surface->current_buffer = get_next_buffer(state->shm, 24 surface->current_buffer = get_next_buffer(state->shm,
25 surface->buffers, buffer_width, buffer_height); 25 surface->buffers, buffer_width, buffer_height);
26 if (surface->current_buffer == NULL) {
27 return;
28 }
29
26 cairo_t *cairo = surface->current_buffer->cairo; 30 cairo_t *cairo = surface->current_buffer->cairo;
27 cairo_identity_matrix(cairo); 31 cairo_identity_matrix(cairo);
28 32