summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/wlclock.1.scd25
-rw-r--r--src/render.c71
-rw-r--r--src/wlclock.c26
-rw-r--r--src/wlclock.h7
4 files changed, 88 insertions, 41 deletions
diff --git a/doc/wlclock.1.scd b/doc/wlclock.1.scd
index cfd50f2..bf4181e 100644
--- a/doc/wlclock.1.scd
+++ b/doc/wlclock.1.scd
@@ -45,6 +45,12 @@ but a desktop-widget.
*--clock-face-size* <size>
The size of the minute markers on the clock face. The default is 1.
+*--corner-radius* <radius>, *--corner-radius* <top-left> <top-right> <bottom-right> <bottom-left>
+ The radius of the corners. Expects either one argument, to set the radius of
+ all corners, or four arguments, to set the individual corner radii. The
+ default radius is 5. If set to sufficiently high values, wlclock will be
+ completely round. Set to 0 to disable corner roundness.
+
*--exclusive-zone* <true|false|stationary>
Exclusive zone of the surface. Can be "true", "false" or "stationary". If
"true", the compositor is informed that it should not obstruct the surface
@@ -56,6 +62,11 @@ but a desktop-widget.
default is "stationary". The exact implementation is compositor dependant;
A compositor may choose to ignore the requested exclusive zone of surfaces.
+*--hand-style* <xclock|lines>
+ Style of the clock hands. Can be "xclock", where wlclock draws xclock-esque
+ triangles, and "lines", where wlclock draws straight lines. The default is
+ "xclock".
+
*--layer* <background|bottom|top|overlay>
Layer of the layer surface. Can be "overlay", "top", "bottom" or
"background". Typically, "bottom" and "background" will be underneath
@@ -76,24 +87,18 @@ but a desktop-widget.
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
on all outputs, which is the default behaviour.
-*--corner-radius* <radius>, *--corner-radius* <top-left> <top-right> <bottom-right> <bottom-left>
- The radius of the corners. Expects either one argument, to set the radius of
- all corners, or four arguments, to set the individual corner radii. The
- default radius is 5. If set to sufficiently high values, wlclock will be
- completely round. Set to 0 to disable corner roundness.
-
*--size* <size>
The size of the clock, without borders. The default size is 165.
+*--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.
+
# AUTHORS
Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de>
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;