summaryrefslogtreecommitdiffstats
path: root/swaylock
diff options
context:
space:
mode:
authorLibravatar Christoph Gysin <christoph.gysin@gmail.com>2016-01-23 14:58:43 +0200
committerLibravatar Christoph Gysin <christoph.gysin@gmail.com>2016-01-23 16:00:14 +0200
commit259dc25ba33d6f9f05a92f9f00ce493f87f1e4c6 (patch)
treea8fff3ef7e3814930e460508b880bf7a85a250a4 /swaylock
parentMerge pull request #463 from christophgysin/typo (diff)
downloadsway-259dc25ba33d6f9f05a92f9f00ce493f87f1e4c6.tar.gz
sway-259dc25ba33d6f9f05a92f9f00ce493f87f1e4c6.tar.zst
sway-259dc25ba33d6f9f05a92f9f00ce493f87f1e4c6.zip
swaylock: add option parsing
Diffstat (limited to 'swaylock')
-rw-r--r--swaylock/main.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 9de95e7a..0bf64621 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -7,6 +7,7 @@
7#include <string.h> 7#include <string.h>
8#include <sys/types.h> 8#include <sys/types.h>
9#include <pwd.h> 9#include <pwd.h>
10#include <getopt.h>
10#include "client/window.h" 11#include "client/window.h"
11#include "client/registry.h" 12#include "client/registry.h"
12#include "client/cairo.h" 13#include "client/cairo.h"
@@ -92,6 +93,44 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
92 93
93int main(int argc, char **argv) { 94int main(int argc, char **argv) {
94 init_log(L_INFO); 95 init_log(L_INFO);
96
97 static struct option long_options[] = {
98 {"help", no_argument, NULL, 'h'},
99 {"version", no_argument, NULL, 'v'},
100 {0, 0, 0, 0}
101 };
102
103 const char *usage =
104 "Usage: swaylock <image> [stretch|fit|fill|center|tile]\n"
105 "\n"
106 " -h, --help Show help message and quit.\n"
107 " -v, --version Show the version number and quit.\n";
108
109 int c;
110 while (1) {
111 int option_index = 0;
112 c = getopt_long(argc, argv, "hv", long_options, &option_index);
113 if (c == -1) {
114 break;
115 }
116 switch (c) {
117 case 'v':
118#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
119 fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
120#else
121 fprintf(stdout, "version not detected\n");
122#endif
123 exit(EXIT_SUCCESS);
124 break;
125 default:
126 fprintf(stderr, "%s", usage);
127 exit(EXIT_FAILURE);
128 }
129 }
130
131 char *image_path = argv[optind];
132 char *scaling_mode_str = argv[optind+1];
133
95 password = malloc(1024); // TODO: Let this grow 134 password = malloc(1024); // TODO: Let this grow
96 password[0] = '\0'; 135 password[0] = '\0';
97 surfaces = create_list(); 136 surfaces = create_list();
@@ -115,7 +154,7 @@ int main(int argc, char **argv) {
115 154
116#ifdef WITH_GDK_PIXBUF 155#ifdef WITH_GDK_PIXBUF
117 GError *err = NULL; 156 GError *err = NULL;
118 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments 157 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(image_path, &err); // TODO: Parse i3lock arguments
119 if (!pixbuf) { 158 if (!pixbuf) {
120 sway_abort("Failed to load background image."); 159 sway_abort("Failed to load background image.");
121 } 160 }
@@ -130,7 +169,6 @@ int main(int argc, char **argv) {
130 double width = cairo_image_surface_get_width(image); 169 double width = cairo_image_surface_get_width(image);
131 double height = cairo_image_surface_get_height(image); 170 double height = cairo_image_surface_get_height(image);
132 171
133 const char *scaling_mode_str = argv[2];
134 enum scaling_mode scaling_mode = SCALING_MODE_STRETCH; 172 enum scaling_mode scaling_mode = SCALING_MODE_STRETCH;
135 if (strcmp(scaling_mode_str, "stretch") == 0) { 173 if (strcmp(scaling_mode_str, "stretch") == 0) {
136 scaling_mode = SCALING_MODE_STRETCH; 174 scaling_mode = SCALING_MODE_STRETCH;