diff options
author | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2020-09-25 17:06:17 +0200 |
---|---|---|
committer | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2020-09-25 17:06:17 +0200 |
commit | af81637f64ba5112e9da0db79f9eadd1934308eb (patch) | |
tree | 48e66e54befb151706e003447b7cde201e9da465 | |
parent | b43d5820318bcbf5c515c282a70c20484818b7e0 (diff) | |
download | wlclock-af81637f64ba5112e9da0db79f9eadd1934308eb.tar.gz wlclock-af81637f64ba5112e9da0db79f9eadd1934308eb.tar.bz2 |
Make hour hand slowly progress instead of snapping
The snapping behaviour can be re-enabled via a command flag
-rw-r--r-- | doc/wlclock.1.scd | 6 | ||||
-rw-r--r-- | src/render.c | 29 | ||||
-rw-r--r-- | src/wlclock.c | 10 | ||||
-rw-r--r-- | src/wlclock.h | 2 |
4 files changed, 29 insertions, 18 deletions
diff --git a/doc/wlclock.1.scd b/doc/wlclock.1.scd index a6c5e42..cfd50f2 100644 --- a/doc/wlclock.1.scd +++ b/doc/wlclock.1.scd @@ -72,10 +72,14 @@ but a desktop-widget. surfaces differently based on their namespace. The default is "wlclock". *--no-input* - If this flag is provided, wlclock will ask the compositor to not send it + If this flag is used, wlclock will ask the compositor to not send it input events; This will make mouse events pass through wlclock to windows beneath it. +*--snap* + If this flag is used, the hour hand will instantly snap to the next position + once the new hour begins, instead of slowly progressing over the hour. + *--output* <output|all> Name of the output on which wlclock should be displayed. Output names are compositor dependant. If set to "all" or "\*", wlclock will be displayed diff --git a/src/render.c b/src/render.c index 7d189ec..f88d913 100644 --- a/src/render.c +++ b/src/render.c @@ -142,28 +142,21 @@ static void draw_clock_face (cairo_t *cairo, struct Wlclock_dimensions *dimensio cairo_restore(cairo); } -static int hour_two_pseudo_min (int hour) -{ - if ( hour > 12 ) - hour -= 12; - return hour * 5; -} - static void draw_clock_hands (cairo_t *cairo, int32_t size, int32_t scale, struct Wlclock *clock) { double cxy = scale * size / 2; double mr = scale * 0.6 * size / 2; /* Radii mimick xclock. */ double hr = scale * 0.4 * size / 2; double ir = scale * 0.075 * size / 2; - double tip_phi, back_phi_1, back_phi_2, phi_step = 2 * PI / 60; + double tip_phi, back_phi_1, back_phi_2, phi_step_min = 2 * PI / 60, phi_step_h = 2 * PI / 12; struct tm tm = *localtime(&clock->now); cairo_save(cairo); /* Minutes */ - tip_phi = phi_step * (tm.tm_min + 45); - back_phi_1 = phi_step * (tm.tm_min + 45 + 20); - back_phi_2 = phi_step * (tm.tm_min + 45 + 40); + tip_phi = phi_step_min * (tm.tm_min + 45); + back_phi_1 = phi_step_min * (tm.tm_min + 45 + 20); + back_phi_2 = phi_step_min * (tm.tm_min + 45 + 40); cairo_move_to(cairo, cxy + mr * cos(tip_phi), cxy + mr * sin(tip_phi)); cairo_line_to(cairo, cxy + ir * cos(back_phi_1), cxy + ir * sin(back_phi_1)); cairo_line_to(cairo, cxy + ir * cos(back_phi_2), cxy + ir * sin(back_phi_2)); @@ -171,10 +164,16 @@ static void draw_clock_hands (cairo_t *cairo, int32_t size, int32_t scale, struc /* Hours */ // TODO optinally make hour hand progress between to hours intstead of instantly snapping - int pseudo_min = hour_two_pseudo_min(tm.tm_hour); - tip_phi = phi_step * (pseudo_min + 45); - back_phi_1 = phi_step * (pseudo_min + 45 + 20); - back_phi_2 = phi_step * (pseudo_min + 45 + 40); + tip_phi = phi_step_h * (tm.tm_hour + 9); + back_phi_1 = phi_step_h * (tm.tm_hour + 9 + 4); + back_phi_2 = phi_step_h * (tm.tm_hour + 9 + 8); + if (! clock->snap) + { + double prog_phi_step = phi_step_h / 60.0; + tip_phi += tm.tm_min * prog_phi_step; + back_phi_1 += tm.tm_min * prog_phi_step; + back_phi_2 += tm.tm_min * prog_phi_step; + } cairo_move_to(cairo, cxy + hr * cos(tip_phi), cxy + hr * sin(tip_phi)); cairo_line_to(cairo, cxy + ir * cos(back_phi_1), cxy + ir * sin(back_phi_1)); cairo_line_to(cairo, cxy + ir * cos(back_phi_2), cxy + ir * sin(back_phi_2)); diff --git a/src/wlclock.c b/src/wlclock.c index e77b866..80b7011 100644 --- a/src/wlclock.c +++ b/src/wlclock.c @@ -188,6 +188,7 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[]) MARGIN, NAMEPSACE, NO_INPUT, + SNAP, OUTPUT, CORNER_RADIUS, SIZE @@ -209,6 +210,7 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[]) {"margin", required_argument, NULL, MARGIN}, {"namespace", required_argument, NULL, NAMEPSACE}, {"no-input", no_argument, NULL, NO_INPUT}, + {"snap", no_argument, NULL, SNAP}, {"output", required_argument, NULL, OUTPUT}, {"corner-radius", required_argument, NULL, CORNER_RADIUS}, {"size", required_argument, NULL, SIZE} @@ -230,7 +232,8 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[]) " --layer Layer of the layer surface.\n" " --margin Directional margins.\n" " --namespace Namespace of the layer surface.\n" - " --no-input Make inputs surface pass trough the layer surface.\n" + " --no-input Let inputs surface pass trough the layer surface.\n" + " --snap Let the hour hand snap to the next position instead of slowly progressing.\n" " --output The output which the clock will be displayed.\n" " --corner-radius Corner radii.\n" " --size Size of the clock.\n" @@ -395,6 +398,10 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[]) clock->input = false; break; + case SNAP: + clock->snap = true; + break; + case OUTPUT: if ( ! strcmp("all", optarg) || ! strcmp("*", optarg) ) free_if_set(clock->output); @@ -572,6 +579,7 @@ int main (int argc, char *argv[]) clock.dimensions.center_size = 165; /* About the size of xclock, at least on my machine. */ clock.exclusive_zone = -1; clock.input = true; + clock.snap = false; clock.layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY; clock.anchor = 0; /* Center */ set_string(&clock.namespace, "wlclock"); diff --git a/src/wlclock.h b/src/wlclock.h index d76bd86..98fa711 100644 --- a/src/wlclock.h +++ b/src/wlclock.h @@ -49,7 +49,7 @@ struct Wlclock int32_t margin_top, margin_right, margin_bottom, margin_left; int32_t radius_top_left, radius_top_right, radius_bottom_left, radius_bottom_right; int32_t anchor; - bool input; + bool input, snap; struct Wlclock_colour background_colour; struct Wlclock_colour border_colour; |