Address review feedback from @emersion

This commit is contained in:
Drew DeVault 2018-04-04 18:52:44 -04:00
parent 053b51c3ff
commit 5d444b34f6
3 changed files with 31 additions and 25 deletions

View file

@ -216,7 +216,8 @@ int main(int argc, char **argv) {
wl_list_init(&state.surfaces);
state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
assert(state.display = wl_display_connect(NULL));
state.display = wl_display_connect(NULL);
assert(state.display);
struct wl_registry *registry = wl_display_get_registry(state.display);
wl_registry_add_listener(registry, &registry_listener, &state);
@ -236,8 +237,8 @@ int main(int argc, char **argv) {
wl_list_for_each(surface, &state.surfaces, link) {
surface->image = background_image;
assert(surface->surface =
wl_compositor_create_surface(state.compositor));
surface->surface = wl_compositor_create_surface(state.compositor);
assert(surface->surface);
surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
state.layer_shell, surface->surface, surface->output,

View file

@ -103,7 +103,8 @@ void swaylock_handle_key(struct swaylock_state *state,
render_frames(state);
wl_display_roundtrip(state->display);
if (attempt_password(&state->password)) {
exit(0);
state->run_display = false;
break;
}
state->auth_state = AUTH_STATE_INVALID;
render_frames(state);

View file

@ -7,18 +7,22 @@
#include "swaylock/swaylock.h"
#define M_PI 3.14159265358979323846
const int ARC_RADIUS = 50;
const int ARC_THICKNESS = 10;
const float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f;
void render_frame(struct swaylock_surface *surface) {
struct swaylock_state *state = surface->state;
surface->current_buffer = get_next_buffer(state->shm,
surface->buffers,
surface->width * surface->scale,
surface->height * surface->scale);
cairo_t *cairo = surface->current_buffer->cairo;
cairo_identity_matrix(cairo);
int buffer_width = surface->width * surface->scale;
int buffer_height = surface->height * surface->scale;
surface->current_buffer = get_next_buffer(state->shm,
surface->buffers, buffer_width, buffer_height);
cairo_t *cairo = surface->current_buffer->cairo;
cairo_identity_matrix(cairo);
if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR) {
cairo_set_source_u32(cairo, state->args.color);
cairo_paint(cairo);
@ -28,15 +32,15 @@ void render_frame(struct swaylock_surface *surface) {
}
cairo_identity_matrix(cairo);
int ARC_RADIUS = 50 * surface->scale;
int ARC_THICKNESS = 10 * surface->scale;
float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f * surface->scale;
int arc_radius = ARC_RADIUS * surface->scale;
int arc_thickness = ARC_THICKNESS * surface->scale;
float type_indicator_border_thickness =
TYPE_INDICATOR_BORDER_THICKNESS * surface->scale;
if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) {
// Draw circle
cairo_set_line_width(cairo, ARC_THICKNESS);
cairo_arc(cairo, buffer_width / 2, buffer_height / 2, ARC_RADIUS, 0, 2 * M_PI);
cairo_set_line_width(cairo, arc_thickness);
cairo_arc(cairo, buffer_width / 2, buffer_height / 2, arc_radius, 0, 2 * M_PI);
switch (state->auth_state) {
case AUTH_STATE_INPUT:
case AUTH_STATE_BACKSPACE: {
@ -65,7 +69,7 @@ void render_frame(struct swaylock_surface *surface) {
cairo_set_source_rgb(cairo, 0, 0, 0);
cairo_select_font_face(cairo, "sans-serif",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cairo, ARC_RADIUS / 3.0f);
cairo_set_font_size(cairo, arc_radius / 3.0f);
switch (state->auth_state) {
case AUTH_STATE_VALIDATING:
text = "verifying";
@ -98,7 +102,7 @@ void render_frame(struct swaylock_surface *surface) {
highlight_start +=
(rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5;
cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
ARC_RADIUS, highlight_start,
arc_radius, highlight_start,
highlight_start + TYPE_INDICATOR_RANGE);
if (state->auth_state == AUTH_STATE_INPUT) {
cairo_set_source_rgb(cairo, 51.0 / 255, 219.0 / 255, 0);
@ -110,14 +114,14 @@ void render_frame(struct swaylock_surface *surface) {
// Draw borders
cairo_set_source_rgb(cairo, 0, 0, 0);
cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
ARC_RADIUS, highlight_start,
highlight_start + TYPE_INDICATOR_BORDER_THICKNESS);
arc_radius, highlight_start,
highlight_start + type_indicator_border_thickness);
cairo_stroke(cairo);
cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE,
arc_radius, highlight_start + TYPE_INDICATOR_RANGE,
highlight_start + TYPE_INDICATOR_RANGE +
TYPE_INDICATOR_BORDER_THICKNESS);
type_indicator_border_thickness);
cairo_stroke(cairo);
}
@ -125,16 +129,16 @@ void render_frame(struct swaylock_surface *surface) {
cairo_set_source_rgb(cairo, 0, 0, 0);
cairo_set_line_width(cairo, 2.0 * surface->scale);
cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
ARC_RADIUS - ARC_THICKNESS / 2, 0, 2 * M_PI);
arc_radius - arc_thickness / 2, 0, 2 * M_PI);
cairo_stroke(cairo);
cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
ARC_RADIUS + ARC_THICKNESS / 2, 0, 2 * M_PI);
arc_radius + arc_thickness / 2, 0, 2 * M_PI);
cairo_stroke(cairo);
}
wl_surface_set_buffer_scale(surface->surface, surface->scale);
wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0);
wl_surface_damage(surface->surface, 0, 0, buffer_width, buffer_height);
wl_surface_damage(surface->surface, 0, 0, surface->width, surface->height);
wl_surface_commit(surface->surface);
}