diff --git a/include/swaylock.h b/include/swaylock.h index 124bf6b..3993fe5 100644 --- a/include/swaylock.h +++ b/include/swaylock.h @@ -50,6 +50,10 @@ struct swaylock_args { uint32_t font_size; uint32_t radius; uint32_t thickness; + uint32_t indicator_x_position; + uint32_t indicator_y_position; + bool override_indicator_x_position; + bool override_indicator_y_position; bool ignore_empty; bool show_indicator; bool show_caps_lock_text; diff --git a/main.c b/main.c index e110f08..c65d68a 100644 --- a/main.c +++ b/main.c @@ -509,6 +509,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, LO_FONT_SIZE, LO_IND_IDLE_VISIBLE, LO_IND_RADIUS, + LO_IND_X_POSITION, + LO_IND_Y_POSITION, LO_IND_THICKNESS, LO_INSIDE_COLOR, LO_INSIDE_CLEAR_COLOR, @@ -564,6 +566,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, {"indicator-idle-visible", no_argument, NULL, LO_IND_IDLE_VISIBLE}, {"indicator-radius", required_argument, NULL, LO_IND_RADIUS}, {"indicator-thickness", required_argument, NULL, LO_IND_THICKNESS}, + {"indicator-x-position", required_argument, NULL, LO_IND_X_POSITION}, + {"indicator-y-position", required_argument, NULL, LO_IND_Y_POSITION}, {"inside-color", required_argument, NULL, LO_INSIDE_COLOR}, {"inside-clear-color", required_argument, NULL, LO_INSIDE_CLEAR_COLOR}, {"inside-caps-lock-color", required_argument, NULL, LO_INSIDE_CAPS_LOCK_COLOR}, @@ -645,6 +649,10 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, "Sets the indicator radius.\n" " --indicator-thickness " "Sets the indicator thickness.\n" + " --indicator-x-position " + "Sets the horizontal position of the indicator.\n" + " --indicator-y-position " + "Sets the vertical position of the indicator.\n" " --inside-color " "Sets the color of the inside of the indicator.\n" " --inside-clear-color " @@ -844,6 +852,18 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.thickness = strtol(optarg, NULL, 0); } break; + case LO_IND_X_POSITION: + if (state) { + state->args.override_indicator_x_position = true; + state->args.indicator_x_position = atoi(optarg); + } + break; + case LO_IND_Y_POSITION: + if (state) { + state->args.override_indicator_y_position = true; + state->args.indicator_y_position = atoi(optarg); + } + break; case LO_INSIDE_COLOR: if (state) { state->args.colors.inside.input = parse_color(optarg); @@ -1087,6 +1107,10 @@ int main(int argc, char **argv) { .font_size = 0, .radius = 50, .thickness = 10, + .indicator_x_position = 0, + .indicator_y_position = 0, + .override_indicator_x_position = false, + .override_indicator_y_position = false, .ignore_empty = false, .show_indicator = true, .show_caps_lock_indicator = false, diff --git a/render.c b/render.c index 30d3f31..65ef47c 100644 --- a/render.c +++ b/render.c @@ -80,10 +80,26 @@ void render_frame(struct swaylock_surface *surface) { int new_width = buffer_diameter; int new_height = buffer_diameter; - int subsurf_xpos = surface->width / 2 - - buffer_width / (2 * surface->scale) + 2 / surface->scale; - int subsurf_ypos = surface->height / 2 - - (state->args.radius + state->args.thickness); + int subsurf_xpos; + int subsurf_ypos; + + // Center the indicator unless overridden by the user + if (state->args.override_indicator_x_position) { + subsurf_xpos = state->args.indicator_x_position - + buffer_width / (2 * surface->scale) + 2 / surface->scale; + } else { + subsurf_xpos = surface->width / 2 - + buffer_width / (2 * surface->scale) + 2 / surface->scale; + } + + if (state->args.override_indicator_y_position) { + subsurf_ypos = state->args.indicator_y_position - + (state->args.radius + state->args.thickness); + } else { + subsurf_ypos = surface->height / 2 - + (state->args.radius + state->args.thickness); + } + wl_subsurface_set_position(surface->subsurface, subsurf_xpos, subsurf_ypos); surface->current_buffer = get_next_buffer(state->shm,