2012-01-03 15:56:05 -05:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
|
*
|
2015-04-21 11:47:51 -04:00
|
|
|
|
* © 2010 Michael Stapelberg
|
2012-01-03 15:56:05 -05:00
|
|
|
|
*
|
|
|
|
|
* See LICENSE for licensing information
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdlib.h>
|
2014-05-02 13:57:22 -04:00
|
|
|
|
#include <stdio.h>
|
2015-02-11 14:52:07 -05:00
|
|
|
|
#include <string.h>
|
2012-01-03 15:56:05 -05:00
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <xcb/xcb.h>
|
2012-01-03 17:18:33 -05:00
|
|
|
|
#include <ev.h>
|
2012-01-03 15:56:05 -05:00
|
|
|
|
#include <cairo.h>
|
|
|
|
|
#include <cairo/cairo-xcb.h>
|
|
|
|
|
|
2014-05-02 13:57:22 -04:00
|
|
|
|
#include "i3lock.h"
|
2012-01-03 15:56:05 -05:00
|
|
|
|
#include "xcb.h"
|
|
|
|
|
#include "unlock_indicator.h"
|
2012-01-03 19:10:36 -05:00
|
|
|
|
#include "xinerama.h"
|
2017-05-19 09:52:29 -04:00
|
|
|
|
#include "tinyexpr.h"
|
2012-01-03 15:56:05 -05:00
|
|
|
|
|
2016-10-14 14:48:43 -04:00
|
|
|
|
/* clock stuff */
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
#define BUTTON_RADIUS 90
|
|
|
|
|
#define BUTTON_SPACE (BUTTON_RADIUS + 5)
|
|
|
|
|
#define BUTTON_CENTER (BUTTON_RADIUS + 5)
|
2012-01-03 19:10:36 -05:00
|
|
|
|
#define BUTTON_DIAMETER (2 * BUTTON_SPACE)
|
2017-05-19 09:52:29 -04:00
|
|
|
|
#define CLOCK_WIDTH 400
|
|
|
|
|
#define CLOCK_HEIGHT 200
|
2012-01-03 15:56:05 -05:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Variables defined in i3lock.c.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2014-05-02 13:57:22 -04:00
|
|
|
|
extern bool debug_mode;
|
|
|
|
|
|
2012-01-03 17:18:33 -05:00
|
|
|
|
/* The current position in the input buffer. Useful to determine if any
|
|
|
|
|
* characters of the password have already been entered or not. */
|
|
|
|
|
int input_position;
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/* The lock window. */
|
|
|
|
|
extern xcb_window_t win;
|
|
|
|
|
|
|
|
|
|
/* The current resolution of the X11 root window. */
|
|
|
|
|
extern uint32_t last_resolution[2];
|
|
|
|
|
|
|
|
|
|
/* Whether the unlock indicator is enabled (defaults to true). */
|
|
|
|
|
extern bool unlock_indicator;
|
|
|
|
|
|
2015-03-26 03:06:18 -04:00
|
|
|
|
/* List of pressed modifiers, or NULL if none are pressed. */
|
|
|
|
|
extern char *modifier_string;
|
2015-02-11 14:52:07 -05:00
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/* A Cairo surface containing the specified image (-i), if any. */
|
|
|
|
|
extern cairo_surface_t *img;
|
2012-01-07 04:57:22 -05:00
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/* Whether the image should be tiled. */
|
|
|
|
|
extern bool tile;
|
|
|
|
|
/* The background color to use (in hex). */
|
|
|
|
|
extern char color[7];
|
2016-02-08 15:53:29 -05:00
|
|
|
|
/* indicator color options */
|
|
|
|
|
extern char insidevercolor[9];
|
|
|
|
|
extern char insidewrongcolor[9];
|
|
|
|
|
extern char insidecolor[9];
|
|
|
|
|
extern char ringvercolor[9];
|
|
|
|
|
extern char ringwrongcolor[9];
|
|
|
|
|
extern char ringcolor[9];
|
|
|
|
|
extern char linecolor[9];
|
|
|
|
|
extern char textcolor[9];
|
2017-05-19 11:28:09 -04:00
|
|
|
|
extern char timecolor[9];
|
|
|
|
|
extern char datecolor[9];
|
2016-02-08 15:53:29 -05:00
|
|
|
|
extern char keyhlcolor[9];
|
|
|
|
|
extern char bshlcolor[9];
|
2016-02-09 09:19:02 -05:00
|
|
|
|
extern char separatorcolor[9];
|
2016-02-09 08:52:59 -05:00
|
|
|
|
extern int internal_line_source;
|
2012-01-03 15:56:05 -05:00
|
|
|
|
|
2016-02-17 07:51:04 -05:00
|
|
|
|
extern int screen_number;
|
2017-05-22 14:05:11 -04:00
|
|
|
|
extern float refresh_rate;
|
2016-02-17 07:51:04 -05:00
|
|
|
|
|
2016-10-14 14:48:43 -04:00
|
|
|
|
extern bool show_clock;
|
2017-05-22 13:34:56 -04:00
|
|
|
|
extern bool show_indicator;
|
2016-10-14 20:57:34 -04:00
|
|
|
|
extern char time_format[32];
|
|
|
|
|
extern char date_format[32];
|
2017-05-19 07:35:45 -04:00
|
|
|
|
extern char time_font[32];
|
|
|
|
|
extern char date_font[32];
|
2017-05-19 11:28:09 -04:00
|
|
|
|
extern char time_x_expr[32];
|
|
|
|
|
extern char time_y_expr[32];
|
|
|
|
|
extern char date_x_expr[32];
|
|
|
|
|
extern char date_y_expr[32];
|
2017-05-19 10:14:37 -04:00
|
|
|
|
|
|
|
|
|
extern double time_size;
|
|
|
|
|
extern double date_size;
|
2014-07-24 16:32:07 -04:00
|
|
|
|
/* Whether the failed attempts should be displayed. */
|
|
|
|
|
extern bool show_failed_attempts;
|
|
|
|
|
/* Number of failed unlock attempts. */
|
|
|
|
|
extern int failed_attempts;
|
|
|
|
|
|
2014-05-02 13:57:22 -04:00
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Variables defined in xcb.c.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* The root screen, to determine the DPI. */
|
|
|
|
|
extern xcb_screen_t *screen;
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Local variables.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2016-10-14 14:48:43 -04:00
|
|
|
|
/* time stuff */
|
|
|
|
|
static struct ev_periodic *time_redraw_tick;
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/* Cache the screen’s visual, necessary for creating a Cairo context. */
|
|
|
|
|
static xcb_visualtype_t *vistype;
|
|
|
|
|
|
|
|
|
|
/* Maintain the current unlock/PAM state to draw the appropriate unlock
|
|
|
|
|
* indicator. */
|
|
|
|
|
unlock_state_t unlock_state;
|
2017-04-15 03:39:13 -04:00
|
|
|
|
auth_state_t auth_state;
|
2012-01-03 15:56:05 -05:00
|
|
|
|
|
2014-05-02 13:57:22 -04:00
|
|
|
|
/*
|
|
|
|
|
* Returns the scaling factor of the current screen. E.g., on a 227 DPI MacBook
|
|
|
|
|
* Pro 13" Retina screen, the scaling factor is 227/96 = 2.36.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static double scaling_factor(void) {
|
|
|
|
|
const int dpi = (double)screen->height_in_pixels * 25.4 /
|
|
|
|
|
(double)screen->height_in_millimeters;
|
|
|
|
|
return (dpi / 96.0);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/*
|
|
|
|
|
* Draws global image with fill color onto a pixmap with the given
|
|
|
|
|
* resolution and returns it.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
xcb_pixmap_t draw_image(uint32_t *resolution) {
|
|
|
|
|
xcb_pixmap_t bg_pixmap = XCB_NONE;
|
2014-05-02 13:57:22 -04:00
|
|
|
|
int button_diameter_physical = ceil(scaling_factor() * BUTTON_DIAMETER);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
int clock_width_physical = ceil(scaling_factor() * CLOCK_WIDTH);
|
|
|
|
|
int clock_height_physical = ceil(scaling_factor() * CLOCK_HEIGHT);
|
2014-05-02 13:57:22 -04:00
|
|
|
|
DEBUG("scaling_factor is %.f, physical diameter is %d px\n",
|
|
|
|
|
scaling_factor(), button_diameter_physical);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
|
|
|
|
|
if (!vistype)
|
|
|
|
|
vistype = get_root_visual_type(screen);
|
|
|
|
|
bg_pixmap = create_bg_pixmap(conn, screen, resolution, color);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
/* Initialize cairo: Create one in-memory surface to render the unlock
|
|
|
|
|
* indicator on, create one XCB surface to actually draw (one or more,
|
2017-05-19 09:52:29 -04:00
|
|
|
|
* depending on the amount of screens) unlock indicators on.
|
2017-05-19 11:28:09 -04:00
|
|
|
|
* create two more surfaces for time and date display
|
2017-05-19 09:52:29 -04:00
|
|
|
|
*/
|
2014-05-02 13:57:22 -04:00
|
|
|
|
cairo_surface_t *output = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, button_diameter_physical, button_diameter_physical);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_t *ctx = cairo_create(output);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_surface_t *time_output = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, clock_width_physical, clock_height_physical);
|
|
|
|
|
cairo_t *time_ctx = cairo_create(time_output);
|
|
|
|
|
|
|
|
|
|
cairo_surface_t *date_output = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, clock_width_physical, clock_height_physical);
|
|
|
|
|
cairo_t *date_ctx = cairo_create(date_output);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_surface_t *xcb_output = cairo_xcb_surface_create(conn, bg_pixmap, vistype, resolution[0], resolution[1]);
|
|
|
|
|
cairo_t *xcb_ctx = cairo_create(xcb_output);
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
if (img) {
|
|
|
|
|
if (!tile) {
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_set_source_surface(xcb_ctx, img, 0, 0);
|
|
|
|
|
cairo_paint(xcb_ctx);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
} else {
|
|
|
|
|
/* create a pattern and fill a rectangle as big as the screen */
|
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
pattern = cairo_pattern_create_for_surface(img);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_set_source(xcb_ctx, pattern);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]);
|
|
|
|
|
cairo_fill(xcb_ctx);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_pattern_destroy(pattern);
|
|
|
|
|
}
|
2012-01-03 19:10:36 -05:00
|
|
|
|
} else {
|
|
|
|
|
char strgroups[3][3] = {{color[0], color[1], '\0'},
|
|
|
|
|
{color[2], color[3], '\0'},
|
|
|
|
|
{color[4], color[5], '\0'}};
|
|
|
|
|
uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroups[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroups[2], NULL, 16))};
|
2012-03-26 12:59:41 -04:00
|
|
|
|
cairo_set_source_rgb(xcb_ctx, rgb16[0] / 255.0, rgb16[1] / 255.0, rgb16[2] / 255.0);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]);
|
|
|
|
|
cairo_fill(xcb_ctx);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 15:53:29 -05:00
|
|
|
|
/* build indicator color arrays */
|
|
|
|
|
char strgroupsiv[4][3] = {{insidevercolor[0], insidevercolor[1], '\0'},
|
|
|
|
|
{insidevercolor[2], insidevercolor[3], '\0'},
|
|
|
|
|
{insidevercolor[4], insidevercolor[5], '\0'},
|
|
|
|
|
{insidevercolor[6], insidevercolor[7], '\0'}};
|
|
|
|
|
uint32_t insidever16[4] = {(strtol(strgroupsiv[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsiv[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsiv[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsiv[3], NULL, 16))};
|
|
|
|
|
char strgroupsiw[4][3] = {{insidewrongcolor[0], insidewrongcolor[1], '\0'},
|
|
|
|
|
{insidewrongcolor[2], insidewrongcolor[3], '\0'},
|
|
|
|
|
{insidewrongcolor[4], insidewrongcolor[5], '\0'},
|
|
|
|
|
{insidewrongcolor[6], insidewrongcolor[7], '\0'}};
|
|
|
|
|
uint32_t insidewrong16[4] = {(strtol(strgroupsiw[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsiw[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsiw[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsiw[3], NULL, 16))};
|
|
|
|
|
char strgroupsi[4][3] = {{insidecolor[0], insidecolor[1], '\0'},
|
|
|
|
|
{insidecolor[2], insidecolor[3], '\0'},
|
|
|
|
|
{insidecolor[4], insidecolor[5], '\0'},
|
|
|
|
|
{insidecolor[6], insidecolor[7], '\0'}};
|
|
|
|
|
uint32_t inside16[4] = {(strtol(strgroupsi[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsi[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsi[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsi[3], NULL, 16))};
|
|
|
|
|
char strgroupsrv[4][3] = {{ringvercolor[0], ringvercolor[1], '\0'},
|
|
|
|
|
{ringvercolor[2], ringvercolor[3], '\0'},
|
|
|
|
|
{ringvercolor[4], ringvercolor[5], '\0'},
|
|
|
|
|
{ringvercolor[6], ringvercolor[7], '\0'}};
|
|
|
|
|
uint32_t ringver16[4] = {(strtol(strgroupsrv[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsrv[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsrv[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsrv[3], NULL, 16))};
|
|
|
|
|
char strgroupsrw[4][3] = {{ringwrongcolor[0], ringwrongcolor[1], '\0'},
|
|
|
|
|
{ringwrongcolor[2], ringwrongcolor[3], '\0'},
|
|
|
|
|
{ringwrongcolor[4], ringwrongcolor[5], '\0'},
|
|
|
|
|
{ringwrongcolor[6], ringwrongcolor[7], '\0'}};
|
|
|
|
|
uint32_t ringwrong16[4] = {(strtol(strgroupsrw[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsrw[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsrw[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsrw[3], NULL, 16))};
|
|
|
|
|
char strgroupsr[4][3] = {{ringcolor[0], ringcolor[1], '\0'},
|
|
|
|
|
{ringcolor[2], ringcolor[3], '\0'},
|
|
|
|
|
{ringcolor[4], ringcolor[5], '\0'},
|
|
|
|
|
{ringcolor[6], ringcolor[7], '\0'}};
|
|
|
|
|
uint32_t ring16[4] = {(strtol(strgroupsr[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsr[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsr[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsr[3], NULL, 16))};
|
|
|
|
|
char strgroupsl[4][3] = {{linecolor[0], linecolor[1], '\0'},
|
|
|
|
|
{linecolor[2], linecolor[3], '\0'},
|
|
|
|
|
{linecolor[4], linecolor[5], '\0'},
|
|
|
|
|
{linecolor[6], linecolor[7], '\0'}};
|
|
|
|
|
uint32_t line16[4] = {(strtol(strgroupsl[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsl[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsl[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsl[3], NULL, 16))};
|
|
|
|
|
char strgroupst[4][3] = {{textcolor[0], textcolor[1], '\0'},
|
|
|
|
|
{textcolor[2], textcolor[3], '\0'},
|
|
|
|
|
{textcolor[4], textcolor[5], '\0'},
|
|
|
|
|
{textcolor[6], textcolor[7], '\0'}};
|
|
|
|
|
uint32_t text16[4] = {(strtol(strgroupst[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupst[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupst[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupst[3], NULL, 16))};
|
2017-05-19 11:28:09 -04:00
|
|
|
|
char strgroupsc[4][3] = {{timecolor[0], timecolor[1], '\0'},
|
|
|
|
|
{timecolor[2], timecolor[3], '\0'},
|
|
|
|
|
{timecolor[4], timecolor[5], '\0'},
|
|
|
|
|
{timecolor[6], timecolor[7], '\0'}};
|
|
|
|
|
uint32_t time16[4] = {(strtol(strgroupsc[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsc[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsc[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsc[3], NULL, 16))};
|
|
|
|
|
char strgroupsd[4][3] = {{timecolor[0], timecolor[1], '\0'},
|
|
|
|
|
{timecolor[2], timecolor[3], '\0'},
|
|
|
|
|
{timecolor[4], timecolor[5], '\0'},
|
|
|
|
|
{timecolor[6], timecolor[7], '\0'}};
|
|
|
|
|
uint32_t date16[4] = {(strtol(strgroupsc[0], NULL, 16)),
|
2017-05-19 07:35:45 -04:00
|
|
|
|
(strtol(strgroupsc[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsc[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsc[3], NULL, 16))};
|
2016-02-09 09:19:02 -05:00
|
|
|
|
char strgroupsk[4][3] = {{keyhlcolor[0], keyhlcolor[1], '\0'},
|
|
|
|
|
{keyhlcolor[2], keyhlcolor[3], '\0'},
|
|
|
|
|
{keyhlcolor[4], keyhlcolor[5], '\0'},
|
|
|
|
|
{keyhlcolor[6], keyhlcolor[7], '\0'}};
|
2016-02-08 15:53:29 -05:00
|
|
|
|
uint32_t keyhl16[4] = {(strtol(strgroupsk[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsk[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsk[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsk[3], NULL, 16))};
|
2016-02-09 09:19:02 -05:00
|
|
|
|
char strgroupsb[4][3] = {{bshlcolor[0], bshlcolor[1], '\0'},
|
|
|
|
|
{bshlcolor[2], bshlcolor[3], '\0'},
|
|
|
|
|
{bshlcolor[4], bshlcolor[5], '\0'},
|
|
|
|
|
{bshlcolor[6], bshlcolor[7], '\0'}};
|
2016-02-08 15:53:29 -05:00
|
|
|
|
uint32_t bshl16[4] = {(strtol(strgroupsb[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsb[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsb[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupsb[3], NULL, 16))};
|
2016-02-09 09:19:02 -05:00
|
|
|
|
char strgroupss[4][3] = {{separatorcolor[0], separatorcolor[1], '\0'},
|
|
|
|
|
{separatorcolor[2], separatorcolor[3], '\0'},
|
|
|
|
|
{separatorcolor[4], separatorcolor[5], '\0'},
|
|
|
|
|
{separatorcolor[6], separatorcolor[7], '\0'}};
|
|
|
|
|
uint32_t sep16[4] = {(strtol(strgroupss[0], NULL, 16)),
|
|
|
|
|
(strtol(strgroupss[1], NULL, 16)),
|
|
|
|
|
(strtol(strgroupss[2], NULL, 16)),
|
|
|
|
|
(strtol(strgroupss[3], NULL, 16))};
|
2016-02-08 15:53:29 -05:00
|
|
|
|
|
2016-10-14 14:48:43 -04:00
|
|
|
|
/* https://github.com/ravinrabbid/i3lock-clock/commit/0de3a411fa5249c3a4822612c2d6c476389a1297 */
|
|
|
|
|
time_t rawtime;
|
|
|
|
|
struct tm* timeinfo;
|
|
|
|
|
time(&rawtime);
|
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
|
|
2015-12-25 16:10:06 -05:00
|
|
|
|
if (unlock_indicator &&
|
2017-05-22 13:34:56 -04:00
|
|
|
|
(unlock_state >= STATE_KEY_PRESSED || auth_state > STATE_AUTH_IDLE || show_indicator)) {
|
2014-05-02 13:57:22 -04:00
|
|
|
|
cairo_scale(ctx, scaling_factor(), scaling_factor());
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/* Draw a (centered) circle with transparent background. */
|
2016-10-14 20:57:34 -04:00
|
|
|
|
cairo_set_line_width(ctx, 7.0);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_arc(ctx,
|
2012-01-03 19:10:36 -05:00
|
|
|
|
BUTTON_CENTER /* x */,
|
|
|
|
|
BUTTON_CENTER /* y */,
|
2012-01-03 15:56:05 -05:00
|
|
|
|
BUTTON_RADIUS /* radius */,
|
|
|
|
|
0 /* start */,
|
|
|
|
|
2 * M_PI /* end */);
|
|
|
|
|
|
|
|
|
|
/* Use the appropriate color for the different PAM states
|
|
|
|
|
* (currently verifying, wrong password, or default) */
|
2017-04-15 03:39:13 -04:00
|
|
|
|
switch (auth_state) {
|
|
|
|
|
case STATE_AUTH_VERIFY:
|
|
|
|
|
case STATE_AUTH_LOCK:
|
2017-04-20 12:35:48 -04:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)insidever16[0]/255, (double)insidever16[1]/255, (double)insidever16[2]/255, (double)insidever16[3]/255);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
break;
|
2017-04-15 03:39:13 -04:00
|
|
|
|
case STATE_AUTH_WRONG:
|
2016-10-11 16:40:51 -04:00
|
|
|
|
case STATE_I3LOCK_LOCK_FAILED:
|
2016-02-08 15:53:29 -05:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)insidewrong16[0]/255, (double)insidewrong16[1]/255, (double)insidewrong16[2]/255, (double)insidewrong16[3]/255);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2016-02-08 15:53:29 -05:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)inside16[0]/255, (double)inside16[1]/255, (double)inside16[2]/255, (double)inside16[3]/255);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
cairo_fill_preserve(ctx);
|
|
|
|
|
|
2017-04-15 03:39:13 -04:00
|
|
|
|
switch (auth_state) {
|
|
|
|
|
case STATE_AUTH_VERIFY:
|
|
|
|
|
case STATE_AUTH_LOCK:
|
2016-02-08 15:53:29 -05:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)ringver16[0]/255, (double)ringver16[1]/255, (double)ringver16[2]/255, (double)ringver16[3]/255);
|
2016-02-09 08:52:59 -05:00
|
|
|
|
if (internal_line_source == 1) {
|
|
|
|
|
line16[0] = ringver16[0];
|
|
|
|
|
line16[1] = ringver16[1];
|
|
|
|
|
line16[2] = ringver16[2];
|
|
|
|
|
line16[3] = ringver16[3];
|
|
|
|
|
}
|
2012-01-03 19:10:36 -05:00
|
|
|
|
break;
|
2017-04-15 03:39:13 -04:00
|
|
|
|
case STATE_AUTH_WRONG:
|
2016-10-11 16:40:51 -04:00
|
|
|
|
case STATE_I3LOCK_LOCK_FAILED:
|
2016-02-08 15:53:29 -05:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)ringwrong16[0]/255, (double)ringwrong16[1]/255, (double)ringwrong16[2]/255, (double)ringwrong16[3]/255);
|
2016-02-09 08:52:59 -05:00
|
|
|
|
if (internal_line_source == 1) {
|
|
|
|
|
line16[0] = ringwrong16[0];
|
|
|
|
|
line16[1] = ringwrong16[1];
|
|
|
|
|
line16[2] = ringwrong16[2];
|
|
|
|
|
line16[3] = ringwrong16[3];
|
|
|
|
|
}
|
2012-01-03 19:10:36 -05:00
|
|
|
|
break;
|
2017-04-15 03:39:13 -04:00
|
|
|
|
case STATE_AUTH_IDLE:
|
2016-02-08 15:53:29 -05:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)ring16[0]/255, (double)ring16[1]/255, (double)ring16[2]/255, (double)ring16[3]/255);
|
2016-02-09 08:52:59 -05:00
|
|
|
|
if (internal_line_source == 1) {
|
|
|
|
|
line16[0] = ring16[0];
|
|
|
|
|
line16[1] = ring16[1];
|
|
|
|
|
line16[2] = ring16[2];
|
|
|
|
|
line16[3] = ring16[3];
|
|
|
|
|
}
|
2012-01-03 19:10:36 -05:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
cairo_stroke(ctx);
|
2012-01-03 17:31:16 -05:00
|
|
|
|
|
2016-02-09 09:19:02 -05:00
|
|
|
|
/* Draw an inner separator line. */
|
|
|
|
|
if (internal_line_source != 2) { //pretty sure this only needs drawn if it's being drawn over the inside?
|
|
|
|
|
cairo_set_source_rgba(ctx, (double)line16[0]/255, (double)line16[1]/255, (double)line16[2]/255, (double)line16[3]/255);
|
|
|
|
|
cairo_set_line_width(ctx, 2.0);
|
|
|
|
|
cairo_arc(ctx,
|
|
|
|
|
BUTTON_CENTER /* x */,
|
|
|
|
|
BUTTON_CENTER /* y */,
|
|
|
|
|
BUTTON_RADIUS - 5 /* radius */,
|
|
|
|
|
0,
|
|
|
|
|
2 * M_PI);
|
|
|
|
|
cairo_stroke(ctx);
|
|
|
|
|
}
|
2012-01-03 15:56:05 -05:00
|
|
|
|
|
|
|
|
|
cairo_set_line_width(ctx, 10.0);
|
|
|
|
|
|
|
|
|
|
char *text = NULL;
|
2016-10-14 14:48:43 -04:00
|
|
|
|
|
2014-07-24 16:32:07 -04:00
|
|
|
|
/* We don't want to show more than a 3-digit number. */
|
|
|
|
|
char buf[4];
|
|
|
|
|
|
2017-04-20 12:35:48 -04:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)text16[0]/255, (double)text16[1]/255, (double)text16[2]/255, (double)text16[3]/255);
|
2016-08-18 14:53:19 -04:00
|
|
|
|
cairo_select_font_face(ctx, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2014-07-24 16:32:07 -04:00
|
|
|
|
cairo_set_font_size(ctx, 28.0);
|
2017-04-15 03:39:13 -04:00
|
|
|
|
switch (auth_state) {
|
|
|
|
|
case STATE_AUTH_VERIFY:
|
2012-01-03 15:56:05 -05:00
|
|
|
|
text = "verifying…";
|
|
|
|
|
break;
|
2017-04-15 03:39:13 -04:00
|
|
|
|
case STATE_AUTH_LOCK:
|
2016-09-27 21:39:52 -04:00
|
|
|
|
text = "locking…";
|
|
|
|
|
break;
|
2017-04-15 03:39:13 -04:00
|
|
|
|
case STATE_AUTH_WRONG:
|
2012-01-03 15:56:05 -05:00
|
|
|
|
text = "wrong!";
|
|
|
|
|
break;
|
2016-10-11 16:40:51 -04:00
|
|
|
|
case STATE_I3LOCK_LOCK_FAILED:
|
|
|
|
|
text = "lock failed!";
|
|
|
|
|
break;
|
2012-01-03 15:56:05 -05:00
|
|
|
|
default:
|
2015-03-16 13:47:16 -04:00
|
|
|
|
if (show_failed_attempts && failed_attempts > 0) {
|
2014-07-24 16:32:07 -04:00
|
|
|
|
if (failed_attempts > 999) {
|
|
|
|
|
text = "> 999";
|
|
|
|
|
} else {
|
|
|
|
|
snprintf(buf, sizeof(buf), "%d", failed_attempts);
|
|
|
|
|
text = buf;
|
|
|
|
|
}
|
|
|
|
|
cairo_set_font_size(ctx, 32.0);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
}
|
2012-01-03 15:56:05 -05:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-15 03:39:13 -04:00
|
|
|
|
if (auth_state == STATE_AUTH_WRONG && (modifier_string != NULL)) {
|
2015-02-11 14:52:07 -05:00
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
double x, y;
|
|
|
|
|
|
2015-03-26 03:06:18 -04:00
|
|
|
|
cairo_set_font_size(ctx, 14.0);
|
2015-02-11 14:52:07 -05:00
|
|
|
|
|
2015-03-26 03:06:18 -04:00
|
|
|
|
cairo_text_extents(ctx, modifier_string, &extents);
|
|
|
|
|
x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing);
|
|
|
|
|
y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing) + 28.0;
|
2015-02-11 14:52:07 -05:00
|
|
|
|
|
2015-03-26 03:06:18 -04:00
|
|
|
|
cairo_move_to(ctx, x, y);
|
|
|
|
|
cairo_show_text(ctx, modifier_string);
|
|
|
|
|
cairo_close_path(ctx);
|
2015-02-11 14:52:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/* After the user pressed any valid key or the backspace key, we
|
|
|
|
|
* highlight a random part of the unlock indicator to confirm this
|
|
|
|
|
* keypress. */
|
|
|
|
|
if (unlock_state == STATE_KEY_ACTIVE ||
|
|
|
|
|
unlock_state == STATE_BACKSPACE_ACTIVE) {
|
2016-10-14 21:04:05 -04:00
|
|
|
|
cairo_set_line_width(ctx, 7.0);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_new_sub_path(ctx);
|
|
|
|
|
double highlight_start = (rand() % (int)(2 * M_PI * 100)) / 100.0;
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_arc(ctx,
|
|
|
|
|
BUTTON_CENTER /* x */,
|
|
|
|
|
BUTTON_CENTER /* y */,
|
|
|
|
|
BUTTON_RADIUS /* radius */,
|
|
|
|
|
highlight_start,
|
2012-01-03 15:56:05 -05:00
|
|
|
|
highlight_start + (M_PI / 3.0));
|
|
|
|
|
if (unlock_state == STATE_KEY_ACTIVE) {
|
2016-02-08 15:53:29 -05:00
|
|
|
|
/* For normal keys, we use a lighter green. */ //lol no
|
|
|
|
|
cairo_set_source_rgba(ctx, (double)keyhl16[0]/255, (double)keyhl16[1]/255, (double)keyhl16[2]/255, (double)keyhl16[3]/255);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
} else {
|
2016-02-08 15:53:29 -05:00
|
|
|
|
/* For backspace, we use red. */ //lol no
|
|
|
|
|
cairo_set_source_rgba(ctx, (double)bshl16[0]/255, (double)bshl16[1]/255, (double)bshl16[2]/255, (double)bshl16[3]/255);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
}
|
2016-10-14 20:57:34 -04:00
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_stroke(ctx);
|
|
|
|
|
|
|
|
|
|
/* Draw two little separators for the highlighted part of the
|
|
|
|
|
* unlock indicator. */
|
2016-02-09 09:19:02 -05:00
|
|
|
|
cairo_set_source_rgba(ctx, (double)sep16[0]/255, (double)sep16[1]/255, (double)sep16[2]/255, (double)sep16[3]/255);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_arc(ctx,
|
2012-01-03 19:10:36 -05:00
|
|
|
|
BUTTON_CENTER /* x */,
|
|
|
|
|
BUTTON_CENTER /* y */,
|
2012-01-03 15:56:05 -05:00
|
|
|
|
BUTTON_RADIUS /* radius */,
|
|
|
|
|
highlight_start /* start */,
|
|
|
|
|
highlight_start + (M_PI / 128.0) /* end */);
|
|
|
|
|
cairo_stroke(ctx);
|
|
|
|
|
cairo_arc(ctx,
|
2012-01-03 19:10:36 -05:00
|
|
|
|
BUTTON_CENTER /* x */,
|
|
|
|
|
BUTTON_CENTER /* y */,
|
2012-01-03 15:56:05 -05:00
|
|
|
|
BUTTON_RADIUS /* radius */,
|
2017-01-10 03:01:19 -05:00
|
|
|
|
(highlight_start + (M_PI / 3.0)) - (M_PI / 128.0) /* start */,
|
|
|
|
|
highlight_start + (M_PI / 3.0) /* end */);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_stroke(ctx);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-19 09:52:29 -04:00
|
|
|
|
if (show_clock) {
|
|
|
|
|
char *text = NULL;
|
|
|
|
|
char *date = NULL;
|
|
|
|
|
char time_text[40] = {0};
|
|
|
|
|
char date_text[40] = {0};
|
|
|
|
|
|
|
|
|
|
strftime(time_text, 40, time_format, timeinfo);
|
|
|
|
|
strftime(date_text, 40, date_format, timeinfo);
|
|
|
|
|
text = time_text;
|
|
|
|
|
date = date_text;
|
|
|
|
|
|
|
|
|
|
double width = 0;
|
|
|
|
|
double height = 0;
|
|
|
|
|
|
|
|
|
|
if (text) {
|
|
|
|
|
double x, y;
|
|
|
|
|
cairo_text_extents_t extents;
|
2017-05-19 10:14:37 -04:00
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_set_font_size(time_ctx, time_size);
|
|
|
|
|
cairo_select_font_face(time_ctx, time_font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
|
|
|
|
cairo_set_source_rgba(time_ctx, (double)time16[0]/255, (double)time16[1]/255, (double)time16[2]/255, (double)time16[3]/255);
|
2017-05-19 10:14:37 -04:00
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_text_extents(time_ctx, text, &extents);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
x = CLOCK_WIDTH/2 - ((extents.width / 2) + extents.x_bearing);
|
2017-05-19 11:28:09 -04:00
|
|
|
|
y = CLOCK_HEIGHT/2;
|
2017-05-19 09:52:29 -04:00
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_move_to(time_ctx, x, y);
|
|
|
|
|
cairo_show_text(time_ctx, text);
|
|
|
|
|
cairo_close_path(time_ctx);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (date) {
|
|
|
|
|
double x, y;
|
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_select_font_face(date_ctx, date_font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
|
|
|
|
cairo_set_source_rgba(date_ctx, (double)date16[0]/255, (double)date16[1]/255, (double)date16[2]/255, (double)date16[3]/255);
|
|
|
|
|
cairo_set_font_size(date_ctx, date_size);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_text_extents(date_ctx, date, &extents);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
x = CLOCK_WIDTH/2 - ((extents.width / 2) + extents.x_bearing);
|
2017-05-19 11:28:09 -04:00
|
|
|
|
y = CLOCK_HEIGHT/2;
|
2017-05-19 09:52:29 -04:00
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_move_to(date_ctx, x, y);
|
|
|
|
|
cairo_show_text(date_ctx, date);
|
|
|
|
|
cairo_close_path(date_ctx);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double ix, iy;
|
|
|
|
|
double x, y;
|
|
|
|
|
double w, h;
|
2017-05-19 11:28:09 -04:00
|
|
|
|
double tx = 0;
|
|
|
|
|
double ty = 0;
|
2017-05-19 09:52:29 -04:00
|
|
|
|
|
|
|
|
|
int te_x_err;
|
|
|
|
|
int te_y_err;
|
|
|
|
|
// variable mapping for evaluating the clock position expression
|
2017-05-19 11:28:09 -04:00
|
|
|
|
te_variable vars[] = {{"ix", &ix}, {"iy", &iy}, {"w", &w}, {"h", &h}, {"tx", &tx}, {"ty", &ty}};
|
2017-05-19 09:52:29 -04:00
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
te_expr *te_time_x_expr = te_compile(time_x_expr, vars, 6, &te_x_err);
|
|
|
|
|
te_expr *te_time_y_expr = te_compile(time_y_expr, vars, 6, &te_y_err);
|
|
|
|
|
te_expr *te_date_x_expr = te_compile(date_x_expr, vars, 6, &te_x_err);
|
|
|
|
|
te_expr *te_date_y_expr = te_compile(date_y_expr, vars, 6, &te_y_err);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
|
|
|
|
|
|
2012-01-03 15:56:05 -05:00
|
|
|
|
|
2012-01-03 19:10:36 -05:00
|
|
|
|
if (xr_screens > 0) {
|
|
|
|
|
/* Composite the unlock indicator in the middle of each screen. */
|
2016-02-17 07:51:04 -05:00
|
|
|
|
// excuse me, just gonna hack something in right here
|
|
|
|
|
if (screen_number != -1 && screen_number < xr_screens) {
|
2017-05-19 09:52:29 -04:00
|
|
|
|
w = xr_resolutions[screen_number].width;
|
|
|
|
|
h = xr_resolutions[screen_number].height;
|
|
|
|
|
ix = xr_resolutions[screen_number].x + (xr_resolutions[screen_number].width / 2);
|
|
|
|
|
iy = xr_resolutions[screen_number].y + (xr_resolutions[screen_number].height / 2);
|
|
|
|
|
x = ix - (button_diameter_physical / 2);
|
|
|
|
|
y = iy - (button_diameter_physical / 2);
|
2016-02-17 07:51:04 -05:00
|
|
|
|
cairo_set_source_surface(xcb_ctx, output, x, y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
cairo_fill(xcb_ctx);
|
|
|
|
|
|
2017-05-19 11:28:09 -04:00
|
|
|
|
if (te_time_x_expr && te_time_y_expr) {
|
|
|
|
|
tx = te_eval(te_time_x_expr);
|
|
|
|
|
ty = te_eval(te_time_y_expr);
|
|
|
|
|
double time_x = xr_resolutions[screen_number].x + tx - CLOCK_WIDTH / 2;
|
|
|
|
|
double time_y = xr_resolutions[screen_number].y + ty - CLOCK_HEIGHT / 2;
|
|
|
|
|
double date_x = xr_resolutions[screen_number].x + te_eval(te_date_x_expr) - CLOCK_WIDTH / 2;
|
|
|
|
|
double date_y = xr_resolutions[screen_number].y + te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2;
|
|
|
|
|
cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
|
|
|
|
|
cairo_fill(xcb_ctx);
|
|
|
|
|
cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
cairo_fill(xcb_ctx);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-17 07:51:04 -05:00
|
|
|
|
else {
|
|
|
|
|
for (int screen = 0; screen < xr_screens; screen++) {
|
2017-05-19 09:52:29 -04:00
|
|
|
|
w = xr_resolutions[screen].width;
|
|
|
|
|
h = xr_resolutions[screen].height;
|
|
|
|
|
ix = xr_resolutions[screen].x + (xr_resolutions[screen].width / 2);
|
|
|
|
|
iy = xr_resolutions[screen].y + (xr_resolutions[screen].height / 2);
|
|
|
|
|
x = ix - (button_diameter_physical / 2);
|
|
|
|
|
y = iy - (button_diameter_physical / 2);
|
2016-02-17 07:51:04 -05:00
|
|
|
|
cairo_set_source_surface(xcb_ctx, output, x, y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
|
|
|
|
|
cairo_fill(xcb_ctx);
|
2017-05-19 11:28:09 -04:00
|
|
|
|
if (te_time_x_expr && te_time_y_expr) {
|
|
|
|
|
tx = te_eval(te_time_x_expr);
|
|
|
|
|
ty = te_eval(te_time_y_expr);
|
|
|
|
|
double time_x = xr_resolutions[screen].x + tx - CLOCK_WIDTH / 2;
|
|
|
|
|
double time_y = xr_resolutions[screen].y + ty - CLOCK_HEIGHT / 2;
|
|
|
|
|
double date_x = xr_resolutions[screen].x + te_eval(te_date_x_expr) - CLOCK_WIDTH / 2;
|
|
|
|
|
double date_y = xr_resolutions[screen].y + te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2;
|
|
|
|
|
cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
|
|
|
|
|
cairo_fill(xcb_ctx);
|
|
|
|
|
cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
cairo_fill(xcb_ctx);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
DEBUG("error codes for exprs are %d, %d\n", te_x_err, te_y_err);
|
2017-05-19 11:28:09 -04:00
|
|
|
|
DEBUG("exprs: %s, %s\n", time_x_expr, time_y_expr);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
}
|
2016-02-17 07:51:04 -05:00
|
|
|
|
}
|
2012-01-03 19:10:36 -05:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* 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. */
|
2017-05-19 09:52:29 -04:00
|
|
|
|
w = last_resolution[0];
|
|
|
|
|
h = last_resolution[1];
|
|
|
|
|
ix = last_resolution[0] / 2;
|
|
|
|
|
iy = last_resolution[1] / 2;
|
|
|
|
|
x = ix - (button_diameter_physical / 2);
|
|
|
|
|
y = iy - (button_diameter_physical / 2);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_set_source_surface(xcb_ctx, output, x, y);
|
2014-05-02 13:57:22 -04:00
|
|
|
|
cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_fill(xcb_ctx);
|
2017-05-19 11:28:09 -04:00
|
|
|
|
if (te_time_x_expr && te_time_y_expr) {
|
|
|
|
|
tx = te_eval(te_time_x_expr);
|
|
|
|
|
ty = te_eval(te_time_y_expr);
|
|
|
|
|
double time_x = tx - CLOCK_WIDTH / 2;
|
|
|
|
|
double time_y = tx - CLOCK_HEIGHT / 2;
|
|
|
|
|
double date_x = te_eval(te_date_x_expr) - CLOCK_WIDTH / 2;
|
|
|
|
|
double date_y = te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2;
|
|
|
|
|
DEBUG("Placing time at %f, %f\n", time_x, time_y);
|
|
|
|
|
cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
|
|
|
|
|
cairo_fill(xcb_ctx);
|
|
|
|
|
cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
|
|
|
|
|
cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT);
|
2017-05-19 09:52:29 -04:00
|
|
|
|
cairo_fill(xcb_ctx);
|
|
|
|
|
}
|
2012-01-03 19:10:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_surface_destroy(xcb_output);
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_surface_destroy(time_output);
|
|
|
|
|
cairo_surface_destroy(date_output);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
cairo_surface_destroy(output);
|
|
|
|
|
cairo_destroy(ctx);
|
2017-05-19 11:28:09 -04:00
|
|
|
|
cairo_destroy(time_ctx);
|
|
|
|
|
cairo_destroy(date_ctx);
|
2012-01-03 19:10:36 -05:00
|
|
|
|
cairo_destroy(xcb_ctx);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
return bg_pixmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Calls draw_image on a new pixmap and swaps that with the current pixmap
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-04-01 06:28:28 -04:00
|
|
|
|
void redraw_screen(void) {
|
2017-04-15 03:39:13 -04:00
|
|
|
|
DEBUG("redraw_screen(unlock_state = %d, auth_state = %d)\n", unlock_state, auth_state);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
xcb_pixmap_t bg_pixmap = draw_image(last_resolution);
|
2015-03-16 13:47:16 -04:00
|
|
|
|
xcb_change_window_attributes(conn, win, XCB_CW_BACK_PIXMAP, (uint32_t[1]){bg_pixmap});
|
2012-01-03 15:56:05 -05:00
|
|
|
|
/* XXX: Possible optimization: Only update the area in the middle of the
|
|
|
|
|
* screen instead of the whole screen. */
|
2012-05-19 15:13:03 -04:00
|
|
|
|
xcb_clear_area(conn, 0, win, 0, 0, last_resolution[0], last_resolution[1]);
|
2012-01-03 15:56:05 -05:00
|
|
|
|
xcb_free_pixmap(conn, bg_pixmap);
|
|
|
|
|
xcb_flush(conn);
|
|
|
|
|
}
|
2012-01-03 17:18:33 -05:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Hides the unlock indicator completely when there is no content in the
|
|
|
|
|
* password buffer.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2014-03-06 15:22:02 -05:00
|
|
|
|
void clear_indicator(void) {
|
2012-01-03 17:18:33 -05:00
|
|
|
|
if (input_position == 0) {
|
|
|
|
|
unlock_state = STATE_STARTED;
|
2015-03-16 13:47:16 -04:00
|
|
|
|
} else
|
|
|
|
|
unlock_state = STATE_KEY_PRESSED;
|
2012-01-03 17:18:33 -05:00
|
|
|
|
redraw_screen();
|
|
|
|
|
}
|
2017-04-17 17:03:47 -04:00
|
|
|
|
|
|
|
|
|
static void time_redraw_cb(struct ev_loop *loop, ev_periodic *w, int revents) {
|
|
|
|
|
redraw_screen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void start_time_redraw_tick(struct ev_loop* main_loop) {
|
2017-05-22 14:05:11 -04:00
|
|
|
|
fprintf(stderr, "redraw rate: %f\n", refresh_rate);
|
2017-04-17 17:03:47 -04:00
|
|
|
|
if (time_redraw_tick) {
|
2017-05-22 14:05:11 -04:00
|
|
|
|
ev_periodic_set(time_redraw_tick, 0., refresh_rate, 0);
|
2017-04-17 17:03:47 -04:00
|
|
|
|
ev_periodic_again(main_loop, time_redraw_tick);
|
|
|
|
|
} else {
|
|
|
|
|
if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-22 14:05:11 -04:00
|
|
|
|
ev_periodic_init(time_redraw_tick, time_redraw_cb, 0., refresh_rate, 0);
|
2017-04-17 17:03:47 -04:00
|
|
|
|
ev_periodic_start(main_loop, time_redraw_tick);
|
|
|
|
|
}
|
|
|
|
|
}
|