diff options
author | Christoph Gysin <christoph.gysin@gmail.com> | 2016-01-23 15:16:36 +0200 |
---|---|---|
committer | Christoph Gysin <christoph.gysin@gmail.com> | 2016-01-23 16:36:19 +0200 |
commit | 7b25caba47af4b2755f675c1326e27e9d51ffa1c (patch) | |
tree | 2bba8b750bc2c90548524691a3a0d8da9eb2f63c /swaylock | |
parent | swaylock: add option parsing (diff) | |
download | sway-7b25caba47af4b2755f675c1326e27e9d51ffa1c.tar.gz sway-7b25caba47af4b2755f675c1326e27e9d51ffa1c.tar.zst sway-7b25caba47af4b2755f675c1326e27e9d51ffa1c.zip |
swaylock: add i3lock compatible options
Diffstat (limited to 'swaylock')
-rw-r--r-- | swaylock/main.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 0bf64621..c01445e7 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -92,28 +92,46 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod | |||
92 | } | 92 | } |
93 | 93 | ||
94 | int main(int argc, char **argv) { | 94 | int main(int argc, char **argv) { |
95 | char *image_path = NULL; | ||
96 | char *scaling_mode_str = "fit"; | ||
97 | |||
95 | init_log(L_INFO); | 98 | init_log(L_INFO); |
96 | 99 | ||
97 | static struct option long_options[] = { | 100 | static struct option long_options[] = { |
98 | {"help", no_argument, NULL, 'h'}, | 101 | {"help", no_argument, NULL, 'h'}, |
102 | {"image", required_argument, NULL, 'i'}, | ||
103 | {"scaling", required_argument, NULL, 's'}, | ||
104 | {"tiling", no_argument, NULL, 't'}, | ||
99 | {"version", no_argument, NULL, 'v'}, | 105 | {"version", no_argument, NULL, 'v'}, |
100 | {0, 0, 0, 0} | 106 | {0, 0, 0, 0} |
101 | }; | 107 | }; |
102 | 108 | ||
103 | const char *usage = | 109 | const char *usage = |
104 | "Usage: swaylock <image> [stretch|fit|fill|center|tile]\n" | 110 | "Usage: swaylock [options...]\n" |
105 | "\n" | 111 | "\n" |
106 | " -h, --help Show help message and quit.\n" | 112 | " -h, --help Show help message and quit.\n" |
107 | " -v, --version Show the version number and quit.\n"; | 113 | " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n" |
114 | " -t, --tiling Same as --scaling=tile.\n" | ||
115 | " -v, --version Show the version number and quit.\n" | ||
116 | " -i, --image <path> Display the given image.\n"; | ||
108 | 117 | ||
109 | int c; | 118 | int c; |
110 | while (1) { | 119 | while (1) { |
111 | int option_index = 0; | 120 | int option_index = 0; |
112 | c = getopt_long(argc, argv, "hv", long_options, &option_index); | 121 | c = getopt_long(argc, argv, "hi:s:tv", long_options, &option_index); |
113 | if (c == -1) { | 122 | if (c == -1) { |
114 | break; | 123 | break; |
115 | } | 124 | } |
116 | switch (c) { | 125 | switch (c) { |
126 | case 'i': | ||
127 | image_path = optarg; | ||
128 | break; | ||
129 | case 's': | ||
130 | scaling_mode_str = optarg; | ||
131 | break; | ||
132 | case 't': | ||
133 | scaling_mode_str = "tile"; | ||
134 | break; | ||
117 | case 'v': | 135 | case 'v': |
118 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE | 136 | #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); | 137 | fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); |
@@ -128,8 +146,11 @@ int main(int argc, char **argv) { | |||
128 | } | 146 | } |
129 | } | 147 | } |
130 | 148 | ||
131 | char *image_path = argv[optind]; | 149 | // TODO: support locking without image |
132 | char *scaling_mode_str = argv[optind+1]; | 150 | if (!image_path) { |
151 | fprintf(stderr, "No image specified!\n"); | ||
152 | exit(EXIT_FAILURE); | ||
153 | } | ||
133 | 154 | ||
134 | password = malloc(1024); // TODO: Let this grow | 155 | password = malloc(1024); // TODO: Let this grow |
135 | password[0] = '\0'; | 156 | password[0] = '\0'; |
@@ -154,7 +175,7 @@ int main(int argc, char **argv) { | |||
154 | 175 | ||
155 | #ifdef WITH_GDK_PIXBUF | 176 | #ifdef WITH_GDK_PIXBUF |
156 | GError *err = NULL; | 177 | GError *err = NULL; |
157 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(image_path, &err); // TODO: Parse i3lock arguments | 178 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(image_path, &err); |
158 | if (!pixbuf) { | 179 | if (!pixbuf) { |
159 | sway_abort("Failed to load background image."); | 180 | sway_abort("Failed to load background image."); |
160 | } | 181 | } |