Skip to content

Commit 0e09892

Browse files
committed
feat: allow indicator offsets to be negative
1 parent b70d85e commit 0e09892

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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
@@ -192,16 +192,26 @@ void render_frame(struct swaylock_surface *surface) {
192192

193193
// Center the indicator unless overridden by the user
194194
if (state->args.override_indicator_x_position) {
195-
subsurf_xpos = state->args.indicator_x_position -
196-
buffer_width / (2 * surface->scale) + 2 / surface->scale;
195+
if (state->args.indicator_x_position < 0) {
196+
subsurf_xpos = surface->width + state->args.indicator_x_position -
197+
buffer_width / (2 * surface->scale) + 2 / surface->scale;
198+
} else {
199+
subsurf_xpos = state->args.indicator_x_position -
200+
buffer_width / (2 * surface->scale) + 2 / surface->scale;
201+
}
197202
} else {
198203
subsurf_xpos = surface->width / 2 -
199204
buffer_width / (2 * surface->scale) + 2 / surface->scale;
200205
}
201206

202207
if (state->args.override_indicator_y_position) {
203-
subsurf_ypos = state->args.indicator_y_position -
204-
(state->args.radius + state->args.thickness);
208+
if (state->args.indicator_y_position < 0) {
209+
subsurf_ypos = surface->height + state->args.indicator_y_position -
210+
(state->args.radius + state->args.thickness);
211+
} else {
212+
subsurf_ypos = state->args.indicator_y_position -
213+
(state->args.radius + state->args.thickness);
214+
}
205215
} else {
206216
subsurf_ypos = surface->height / 2 -
207217
(state->args.radius + state->args.thickness);

0 commit comments

Comments
 (0)