Added password indicator so you can see how much of your password you have entered.

pull/49/head
Michael Cypher 2015-12-10 13:48:24 +00:00
parent cc73d88aea
commit 24b3b260e9
3 changed files with 46 additions and 5 deletions

View File

@ -78,6 +78,13 @@ after pressing keys. This will give feedback for every keypress and it will
show you the current PAM state (whether your password is currently being
verified or whether it is wrong).
.TP
.B \-h, \-\-no-password-indicator
Disable the password indicator. i3lock will by default show an password indicator
after pressing keys. This will give feedback for every keypress by showing you
how much of the password you have already typed using the ● character up to a
max length of 15 characters.
.TP
.BI \-i\ path \fR,\ \fB\-\-image= path
Display the given PNG image instead of a blank screen.

View File

@ -56,6 +56,7 @@ static char password[512];
static bool beep = false;
bool debug_mode = false;
bool unlock_indicator = true;
bool pwd_indicator = true;
char *modifier_string = NULL;
static bool dont_fork = false;
struct ev_loop *main_loop;
@ -226,7 +227,7 @@ static void clear_input(void) {
/* Hide the unlock indicator after a bit if the password buffer is
* empty. */
if (unlock_indicator) {
if (unlock_indicator || pwd_indicator) {
START_TIMER(clear_indicator_timeout, 1.0, clear_indicator_cb);
unlock_state = STATE_BACKSPACE_ACTIVE;
redraw_screen();
@ -299,7 +300,7 @@ static void input_done(void) {
pam_state = STATE_PAM_WRONG;
failed_attempts += 1;
clear_input();
if (unlock_indicator)
if (unlock_indicator || pwd_indicator)
redraw_screen();
/* Clear this state after 2 seconds (unless the user enters another
@ -448,7 +449,7 @@ static void handle_key_press(xcb_key_press_event_t *event) {
input_position += n - 1;
DEBUG("current password = %.*s\n", input_position, password);
if (unlock_indicator) {
if (unlock_indicator || pwd_indicator) {
unlock_state = STATE_KEY_ACTIVE;
redraw_screen();
unlock_state = STATE_KEY_PRESSED;
@ -749,6 +750,7 @@ int main(int argc, char *argv[]) {
{"debug", no_argument, NULL, 0},
{"help", no_argument, NULL, 'h'},
{"no-unlock-indicator", no_argument, NULL, 'u'},
{"no-password-indicator", no_argument, NULL, 'h'},
{"image", required_argument, NULL, 'i'},
{"tiling", no_argument, NULL, 't'},
{"ignore-empty-password", no_argument, NULL, 'e'},
@ -797,6 +799,9 @@ int main(int argc, char *argv[]) {
case 'u':
unlock_indicator = false;
break;
case 'h':
pwd_indicator = false;
break;
case 'i':
image_path = strdup(optarg);
break;

View File

@ -21,11 +21,14 @@
#include "unlock_indicator.h"
#include "xinerama.h"
#define CANVAS_SCALE 4
#define BUTTON_RADIUS 90
#define BUTTON_SPACE (BUTTON_RADIUS + 5)
#define BUTTON_CENTER (BUTTON_RADIUS + 5)
#define BUTTON_CENTER (BUTTON_RADIUS + 5) * CANVAS_SCALE
#define BUTTON_DIAMETER (2 * BUTTON_SPACE)
#define MAX_PWD_INDICATOR 15
/*******************************************************************************
* Variables defined in i3lock.c.
******************************************************************************/
@ -45,6 +48,9 @@ extern uint32_t last_resolution[2];
/* Whether the unlock indicator is enabled (defaults to true). */
extern bool unlock_indicator;
/* Whether the password indicator is enabled (defaults to true). */
extern bool pwd_indicator;
/* List of pressed modifiers, or NULL if none are pressed. */
extern char *modifier_string;
@ -98,7 +104,7 @@ static double scaling_factor(void) {
*/
xcb_pixmap_t draw_image(uint32_t *resolution) {
xcb_pixmap_t bg_pixmap = XCB_NONE;
int button_diameter_physical = ceil(scaling_factor() * BUTTON_DIAMETER);
int button_diameter_physical = ceil(scaling_factor() * BUTTON_DIAMETER) * CANVAS_SCALE;
DEBUG("scaling_factor is %.f, physical diameter is %d px\n",
scaling_factor(), button_diameter_physical);
@ -290,6 +296,29 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
}
}
if (pwd_indicator) {
/* Display the unicode password characters */
char pwd_placeholder[MAX_PWD_INDICATOR * 4];
pwd_placeholder[0] = '\0';
for (int i = 0; i < MAX_PWD_INDICATOR; i++) {
if (i < input_position)
strcat(pwd_placeholder, "\u25CF");
}
cairo_text_extents_t extents;
double x, y;
cairo_set_font_size(ctx, 32.0);
cairo_text_extents(ctx, pwd_placeholder, &extents);
x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing);
y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing) + BUTTON_RADIUS * 2;
cairo_move_to(ctx, x, y);
cairo_show_text(ctx, pwd_placeholder);
cairo_close_path(ctx);
}
if (xr_screens > 0) {
/* Composite the unlock indicator in the middle of each screen. */
for (int screen = 0; screen < xr_screens; screen++) {