summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/render.c71
-rw-r--r--src/wlclock.c26
-rw-r--r--src/wlclock.h7
3 files changed, 73 insertions, 31 deletions
diff --git a/src/render.c b/src/render.c
index f88d913..25fada5 100644
--- a/src/render.c
+++ b/src/render.c
@@ -148,40 +148,57 @@ static void draw_clock_hands (cairo_t *cairo, int32_t size, int32_t scale, struc
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_min = 2 * PI / 60, phi_step_h = 2 * PI / 12;
struct tm tm = *localtime(&clock->now);
-
- cairo_save(cairo);
-
- /* Minutes */
- 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));
- cairo_line_to(cairo, cxy + mr * cos(tip_phi), cxy + mr * sin(tip_phi));
-
- /* Hours */
- // TODO optinally make hour hand progress between to hours intstead of instantly snapping
- 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);
+
+ double phi_step_min = 2 * PI / 60;
+ double tip_phi_min = phi_step_min * (tm.tm_min + 45);
+ double back_phi_1_min = phi_step_min * (tm.tm_min + 45 + 20);
+ double back_phi_2_min = phi_step_min * (tm.tm_min + 45 + 40);
+
+ double phi_step_h = 2 * PI / 12;
+ double tip_phi_h = phi_step_h * (tm.tm_hour + 9);
+ double back_phi_1_h = phi_step_h * (tm.tm_hour + 9 + 4);
+ double back_phi_2_h = 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;
+ tip_phi_h += tm.tm_min * prog_phi_step;
+ back_phi_1_h += tm.tm_min * prog_phi_step;
+ back_phi_2_h += 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));
- cairo_line_to(cairo, cxy + hr * cos(tip_phi), cxy + hr * sin(tip_phi));
- cairo_close_path(cairo);
+ cairo_save(cairo);
colour_set_cairo_source(cairo, &clock->clock_colour);
- cairo_fill(cairo);
+
+ if ( clock->hand_style == STYLE_XCLOCK )
+ {
+ /* Minutes */
+ cairo_move_to(cairo, cxy + mr * cos(tip_phi_min), cxy + mr * sin(tip_phi_min));
+ cairo_line_to(cairo, cxy + ir * cos(back_phi_1_min), cxy + ir * sin(back_phi_1_min));
+ cairo_line_to(cairo, cxy + ir * cos(back_phi_2_min), cxy + ir * sin(back_phi_2_min));
+ cairo_line_to(cairo, cxy + mr * cos(tip_phi_min), cxy + mr * sin(tip_phi_min));
+
+ /* Hours */
+ cairo_move_to(cairo, cxy + hr * cos(tip_phi_h), cxy + hr * sin(tip_phi_h));
+ cairo_line_to(cairo, cxy + ir * cos(back_phi_1_h), cxy + ir * sin(back_phi_1_h));
+ cairo_line_to(cairo, cxy + ir * cos(back_phi_2_h), cxy + ir * sin(back_phi_2_h));
+ cairo_line_to(cairo, cxy + hr * cos(tip_phi_h), cxy + hr * sin(tip_phi_h));
+
+ cairo_close_path(cairo);
+ cairo_fill(cairo);
+ }
+ else if ( clock->hand_style == STYLE_LINES )
+ {
+ /* Minutes */
+ cairo_move_to(cairo, cxy + mr * cos(tip_phi_min), cxy + mr * sin(tip_phi_min));
+ cairo_line_to(cairo, cxy, cxy);
+
+ /* Hours */
+ cairo_line_to(cairo, cxy + hr * cos(tip_phi_h), cxy + hr * sin(tip_phi_h));
+
+ cairo_set_line_width(cairo, scale * clock->clock_size);
+ cairo_stroke(cairo);
+ }
cairo_restore(cairo);
}
diff --git a/src/wlclock.c b/src/wlclock.c
index 80b7011..c3ad2a4 100644
--- a/src/wlclock.c
+++ b/src/wlclock.c
@@ -191,7 +191,8 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
SNAP,
OUTPUT,
CORNER_RADIUS,
- SIZE
+ SIZE,
+ HAND_STYLE
};
static struct option opts[] = {
@@ -213,7 +214,8 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
{"snap", no_argument, NULL, SNAP},
{"output", required_argument, NULL, OUTPUT},
{"corner-radius", required_argument, NULL, CORNER_RADIUS},
- {"size", required_argument, NULL, SIZE}
+ {"size", required_argument, NULL, SIZE},
+ {"hand-style", required_argument, NULL, HAND_STYLE}
};
const char *usage =
@@ -228,15 +230,16 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
" --border-size Size of the border.\n"
" --clock-colour Colour of the clock elements.\n"
" --clock-face-size Size of clock face lines.\n"
+ " --corner-radius Corner radii.\n"
" --exclusive-zone Exclusive zone of the layer surface.\n"
+ " --hand-style Style of the clock hands.\n"
" --layer Layer of the layer surface.\n"
" --margin Directional margins.\n"
" --namespace Namespace of 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"
+ " --snap Let the hour hand snap to the next position instead of slowly progressing.\n"
"\n";
int opt, args;
@@ -447,6 +450,20 @@ static bool handle_command_flags (struct Wlclock *clock, int argc, char *argv[])
}
break;
+ case HAND_STYLE:
+ if (! strcmp(optarg, "xclock"))
+ clock->hand_style = STYLE_XCLOCK;
+ else if (! strcmp(optarg, "lines"))
+ clock->hand_style = STYLE_LINES;
+ else
+ {
+ clocklog(NULL, 0, "ERROR: Unrecognized hand style \"%s\".\n"
+ "INFO: Possible hand styles are "
+ "'xclock' and 'lines'.\n", optarg);
+ return false;
+ }
+ break;
+
default:
return false;
}
@@ -590,6 +607,7 @@ int main (int argc, char *argv[])
clock.margin_bottom = clock.margin_top
= clock.margin_left = clock.margin_right = 0;
clock.clock_size = 1;
+ clock.hand_style = STYLE_XCLOCK;
colour_from_string(&clock.background_colour, "#FFFFFF");
colour_from_string(&clock.border_colour, "#000000");
colour_from_string(&clock.clock_colour, "#000000");
diff --git a/src/wlclock.h b/src/wlclock.h
index 98fa711..48a2147 100644
--- a/src/wlclock.h
+++ b/src/wlclock.h
@@ -10,6 +10,12 @@
#include"colour.h"
+enum Hand_style
+{
+ STYLE_XCLOCK,
+ STYLE_LINES
+};
+
struct Wlclock_dimensions
{
/* Width and height of entire surface (size + borders). */
@@ -50,6 +56,7 @@ struct Wlclock
int32_t radius_top_left, radius_top_right, radius_bottom_left, radius_bottom_right;
int32_t anchor;
bool input, snap;
+ enum Hand_style hand_style;
struct Wlclock_colour background_colour;
struct Wlclock_colour border_colour;