Reread image on USR1 signal

pull/83/head
Mikhail Skorzhinskiy 2016-07-09 21:59:34 +03:00
parent 679fb57acc
commit 1ecf801242
1 changed files with 31 additions and 1 deletions

View File

@ -75,6 +75,9 @@ static struct xkb_compose_state *xkb_compose_state;
static uint8_t xkb_base_event;
static uint8_t xkb_base_error;
struct ev_timer *img_reread_timer = NULL;
char *image_path = NULL;
cairo_surface_t *img = NULL;
bool tile = false;
bool ignore_empty_password = false;
@ -760,10 +763,34 @@ static void raise_loop(xcb_window_t window) {
}
}
/* Rereads image from disk */
void cb_reread_image(EV_P_ ev_timer *w, int revents) {
if (image_path && img)
{
cairo_surface_t *new = cairo_image_surface_create_from_png(image_path);
if (cairo_surface_status(new) != CAIRO_STATUS_SUCCESS) {
fprintf(stderr, "Could not load image \"%s\": %s\n",
image_path, cairo_status_to_string(cairo_surface_status(new)));
new = NULL;
}
if (new) {
cairo_surface_destroy(img);
img = new;
}
}
redraw_screen();
STOP_TIMER(img_reread_timer);
}
void usr1_handle(int sig) {
/* Create deferred work */
START_TIMER(img_reread_timer, TSTAMP_N_SECS(0.25), cb_reread_image);
}
int main(int argc, char *argv[]) {
struct passwd *pw;
char *username;
char *image_path = NULL;
int ret;
struct pam_conv conv = {conv_callback, NULL};
int curs_choice = CURS_NONE;
@ -1005,6 +1032,9 @@ int main(int argc, char *argv[]) {
ev_prepare_init(xcb_prepare, xcb_prepare_cb);
ev_prepare_start(main_loop, xcb_prepare);
/* Set up handler for SIGUSR1 */
signal(SIGUSR1, usr1_handle);
/* Invoke the event callback once to catch all the events which were
* received up until now. ev will only pick up new events (when the X11
* file descriptor becomes readable). */