summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2016-01-23 14:27:28 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2016-01-23 14:27:28 -0500
commitf8de29baf6ec1b1ab598b96867f9c499e094f3bb (patch)
tree1fd790b3f921f5283babd1365c2ee439ebb550c0
parentMerge pull request #465 from sardemff7/master (diff)
parentswaylock: add i3lock compatible options (diff)
downloadsway-f8de29baf6ec1b1ab598b96867f9c499e094f3bb.tar.gz
sway-f8de29baf6ec1b1ab598b96867f9c499e094f3bb.tar.zst
sway-f8de29baf6ec1b1ab598b96867f9c499e094f3bb.zip
Merge pull request #464 from christophgysin/swaylock
swaylock: option parsing
-rw-r--r--swaylock/main.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 9de95e7a..c01445e7 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"
@@ -91,7 +92,66 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
91} 92}
92 93
93int main(int argc, char **argv) { 94int main(int argc, char **argv) {
95 char *image_path = NULL;
96 char *scaling_mode_str = "fit";
97
94 init_log(L_INFO); 98 init_log(L_INFO);
99
100 static struct option long_options[] = {
101 {"help", no_argument, NULL, 'h'},
102 {"image", required_argument, NULL, 'i'},
103 {"scaling", required_argument, NULL, 's'},
104 {"tiling", no_argument, NULL, 't'},
105 {"version", no_argument, NULL, 'v'},
106 {0, 0, 0, 0}
107 };
108
109 const char *usage =
110 "Usage: swaylock [options...]\n"
111 "\n"
112 " -h, --help Show help message 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";
117
118 int c;
119 while (1) {
120 int option_index = 0;
121 c = getopt_long(argc, argv, "hi:s:tv", long_options, &option_index);
122 if (c == -1) {
123 break;
124 }
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;
135 case 'v':
136#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
137 fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
138#else
139 fprintf(stdout, "version not detected\n");
140#endif
141 exit(EXIT_SUCCESS);
142 break;
143 default:
144 fprintf(stderr, "%s", usage);
145 exit(EXIT_FAILURE);
146 }
147 }
148
149 // TODO: support locking without image
150 if (!image_path) {
151 fprintf(stderr, "No image specified!\n");
152 exit(EXIT_FAILURE);
153 }
154
95 password = malloc(1024); // TODO: Let this grow 155 password = malloc(1024); // TODO: Let this grow
96 password[0] = '\0'; 156 password[0] = '\0';
97 surfaces = create_list(); 157 surfaces = create_list();
@@ -115,7 +175,7 @@ int main(int argc, char **argv) {
115 175
116#ifdef WITH_GDK_PIXBUF 176#ifdef WITH_GDK_PIXBUF
117 GError *err = NULL; 177 GError *err = NULL;
118 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments 178 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(image_path, &err);
119 if (!pixbuf) { 179 if (!pixbuf) {
120 sway_abort("Failed to load background image."); 180 sway_abort("Failed to load background image.");
121 } 181 }
@@ -130,7 +190,6 @@ int main(int argc, char **argv) {
130 double width = cairo_image_surface_get_width(image); 190 double width = cairo_image_surface_get_width(image);
131 double height = cairo_image_surface_get_height(image); 191 double height = cairo_image_surface_get_height(image);
132 192
133 const char *scaling_mode_str = argv[2];
134 enum scaling_mode scaling_mode = SCALING_MODE_STRETCH; 193 enum scaling_mode scaling_mode = SCALING_MODE_STRETCH;
135 if (strcmp(scaling_mode_str, "stretch") == 0) { 194 if (strcmp(scaling_mode_str, "stretch") == 0) {
136 scaling_mode = SCALING_MODE_STRETCH; 195 scaling_mode = SCALING_MODE_STRETCH;