diff options
Diffstat (limited to 'swaylock/main.c')
| -rw-r--r-- | swaylock/main.c | 192 | 
1 files changed, 135 insertions, 57 deletions
| diff --git a/swaylock/main.c b/swaylock/main.c index 9b74b671..0b167da1 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -1,10 +1,10 @@ -#define _XOPEN_SOURCE 700 -#define _POSIX_C_SOURCE 200112L +#define _POSIX_C_SOURCE 200809L  #include <assert.h>  #include <ctype.h>  #include <errno.h>  #include <fcntl.h>  #include <getopt.h> +#include <poll.h>  #include <stdbool.h>  #include <stdio.h>  #include <stdlib.h> @@ -23,7 +23,6 @@  #include "cairo.h"  #include "log.h"  #include "loop.h" -#include "readline.h"  #include "stringop.h"  #include "util.h"  #include "wlr-input-inhibitor-unstable-v1-client-protocol.h" @@ -397,28 +396,34 @@ static void set_default_colors(struct swaylock_colors *colors) {  	colors->background = 0xFFFFFFFF;  	colors->bs_highlight = 0xDB3300FF;  	colors->key_highlight = 0x33DB00FF; +	colors->caps_lock_bs_highlight = 0xDB3300FF; +	colors->caps_lock_key_highlight = 0x33DB00FF;  	colors->separator = 0x000000FF;  	colors->inside = (struct swaylock_colorset){  		.input = 0x000000C0,  		.cleared = 0xE5A445C0, +		.caps_lock = 0x000000C0,  		.verifying = 0x0072FFC0,  		.wrong = 0xFA0000C0,  	};  	colors->line = (struct swaylock_colorset){  		.input = 0x000000FF,  		.cleared = 0x000000FF, +		.caps_lock = 0x000000FF,  		.verifying = 0x000000FF,  		.wrong = 0x000000FF,  	};  	colors->ring = (struct swaylock_colorset){  		.input = 0x337D00FF,  		.cleared = 0xE5A445FF, +		.caps_lock = 0xE5A445FF,  		.verifying = 0x3300FFFF,  		.wrong = 0x7D3300FF,  	};  	colors->text = (struct swaylock_colorset){  		.input = 0xE5A445FF,  		.cleared = 0x000000FF, +		.caps_lock = 0xE5A445FF,  		.verifying = 0x000000FF,  		.wrong = 0x000000FF,  	}; @@ -434,25 +439,31 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  		enum line_mode *line_mode, char **config_path) {  	enum long_option_codes {  		LO_BS_HL_COLOR = 256, +		LO_CAPS_LOCK_BS_HL_COLOR, +		LO_CAPS_LOCK_KEY_HL_COLOR,  		LO_FONT,  		LO_IND_RADIUS,  		LO_IND_THICKNESS,  		LO_INSIDE_COLOR,  		LO_INSIDE_CLEAR_COLOR, +		LO_INSIDE_CAPS_LOCK_COLOR,  		LO_INSIDE_VER_COLOR,  		LO_INSIDE_WRONG_COLOR,  		LO_KEY_HL_COLOR,  		LO_LINE_COLOR,  		LO_LINE_CLEAR_COLOR, +		LO_LINE_CAPS_LOCK_COLOR,  		LO_LINE_VER_COLOR,  		LO_LINE_WRONG_COLOR,  		LO_RING_COLOR,  		LO_RING_CLEAR_COLOR, +		LO_RING_CAPS_LOCK_COLOR,  		LO_RING_VER_COLOR,  		LO_RING_WRONG_COLOR,  		LO_SEP_COLOR,  		LO_TEXT_COLOR,  		LO_TEXT_CLEAR_COLOR, +		LO_TEXT_CAPS_LOCK_COLOR,  		LO_TEXT_VER_COLOR,  		LO_TEXT_WRONG_COLOR,  	}; @@ -464,6 +475,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  		{"daemonize", no_argument, NULL, 'f'},  		{"help", no_argument, NULL, 'h'},  		{"image", required_argument, NULL, 'i'}, +		{"disable-caps-lock-text", no_argument, NULL, 'L'}, +		{"indicator-caps-lock", no_argument, NULL, 'l'},  		{"line-uses-inside", no_argument, NULL, 'n'},  		{"socket", required_argument, NULL, 'p'},  		{"line-uses-ring", no_argument, NULL, 'r'}, @@ -472,25 +485,31 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  		{"no-unlock-indicator", no_argument, NULL, 'u'},  		{"version", no_argument, NULL, 'v'},  		{"bs-hl-color", required_argument, NULL, LO_BS_HL_COLOR}, +		{"caps-lock-bs-hl-color", required_argument, NULL, LO_CAPS_LOCK_BS_HL_COLOR}, +		{"caps-lock-key-hl-color", required_argument, NULL, LO_CAPS_LOCK_KEY_HL_COLOR},  		{"font", required_argument, NULL, LO_FONT},  		{"indicator-radius", required_argument, NULL, LO_IND_RADIUS},  		{"indicator-thickness", required_argument, NULL, LO_IND_THICKNESS},  		{"inside-color", required_argument, NULL, LO_INSIDE_COLOR},  		{"inside-clear-color", required_argument, NULL, LO_INSIDE_CLEAR_COLOR}, +		{"inside-caps-lock-color", required_argument, NULL, LO_INSIDE_CAPS_LOCK_COLOR},  		{"inside-ver-color", required_argument, NULL, LO_INSIDE_VER_COLOR},  		{"inside-wrong-color", required_argument, NULL, LO_INSIDE_WRONG_COLOR},  		{"key-hl-color", required_argument, NULL, LO_KEY_HL_COLOR},  		{"line-color", required_argument, NULL, LO_LINE_COLOR},  		{"line-clear-color", required_argument, NULL, LO_LINE_CLEAR_COLOR}, +		{"line-caps-lock-color", required_argument, NULL, LO_LINE_CAPS_LOCK_COLOR},  		{"line-ver-color", required_argument, NULL, LO_LINE_VER_COLOR},  		{"line-wrong-color", required_argument, NULL, LO_LINE_WRONG_COLOR},  		{"ring-color", required_argument, NULL, LO_RING_COLOR},  		{"ring-clear-color", required_argument, NULL, LO_RING_CLEAR_COLOR}, +		{"ring-caps-lock-color", required_argument, NULL, LO_RING_CAPS_LOCK_COLOR},  		{"ring-ver-color", required_argument, NULL, LO_RING_VER_COLOR},  		{"ring-wrong-color", required_argument, NULL, LO_RING_WRONG_COLOR},  		{"separator-color", required_argument, NULL, LO_SEP_COLOR},  		{"text-color", required_argument, NULL, LO_TEXT_COLOR},  		{"text-clear-color", required_argument, NULL, LO_TEXT_CLEAR_COLOR}, +		{"text-caps-lock-color", required_argument, NULL, LO_TEXT_CAPS_LOCK_COLOR},  		{"text-ver-color", required_argument, NULL, LO_TEXT_VER_COLOR},  		{"text-wrong-color", required_argument, NULL, LO_TEXT_WRONG_COLOR},  		{0, 0, 0, 0} @@ -499,76 +518,97 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  	const char usage[] =  		"Usage: swaylock [options...]\n"  		"\n" -		"  -C, --config <config_file>     " +		"  -C, --config <config_file>       "  			"Path to the config file.\n" -		"  -c, --color <color>            " +		"  -c, --color <color>              "  			"Turn the screen into the given color instead of white.\n" -		"  -e, --ignore-empty-password    " +		"  -e, --ignore-empty-password      "  			"When an empty password is provided, do not validate it.\n" -		"  -f, --daemonize                " +		"  -f, --daemonize                  "  			"Detach from the controlling terminal after locking.\n" -		"  -h, --help                     " +		"  -h, --help                       "  			"Show help message and quit.\n" -		"  -i, --image [<output>:]<path>  " +		"  -i, --image [<output>:]<path>    "  			"Display the given image.\n" -		"  -s, --scaling <mode>           " +		"  -L, --disable-caps-lock-text     " +			"Disable the Caps Lock text.\n" +		"  -l, --indicator-caps-lock        " +			"Show the current Caps Lock state also on the indicator.\n" +		"  -s, --scaling <mode>             "  			"Scaling mode: stretch, fill, fit, center, tile.\n" -		"  -t, --tiling                   " +		"  -t, --tiling                     "  			"Same as --scaling=tile.\n" -		"  -u, --no-unlock-indicator      " +		"  -u, --no-unlock-indicator        "  			"Disable the unlock indicator.\n" -		"  -v, --version                  " +		"  -v, --version                    "  			"Show the version number and quit.\n" -		"  --bs-hl-color <color>          " +		"  --bs-hl-color <color>            "  			"Sets the color of backspace highlight segments.\n" -		"  --font <font>                  " +		"  --caps-lock-bs-hl-color <color>  " +			"Sets the color of backspace highlight segments when Caps Lock " +			"is active.\n" +		"  --caps-lock-key-hl-color <color> " +			"Sets the color of the key press highlight segments when " +			"Caps Lock is active.\n" +		"  --font <font>                    "  			"Sets the font of the text.\n" -		"  --indicator-radius <radius>    " +		"  --indicator-radius <radius>      "  			"Sets the indicator radius.\n" -		"  --indicator-thickness <thick>  " +		"  --indicator-thickness <thick>    "  			"Sets the indicator thickness.\n" -		"  --inside-color <color>         " +		"  --inside-color <color>           "  			"Sets the color of the inside of the indicator.\n" -		"  --inside-clear-color <color>   " +		"  --inside-clear-color <color>     "  			"Sets the color of the inside of the indicator when cleared.\n" -		"  --inside-ver-color <color>     " +		"  --inside-caps-lock-color <color> " +			"Sets the color of the inside of the indicator when Caps Lock " +			"is active.\n" +		"  --inside-ver-color <color>       "  			"Sets the color of the inside of the indicator when verifying.\n" -		"  --inside-wrong-color <color>   " +		"  --inside-wrong-color <color>     "  			"Sets the color of the inside of the indicator when invalid.\n" -		"  --key-hl-color <color>         " +		"  --key-hl-color <color>           "  			"Sets the color of the key press highlight segments.\n" -		"  --line-color <color>           " +		"  --line-color <color>             "  			"Sets the color of the line between the inside and ring.\n" -		"  --line-clear-color <color>     " +		"  --line-clear-color <color>       "  			"Sets the color of the line between the inside and ring when "  			"cleared.\n" -		"  --line-ver-color <color>       " +		"  --line-caps-lock-color <color>   " +			"Sets the color of the line between the inside and ring when " +			"Caps Lock is active.\n" +		"  --line-ver-color <color>         "  			"Sets the color of the line between the inside and ring when "  			"verifying.\n" -		"  --line-wrong-color <color>     " +		"  --line-wrong-color <color>       "  			"Sets the color of the line between the inside and ring when "  			"invalid.\n" -		"  -n, --line-uses-inside         " +		"  -n, --line-uses-inside           "  			"Use the inside color for the line between the inside and ring.\n" -		"  -r, --line-uses-ring           " +		"  -r, --line-uses-ring             "  			"Use the ring color for the line between the inside and ring.\n" -		"  --ring-color <color>           " +		"  --ring-color <color>             "  			"Sets the color of the ring of the indicator.\n" -		"  --ring-clear-color <color>     " +		"  --ring-clear-color <color>       "  			"Sets the color of the ring of the indicator when cleared.\n" -		"  --ring-ver-color <color>       " +		"  --ring-caps-lock-color <color>   " +			"Sets the color of the ring of the indicator when Caps Lock " +			"is active.\n" +		"  --ring-ver-color <color>         "  			"Sets the color of the ring of the indicator when verifying.\n" -		"  --ring-wrong-color <color>     " +		"  --ring-wrong-color <color>       "  			"Sets the color of the ring of the indicator when invalid.\n" -		"  --separator-color <color>      " +		"  --separator-color <color>        "  			"Sets the color of the lines that separate highlight segments.\n" -		"  --text-color <color>           " +		"  --text-color <color>             "  			"Sets the color of the text.\n" -		"  --text-clear-color <color>     " +		"  --text-clear-color <color>       "  			"Sets the color of the text when cleared.\n" -		"  --text-ver-color <color>       " +		"  --text-caps-lock-color <color>   " +			"Sets the color of the text when Caps Lock is active.\n" +		"  --text-ver-color <color>         "  			"Sets the color of the text when verifying.\n" -		"  --text-wrong-color <color>     " +		"  --text-wrong-color <color>       "  			"Sets the color of the text when invalid.\n"  		"\n"  		"All <color> options are of the form <rrggbb[aa]>.\n"; @@ -577,7 +617,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  	optind = 1;  	while (1) {  		int opt_idx = 0; -		c = getopt_long(argc, argv, "c:efhi:nrs:tuvC:", long_options, &opt_idx); +		c = getopt_long(argc, argv, "c:efhi:Llnrs:tuvC:", long_options, &opt_idx);  		if (c == -1) {  			break;  		} @@ -608,6 +648,16 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  				load_image(optarg, state);  			}  			break; +		case 'L': +			if (state) { +				state->args.show_caps_lock_text = false; +			} +			break; +		case 'l': +			if (state) { +				state->args.show_caps_lock_indicator = true; +			} +			break;  		case 'n':  			if (line_mode) {  				*line_mode = LM_INSIDE; @@ -645,6 +695,16 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  				state->args.colors.bs_highlight = parse_color(optarg);  			}  			break; +		case LO_CAPS_LOCK_BS_HL_COLOR: +			if (state) { +				state->args.colors.caps_lock_bs_highlight = parse_color(optarg); +			} +			break; +		case LO_CAPS_LOCK_KEY_HL_COLOR: +			if (state) { +				state->args.colors.caps_lock_key_highlight = parse_color(optarg); +			} +			break;  		case LO_FONT:  			if (state) {  				free(state->args.font); @@ -671,6 +731,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  				state->args.colors.inside.cleared = parse_color(optarg);  			}  			break; +		case LO_INSIDE_CAPS_LOCK_COLOR: +			if (state) { +				state->args.colors.inside.caps_lock = parse_color(optarg); +			} +			break;  		case LO_INSIDE_VER_COLOR:  			if (state) {  				state->args.colors.inside.verifying = parse_color(optarg); @@ -696,6 +761,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  				state->args.colors.line.cleared = parse_color(optarg);  			}  			break; +		case LO_LINE_CAPS_LOCK_COLOR: +			if (state) { +				state->args.colors.line.caps_lock = parse_color(optarg); +			} +			break;  		case LO_LINE_VER_COLOR:  			if (state) {  				state->args.colors.line.verifying = parse_color(optarg); @@ -716,6 +786,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  				state->args.colors.ring.cleared = parse_color(optarg);  			}  			break; +		case LO_RING_CAPS_LOCK_COLOR: +			if (state) { +				state->args.colors.ring.caps_lock = parse_color(optarg); +			} +			break;  		case LO_RING_VER_COLOR:  			if (state) {  				state->args.colors.ring.verifying = parse_color(optarg); @@ -741,6 +816,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,  				state->args.colors.text.cleared = parse_color(optarg);  			}  			break; +		case LO_TEXT_CAPS_LOCK_COLOR: +			if (state) { +				state->args.colors.text.caps_lock = parse_color(optarg); +			} +			break;  		case LO_TEXT_VER_COLOR:  			if (state) {  				state->args.colors.text.verifying = parse_color(optarg); @@ -808,36 +888,32 @@ static int load_config(char *path, struct swaylock_state *state,  		wlr_log(WLR_ERROR, "Failed to read config. Running without it.");  		return 0;  	} -	char *line; +	char *line = NULL; +	size_t line_size = 0; +	ssize_t nread;  	int line_number = 0; -	while (!feof(config)) { -		line = read_line(config); -		if (!line) { -			continue; -		} - +	int result = 0; +	while ((nread = getline(&line, &line_size, config)) != -1) {  		line_number++; -		if (line[0] == '#') { -			free(line); -			continue; + +		if (line[nread - 1] == '\n') { +			line[--nread] = '\0';  		} -		if (strlen(line) == 0) { -			free(line); + +		if (!*line || line[0] == '#') {  			continue;  		}  		wlr_log(WLR_DEBUG, "Config Line #%d: %s", line_number, line); -		char flag[strlen(line) + 3]; +		char flag[nread + 3];  		sprintf(flag, "--%s", line);  		char *argv[] = {"swaylock", flag}; -		int result = parse_options(2, argv, state, line_mode, NULL); +		result = parse_options(2, argv, state, line_mode, NULL);  		if (result != 0) { -			free(line); -			fclose(config); -			return result; +			break;  		} -		free(line);  	} +	free(line);  	fclose(config);  	return 0;  } @@ -862,6 +938,8 @@ int main(int argc, char **argv) {  		.thickness = 10,  		.ignore_empty = false,  		.show_indicator = true, +		.show_caps_lock_indicator = false, +		.show_caps_lock_text = true  	};  	wl_list_init(&state.images);  	set_default_colors(&state.args.colors); @@ -962,7 +1040,7 @@ int main(int argc, char **argv) {  	}  	state.eventloop = loop_create(); -	loop_add_fd(state.eventloop, wl_display_get_fd(state.display), POLL_IN, +	loop_add_fd(state.eventloop, wl_display_get_fd(state.display), POLLIN,  			display_in, NULL);  	state.run_display = true; | 
