aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Magahern <james@magahern.com>2019-01-19 16:49:09 -0800
committerJames Magahern <james@magahern.com>2019-01-19 16:49:09 -0800
commit0c214a8fbb2819be14b4e305f1cef3e43b1a2be8 (patch)
treee462c5edb9b905078e42094aa6fe64552e4d28b1
parentSwitch to using gresources for svgs (diff)
Start working on accept anim
-rw-r--r--meson.build3
-rw-r--r--src/main.c53
-rw-r--r--src/render.c9
-rw-r--r--src/render.h2
4 files changed, 48 insertions, 19 deletions
diff --git a/meson.build b/meson.build
index 52804bb..3b5a780 100644
--- a/meson.build
+++ b/meson.build
@@ -27,5 +27,6 @@ resources = gnome.compile_resources(
executable('buzzlocker',
sources: sources + resources,
dependencies: dependencies,
+ c_std: 'c11',
install: true
-)
+) \ No newline at end of file
diff --git a/src/main.c b/src/main.c
index 6729a7f..ffbc098 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,7 +15,13 @@
static const size_t kMaxPasswordLength = 128;
-void window_changed_size(saver_state_t *state, XConfigureEvent *event)
+static void accept_password(saver_state_t *state);
+
+/*
+ * Event handling
+ */
+
+static void window_changed_size(saver_state_t *state, XConfigureEvent *event)
{
state->canvas_width = event->width;
state->canvas_height = event->height;
@@ -23,7 +29,7 @@ void window_changed_size(saver_state_t *state, XConfigureEvent *event)
cairo_xlib_surface_set_size(state->surface, event->width, event->height);
}
-void handle_key_event(saver_state_t *state, XKeyEvent *event)
+static void handle_key_event(saver_state_t *state, XKeyEvent *event)
{
KeySym key;
char keybuf[8];
@@ -36,6 +42,8 @@ void handle_key_event(saver_state_t *state, XKeyEvent *event)
if (length > 0) {
password_buf[length - 1] = '\0';
}
+ } else if (XK_Return == key) {
+ accept_password(state);
} else if (strlen(keybuf) > 0) {
size_t add_len = strlen(keybuf);
if ( (length + add_len) < state->password_buffer_len - 1 ) {
@@ -44,7 +52,7 @@ void handle_key_event(saver_state_t *state, XKeyEvent *event)
}
}
-int poll_events(saver_state_t *state)
+static int poll_events(saver_state_t *state)
{
XEvent e;
const bool block_for_next_event = false;
@@ -77,29 +85,41 @@ int poll_events(saver_state_t *state)
}
/*
+ * Actions
+ */
+
+static void accept_password(saver_state_t *state)
+{
+ state->cursor_animating = false;
+}
+
+/*
* Main drawing/update routines
*/
-void update(saver_state_t *state)
+static void update(saver_state_t *state)
{
- const double cursor_fade_speed = 0.007;
- if (state->cursor_fade_direction > 0) {
- state->cursor_opacity += cursor_fade_speed;
- if (state->cursor_opacity > 1.0) {
- state->cursor_fade_direction *= -1;
+ if (state->cursor_animating) {
+ const double cursor_fade_speed = 0.007;
+ if (state->cursor_fade_direction > 0) {
+ state->cursor_opacity += cursor_fade_speed;
+ if (state->cursor_opacity > 1.0) {
+ state->cursor_fade_direction *= -1;
+ }
+ } else {
+ state->cursor_opacity -= cursor_fade_speed;
+ if (state->cursor_opacity <= 0.0) {
+ state->cursor_fade_direction *= -1;
+ }
}
} else {
- state->cursor_opacity -= cursor_fade_speed;
- if (state->cursor_opacity <= 0.0) {
- state->cursor_fade_direction *= -1;
- }
+ state->cursor_opacity = 1.0;
}
-
poll_events(state);
}
-void draw(saver_state_t *state)
+static void draw(saver_state_t *state)
{
// Draw background
cairo_t *cr = state->ctx;
@@ -110,7 +130,7 @@ void draw(saver_state_t *state)
draw_password_field(state);
}
-int runloop(cairo_surface_t *surface)
+static int runloop(cairo_surface_t *surface)
{
cairo_t *cr = cairo_create(surface);
@@ -127,6 +147,7 @@ int runloop(cairo_surface_t *surface)
state.status_font = status_font;
state.password_buffer = calloc(1, kMaxPasswordLength);
state.password_buffer_len = kMaxPasswordLength;
+ state.cursor_animating = true;
// Main run loop
struct timespec sleep_time = { 0, 5000000 };
diff --git a/src/render.c b/src/render.c
index 1439b08..214af8b 100644
--- a/src/render.c
+++ b/src/render.c
@@ -42,7 +42,6 @@ void draw_logo(saver_state_t *state)
g_bytes_unref(bytes);
if (error != NULL) {
fprintf(stderr, "Error loading logo SVG\n");
-
return;
}
}
@@ -132,7 +131,13 @@ void draw_password_field(saver_state_t *state)
// Draw cursor
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, state->cursor_opacity);
- cairo_rectangle(cr, field_x + cursor_offset_x, field_y, cursor_width, cursor_height);
+ if (state->cursor_animating) {
+ cairo_rectangle(cr, field_x + cursor_offset_x, field_y, cursor_width, cursor_height);
+ } else {
+ // Fill asterisks
+ cairo_rectangle(cr, field_x, field_y, cursor_offset_x, cursor_height);
+ }
cairo_fill(cr);
+
}
diff --git a/src/render.h b/src/render.h
index 6d2c095..5d387e6 100644
--- a/src/render.h
+++ b/src/render.h
@@ -10,6 +10,7 @@
#include <cairo-xlib.h>
#include <librsvg/rsvg.h>
#include <pango/pangocairo.h>
+#include <stdbool.h>
typedef struct {
cairo_t *ctx;
@@ -24,6 +25,7 @@ typedef struct {
int canvas_width;
int canvas_height;
+ bool cursor_animating;
double cursor_opacity;
double cursor_fade_direction;