]> git.sur5r.net Git - i3/i3lock/blobdiff - unlock_indicator.c
Replace '1' with "EXIT_FAILURE"
[i3/i3lock] / unlock_indicator.c
index d603531e2cd14d74f281ba65b8d9eebe90083c74..daaeeb1409087974ebf7b5689641b54abee010f0 100644 (file)
 #include <stdlib.h>
 #include <math.h>
 #include <xcb/xcb.h>
-#include <xcb/xcb_keysyms.h>
 #include <ev.h>
-
-#ifndef NOLIBCAIRO
 #include <cairo.h>
 #include <cairo/cairo-xcb.h>
-#endif
 
 #include "xcb.h"
 #include "unlock_indicator.h"
@@ -35,9 +31,6 @@
  * characters of the password have already been entered or not. */
 int input_position;
 
-/* The ev main loop. */
-struct ev_loop *main_loop;
-
 /* The lock window. */
 extern xcb_window_t win;
 
@@ -47,10 +40,8 @@ extern uint32_t last_resolution[2];
 /* Whether the unlock indicator is enabled (defaults to true). */
 extern bool unlock_indicator;
 
-#ifndef NOLIBCAIRO
 /* A Cairo surface containing the specified image (-i), if any. */
 extern cairo_surface_t *img;
-#endif
 
 /* Whether the image should be tiled. */
 extern bool tile;
@@ -61,8 +52,6 @@ extern char color[7];
  * Local variables.
  ******************************************************************************/
 
-static struct ev_timer *clear_indicator_timeout;
-
 /* Cache the screen’s visual, necessary for creating a Cairo context. */
 static xcb_visualtype_t *vistype;
 
@@ -79,7 +68,6 @@ pam_state_t pam_state;
 xcb_pixmap_t draw_image(uint32_t *resolution) {
     xcb_pixmap_t bg_pixmap = XCB_NONE;
 
-#ifndef NOLIBCAIRO
     if (!vistype)
         vistype = get_root_visual_type(screen);
     bg_pixmap = create_bg_pixmap(conn, screen, resolution, color);
@@ -253,8 +241,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
         /* We have no information about the screen sizes/positions, so we just
          * place the unlock indicator in the middle of the X root window and
          * hope for the best. */
-        int x = (last_resolution[0] / 2);
-        int y = (last_resolution[1] / 2);
+        int x = (last_resolution[0] / 2) - (BUTTON_DIAMETER / 2);
+        int y = (last_resolution[1] / 2) - (BUTTON_DIAMETER / 2);
         cairo_set_source_surface(xcb_ctx, output, x, y);
         cairo_rectangle(xcb_ctx, x, y, BUTTON_DIAMETER, BUTTON_DIAMETER);
         cairo_fill(xcb_ctx);
@@ -264,7 +252,6 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
     cairo_surface_destroy(output);
     cairo_destroy(ctx);
     cairo_destroy(xcb_ctx);
-#endif
     return bg_pixmap;
 }
 
@@ -272,12 +259,12 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
  * Calls draw_image on a new pixmap and swaps that with the current pixmap
  *
  */
-void redraw_screen() {
+void redraw_screen(void) {
     xcb_pixmap_t bg_pixmap = draw_image(last_resolution);
     xcb_change_window_attributes(conn, win, XCB_CW_BACK_PIXMAP, (uint32_t[1]){ bg_pixmap });
     /* XXX: Possible optimization: Only update the area in the middle of the
      * screen instead of the whole screen. */
-    xcb_clear_area(conn, 0, win, 0, 0, screen->width_in_pixels, screen->height_in_pixels);
+    xcb_clear_area(conn, 0, win, 0, 0, last_resolution[0], last_resolution[1]);
     xcb_free_pixmap(conn, bg_pixmap);
     xcb_flush(conn);
 }
@@ -287,45 +274,9 @@ void redraw_screen() {
  * password buffer.
  *
  */
-static void clear_indicator(EV_P_ ev_timer *w, int revents) {
+void clear_indicator(void) {
     if (input_position == 0) {
         unlock_state = STATE_STARTED;
     } else unlock_state = STATE_KEY_PRESSED;
     redraw_screen();
-
-    ev_timer_stop(main_loop, clear_indicator_timeout);
-    free(clear_indicator_timeout);
-    clear_indicator_timeout = NULL;
-}
-
-/*
- * (Re-)starts the clear_indicator timeout. Called after pressing backspace or
- * after an unsuccessful authentication attempt.
- *
- */
-void start_clear_indicator_timeout() {
-    if (clear_indicator_timeout) {
-        ev_timer_stop(main_loop, clear_indicator_timeout);
-        ev_timer_set(clear_indicator_timeout, 1.0, 0.);
-        ev_timer_start(main_loop, clear_indicator_timeout);
-    } else {
-        /* When there is no memory, we just don’t have a timeout. We cannot
-         * exit() here, since that would effectively unlock the screen. */
-        if (!(clear_indicator_timeout = calloc(sizeof(struct ev_timer), 1)))
-            return;
-        ev_timer_init(clear_indicator_timeout, clear_indicator, 1.0, 0.);
-        ev_timer_start(main_loop, clear_indicator_timeout);
-    }
-}
-
-/*
- * Stops the clear_indicator timeout.
- *
- */
-void stop_clear_indicator_timeout() {
-    if (clear_indicator_timeout) {
-        ev_timer_stop(main_loop, clear_indicator_timeout);
-        free(clear_indicator_timeout);
-        clear_indicator_timeout = NULL;
-    }
 }