summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-12-14 11:25:31 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-12-14 11:25:31 -0500
commit2be742d02d8dd26e111713d9bb52cd240d7d630b (patch)
tree84a5091db97f6c14515ce871922c431c0fe9eaca
parentMerge pull request #316 from Streetwalrus/fglrx (diff)
parentAdd bar id to debug logs (diff)
downloadsway-2be742d02d8dd26e111713d9bb52cd240d7d630b.tar.gz
sway-2be742d02d8dd26e111713d9bb52cd240d7d630b.tar.zst
sway-2be742d02d8dd26e111713d9bb52cd240d7d630b.zip
Merge pull request #314 from mikkeloscar/bar-id
Add initial support for custom bar-id
-rw-r--r--common/CMakeLists.txt1
-rw-r--r--common/util.c15
-rw-r--r--include/config.h7
-rw-r--r--include/util.h5
-rw-r--r--sway/CMakeLists.txt1
-rw-r--r--sway/commands.c26
-rw-r--r--sway/util.c5
-rw-r--r--swaygrab/main.c11
8 files changed, 48 insertions, 23 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index f7d44ec5..a40f096d 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -2,6 +2,7 @@ add_library(sway-common
2 ipc-client.c 2 ipc-client.c
3 list.c 3 list.c
4 log.c 4 log.c
5 util.c
5 readline.c 6 readline.c
6 stringop.c 7 stringop.c
7 ) 8 )
diff --git a/common/util.c b/common/util.c
new file mode 100644
index 00000000..ed6d033f
--- /dev/null
+++ b/common/util.c
@@ -0,0 +1,15 @@
1#include "util.h"
2
3int wrap(int i, int max) {
4 return ((i % max) + max) % max;
5}
6
7int numlen(int n) {
8 if (n >= 1000000) return 7;
9 if (n >= 100000) return 6;
10 if (n >= 10000) return 5;
11 if (n >= 1000) return 4;
12 if (n >= 100) return 3;
13 if (n >= 10) return 2;
14 return 1;
15}
diff --git a/include/config.h b/include/config.h
index 04528e27..0f3ce550 100644
--- a/include/config.h
+++ b/include/config.h
@@ -72,6 +72,13 @@ struct bar_config {
72 * In "show" mode, it will always be shown on top of the active workspace. 72 * In "show" mode, it will always be shown on top of the active workspace.
73 */ 73 */
74 char *hidden_state; 74 char *hidden_state;
75 /**
76 * Id name used to identify the bar through IPC.
77 *
78 * Defaults to bar-x, where x corresponds to the position of the
79 * embedding bar block in the config file (bar-0, bar-1, ...).
80 */
81 char *id;
75 uint32_t modifier; 82 uint32_t modifier;
76 enum desktop_shell_panel_position position; 83 enum desktop_shell_panel_position position;
77 char *status_command; 84 char *status_command;
diff --git a/include/util.h b/include/util.h
index 8e65e6d6..9cb861dd 100644
--- a/include/util.h
+++ b/include/util.h
@@ -6,4 +6,9 @@
6 */ 6 */
7int wrap(int i, int max); 7int wrap(int i, int max);
8 8
9/**
10 * Count number of digits in int
11 */
12int numlen(int n);
13
9#endif 14#endif
diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt
index aa553492..894163b8 100644
--- a/sway/CMakeLists.txt
+++ b/sway/CMakeLists.txt
@@ -21,7 +21,6 @@ add_executable(sway
21 main.c 21 main.c
22 output.c 22 output.c
23 resize.c 23 resize.c
24 util.c
25 workspace.c 24 workspace.c
26) 25)
27 26
diff --git a/sway/commands.c b/sway/commands.c
index 604e10aa..c565adbb 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -15,6 +15,7 @@
15#include "layout.h" 15#include "layout.h"
16#include "focus.h" 16#include "focus.h"
17#include "log.h" 17#include "log.h"
18#include "util.h"
18#include "workspace.h" 19#include "workspace.h"
19#include "commands.h" 20#include "commands.h"
20#include "container.h" 21#include "container.h"
@@ -1124,9 +1125,20 @@ static struct cmd_results *cmd_bar(int argc, char **argv) {
1124 bar->tray_padding = config->bar.tray_padding; 1125 bar->tray_padding = config->bar.tray_padding;
1125 list_add(config->bars, bar); 1126 list_add(config->bars, bar);
1126 1127
1128 // set bar id
1129 int i;
1130 for (i = 0; i < config->bars->length; ++i) {
1131 if (bar == config->bars->items[i]) {
1132 const int len = 5 + numlen(i); // "bar-" + i + \0
1133 bar->id = malloc(len * sizeof(char));
1134 snprintf(bar->id, len, "bar-%d", i);
1135 break;
1136 }
1137 }
1138
1127 // Set current bar 1139 // Set current bar
1128 config->current_bar = bar; 1140 config->current_bar = bar;
1129 sway_log(L_DEBUG, "Configuring bar"); 1141 sway_log(L_DEBUG, "Configuring bar %s", bar->id);
1130 return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); 1142 return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL);
1131} 1143}
1132 1144
@@ -1534,7 +1546,7 @@ static struct cmd_results *bar_cmd_position(int argc, char **argv) {
1534 return error; 1546 return error;
1535 } 1547 }
1536 1548
1537 sway_log(L_DEBUG, "Setting bar position '%s'", argv[0]); 1549 sway_log(L_DEBUG, "Setting bar position '%s' for bar: %s", argv[0], config->current_bar->id);
1538 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1550 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1539} 1551}
1540 1552
@@ -1550,10 +1562,10 @@ static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv
1550 1562
1551 if (strcasecmp("yes", argv[0]) == 0) { 1563 if (strcasecmp("yes", argv[0]) == 0) {
1552 config->current_bar->strip_workspace_numbers = true; 1564 config->current_bar->strip_workspace_numbers = true;
1553 sway_log(L_DEBUG, "Stripping workspace numbers on bar"); 1565 sway_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id);
1554 } else if (strcasecmp("no", argv[0]) == 0) { 1566 } else if (strcasecmp("no", argv[0]) == 0) {
1555 config->current_bar->strip_workspace_numbers = false; 1567 config->current_bar->strip_workspace_numbers = false;
1556 sway_log(L_DEBUG, "Enabling workspace numbers on bar"); 1568 sway_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id);
1557 } else { 1569 } else {
1558 error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]); 1570 error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]);
1559 return error; 1571 return error;
@@ -1587,7 +1599,7 @@ static struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
1587 "Unknown unit %s", argv[1]); 1599 "Unknown unit %s", argv[1]);
1588 } 1600 }
1589 config->current_bar->tray_padding = padding; 1601 config->current_bar->tray_padding = padding;
1590 sway_log(L_DEBUG, "Enabling tray padding of %d px", padding); 1602 sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id);
1591 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1603 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1592} 1604}
1593 1605
@@ -1603,10 +1615,10 @@ static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
1603 1615
1604 if (strcasecmp("yes", argv[0]) == 0) { 1616 if (strcasecmp("yes", argv[0]) == 0) {
1605 config->current_bar->workspace_buttons = true; 1617 config->current_bar->workspace_buttons = true;
1606 sway_log(L_DEBUG, "Enabling workspace buttons on bar"); 1618 sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id);
1607 } else if (strcasecmp("no", argv[0]) == 0) { 1619 } else if (strcasecmp("no", argv[0]) == 0) {
1608 config->current_bar->workspace_buttons = false; 1620 config->current_bar->workspace_buttons = false;
1609 sway_log(L_DEBUG, "Disabling workspace buttons on bar"); 1621 sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id);
1610 } else { 1622 } else {
1611 error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]); 1623 error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]);
1612 return error; 1624 return error;
diff --git a/sway/util.c b/sway/util.c
deleted file mode 100644
index 9a59ddf9..00000000
--- a/sway/util.c
+++ /dev/null
@@ -1,5 +0,0 @@
1#include "util.h"
2
3int wrap(int i, int max) {
4 return ((i % max) + max) % max;
5}
diff --git a/swaygrab/main.c b/swaygrab/main.c
index 681a6da4..2c6cf2dd 100644
--- a/swaygrab/main.c
+++ b/swaygrab/main.c
@@ -8,21 +8,12 @@
8#include <time.h> 8#include <time.h>
9#include "log.h" 9#include "log.h"
10#include "ipc-client.h" 10#include "ipc-client.h"
11#include "util.h"
11 12
12void sway_terminate(void) { 13void sway_terminate(void) {
13 exit(EXIT_FAILURE); 14 exit(EXIT_FAILURE);
14} 15}
15 16
16int numlen(int n) {
17 if (n >= 1000000) return 7;
18 if (n >= 100000) return 6;
19 if (n >= 10000) return 5;
20 if (n >= 1000) return 4;
21 if (n >= 100) return 3;
22 if (n >= 10) return 2;
23 return 1;
24}
25
26void grab_and_apply_magick(const char *file, const char *output, 17void grab_and_apply_magick(const char *file, const char *output,
27 int socketfd, int raw) { 18 int socketfd, int raw) {
28 uint32_t len = strlen(output); 19 uint32_t len = strlen(output);