aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-12-28 21:15:54 -0500
committerLibravatar Simon Ser <contact@emersion.fr>2019-12-29 10:40:06 +0100
commitde43f7c1db9bb47ef042bc310fdcf2cd2b346c98 (patch)
tree5db71352762a7d2089bf060dbd12618516381b4d
parentFix typo in swaybar-protocol.7.scd (diff)
downloadsway-de43f7c1db9bb47ef042bc310fdcf2cd2b346c98.tar.gz
sway-de43f7c1db9bb47ef042bc310fdcf2cd2b346c98.tar.zst
sway-de43f7c1db9bb47ef042bc310fdcf2cd2b346c98.zip
cmd_client_*: support optional args for i3 compat
For i3 compatibility, allow the indicator and child_border colors values to be optional. The indicator will fallback to sane defaults and child_border will fallback to the background color for the class.
-rw-r--r--sway/commands/client.c38
-rw-r--r--sway/sway.5.scd15
2 files changed, 31 insertions, 22 deletions
diff --git a/sway/commands/client.c b/sway/commands/client.c
index e4282341..dd0694df 100644
--- a/sway/commands/client.c
+++ b/sway/commands/client.c
@@ -10,30 +10,34 @@ static void rebuild_textures_iterator(struct sway_container *con, void *data) {
10 container_update_title_textures(con); 10 container_update_title_textures(con);
11} 11}
12 12
13static struct cmd_results *handle_command(int argc, char **argv, 13static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name,
14 struct border_colors *class, char *cmd_name) { 14 struct border_colors *class, const char *default_indicator) {
15 struct cmd_results *error = NULL; 15 struct cmd_results *error = NULL;
16 if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 5))) { 16 if ((error = checkarg(argc, cmd_name, EXPECTED_AT_LEAST, 3)) ||
17 (error = checkarg(argc, cmd_name, EXPECTED_AT_MOST, 5))) {
17 return error; 18 return error;
18 } 19 }
19 20
20 struct border_colors colors = {0}; 21 struct border_colors colors = {0};
22 const char *ind_hex = argc > 3 ? argv[3] : default_indicator;
23 const char *child_hex = argc > 4 ? argv[4] : argv[1]; // def to background
21 24
22 struct { 25 struct {
23 const char *name; 26 const char *name;
27 const char *hex;
24 float *rgba[4]; 28 float *rgba[4];
25 } properties[] = { 29 } properties[] = {
26 { "border", colors.border }, 30 { "border", argv[0], colors.border },
27 { "background", colors.background }, 31 { "background", argv[1], colors.background },
28 { "text", colors.text }, 32 { "text", argv[2], colors.text },
29 { "indicator", colors.indicator }, 33 { "indicator", ind_hex, colors.indicator },
30 { "child_border", colors.child_border } 34 { "child_border", child_hex, colors.child_border }
31 }; 35 };
32 for (size_t i = 0; i < sizeof(properties) / sizeof(properties[0]); i++) { 36 for (size_t i = 0; i < sizeof(properties) / sizeof(properties[0]); i++) {
33 uint32_t color; 37 uint32_t color;
34 if (!parse_color(argv[i], &color)) { 38 if (!parse_color(properties[i].hex, &color)) {
35 return cmd_results_new(CMD_INVALID, 39 return cmd_results_new(CMD_INVALID, "Invalid %s color %s",
36 "Invalid %s color %s", properties[i].name, argv[i]); 40 properties[i].name, properties[i].hex);
37 } 41 }
38 color_to_rgba(*properties[i].rgba, color); 42 color_to_rgba(*properties[i].rgba, color);
39 } 43 }
@@ -53,19 +57,23 @@ static struct cmd_results *handle_command(int argc, char **argv,
53} 57}
54 58
55struct cmd_results *cmd_client_focused(int argc, char **argv) { 59struct cmd_results *cmd_client_focused(int argc, char **argv) {
56 return handle_command(argc, argv, &config->border_colors.focused, "client.focused"); 60 return handle_command(argc, argv, "client.focused",
61 &config->border_colors.focused, "#2e9ef4ff");
57} 62}
58 63
59struct cmd_results *cmd_client_focused_inactive(int argc, char **argv) { 64struct cmd_results *cmd_client_focused_inactive(int argc, char **argv) {
60 return handle_command(argc, argv, &config->border_colors.focused_inactive, "client.focused_inactive"); 65 return handle_command(argc, argv, "client.focused_inactive",
66 &config->border_colors.focused_inactive, "#484e50ff");
61} 67}
62 68
63struct cmd_results *cmd_client_unfocused(int argc, char **argv) { 69struct cmd_results *cmd_client_unfocused(int argc, char **argv) {
64 return handle_command(argc, argv, &config->border_colors.unfocused, "client.unfocused"); 70 return handle_command(argc, argv, "client.unfocused",
71 &config->border_colors.unfocused, "#292d2eff");
65} 72}
66 73
67struct cmd_results *cmd_client_urgent(int argc, char **argv) { 74struct cmd_results *cmd_client_urgent(int argc, char **argv) {
68 return handle_command(argc, argv, &config->border_colors.urgent, "client.urgent"); 75 return handle_command(argc, argv, "client.urgent",
76 &config->border_colors.urgent, "#900000ff");
69} 77}
70 78
71struct cmd_results *cmd_client_noop(int argc, char **argv) { 79struct cmd_results *cmd_client_noop(int argc, char **argv) {
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 52ee9d28..29e9809b 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -442,15 +442,16 @@ runtime.
442 bindswitch lid:toggle exec echo "Lid moved" 442 bindswitch lid:toggle exec echo "Lid moved"
443``` 443```
444 444
445*client.<class>* <border> <background> <text> <indicator> <child_border> 445*client.background* <color>
446 Configures the color of window borders and title bars. All 5 colors are 446 This command is ignored and is only present for i3 compatibility.
447 required, with the exception of *client.background*, which requires exactly
448 one. Colors may be specified in hex, either as _#RRGGBB_ or _#RRGGBBAA_.
449 447
450 The available classes are: 448*client.<class>* <border> <background> <text> [<indicator> [<child_border>]]
449 Configures the color of window borders and title bars. The first three
450 colors are required. When omitted _indicator_ will use a sane default and
451 _child_border_ will use the color set for _background_. Colors may be
452 specified in hex, either as _#RRGGBB_ or _#RRGGBBAA_.
451 453
452 *client.background* 454 The available classes are:
453 Ignored (present for i3 compatibility).
454 455
455 *client.focused* 456 *client.focused*
456 The window that has focus. 457 The window that has focus.