Skip to content

Commit

Permalink
changed indent from tabs to spaces, reverted readme
Browse files Browse the repository at this point in the history
  • Loading branch information
LordCMonkey committed Sep 21, 2020
1 parent fabae09 commit 765b578
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 74 deletions.
15 changes: 7 additions & 8 deletions include/swaylock.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct swaylock_args {
int effects_count;
bool indicator;
bool gif;
bool clock;
bool clock;
char *timestr;
char *datestr;
uint32_t fade_in;
Expand All @@ -88,12 +88,11 @@ struct swaylock_password {
};

struct swaylock_gif {
GdkPixbufAnimation *pixbuf_animation;
GTimeVal *time;
GdkPixbufAnimationIter *iter;
int delay, height, width;
GdkPixbuf *pixbuf;
struct wl_list link;
GdkPixbufAnimation *pixbuf_animation;
GTimeVal *time;
GdkPixbufAnimationIter *iter;
int delay, height, width;
GdkPixbuf *pixbuf;
};

struct swaylock_state {
Expand All @@ -109,7 +108,7 @@ struct swaylock_state {
struct wl_shm *shm;
struct wl_list surfaces;
struct wl_list images;
struct swaylock_gif gif;
struct swaylock_gif gif;
struct swaylock_args args;
struct swaylock_password password;
struct swaylock_xkb xkb;
Expand Down
79 changes: 39 additions & 40 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,34 +715,33 @@ static bool file_exists(const char *path) {
}

static void load_gif(char *arg, struct swaylock_state *state){

state->gif.pixbuf_animation = gdk_pixbuf_animation_new_from_file (arg, NULL);
if (state->gif.pixbuf_animation != NULL){
state->args.gif = true;
swaylock_log(LOG_DEBUG, "Loading gif at %s", arg);

// fake start time to manipulate gif playback, every keystroke
// the time gets increased by duration of one gif frame

struct _GTimeVal *fakeTime = calloc(1, sizeof(struct _GTimeVal));
fakeTime->tv_sec = 0;
fakeTime->tv_usec = 0;

state->gif.time = fakeTime;

state->gif.iter = gdk_pixbuf_animation_get_iter (state->gif.pixbuf_animation, state->gif.time);


state->gif.delay = gdk_pixbuf_animation_iter_get_delay_time(state->gif.iter) * 1000;

state->gif.pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(state->gif.iter);

state->gif.height = gdk_pixbuf_get_height(state->gif.pixbuf);
state->gif.width = gdk_pixbuf_get_width(state->gif.pixbuf);

} else {
fprintf(stderr, "ERROR: Animation could not be opened / no loader for the file format exists / not enough memory to allocate image buffer / image contains invalid data\n");
}
state->gif.pixbuf_animation = gdk_pixbuf_animation_new_from_file (arg, NULL);
if (state->gif.pixbuf_animation != NULL){
state->args.gif = true;
swaylock_log(LOG_DEBUG, "Loading gif at %s", arg);

// fake start time to manipulate gif playback, every keystroke
// the time gets increased by duration of one gif frame

struct _GTimeVal *fakeTime = calloc(1, sizeof(struct _GTimeVal));
fakeTime->tv_sec = 0;
fakeTime->tv_usec = 0;

state->gif.time = fakeTime;

state->gif.iter = gdk_pixbuf_animation_get_iter (state->gif.pixbuf_animation, state->gif.time);


state->gif.delay = gdk_pixbuf_animation_iter_get_delay_time(state->gif.iter) * 1000;

state->gif.pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(state->gif.iter);

state->gif.height = gdk_pixbuf_get_height(state->gif.pixbuf);
state->gif.width = gdk_pixbuf_get_width(state->gif.pixbuf);

} else {
fprintf(stderr, "ERROR: Animation could not be opened / no loader for the file format exists / not enough memory to allocate image buffer / image contains invalid data\n");
}
}

static void load_image(char *arg, struct swaylock_state *state) {
Expand Down Expand Up @@ -897,7 +896,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
LO_EFFECT_COMPOSE,
LO_EFFECT_CUSTOM,
LO_INDICATOR,
LO_GIF,
LO_GIF,
LO_CLOCK,
LO_TIMESTR,
LO_DATESTR,
Expand Down Expand Up @@ -971,7 +970,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
{"effect-compose", required_argument, NULL, LO_EFFECT_COMPOSE},
{"effect-custom", required_argument, NULL, LO_EFFECT_CUSTOM},
{"indicator", no_argument, NULL, LO_INDICATOR},
{"gif", required_argument, NULL, LO_GIF},
{"gif", required_argument, NULL, LO_GIF},
{"clock", no_argument, NULL, LO_CLOCK},
{"timestr", required_argument, NULL, LO_TIMESTR},
{"datestr", required_argument, NULL, LO_DATESTR},
Expand Down Expand Up @@ -1036,8 +1035,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
"The format string for the time. Defaults to '%T'.\n"
" --datestr <format> "
"The format string for the date. Defaults to '%a, %x'.\n"
" --gif <path> "
"Sets the gif to show, which advances by 1 frame every keystroke.\n"
" --gif <path> "
"Sets the gif to show, which advances by 1 frame every keystroke.\n"
" -v, --version "
"Show the version number and quit.\n"
" --bs-hl-color <color> "
Expand Down Expand Up @@ -1491,13 +1490,13 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
state->args.indicator = true;
}
break;
case LO_GIF:
if (state) {
load_gif(optarg, state);
//centers the gif on screen (if no indicator offset was set)
state->args.radius = state->gif.width/2; //pretty hacky, is obsolete if the gif is placed onto its own surface,
}
break;
case LO_GIF:
if (state) {
load_gif(optarg, state);
//centers the gif on screen (if no indicator offset was set)
state->args.radius = state->gif.width/2; //pretty hacky, is obsolete if the gif is placed onto its own surface,
}
break;
case LO_CLOCK:
if (state) {
state->args.clock = true;
Expand Down Expand Up @@ -1685,7 +1684,7 @@ int main(int argc, char **argv) {
.effects = NULL,
.effects_count = 0,
.indicator = false,
.gif = false,
.gif = false,
.clock = false,
.timestr = strdup("%T"),
.datestr = strdup("%a, %x"),
Expand Down
6 changes: 3 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ project(
meson_version: '>=0.48.0',
default_options: [
'c_std=c11',
'warning_level=1',
'warning_level=1',
],
)

add_project_arguments(
[
# '-Wno-deprecated-declarations',
#'-Wno-deprecated-declarations',
'-Wno-unused-parameter',
'-Wno-unused-result',
'-Wundef',
Expand Down Expand Up @@ -135,7 +135,7 @@ dependencies = [
dl,
xkbcommon,
wayland_client,
gtk
gtk
]

sources = [
Expand Down
49 changes: 26 additions & 23 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,31 +215,34 @@ void render_frame(struct swaylock_surface *surface) {
state->args.show_indicator && (state->auth_state != AUTH_STATE_IDLE ||
state->args.indicator_idle_visible);

if (state->args.gif){
if (state->auth_state == AUTH_STATE_INPUT){ //advance by 1 frame
state->gif.time->tv_usec += state->gif.delay;
}else if (state->auth_state == AUTH_STATE_BACKSPACE){ //reverse by 1 frame
state->gif.time->tv_usec -= state->gif.delay;
}else if (state->auth_state == AUTH_STATE_INVALID || state->auth_state == AUTH_STATE_CLEAR || state->auth_state == AUTH_STATE_IDLE){ //reset
state->gif.time->tv_usec = 0;
state->gif.time->tv_sec = 0;
}


if (state->gif.time->tv_usec > 1000000){
state->gif.time->tv_usec %= 1000000;
state->gif.time->tv_sec++;
}


gdk_pixbuf_animation_iter_advance(state->gif.iter, state->gif.time);
state->gif.pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(state->gif.iter);

if (state->args.gif){
switch(state->auth_state){
case AUTH_STATE_INPUT: //advance by 1 frame
state->gif.time->tv_usec += state->gif.delay;
break;
case AUTH_STATE_BACKSPACE: //reverse by 1 frame
state->gif.time->tv_usec -= state->gif.delay;
break;
case AUTH_STATE_INVALID:
case AUTH_STATE_CLEAR:
case AUTH_STATE_IDLE: //reset
state->gif.time->tv_usec = 0;
state->gif.time->tv_sec = 0;
break;
default:
break;
}
if (state->gif.time->tv_usec > 1000000){
state->gif.time->tv_usec %= 1000000;
state->gif.time->tv_sec++;
}

gdk_cairo_set_source_pixbuf(cairo, state->gif.pixbuf, 0, 0); //draws to top left corner of indicator surface
cairo_paint(cairo);
}
gdk_pixbuf_animation_iter_advance(state->gif.iter, state->gif.time);
state->gif.pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(state->gif.iter);

gdk_cairo_set_source_pixbuf(cairo, state->gif.pixbuf, 0, 0); //draws to top left corner of indicator surface
cairo_paint(cairo);
}

if (state->args.indicator ||
(upstream_show_indicator && state->auth_state != AUTH_STATE_GRACE)) {
Expand Down

0 comments on commit 765b578

Please sign in to comment.