Skip to content

Commit 4920faf

Browse files
committed
s/offset/rotation/g
1 parent c7b6014 commit 4920faf

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

i3lock-zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ _i3lock() {
9595
"--bar-total-width[The total width of the bar]:float:"
9696
# Polygon indicator
9797
"--polygon-sides[Draws the indicator as a regular polygon]:int:"
98-
"--polygon-offset[Rotates the indicator polygon]:float:"
98+
"--polygon-rotation[Rotates the indicator polygon]:float:"
9999
"--polygon-highlight[Sets the polygon highlight mode]:mode:((0\:'random' 1\:'clockwise' 2\:'counterclockwise'))"
100100
# Extra configs
101101
"--redraw-thread[Starts a separate thread for redrawing the screen]"

i3lock.1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,11 @@ Sets the number of minibars to draw on each screen.
445445
The total width of the bar. Can be an expression.
446446

447447
.TP
448-
.B \-\-polygon\-sides=0
449-
If set to an integer greater then 2, draw the indicator as a regular polygon
450-
instead of a circle.
448+
.B \-\-polygon\-sides
449+
Draw the indicator as a regular polygon instead of a circle.
451450

452451
.TP
453-
.B \-\-polygon\-offset=degrees\-as\-double
452+
.B \-\-polygon\-rotation=degrees\-as\-double
454453
The angle to rotate the indicator polygon by.
455454

456455
.TP

i3lock.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ bool bar_reversed = false;
296296

297297
// Polygon indicator
298298
int polygon_sides = 0;
299-
double polygon_offset = 0;
299+
double polygon_rotation = 0;
300300
int polygon_highlight = 0;
301301

302302
/* isutf, u8_dec © 2005 Jeff Bezanson, public domain */
@@ -1499,7 +1499,7 @@ int main(int argc, char *argv[]) {
14991499
{"radius", required_argument, NULL, 402},
15001500
{"ring-width", required_argument, NULL, 403},
15011501
{"polygon-sides", required_argument, NULL, 404},
1502-
{"polygon-offset", required_argument, NULL, 405},
1502+
{"polygon-rotation", required_argument, NULL, 405},
15031503
{"polygon-highlight", required_argument, NULL, 406},
15041504

15051505
// alignment
@@ -1822,17 +1822,15 @@ int main(int argc, char *argv[]) {
18221822
case 404:
18231823
arg = optarg;
18241824
if (sscanf(arg, "%d", &polygon_sides) != 1)
1825-
errx(1, "polygon-sides must be a number\n");
1826-
if (polygon_sides < 3 && polygon_sides != 0) {
1827-
fprintf(stderr, "polygon-sides must be greater then 2 or 0; ignoring...\n");
1828-
polygon_sides = 0;
1829-
}
1825+
errx(EXIT_FAILURE, "polygon-sides must be a number\n");
1826+
if (polygon_sides < 3)
1827+
errx(EXIT_FAILURE, "polygon-sides must be greater then 2 or 0\n");
18301828
break;
18311829
case 405:
18321830
arg = optarg;
1833-
if (sscanf(arg, "%lf", &polygon_offset) != 1)
1834-
errx(1, "polygon-offset must be a number\n");
1835-
polygon_offset = polygon_offset * (M_PI / 180);
1831+
if (sscanf(arg, "%lf", &polygon_rotation) != 1)
1832+
errx(1, "polygon-rotation must be a number\n");
1833+
polygon_rotation = polygon_rotation * (M_PI / 180);
18361834
break;
18371835
case 406:
18381836
arg = optarg;

unlock_indicator.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ extern bool bar_reversed;
249249

250250
// Polygon indicator
251251
extern int polygon_sides;
252-
extern double polygon_offset;
252+
extern double polygon_rotation;
253253
extern int polygon_highlight;
254254

255255
static cairo_font_face_t *font_faces[6] = {
@@ -523,11 +523,21 @@ static void draw_bar(cairo_t *ctx, double bar_x, double bar_y, double bar_width,
523523
cairo_restore(ctx);
524524
}
525525

526-
void draw_polygon(cairo_t *ctx, double center_x, double center_y, double radius, int points, int start, int end, double offset) {
526+
/* Draw some number of edges of a polygon
527+
* center_x/center_y: The center of the polygon
528+
* radius: The distance from the center to the vertices
529+
* points: The number of verticies
530+
* start/end: The index of the edges to draw. Settings start to 0 and end to
531+
* points will draw the entire polygon. Edges are indexed counter
532+
* clockwise around the polygon.
533+
* angle_offset: How far offset clockwise the first vertex is from the positive
534+
* x axis (radians).
535+
*/
536+
void draw_polygon(cairo_t *ctx, double center_x, double center_y, double radius, int points, int start, int end, double angle_offset) {
527537
int count = end - start;
528538

529539
for (int v = 0; v < count + 1; v++) {
530-
double theta = (start + v) * ((M_PI * 2) / points) + offset;
540+
double theta = (start + v) * ((M_PI * 2) / points) + angle_offset;
531541

532542
int x = radius * cos(theta);
533543
int y = radius * sin(theta);
@@ -545,7 +555,7 @@ static void draw_indic(cairo_t *ctx, double ind_x, double ind_y) {
545555
/* Draw a (centered) circle with transparent background. */
546556
cairo_set_line_width(ctx, RING_WIDTH);
547557
if (polygon_sides > 0)
548-
draw_polygon(ctx, ind_x, ind_y, BUTTON_RADIUS, polygon_sides, 0, polygon_sides, polygon_offset);
558+
draw_polygon(ctx, ind_x, ind_y, BUTTON_RADIUS, polygon_sides, 0, polygon_sides, polygon_rotation);
549559
else
550560
cairo_arc(ctx, ind_x, ind_y, BUTTON_RADIUS, 0, 2 * M_PI);
551561

@@ -618,7 +628,7 @@ static void draw_indic(cairo_t *ctx, double ind_x, double ind_y) {
618628
cairo_set_source_rgba(ctx, line16.red, line16.green, line16.blue, line16.alpha);
619629
cairo_set_line_width(ctx, 2.0);
620630
if (polygon_sides > 0)
621-
draw_polygon(ctx, ind_x, ind_y, BUTTON_RADIUS - 5, polygon_sides, 0, polygon_sides, polygon_offset);
631+
draw_polygon(ctx, ind_x, ind_y, BUTTON_RADIUS - 5, polygon_sides, 0, polygon_sides, polygon_rotation);
622632
else
623633
cairo_arc(ctx, ind_x, ind_y, BUTTON_RADIUS - 5, 0, 2 * M_PI);
624634
cairo_stroke(ctx);
@@ -643,7 +653,7 @@ static void draw_indic(cairo_t *ctx, double ind_x, double ind_y) {
643653
highlight_start = input_position % polygon_sides;
644654
else if(polygon_highlight == 2)
645655
highlight_start = -input_position % polygon_sides;
646-
draw_polygon(ctx, ind_x, ind_y, BUTTON_RADIUS, polygon_sides, highlight_start, highlight_start+1, polygon_offset);
656+
draw_polygon(ctx, ind_x, ind_y, BUTTON_RADIUS, polygon_sides, highlight_start, highlight_start+1, polygon_rotation);
647657
cairo_stroke(ctx);
648658
return;
649659
}

0 commit comments

Comments
 (0)