Display "locking…" message when grabbing the pointer/keyboard,
after at least 250 ms of unfruitful attempts. If grabbing
eventually fails, application will not fork and return 1.
/* Pixmap on which the image is rendered to (if any) */
xcb_pixmap_t bg_pixmap = draw_image(last_resolution);
/* Pixmap on which the image is rendered to (if any) */
xcb_pixmap_t bg_pixmap = draw_image(last_resolution);
- /* open the fullscreen window, already with the correct pixmap in place */
+ /* Open the fullscreen window, already with the correct pixmap in place */
win = open_fullscreen_window(conn, screen, color, bg_pixmap);
xcb_free_pixmap(conn, bg_pixmap);
win = open_fullscreen_window(conn, screen, color, bg_pixmap);
xcb_free_pixmap(conn, bg_pixmap);
+ cursor = create_cursor(conn, screen, win, curs_choice);
+
+ /* Display the "locking…" message while trying to grab the pointer/keyboard. */
+ pam_state = STATE_PAM_LOCK;
+ grab_pointer_and_keyboard(conn, screen, cursor);
+
pid_t pid = fork();
/* The pid == -1 case is intentionally ignored here:
* While the child process is useful for preventing other windows from
pid_t pid = fork();
/* The pid == -1 case is intentionally ignored here:
* While the child process is useful for preventing other windows from
- cursor = create_cursor(conn, screen, win, curs_choice);
-
- grab_pointer_and_keyboard(conn, screen, cursor);
/* Load the keymap again to sync the current modifier state. Since we first
* loaded the keymap, there might have been changes, but starting from now,
* we should get all key presses/releases due to having grabbed the
/* Load the keymap again to sync the current modifier state. Since we first
* loaded the keymap, there might have been changes, but starting from now,
* we should get all key presses/releases due to having grabbed the
if (main_loop == NULL)
errx(EXIT_FAILURE, "Could not initialize libev. Bad LIBEV_FLAGS?\n");
if (main_loop == NULL)
errx(EXIT_FAILURE, "Could not initialize libev. Bad LIBEV_FLAGS?\n");
+ /* Explicitly call the screen redraw in case "locking…" message was displayed */
+ pam_state = STATE_PAM_IDLE;
+ redraw_screen();
+
struct ev_io *xcb_watcher = calloc(sizeof(struct ev_io), 1);
struct ev_check *xcb_check = calloc(sizeof(struct ev_check), 1);
struct ev_prepare *xcb_prepare = calloc(sizeof(struct ev_prepare), 1);
struct ev_io *xcb_watcher = calloc(sizeof(struct ev_io), 1);
struct ev_check *xcb_check = calloc(sizeof(struct ev_check), 1);
struct ev_prepare *xcb_prepare = calloc(sizeof(struct ev_prepare), 1);
* (currently verifying, wrong password, or default) */
switch (pam_state) {
case STATE_PAM_VERIFY:
* (currently verifying, wrong password, or default) */
switch (pam_state) {
case STATE_PAM_VERIFY:
cairo_set_source_rgba(ctx, 0, 114.0 / 255, 255.0 / 255, 0.75);
break;
case STATE_PAM_WRONG:
cairo_set_source_rgba(ctx, 0, 114.0 / 255, 255.0 / 255, 0.75);
break;
case STATE_PAM_WRONG:
switch (pam_state) {
case STATE_PAM_VERIFY:
switch (pam_state) {
case STATE_PAM_VERIFY:
cairo_set_source_rgb(ctx, 51.0 / 255, 0, 250.0 / 255);
break;
case STATE_PAM_WRONG:
cairo_set_source_rgb(ctx, 51.0 / 255, 0, 250.0 / 255);
break;
case STATE_PAM_WRONG:
case STATE_PAM_VERIFY:
text = "verifying…";
break;
case STATE_PAM_VERIFY:
text = "verifying…";
break;
+ case STATE_PAM_LOCK:
+ text = "locking…";
+ break;
case STATE_PAM_WRONG:
text = "wrong!";
break;
case STATE_PAM_WRONG:
text = "wrong!";
break;
typedef enum {
STATE_PAM_IDLE = 0, /* no PAM interaction at the moment */
STATE_PAM_VERIFY = 1, /* currently verifying the password via PAM */
typedef enum {
STATE_PAM_IDLE = 0, /* no PAM interaction at the moment */
STATE_PAM_VERIFY = 1, /* currently verifying the password via PAM */
- STATE_PAM_WRONG = 2 /* the password was wrong */
+ STATE_PAM_LOCK = 2, /* currently locking the screen */
+ STATE_PAM_WRONG = 3 /* the password was wrong */
} pam_state_t;
xcb_pixmap_t draw_image(uint32_t* resolution);
} pam_state_t;
xcb_pixmap_t draw_image(uint32_t* resolution);
#include <unistd.h>
#include <assert.h>
#include <err.h>
#include <unistd.h>
#include <assert.h>
#include <err.h>
+#include "unlock_indicator.h"
xcb_connection_t *conn;
xcb_screen_t *screen;
xcb_connection_t *conn;
xcb_screen_t *screen;
+ /* Using few variables to trigger a redraw_screen() if too many tries */
+ bool redrawn = false;
+ time_t start = clock();
+
while (tries-- > 0) {
pcookie = xcb_grab_pointer(
conn,
while (tries-- > 0) {
pcookie = xcb_grab_pointer(
conn,
/* Make this quite a bit slower */
usleep(50);
/* Make this quite a bit slower */
usleep(50);
+
+ /* Measure elapsed time and trigger a screen redraw if elapsed > 250000 */
+ if (!redrawn &&
+ (tries % 100) == 0 &&
+ (clock() - start) > 250000) {
+ redraw_screen();
+ redrawn = true;
+ }
/* Make this quite a bit slower */
usleep(50);
/* Make this quite a bit slower */
usleep(50);
+
+ /* Measure elapsed time and trigger a screen redraw if elapsed > 250000 */
+ if (!redrawn &&
+ (tries % 100) == 0 &&
+ (clock() - start) > 250000) {
+ redraw_screen();
+ redrawn = true;
+ }