aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/opacity.c
diff options
context:
space:
mode:
authorLibravatar Jeff Peeler <jpeeler@gmail.com>2019-07-15 10:06:05 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-08-05 22:10:36 -0400
commit140ce785fe52c511b220a0d74997466c995db695 (patch)
treebd7cfa0c6d2422691443e28aa18e80a270e35ccd /sway/commands/opacity.c
parentinput/libinput: typo fixes (get -> get_default) (diff)
downloadsway-140ce785fe52c511b220a0d74997466c995db695.tar.gz
sway-140ce785fe52c511b220a0d74997466c995db695.tar.zst
sway-140ce785fe52c511b220a0d74997466c995db695.zip
cmd_opacity: add relative opacity changes
This enhances the opacity command to support relative assignment as well as the currently implemented absolute assignment. The syntax is copied from the same format that gaps uses for relative and absolute setting. An example usage in a sway config looks like: // relative change (this feature) bindsym button4 opacity plus .1 bindsym button5 opacity minus .1 // absolute change (this feature) bindsym button4 opacity set 1 bindsym button5 opacity set .3 // old way, still supported bindsym button4 opacity 1 bindsym button5 opacity .3
Diffstat (limited to 'sway/commands/opacity.c')
-rw-r--r--sway/commands/opacity.c33
1 files changed, 18 insertions, 15 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
7static 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
16struct cmd_results *cmd_opacity(int argc, char **argv) { 8struct 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}