Merge pull request #314 from mikkeloscar/bar-id

Add initial support for custom bar-id
This commit is contained in:
Drew DeVault 2015-12-14 11:25:31 -05:00
commit 2be742d02d
8 changed files with 48 additions and 23 deletions

View file

@ -2,6 +2,7 @@ add_library(sway-common
ipc-client.c ipc-client.c
list.c list.c
log.c log.c
util.c
readline.c readline.c
stringop.c stringop.c
) )

15
common/util.c Normal file
View file

@ -0,0 +1,15 @@
#include "util.h"
int wrap(int i, int max) {
return ((i % max) + max) % max;
}
int numlen(int n) {
if (n >= 1000000) return 7;
if (n >= 100000) return 6;
if (n >= 10000) return 5;
if (n >= 1000) return 4;
if (n >= 100) return 3;
if (n >= 10) return 2;
return 1;
}

View file

@ -72,6 +72,13 @@ struct bar_config {
* In "show" mode, it will always be shown on top of the active workspace. * In "show" mode, it will always be shown on top of the active workspace.
*/ */
char *hidden_state; char *hidden_state;
/**
* Id name used to identify the bar through IPC.
*
* Defaults to bar-x, where x corresponds to the position of the
* embedding bar block in the config file (bar-0, bar-1, ...).
*/
char *id;
uint32_t modifier; uint32_t modifier;
enum desktop_shell_panel_position position; enum desktop_shell_panel_position position;
char *status_command; char *status_command;

View file

@ -6,4 +6,9 @@
*/ */
int wrap(int i, int max); int wrap(int i, int max);
/**
* Count number of digits in int
*/
int numlen(int n);
#endif #endif

View file

@ -21,7 +21,6 @@ add_executable(sway
main.c main.c
output.c output.c
resize.c resize.c
util.c
workspace.c workspace.c
) )

View file

@ -15,6 +15,7 @@
#include "layout.h" #include "layout.h"
#include "focus.h" #include "focus.h"
#include "log.h" #include "log.h"
#include "util.h"
#include "workspace.h" #include "workspace.h"
#include "commands.h" #include "commands.h"
#include "container.h" #include "container.h"
@ -1124,9 +1125,20 @@ static struct cmd_results *cmd_bar(int argc, char **argv) {
bar->tray_padding = config->bar.tray_padding; bar->tray_padding = config->bar.tray_padding;
list_add(config->bars, bar); list_add(config->bars, bar);
// set bar id
int i;
for (i = 0; i < config->bars->length; ++i) {
if (bar == config->bars->items[i]) {
const int len = 5 + numlen(i); // "bar-" + i + \0
bar->id = malloc(len * sizeof(char));
snprintf(bar->id, len, "bar-%d", i);
break;
}
}
// Set current bar // Set current bar
config->current_bar = bar; config->current_bar = bar;
sway_log(L_DEBUG, "Configuring bar"); sway_log(L_DEBUG, "Configuring bar %s", bar->id);
return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL);
} }
@ -1534,7 +1546,7 @@ static struct cmd_results *bar_cmd_position(int argc, char **argv) {
return error; return error;
} }
sway_log(L_DEBUG, "Setting bar position '%s'", argv[0]); sway_log(L_DEBUG, "Setting bar position '%s' for bar: %s", argv[0], config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
@ -1550,10 +1562,10 @@ static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv
if (strcasecmp("yes", argv[0]) == 0) { if (strcasecmp("yes", argv[0]) == 0) {
config->current_bar->strip_workspace_numbers = true; config->current_bar->strip_workspace_numbers = true;
sway_log(L_DEBUG, "Stripping workspace numbers on bar"); sway_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id);
} else if (strcasecmp("no", argv[0]) == 0) { } else if (strcasecmp("no", argv[0]) == 0) {
config->current_bar->strip_workspace_numbers = false; config->current_bar->strip_workspace_numbers = false;
sway_log(L_DEBUG, "Enabling workspace numbers on bar"); sway_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id);
} else { } else {
error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]); error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]);
return error; return error;
@ -1587,7 +1599,7 @@ static struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
"Unknown unit %s", argv[1]); "Unknown unit %s", argv[1]);
} }
config->current_bar->tray_padding = padding; config->current_bar->tray_padding = padding;
sway_log(L_DEBUG, "Enabling tray padding of %d px", padding); sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
@ -1603,10 +1615,10 @@ static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
if (strcasecmp("yes", argv[0]) == 0) { if (strcasecmp("yes", argv[0]) == 0) {
config->current_bar->workspace_buttons = true; config->current_bar->workspace_buttons = true;
sway_log(L_DEBUG, "Enabling workspace buttons on bar"); sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id);
} else if (strcasecmp("no", argv[0]) == 0) { } else if (strcasecmp("no", argv[0]) == 0) {
config->current_bar->workspace_buttons = false; config->current_bar->workspace_buttons = false;
sway_log(L_DEBUG, "Disabling workspace buttons on bar"); sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id);
} else { } else {
error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]); error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]);
return error; return error;

View file

@ -1,5 +0,0 @@
#include "util.h"
int wrap(int i, int max) {
return ((i % max) + max) % max;
}

View file

@ -8,21 +8,12 @@
#include <time.h> #include <time.h>
#include "log.h" #include "log.h"
#include "ipc-client.h" #include "ipc-client.h"
#include "util.h"
void sway_terminate(void) { void sway_terminate(void) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int numlen(int n) {
if (n >= 1000000) return 7;
if (n >= 100000) return 6;
if (n >= 10000) return 5;
if (n >= 1000) return 4;
if (n >= 100) return 3;
if (n >= 10) return 2;
return 1;
}
void grab_and_apply_magick(const char *file, const char *output, void grab_and_apply_magick(const char *file, const char *output,
int socketfd, int raw) { int socketfd, int raw) {
uint32_t len = strlen(output); uint32_t len = strlen(output);