Skip to content

Commit 5aebb55

Browse files
committed
feat: allow indicator offsets to be negative
1 parent 96f0a0f commit 5aebb55

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

include/swaylock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ struct swaylock_args {
5555
uint32_t font_size;
5656
uint32_t radius;
5757
uint32_t thickness;
58-
uint32_t indicator_x_position;
59-
uint32_t indicator_y_position;
58+
int32_t indicator_x_position;
59+
int32_t indicator_y_position;
6060
bool override_indicator_x_position;
6161
bool override_indicator_y_position;
6262
bool ignore_empty;

render.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,26 @@ static bool render_frame(struct swaylock_surface *surface) {
222222

223223
// Center the indicator unless overridden by the user
224224
if (state->args.override_indicator_x_position) {
225-
subsurf_xpos = state->args.indicator_x_position -
226-
buffer_width / (2 * surface->scale) + 2 / surface->scale;
225+
if (state->args.indicator_x_position < 0) {
226+
subsurf_xpos = surface->width + state->args.indicator_x_position -
227+
buffer_width / (2 * surface->scale) + 2 / surface->scale;
228+
} else {
229+
subsurf_xpos = state->args.indicator_x_position -
230+
buffer_width / (2 * surface->scale) + 2 / surface->scale;
231+
}
227232
} else {
228233
subsurf_xpos = surface->width / 2 -
229234
buffer_width / (2 * surface->scale) + 2 / surface->scale;
230235
}
231236

232237
if (state->args.override_indicator_y_position) {
233-
subsurf_ypos = state->args.indicator_y_position -
234-
(state->args.radius + state->args.thickness);
238+
if (state->args.indicator_y_position < 0) {
239+
subsurf_ypos = surface->height + state->args.indicator_y_position -
240+
(state->args.radius + state->args.thickness);
241+
} else {
242+
subsurf_ypos = state->args.indicator_y_position -
243+
(state->args.radius + state->args.thickness);
244+
}
235245
} else {
236246
subsurf_ypos = surface->height / 2 -
237247
(state->args.radius + state->args.thickness);

0 commit comments

Comments
 (0)