diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-04-03 00:47:45 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-04-04 21:57:05 -0400 |
commit | fc9398a42e1dfc15bbb8490c049981034abb4926 (patch) | |
tree | 490f5c672ea2362b1b4cf4e34e13232df0502270 /sway/commands | |
parent | Merge pull request #1705 from swaywm/swaylock-layers (diff) | |
download | sway-fc9398a42e1dfc15bbb8490c049981034abb4926.tar.gz sway-fc9398a42e1dfc15bbb8490c049981034abb4926.tar.zst sway-fc9398a42e1dfc15bbb8490c049981034abb4926.zip |
Implement opacity command
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/opacity.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sway/commands/opacity.c b/sway/commands/opacity.c new file mode 100644 index 00000000..b8cd1f09 --- /dev/null +++ b/sway/commands/opacity.c | |||
@@ -0,0 +1,39 @@ | |||
1 | #include <assert.h> | ||
2 | #include <stdlib.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/tree/view.h" | ||
5 | #include "log.h" | ||
6 | |||
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) { | ||
17 | struct cmd_results *error = NULL; | ||
18 | if ((error = checkarg(argc, "layout", EXPECTED_EQUAL_TO, 1))) { | ||
19 | return error; | ||
20 | } | ||
21 | |||
22 | struct sway_container *con = | ||
23 | config->handler_context.current_container; | ||
24 | |||
25 | float opacity = 0.0f; | ||
26 | |||
27 | if (!parse_opacity(argv[0], &opacity)) { | ||
28 | return cmd_results_new(CMD_INVALID, "opacity <value>", | ||
29 | "Invalid value (expected 0..1): %s", argv[0]); | ||
30 | } | ||
31 | |||
32 | con->alpha = opacity; | ||
33 | |||
34 | if (con->type == C_VIEW) { | ||
35 | view_damage_whole(con->sway_view); | ||
36 | } | ||
37 | |||
38 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
39 | } | ||