aboutsummaryrefslogtreecommitdiffstats
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.c35
-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, 106 insertions, 43 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);
98 * Does variable replacement for a string based on the config's currently loaded variables. 98 * Does variable replacement for a string based on the config's currently loaded variables.
99 */ 99 */
100char *do_var_replacement(char *str); 100char *do_var_replacement(char *str);
101int output_name_cmp(const void *item, const void *data);
101/** Sets up a WLC output handle based on a given output_config. 102/** Sets up a WLC output handle based on a given output_config.
102 */ 103 */
103void apply_output_config(struct output_config *oc, swayc_t *output); 104void 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
17Options 17Options
18------- 18-------
19 19
20*-h, --help*::
21 Show help message and quit.
22
20*-c, \--config* <config>:: 23*-c, \--config* <config>::
21 Specifies a config file. 24 Specifies a config file.
22 25
diff --git a/sway/commands.c b/sway/commands.c
index 42845f65..e00cc94d 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -716,20 +716,23 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
716 if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { 716 if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) {
717 return error; 717 return error;
718 } 718 }
719 const char *name = argv[0];
720
719 struct output_config *output = calloc(1, sizeof(struct output_config)); 721 struct output_config *output = calloc(1, sizeof(struct output_config));
720 output->x = output->y = output->width = output->height = -1; 722 output->x = output->y = output->width = output->height = -1;
721 output->name = strdup(argv[0]); 723 output->name = strdup(name);
722 output->enabled = true; 724 output->enabled = true;
723 725
724 // TODO: atoi doesn't handle invalid numbers 726 // TODO: atoi doesn't handle invalid numbers
725 if (strcasecmp(argv[1], "disable") == 0) {
726 output->enabled = false;
727 }
728 // TODO: Check missing params after each sub-command 727 // TODO: Check missing params after each sub-command
729 728
730 int i; 729 int i;
731 for (i = 1; i < argc; ++i) { 730 for (i = 1; i < argc; ++i) {
732 if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) { 731 const char *command = argv[i];
732
733 if (strcasecmp(command, "disable") == 0) {
734 output->enabled = false;
735 } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) {
733 char *res = argv[++i]; 736 char *res = argv[++i];
734 char *x = strchr(res, 'x'); 737 char *x = strchr(res, 'x');
735 int width = -1, height = -1; 738 int width = -1, height = -1;
@@ -747,7 +750,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
747 } 750 }
748 output->width = width; 751 output->width = width;
749 output->height = height; 752 output->height = height;
750 } else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) { 753 } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) {
751 char *res = argv[++i]; 754 char *res = argv[++i];
752 char *c = strchr(res, ','); 755 char *c = strchr(res, ',');
753 int x = -1, y = -1; 756 int x = -1, y = -1;
@@ -765,7 +768,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
765 } 768 }
766 output->x = x; 769 output->x = x;
767 output->y = y; 770 output->y = y;
768 } else if (strcasecmp(argv[i], "bg") == 0 || strcasecmp(argv[i], "background") == 0) { 771 } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) {
769 wordexp_t p; 772 wordexp_t p;
770 if (++i >= argc) { 773 if (++i >= argc) {
771 return cmd_results_new(CMD_INVALID, "output", "Missing background file."); 774 return cmd_results_new(CMD_INVALID, "output", "Missing background file.");
@@ -801,20 +804,19 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
801 } 804 }
802 } 805 }
803 806
804 for (i = 0; i < config->output_configs->length; ++i) { 807 i = list_seq_find(config->output_configs, output_name_cmp, name);
808 if (i >= 0) {
809 // replace existing config
805 struct output_config *oc = config->output_configs->items[i]; 810 struct output_config *oc = config->output_configs->items[i];
806 if (strcmp(oc->name, output->name) == 0) { 811 list_del(config->output_configs, i);
807 // replace existing config 812 free_output_config(oc);
808 list_del(config->output_configs, i);
809 free_output_config(oc);
810 break;
811 }
812 } 813 }
813 list_add(config->output_configs, output); 814 list_add(config->output_configs, output);
814 815
815 sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d) (bg %s %s)", 816 sway_log(L_DEBUG, "Config stored for output %s (%s) (%d x %d @ %d, %d) (bg %s %s)",
816 output->name, output->width, output->height, output->x, output->y, 817 output->name, output->enabled ? "enable" : "disable", output->width,
817 output->background, output->background_option); 818 output->height, output->x, output->y, output->background,
819 output->background_option);
818 820
819 if (output->name) { 821 if (output->name) {
820 // Try to find the output container and apply configuration now. If 822 // 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) {
261 return success; 261 return success;
262} 262}
263 263
264int output_name_cmp(const void *item, const void *data)
265{
266 const struct output_config *output = item;
267 const char *name = data;
268
269 return strcmp(output->name, name);
270}
271
264void apply_output_config(struct output_config *oc, swayc_t *output) { 272void apply_output_config(struct output_config *oc, swayc_t *output) {
265 if (oc && oc->width > 0 && oc->height > 0) { 273 if (oc && oc->width > 0 && oc->height > 0) {
266 output->width = oc->width; 274 output->width = oc->width;
@@ -291,12 +299,10 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
291 299
292 if (!oc || !oc->background) { 300 if (!oc || !oc->background) {
293 // Look for a * config for background 301 // Look for a * config for background
294 int i; 302 int i = list_seq_find(config->output_configs, output_name_cmp, "*");
295 for (i = 0; i < config->output_configs->length; ++i) { 303 if (i >= 0) {
296 oc = config->output_configs->items[i]; 304 oc = config->output_configs->items[i];
297 if (strcasecmp("*", oc->name) == 0) { 305 } else {
298 break;
299 }
300 oc = NULL; 306 oc = NULL;
301 } 307 }
302 } 308 }
diff --git a/sway/main.c b/sway/main.c
index 1a4087d3..c7696e2e 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -55,25 +55,41 @@ int main(int argc, char **argv) {
55 static int verbose = 0, debug = 0, validate = 0; 55 static int verbose = 0, debug = 0, validate = 0;
56 56
57 static struct option long_options[] = { 57 static struct option long_options[] = {
58 {"help", no_argument, NULL, 'h'},
58 {"config", required_argument, NULL, 'c'}, 59 {"config", required_argument, NULL, 'c'},
59 {"validate", no_argument, &validate, 1}, 60 {"validate", no_argument, NULL, 'C'},
60 {"debug", no_argument, &debug, 1}, 61 {"debug", no_argument, NULL, 'd'},
61 {"version", no_argument, NULL, 'v'}, 62 {"version", no_argument, NULL, 'v'},
62 {"verbose", no_argument, &verbose, 1}, 63 {"verbose", no_argument, NULL, 'V'},
63 {"get-socketpath", no_argument, NULL, 'p'}, 64 {"get-socketpath", no_argument, NULL, 'p'},
64 {0, 0, 0, 0} 65 {0, 0, 0, 0}
65 }; 66 };
66 67
67 char *config_path = NULL; 68 char *config_path = NULL;
69
70 const char* usage =
71 "Usage: sway [options] [command]\n"
72 "\n"
73 " -h, --help Show help message and quit.\n"
74 " -c, --config <config> Specify a config file.\n"
75 " -C, --validate Check the validity of the config file, then exit.\n"
76 " -d, --debug Enables full logging, including debug information.\n"
77 " -v, --version Show the version number and quit.\n"
78 " -V, --verbose Enables more verbose logging.\n"
79 " --get-socketpath Gets the IPC socket path and prints it, then exits.\n"
80 "\n";
81
68 int c; 82 int c;
69 while (1) { 83 while (1) {
70 int option_index = 0; 84 int option_index = 0;
71 c = getopt_long(argc, argv, "CdvVpc:", long_options, &option_index); 85 c = getopt_long(argc, argv, "hCdvVpc:", long_options, &option_index);
72 if (c == -1) { 86 if (c == -1) {
73 break; 87 break;
74 } 88 }
75 switch (c) { 89 switch (c) {
76 case 0: // Flag 90 case 'h': // help
91 fprintf(stdout, "%s", usage);
92 exit(EXIT_SUCCESS);
77 break; 93 break;
78 case 'c': // config 94 case 'c': // config
79 config_path = strdup(optarg); 95 config_path = strdup(optarg);
@@ -90,7 +106,7 @@ int main(int argc, char **argv) {
90#else 106#else
91 fprintf(stdout, "version not detected\n"); 107 fprintf(stdout, "version not detected\n");
92#endif 108#endif
93 exit(0); 109 exit(EXIT_SUCCESS);
94 break; 110 break;
95 case 'V': // verbose 111 case 'V': // verbose
96 verbose = 1; 112 verbose = 1;
@@ -98,12 +114,15 @@ int main(int argc, char **argv) {
98 case 'p': ; // --get-socketpath 114 case 'p': ; // --get-socketpath
99 if (getenv("SWAYSOCK")) { 115 if (getenv("SWAYSOCK")) {
100 fprintf(stdout, "%s\n", getenv("SWAYSOCK")); 116 fprintf(stdout, "%s\n", getenv("SWAYSOCK"));
101 exit(0); 117 exit(EXIT_SUCCESS);
102 } else { 118 } else {
103 fprintf(stderr, "sway socket not detected.\n"); 119 fprintf(stderr, "sway socket not detected.\n");
104 exit(1); 120 exit(EXIT_FAILURE);
105 } 121 }
106 break; 122 break;
123 default:
124 fprintf(stderr, "%s", usage);
125 exit(EXIT_FAILURE);
107 } 126 }
108 } 127 }
109 128
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) {
29 } 29 }
30 list_free(surfaces); 30 list_free(surfaces);
31 registry_teardown(registry); 31 registry_teardown(registry);
32 exit(1); 32 exit(EXIT_FAILURE);
33} 33}
34 34
35int main(int argc, const char **argv) { 35int 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.
20Options 20Options
21------- 21-------
22 22
23*-h, --help*::
24 Show help message and quit.
25
23*-c, \--capture*:: 26*-c, \--capture*::
24 Captures multiple frames as video and passes them into ffmpeg. Continues until 27 Captures multiple frames as video and passes them into ffmpeg. Continues until
25 you send SIGTERM (ctrl+c) to swaygrab. 28 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 @@
10#include "ipc-client.h" 10#include "ipc-client.h"
11 11
12void sway_terminate(void) { 12void sway_terminate(void) {
13 exit(1); 13 exit(EXIT_FAILURE);
14} 14}
15 15
16int numlen(int n) { 16int numlen(int n) {
@@ -127,24 +127,33 @@ int main(int argc, char **argv) {
127 init_log(L_INFO); 127 init_log(L_INFO);
128 128
129 static struct option long_options[] = { 129 static struct option long_options[] = {
130 {"capture", no_argument, &capture, 'c'}, 130 {"help", no_argument, NULL, 'h'},
131 {"capture", no_argument, NULL, 'c'},
131 {"version", no_argument, NULL, 'v'}, 132 {"version", no_argument, NULL, 'v'},
132 {"socket", required_argument, NULL, 's'}, 133 {"socket", required_argument, NULL, 's'},
133 {"raw", no_argument, &raw, 'r'}, 134 {"raw", no_argument, NULL, 'r'},
134 {"rate", required_argument, NULL, 'R'}, 135 {"rate", required_argument, NULL, 'R'},
135 {0, 0, 0, 0} 136 {0, 0, 0, 0}
136 }; 137 };
137 138
139 const char *usage =
140 "Usage: swaygrab [options] <output> [file]\n"
141 "\n"
142 " -h, --help Show help message and quit.\n"
143 " -c, --capture Capture video.\n"
144 " -v, --version Show the version number and quit.\n"
145 " -s, --socket <socket> Use the specified socket.\n"
146 " -R, --rate <rate> Specify framerate (default: 30)\n"
147 " -r, --raw Write raw rgba data to stdout.\n";
148
138 int c; 149 int c;
139 while (1) { 150 while (1) {
140 int option_index = 0; 151 int option_index = 0;
141 c = getopt_long(argc, argv, "cvs:r", long_options, &option_index); 152 c = getopt_long(argc, argv, "hcvs:r", long_options, &option_index);
142 if (c == -1) { 153 if (c == -1) {
143 break; 154 break;
144 } 155 }
145 switch (c) { 156 switch (c) {
146 case 0: // Flag
147 break;
148 case 's': // Socket 157 case 's': // Socket
149 socket_path = strdup(optarg); 158 socket_path = strdup(optarg);
150 break; 159 break;
@@ -163,8 +172,11 @@ int main(int argc, char **argv) {
163#else 172#else
164 fprintf(stdout, "version not detected\n"); 173 fprintf(stdout, "version not detected\n");
165#endif 174#endif
166 exit(0); 175 exit(EXIT_SUCCESS);
167 break; 176 break;
177 default:
178 fprintf(stderr, "%s", usage);
179 exit(EXIT_FAILURE);
168 } 180 }
169 } 181 }
170 182
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
17Options 17Options
18------- 18-------
19 19
20*-h, --help*::
21 Show help message and quit.
22
20*-q, \--quiet*:: 23*-q, \--quiet*::
21 Sends the IPC message but does not print the response from sway. 24 Sends the IPC message but does not print the response from sway.
22 25
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 @@
12#include "log.h" 12#include "log.h"
13 13
14void sway_terminate(void) { 14void sway_terminate(void) {
15 exit(1); 15 exit(EXIT_FAILURE);
16} 16}
17 17
18int main(int argc, char **argv) { 18int main(int argc, char **argv) {
@@ -23,22 +23,33 @@ int main(int argc, char **argv) {
23 init_log(L_INFO); 23 init_log(L_INFO);
24 24
25 static struct option long_options[] = { 25 static struct option long_options[] = {
26 {"quiet", no_argument, &quiet, 'q'}, 26 {"help", no_argument, NULL, 'h'},
27 {"quiet", no_argument, NULL, 'q'},
27 {"version", no_argument, NULL, 'v'}, 28 {"version", no_argument, NULL, 'v'},
28 {"socket", required_argument, NULL, 's'}, 29 {"socket", required_argument, NULL, 's'},
29 {"type", required_argument, NULL, 't'}, 30 {"type", required_argument, NULL, 't'},
30 {0, 0, 0, 0} 31 {0, 0, 0, 0}
31 }; 32 };
32 33
34 const char *usage =
35 "Usage: swaymsg [options] [message]\n"
36 "\n"
37 " -h, --help Show help message and quit.\n"
38 " -q, --quiet Be quiet.\n"
39 " -v, --version Show the version number and quit.\n"
40 " -s, --socket <socket> Use the specified socket.\n"
41 " -t, --type <type> Specify the message type.\n";
42
33 int c; 43 int c;
34 while (1) { 44 while (1) {
35 int option_index = 0; 45 int option_index = 0;
36 c = getopt_long(argc, argv, "qvs:t:", long_options, &option_index); 46 c = getopt_long(argc, argv, "hqvs:t:", long_options, &option_index);
37 if (c == -1) { 47 if (c == -1) {
38 break; 48 break;
39 } 49 }
40 switch (c) { 50 switch (c) {
41 case 0: // Flag 51 case 'q': // Quiet
52 quiet = 1;
42 break; 53 break;
43 case 's': // Socket 54 case 's': // Socket
44 socket_path = strdup(optarg); 55 socket_path = strdup(optarg);
@@ -52,8 +63,11 @@ int main(int argc, char **argv) {
52#else 63#else
53 fprintf(stdout, "version not detected\n"); 64 fprintf(stdout, "version not detected\n");
54#endif 65#endif
55 exit(0); 66 exit(EXIT_SUCCESS);
56 break; 67 break;
68 default:
69 fprintf(stderr, "%s", usage);
70 exit(EXIT_FAILURE);
57 } 71 }
58 } 72 }
59 73