diff options
-rw-r--r-- | sway/commands/opacity.c | 33 | ||||
-rw-r--r-- | sway/sway.5.scd | 6 |
2 files changed, 21 insertions, 18 deletions
diff --git a/sway/commands/opacity.c b/sway/commands/opacity.c index 14a07051..96e6228e 100644 --- a/sway/commands/opacity.c +++ b/sway/commands/opacity.c | |||
@@ -1,21 +1,13 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <strings.h> | ||
3 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
4 | #include "sway/tree/view.h" | 5 | #include "sway/tree/view.h" |
5 | #include "log.h" | 6 | #include "log.h" |
6 | 7 | ||
7 | static bool parse_opacity(const char *opacity, float *val) { | ||
8 | char *err; | ||
9 | *val = strtof(opacity, &err); | ||
10 | if (*val < 0 || *val > 1 || *err) { | ||
11 | return false; | ||
12 | } | ||
13 | return true; | ||
14 | } | ||
15 | |||
16 | struct cmd_results *cmd_opacity(int argc, char **argv) { | 8 | struct cmd_results *cmd_opacity(int argc, char **argv) { |
17 | struct cmd_results *error = NULL; | 9 | struct cmd_results *error = NULL; |
18 | if ((error = checkarg(argc, "opacity", EXPECTED_EQUAL_TO, 1))) { | 10 | if ((error = checkarg(argc, "opacity", EXPECTED_AT_LEAST, 1))) { |
19 | return error; | 11 | return error; |
20 | } | 12 | } |
21 | 13 | ||
@@ -25,15 +17,26 @@ struct cmd_results *cmd_opacity(int argc, char **argv) { | |||
25 | return cmd_results_new(CMD_FAILURE, "No current container"); | 17 | return cmd_results_new(CMD_FAILURE, "No current container"); |
26 | } | 18 | } |
27 | 19 | ||
28 | float opacity = 0.0f; | 20 | char *err; |
21 | float val = strtof(argc == 1 ? argv[0] : argv[1], &err); | ||
22 | if (*err) { | ||
23 | return cmd_results_new(CMD_INVALID, "opacity float invalid"); | ||
24 | } | ||
29 | 25 | ||
30 | if (!parse_opacity(argv[0], &opacity)) { | 26 | if (!strcasecmp(argv[0], "plus")) { |
27 | val = con->alpha + val; | ||
28 | } else if (!strcasecmp(argv[0], "minus")) { | ||
29 | val = con->alpha - val; | ||
30 | } else if (argc > 1 && strcasecmp(argv[0], "set")) { | ||
31 | return cmd_results_new(CMD_INVALID, | 31 | return cmd_results_new(CMD_INVALID, |
32 | "Invalid value (expected 0..1): %s", argv[0]); | 32 | "Expected: set|plus|minus <0..1>: %s", argv[0]); |
33 | } | 33 | } |
34 | 34 | ||
35 | con->alpha = opacity; | 35 | if (val < 0 || val > 1) { |
36 | container_damage_whole(con); | 36 | return cmd_results_new(CMD_FAILURE, "opacity value out of bounds"); |
37 | } | ||
37 | 38 | ||
39 | con->alpha = val; | ||
40 | container_damage_whole(con); | ||
38 | return cmd_results_new(CMD_SUCCESS, NULL); | 41 | return cmd_results_new(CMD_SUCCESS, NULL); |
39 | } | 42 | } |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 3e445e0e..768f125e 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -664,9 +664,9 @@ The default colors are: | |||
664 | Any mark that starts with an underscore will not be drawn even if | 664 | Any mark that starts with an underscore will not be drawn even if |
665 | *show_marks* is yes. The default is _yes_. | 665 | *show_marks* is yes. The default is _yes_. |
666 | 666 | ||
667 | *opacity* <value> | 667 | *opacity* [set|plus|minus] <value> |
668 | Set the opacity of the window between 0 (completely transparent) and 1 | 668 | Adjusts the opacity of the window between 0 (completely transparent) and |
669 | (completely opaque). | 669 | 1 (completely opaque). If the operation is omitted, _set_ will be used. |
670 | 670 | ||
671 | *tiling_drag* enable|disable|toggle | 671 | *tiling_drag* enable|disable|toggle |
672 | Sets whether or not tiling containers can be dragged with the mouse. If | 672 | Sets whether or not tiling containers can be dragged with the mouse. If |