aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/config.h1
-rw-r--r--sway.1.txt3
-rw-r--r--sway/commands.c36
-rw-r--r--sway/config.c16
-rw-r--r--sway/main.c51
-rw-r--r--swaybg/main.c2
-rw-r--r--swaygrab.1.txt3
-rw-r--r--swaygrab/main.c26
-rw-r--r--swaymsg.1.txt3
-rw-r--r--swaymsg/main.c24
10 files changed, 114 insertions, 51 deletions
diff --git a/include/config.h b/include/config.h
index 6b48063a..9caadec8 100644
--- a/include/config.h
+++ b/include/config.h
@@ -98,6 +98,7 @@ bool read_config(FILE *file, bool is_active);
* Does variable replacement for a string based on the config's currently loaded variables.
*/
char *do_var_replacement(char *str);
+int output_name_cmp(const void *item, const void *data);
/** Sets up a WLC output handle based on a given output_config.
*/
void apply_output_config(struct output_config *oc, swayc_t *output);
diff --git a/sway.1.txt b/sway.1.txt
index c0715841..c80bd917 100644
--- a/sway.1.txt
+++ b/sway.1.txt
@@ -17,6 +17,9 @@ Synopsis
Options
-------
+*-h, --help*::
+ Show help message and quit.
+
*-c, \--config* <config>::
Specifies a config file.
diff --git a/sway/commands.c b/sway/commands.c
index 13fc29ad..ba42a9ae 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -714,20 +714,23 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ const char *name = argv[0];
+
struct output_config *output = calloc(1, sizeof(struct output_config));
output->x = output->y = output->width = output->height = -1;
- output->name = strdup(argv[0]);
+ output->name = strdup(name);
output->enabled = true;
// TODO: atoi doesn't handle invalid numbers
- if (strcasecmp(argv[1], "disable") == 0) {
- output->enabled = false;
- }
// TODO: Check missing params after each sub-command
int i;
for (i = 1; i < argc; ++i) {
- if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) {
+ const char *command = argv[i];
+
+ if (strcasecmp(command, "disable") == 0) {
+ output->enabled = false;
+ } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) {
char *res = argv[++i];
char *x = strchr(res, 'x');
int width = -1, height = -1;
@@ -745,7 +748,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
}
output->width = width;
output->height = height;
- } else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) {
+ } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) {
char *res = argv[++i];
char *c = strchr(res, ',');
int x = -1, y = -1;
@@ -763,7 +766,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
}
output->x = x;
output->y = y;
- } else if (strcasecmp(argv[i], "bg") == 0 || strcasecmp(argv[i], "background") == 0) {
+ } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) {
wordexp_t p;
if (++i >= argc) {
return cmd_results_new(CMD_INVALID, "output", "Missing background file.");
@@ -799,20 +802,19 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
}
}
- for (i = 0; i < config->output_configs->length; ++i) {
+ i = list_seq_find(config->output_configs, output_name_cmp, name);
+ if (i >= 0) {
+ // replace existing config
struct output_config *oc = config->output_configs->items[i];
- if (strcmp(oc->name, output->name) == 0) {
- // replace existing config
- list_del(config->output_configs, i);
- free_output_config(oc);
- break;
- }
+ list_del(config->output_configs, i);
+ free_output_config(oc);
}
list_add(config->output_configs, output);
- sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d) (bg %s %s)",
- output->name, output->width, output->height, output->x, output->y,
- output->background, output->background_option);
+ sway_log(L_DEBUG, "Config stored for output %s (%s) (%d x %d @ %d, %d) (bg %s %s)",
+ output->name, output->enabled ? "enable" : "disable", output->width,
+ output->height, output->x, output->y, output->background,
+ output->background_option);
if (output->name) {
// Try to find the output container and apply configuration now. If
diff --git a/sway/config.c b/sway/config.c
index e9785aba..dd466e5b 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -261,6 +261,14 @@ bool read_config(FILE *file, bool is_active) {
return success;
}
+int output_name_cmp(const void *item, const void *data)
+{
+ const struct output_config *output = item;
+ const char *name = data;
+
+ return strcmp(output->name, name);
+}
+
void apply_output_config(struct output_config *oc, swayc_t *output) {
if (oc && oc->width > 0 && oc->height > 0) {
output->width = oc->width;
@@ -291,12 +299,10 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
if (!oc || !oc->background) {
// Look for a * config for background
- int i;
- for (i = 0; i < config->output_configs->length; ++i) {
+ int i = list_seq_find(config->output_configs, output_name_cmp, "*");
+ if (i >= 0) {
oc = config->output_configs->items[i];
- if (strcasecmp("*", oc->name) == 0) {
- break;
- }
+ } else {
oc = NULL;
}
}
diff --git a/sway/main.c b/sway/main.c
index dd609214..c7696e2e 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -55,25 +55,41 @@ int main(int argc, char **argv) {
static int verbose = 0, debug = 0, validate = 0;
static struct option long_options[] = {
+ {"help", no_argument, NULL, 'h'},
{"config", required_argument, NULL, 'c'},
- {"validate", no_argument, &validate, 1},
- {"debug", no_argument, &debug, 1},
+ {"validate", no_argument, NULL, 'C'},
+ {"debug", no_argument, NULL, 'd'},
{"version", no_argument, NULL, 'v'},
- {"verbose", no_argument, &verbose, 1},
+ {"verbose", no_argument, NULL, 'V'},
{"get-socketpath", no_argument, NULL, 'p'},
{0, 0, 0, 0}
};
char *config_path = NULL;
+
+ const char* usage =
+ "Usage: sway [options] [command]\n"
+ "\n"
+ " -h, --help Show help message and quit.\n"
+ " -c, --config <config> Specify a config file.\n"
+ " -C, --validate Check the validity of the config file, then exit.\n"
+ " -d, --debug Enables full logging, including debug information.\n"
+ " -v, --version Show the version number and quit.\n"
+ " -V, --verbose Enables more verbose logging.\n"
+ " --get-socketpath Gets the IPC socket path and prints it, then exits.\n"
+ "\n";
+
int c;
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "CdvVpc:", long_options, &option_index);
+ c = getopt_long(argc, argv, "hCdvVpc:", long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
- case 0: // Flag
+ case 'h': // help
+ fprintf(stdout, "%s", usage);
+ exit(EXIT_SUCCESS);
break;
case 'c': // config
config_path = strdup(optarg);
@@ -90,7 +106,7 @@ int main(int argc, char **argv) {
#else
fprintf(stdout, "version not detected\n");
#endif
- exit(0);
+ exit(EXIT_SUCCESS);
break;
case 'V': // verbose
verbose = 1;
@@ -98,15 +114,26 @@ int main(int argc, char **argv) {
case 'p': ; // --get-socketpath
if (getenv("SWAYSOCK")) {
fprintf(stdout, "%s\n", getenv("SWAYSOCK"));
- exit(0);
+ exit(EXIT_SUCCESS);
} else {
fprintf(stderr, "sway socket not detected.\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
break;
+ default:
+ fprintf(stderr, "%s", usage);
+ exit(EXIT_FAILURE);
}
}
+ // we need to setup logging before wlc_init in case it fails.
+ if (debug) {
+ init_log(L_DEBUG);
+ } else if (verbose || validate) {
+ init_log(L_INFO);
+ } else {
+ init_log(L_ERROR);
+ }
setenv("WLC_DIM", "0", 0);
wlc_log_set_handler(wlc_log_handler);
detect_nvidia();
@@ -119,14 +146,6 @@ int main(int argc, char **argv) {
}
register_extensions();
- if (debug) {
- init_log(L_DEBUG);
- } else if (verbose || validate) {
- init_log(L_INFO);
- } else {
- init_log(L_ERROR);
- }
-
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#endif
diff --git a/swaybg/main.c b/swaybg/main.c
index ec64ddb7..69d718c5 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -29,7 +29,7 @@ void sway_terminate(void) {
}
list_free(surfaces);
registry_teardown(registry);
- exit(1);
+ exit(EXIT_FAILURE);
}
int main(int argc, const char **argv) {
diff --git a/swaygrab.1.txt b/swaygrab.1.txt
index 009fbe7e..cd4b8bd2 100644
--- a/swaygrab.1.txt
+++ b/swaygrab.1.txt
@@ -20,6 +20,9 @@ ImageMagick convert for processing.
Options
-------
+*-h, --help*::
+ Show help message and quit.
+
*-c, \--capture*::
Captures multiple frames as video and passes them into ffmpeg. Continues until
you send SIGTERM (ctrl+c) to swaygrab.
diff --git a/swaygrab/main.c b/swaygrab/main.c
index 63cf223f..681a6da4 100644
--- a/swaygrab/main.c
+++ b/swaygrab/main.c
@@ -10,7 +10,7 @@
#include "ipc-client.h"
void sway_terminate(void) {
- exit(1);
+ exit(EXIT_FAILURE);
}
int numlen(int n) {
@@ -127,24 +127,33 @@ int main(int argc, char **argv) {
init_log(L_INFO);
static struct option long_options[] = {
- {"capture", no_argument, &capture, 'c'},
+ {"help", no_argument, NULL, 'h'},
+ {"capture", no_argument, NULL, 'c'},
{"version", no_argument, NULL, 'v'},
{"socket", required_argument, NULL, 's'},
- {"raw", no_argument, &raw, 'r'},
+ {"raw", no_argument, NULL, 'r'},
{"rate", required_argument, NULL, 'R'},
{0, 0, 0, 0}
};
+ const char *usage =
+ "Usage: swaygrab [options] <output> [file]\n"
+ "\n"
+ " -h, --help Show help message and quit.\n"
+ " -c, --capture Capture video.\n"
+ " -v, --version Show the version number and quit.\n"
+ " -s, --socket <socket> Use the specified socket.\n"
+ " -R, --rate <rate> Specify framerate (default: 30)\n"
+ " -r, --raw Write raw rgba data to stdout.\n";
+
int c;
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "cvs:r", long_options, &option_index);
+ c = getopt_long(argc, argv, "hcvs:r", long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
- case 0: // Flag
- break;
case 's': // Socket
socket_path = strdup(optarg);
break;
@@ -163,8 +172,11 @@ int main(int argc, char **argv) {
#else
fprintf(stdout, "version not detected\n");
#endif
- exit(0);
+ exit(EXIT_SUCCESS);
break;
+ default:
+ fprintf(stderr, "%s", usage);
+ exit(EXIT_FAILURE);
}
}
diff --git a/swaymsg.1.txt b/swaymsg.1.txt
index d832dd17..984780fa 100644
--- a/swaymsg.1.txt
+++ b/swaymsg.1.txt
@@ -17,6 +17,9 @@ Synopsis
Options
-------
+*-h, --help*::
+ Show help message and quit.
+
*-q, \--quiet*::
Sends the IPC message but does not print the response from sway.
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 3a2e1ee7..f8c9e14c 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -12,7 +12,7 @@
#include "log.h"
void sway_terminate(void) {
- exit(1);
+ exit(EXIT_FAILURE);
}
int main(int argc, char **argv) {
@@ -23,22 +23,33 @@ int main(int argc, char **argv) {
init_log(L_INFO);
static struct option long_options[] = {
- {"quiet", no_argument, &quiet, 'q'},
+ {"help", no_argument, NULL, 'h'},
+ {"quiet", no_argument, NULL, 'q'},
{"version", no_argument, NULL, 'v'},
{"socket", required_argument, NULL, 's'},
{"type", required_argument, NULL, 't'},
{0, 0, 0, 0}
};
+ const char *usage =
+ "Usage: swaymsg [options] [message]\n"
+ "\n"
+ " -h, --help Show help message and quit.\n"
+ " -q, --quiet Be quiet.\n"
+ " -v, --version Show the version number and quit.\n"
+ " -s, --socket <socket> Use the specified socket.\n"
+ " -t, --type <type> Specify the message type.\n";
+
int c;
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "qvs:t:", long_options, &option_index);
+ c = getopt_long(argc, argv, "hqvs:t:", long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
- case 0: // Flag
+ case 'q': // Quiet
+ quiet = 1;
break;
case 's': // Socket
socket_path = strdup(optarg);
@@ -52,8 +63,11 @@ int main(int argc, char **argv) {
#else
fprintf(stdout, "version not detected\n");
#endif
- exit(0);
+ exit(EXIT_SUCCESS);
break;
+ default:
+ fprintf(stderr, "%s", usage);
+ exit(EXIT_FAILURE);
}
}