1
0
Fork 0
mirror of https://github.com/Raymo111/i3lock-color.git synced 2024-11-11 13:50:52 -05:00

merge upstream

This commit is contained in:
Chris Guillott 2016-10-01 01:08:08 -04:00
commit 16006c60b8
4 changed files with 39 additions and 5 deletions

View file

@ -1151,10 +1151,16 @@ int main(int argc, char *argv[]) {
/* Pixmap on which the image is rendered to (if any) */ /* Pixmap on which the image is rendered to (if any) */
xcb_pixmap_t bg_pixmap = draw_image(last_resolution); 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); win = open_fullscreen_window(conn, screen, color, bg_pixmap);
xcb_free_pixmap(conn, 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(); pid_t pid = fork();
/* The pid == -1 case is intentionally ignored here: /* The pid == -1 case is intentionally ignored here:
* While the child process is useful for preventing other windows from * While the child process is useful for preventing other windows from
@ -1167,9 +1173,6 @@ int main(int argc, char *argv[]) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
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 /* 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, * loaded the keymap, there might have been changes, but starting from now,
* we should get all key presses/releases due to having grabbed the * we should get all key presses/releases due to having grabbed the
@ -1181,6 +1184,10 @@ int main(int argc, char *argv[]) {
if (main_loop == NULL) if (main_loop == NULL)
errx(EXIT_FAILURE, "Could not initialize libev. Bad LIBEV_FLAGS?\n"); 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_io *xcb_watcher = calloc(sizeof(struct ev_io), 1);
struct ev_check *xcb_check = calloc(sizeof(struct ev_check), 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_prepare *xcb_prepare = calloc(sizeof(struct ev_prepare), 1);

View file

@ -274,6 +274,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
switch (pam_state) { switch (pam_state) {
case STATE_PAM_VERIFY: case STATE_PAM_VERIFY:
case STATE_PAM_LOCK:
cairo_set_source_rgba(ctx, (double)ringver16[0]/255, (double)ringver16[1]/255, (double)ringver16[2]/255, (double)ringver16[3]/255); cairo_set_source_rgba(ctx, (double)ringver16[0]/255, (double)ringver16[1]/255, (double)ringver16[2]/255, (double)ringver16[3]/255);
if (internal_line_source == 1) { if (internal_line_source == 1) {
line16[0] = ringver16[0]; line16[0] = ringver16[0];
@ -330,6 +331,9 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
case STATE_PAM_VERIFY: case STATE_PAM_VERIFY:
text = "verifying…"; text = "verifying…";
break; break;
case STATE_PAM_LOCK:
text = "locking…";
break;
case STATE_PAM_WRONG: case STATE_PAM_WRONG:
text = "wrong!"; text = "wrong!";
break; break;

View file

@ -13,7 +13,8 @@ typedef enum {
typedef enum { typedef enum {
STATE_PAM_IDLE = 0, /* no PAM interaction at the moment */ STATE_PAM_IDLE = 0, /* no PAM interaction at the moment */
STATE_PAM_VERIFY = 1, /* currently verifying the password via PAM */ 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; } pam_state_t;
xcb_pixmap_t draw_image(uint32_t* resolution); xcb_pixmap_t draw_image(uint32_t* resolution);

22
xcb.c
View file

@ -18,8 +18,10 @@
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <err.h> #include <err.h>
#include <time.h>
#include "cursors.h" #include "cursors.h"
#include "unlock_indicator.h"
xcb_connection_t *conn; xcb_connection_t *conn;
xcb_screen_t *screen; xcb_screen_t *screen;
@ -170,6 +172,10 @@ void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb
int tries = 10000; int tries = 10000;
/* Using few variables to trigger a redraw_screen() if too many tries */
bool redrawn = false;
time_t start = clock();
while (tries-- > 0) { while (tries-- > 0) {
pcookie = xcb_grab_pointer( pcookie = xcb_grab_pointer(
conn, conn,
@ -190,6 +196,14 @@ void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb
/* Make this quite a bit slower */ /* Make this quite a bit slower */
usleep(50); 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;
}
} }
while (tries-- > 0) { while (tries-- > 0) {
@ -209,6 +223,14 @@ void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb
/* Make this quite a bit slower */ /* Make this quite a bit slower */
usleep(50); 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;
}
} }
if (tries <= 0) if (tries <= 0)