summaryrefslogtreecommitdiff
path: root/i3lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'i3lock.c')
-rw-r--r--i3lock.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/i3lock.c b/i3lock.c
index 44a30f2..c35330e 100644
--- a/i3lock.c
+++ b/i3lock.c
@@ -84,6 +84,7 @@ static void input_done(void);
84bool digital_clock = false; 84bool digital_clock = false;
85bool led_clock = false; 85bool led_clock = false;
86bool elapsed_time = false; 86bool elapsed_time = false;
87bool unix_time = false; /* display seconds since epoch */
87int count_until = 0; /* count seconds until */ 88int count_until = 0; /* count seconds until */
88int refresh_rate = 2; /* 2 frames per second */ 89int refresh_rate = 2; /* 2 frames per second */
89i3lock_digital_clock_t i3lock_digital_clock = {28, 90i3lock_digital_clock_t i3lock_digital_clock = {28,
@@ -103,7 +104,7 @@ i3lock_led_clock_t i3lock_led_clock = {"ffff00",
103 "000000", 104 "000000",
104 I3LOCK_ALIGN_CENTER, 105 I3LOCK_ALIGN_CENTER,
105 I3LOCK_ALIGN_BOTTOM}; 106 I3LOCK_ALIGN_BOTTOM};
106char *display_text = NULL; 107char *display_text_template = NULL;
107#endif 108#endif
108 109
109char color[7] = "a3a3a3"; 110char color[7] = "a3a3a3";
@@ -1081,17 +1082,17 @@ int main(int argc, char *argv[]) {
1081 {"dpms", no_argument, NULL, 'd'}, 1082 {"dpms", no_argument, NULL, 'd'},
1082 {"color", required_argument, NULL, 'c'}, 1083 {"color", required_argument, NULL, 'c'},
1083#ifdef EXTRAS 1084#ifdef EXTRAS
1084 {"count-until", no_argument, NULL, 'C'}, 1085 {"count-until", required_argument, NULL, 'C'},
1085 {"digital-clock", no_argument, NULL, 'D'}, 1086 {"digital-clock", no_argument, NULL, 'D'},
1086 {"digital-clock-color", required_argument, NULL, 'G'}, 1087 {"digital-clock-color", required_argument, NULL, 'G'},
1087 {"digital-clock-template", required_argument, NULL, 'T'}, 1088 {"digital-clock-template", required_argument, NULL, 'T'},
1088 {"digital-clock-halign", required_argument, NULL, 'x'}, 1089 {"digital-clock-halign", required_argument, NULL, 'x'},
1089 {"digital-clock-valign", required_argument, NULL, 'y'}, 1090 {"digital-clock-valign", required_argument, NULL, 'y'},
1090 {"display-text", no_argument, NULL, 'J'}, 1091 {"display-text", required_argument, NULL, 'J'},
1091 {"elapsed-time", no_argument, NULL, 'E'}, 1092 {"elapsed-time", no_argument, NULL, 'E'},
1092 {"elapsed-time-color", required_argument, NULL, 'R'}, 1093 {"display-text-color", required_argument, NULL, 'R'},
1093 {"elapsed-time-halign", required_argument, NULL, 'W'}, 1094 {"display-text-halign", required_argument, NULL, 'W'},
1094 {"elapsed-time-valign", required_argument, NULL, 'Z'}, 1095 {"display-text-valign", required_argument, NULL, 'Z'},
1095 {"led-clock", no_argument, NULL, 'L'}, 1096 {"led-clock", no_argument, NULL, 'L'},
1096 {"led-clock-halign", required_argument, NULL, 'X'}, 1097 {"led-clock-halign", required_argument, NULL, 'X'},
1097 {"led-clock-valign", required_argument, NULL, 'Y'}, 1098 {"led-clock-valign", required_argument, NULL, 'Y'},
@@ -1100,6 +1101,7 @@ int main(int argc, char *argv[]) {
1100 {"led-on-color", required_argument, NULL, 'O'}, 1101 {"led-on-color", required_argument, NULL, 'O'},
1101 {"refresh-rate", required_argument, NULL, 'r'}, 1102 {"refresh-rate", required_argument, NULL, 'r'},
1102 {"text-size", required_argument, NULL, 'S'}, 1103 {"text-size", required_argument, NULL, 'S'},
1104 {"unix-time", no_argument, NULL, 'U'},
1103#endif 1105#endif
1104 {"pointer", required_argument, NULL, 'p'}, 1106 {"pointer", required_argument, NULL, 'p'},
1105 {"debug", no_argument, NULL, 0}, 1107 {"debug", no_argument, NULL, 0},
@@ -1117,7 +1119,7 @@ int main(int argc, char *argv[]) {
1117 int code = EXIT_FAILURE; 1119 int code = EXIT_FAILURE;
1118 1120
1119#ifdef EXTRAS 1121#ifdef EXTRAS
1120 char *optstring = "hvnbDdELC:c:B:G:F:J:O:R:r:S:T:W:X:x:Y:y:Z:p:ui:teI:fk"; 1122 char *optstring = "hvnbDdELUC:c:B:G:F:J:O:R:r:S:T:W:X:x:Y:y:Z:p:ui:teI:fk";
1121#else 1123#else
1122 char *optstring = "hvnbdc:p:ui:teI:fk"; 1124 char *optstring = "hvnbdc:p:ui:teI:fk";
1123#endif 1125#endif
@@ -1163,6 +1165,9 @@ int main(int argc, char *argv[]) {
1163 digital_clock = true; 1165 digital_clock = true;
1164 break; 1166 break;
1165 case 'E': 1167 case 'E':
1168 if ((display_text_template != NULL) || (unix_time)) {
1169 errx(EXIT_FAILURE, "Display text, elapsed time and UNIX time are mutually exclusive options\n");
1170 }
1166 elapsed_time = true; 1171 elapsed_time = true;
1167 i3lock_elapsed_time.start_time = time(NULL); 1172 i3lock_elapsed_time.start_time = time(NULL);
1168 break; 1173 break;
@@ -1205,13 +1210,16 @@ int main(int argc, char *argv[]) {
1205 DEBUG("led-off-color: %s\n", i3lock_led_clock.led_off_color); 1210 DEBUG("led-off-color: %s\n", i3lock_led_clock.led_off_color);
1206 break; 1211 break;
1207 } 1212 }
1208 case 'J': { 1213 case 'J': { /* display-text */
1209 display_text = strdup(optarg); 1214 if ((elapsed_time) || (unix_time)) {
1210 if (display_text == NULL) { 1215 errx(EXIT_FAILURE, "Display text, elapsed time and UNIX time are mutually exclusive options\n");
1216 }
1217 display_text_template = strdup(optarg);
1218 if (display_text_template == NULL) {
1211 errx(EXIT_FAILURE, 1219 errx(EXIT_FAILURE,
1212 "Unable to initialize display_text\n"); 1220 "Unable to initialize display_text\n");
1213 } 1221 }
1214 DEBUG("display_text: %s\n", display_text); 1222 DEBUG("display_text: %s\n", display_text_template);
1215 break; 1223 break;
1216 } 1224 }
1217 case 'O': { /* led-on-color */ 1225 case 'O': { /* led-on-color */
@@ -1226,16 +1234,17 @@ int main(int argc, char *argv[]) {
1226 DEBUG("led-on-color: %s\n", i3lock_led_clock.led_on_color); 1234 DEBUG("led-on-color: %s\n", i3lock_led_clock.led_on_color);
1227 break; 1235 break;
1228 } 1236 }
1229 case 'R': { /* elapsed-time-color */ 1237 case 'R': { /* display-text-color */
1230 char *arg = optarg; 1238 char *arg = optarg;
1231 1239
1232 /* Skip # if present */ 1240 /* Skip # if present */
1233 if (arg[0] == '#') 1241 if (arg[0] == '#')
1234 arg++; 1242 arg++;
1235 1243
1244 /* since display-text is a subset of elapsed time, we store it in a i3lock_elapsed_time */
1236 if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", i3lock_elapsed_time.color) != 1) 1245 if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", i3lock_elapsed_time.color) != 1)
1237 errx(EXIT_FAILURE, "elapsed-time-color is invalid, it must be given in 3-byte hexadecimal format: rrggbb\n"); 1246 errx(EXIT_FAILURE, "display-text-color is invalid, it must be given in 3-byte hexadecimal format: rrggbb\n");
1238 DEBUG("elapsed-time-color: %s\n", i3lock_elapsed_time.color); 1247 DEBUG("display-text-color: %s\n", i3lock_elapsed_time.color);
1239 break; 1248 break;
1240 } 1249 }
1241 case 'r': /* refresh-rate */ 1250 case 'r': /* refresh-rate */
@@ -1254,17 +1263,23 @@ int main(int argc, char *argv[]) {
1254 DEBUG("digital-clock-template: %s\n", 1263 DEBUG("digital-clock-template: %s\n",
1255 i3lock_digital_clock.template); 1264 i3lock_digital_clock.template);
1256 break; 1265 break;
1257 case 'W': /* elapsed-time-halign */ 1266 case 'U': /* UNIX time (epoch time) */
1267 if ((display_text_template != NULL) || (elapsed_time)) {
1268 errx(EXIT_FAILURE, "Display text, elapsed time and UNIX time are mutually exclusive options\n");
1269 }
1270 unix_time = true;
1271 break;
1272 case 'W': /* display-text-halign */
1258 /* the default is right */ 1273 /* the default is right */
1259 if (strcasecmp(optarg, "left") == 0) { 1274 if (strcasecmp(optarg, "left") == 0) {
1260 i3lock_elapsed_time.horizontal_alignment = I3LOCK_ALIGN_LEFT; 1275 i3lock_elapsed_time.horizontal_alignment = I3LOCK_ALIGN_LEFT;
1261 DEBUG("elapsed-time-halign: left\n"); 1276 DEBUG("display-text-halign: left\n");
1262 } else if (strcasecmp(optarg, "center") == 0) { 1277 } else if (strcasecmp(optarg, "center") == 0) {
1263 i3lock_elapsed_time.horizontal_alignment = I3LOCK_ALIGN_CENTER; 1278 i3lock_elapsed_time.horizontal_alignment = I3LOCK_ALIGN_CENTER;
1264 DEBUG("elapsed-time-halign: center\n"); 1279 DEBUG("display-text-halign: center\n");
1265 } else { 1280 } else {
1266 /* value already set */ 1281 /* value already set */
1267 DEBUG("elapsed-time-halign: right\n"); 1282 DEBUG("display-tex-halign: right\n");
1268 } 1283 }
1269 break; 1284 break;
1270 case 'X': /* led-clock-halign */ 1285 case 'X': /* led-clock-halign */
@@ -1319,17 +1334,17 @@ int main(int argc, char *argv[]) {
1319 DEBUG("digital-clock-valign: top\n"); 1334 DEBUG("digital-clock-valign: top\n");
1320 } 1335 }
1321 break; 1336 break;
1322 case 'Z': /* elapsed-time-valign */ 1337 case 'Z': /* display-tex-valign */
1323 /* the default is bottom */ 1338 /* the default is bottom */
1324 if (strcasecmp(optarg, "middle") == 0) { 1339 if (strcasecmp(optarg, "middle") == 0) {
1325 i3lock_elapsed_time.vertical_alignment = I3LOCK_ALIGN_MIDDLE; 1340 i3lock_elapsed_time.vertical_alignment = I3LOCK_ALIGN_MIDDLE;
1326 DEBUG("elapsed-time-valign: middle\n"); 1341 DEBUG("display-tex-valign: middle\n");
1327 } else if (strcasecmp(optarg, "top") == 0) { 1342 } else if (strcasecmp(optarg, "top") == 0) {
1328 i3lock_elapsed_time.vertical_alignment = I3LOCK_ALIGN_TOP; 1343 i3lock_elapsed_time.vertical_alignment = I3LOCK_ALIGN_TOP;
1329 DEBUG("elapsed-time-valign: top\n"); 1344 DEBUG("display-text-valign: top\n");
1330 } else { 1345 } else {
1331 /* value already set */ 1346 /* value already set */
1332 DEBUG("elapsed-time-valign: bottom\n"); 1347 DEBUG("display-text-valign: bottom\n");
1333 } 1348 }
1334 break; 1349 break;
1335#endif 1350#endif
@@ -1378,8 +1393,8 @@ int main(int argc, char *argv[]) {
1378 "[-c color] [-D] [-d] [-E] [-e] [-F color] [-f] [-k]" 1393 "[-c color] [-D] [-d] [-E] [-e] [-F color] [-f] [-k]"
1379 "[-G color] [-h] [-I timeout] [-i image.png] [-J text] " 1394 "[-G color] [-h] [-I timeout] [-i image.png] [-J text] "
1380 "[-L] [-n] [-O color] [-p win|default] [-R color] " 1395 "[-L] [-n] [-O color] [-p win|default] [-R color] "
1381 "[-r refresh rate] [-S size] [-T template] [-t] [-u] [-v] " 1396 "[-r refresh rate] [-S size] [-T template] [-t] [-U] [-u] "
1382 "[-W horizontal-alignment] [-X horizontal-alignment] " 1397 "[-v] [-W horizontal-alignment] [-X horizontal-alignment] "
1383 "[-x horizontal-alignment] [-Y vertical-alignment] " 1398 "[-x horizontal-alignment] [-Y vertical-alignment] "
1384 "[-y vertical-alignment] [-Z vertical-alignment]"); 1399 "[-y vertical-alignment] [-Z vertical-alignment]");
1385#else 1400#else