mirror of
https://github.com/swaywm/sway.git
synced 2024-11-16 13:13:17 +00:00
Merge pull request #314 from mikkeloscar/bar-id
Add initial support for custom bar-id
This commit is contained in:
commit
2be742d02d
|
@ -2,6 +2,7 @@ add_library(sway-common
|
|||
ipc-client.c
|
||||
list.c
|
||||
log.c
|
||||
util.c
|
||||
readline.c
|
||||
stringop.c
|
||||
)
|
||||
|
|
15
common/util.c
Normal file
15
common/util.c
Normal 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;
|
||||
}
|
|
@ -72,6 +72,13 @@ struct bar_config {
|
|||
* In "show" mode, it will always be shown on top of the active workspace.
|
||||
*/
|
||||
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;
|
||||
enum desktop_shell_panel_position position;
|
||||
char *status_command;
|
||||
|
|
|
@ -6,4 +6,9 @@
|
|||
*/
|
||||
int wrap(int i, int max);
|
||||
|
||||
/**
|
||||
* Count number of digits in int
|
||||
*/
|
||||
int numlen(int n);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,6 @@ add_executable(sway
|
|||
main.c
|
||||
output.c
|
||||
resize.c
|
||||
util.c
|
||||
workspace.c
|
||||
)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "layout.h"
|
||||
#include "focus.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "workspace.h"
|
||||
#include "commands.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;
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1534,7 +1546,7 @@ static struct cmd_results *bar_cmd_position(int argc, char **argv) {
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -1550,10 +1562,10 @@ static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv
|
|||
|
||||
if (strcasecmp("yes", argv[0]) == 0) {
|
||||
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) {
|
||||
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 {
|
||||
error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
|
@ -1587,7 +1599,7 @@ static struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
|
|||
"Unknown unit %s", argv[1]);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1603,10 +1615,10 @@ static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
|
|||
|
||||
if (strcasecmp("yes", argv[0]) == 0) {
|
||||
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) {
|
||||
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 {
|
||||
error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
#include "util.h"
|
||||
|
||||
int wrap(int i, int max) {
|
||||
return ((i % max) + max) % max;
|
||||
}
|
|
@ -8,21 +8,12 @@
|
|||
#include <time.h>
|
||||
#include "log.h"
|
||||
#include "ipc-client.h"
|
||||
#include "util.h"
|
||||
|
||||
void sway_terminate(void) {
|
||||
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,
|
||||
int socketfd, int raw) {
|
||||
uint32_t len = strlen(output);
|
||||
|
|
Loading…
Reference in a new issue