mirror of
https://github.com/swaywm/sway
synced 2024-11-23 13:22:17 +01:00
Added plaintext markup configuration
This commit is contained in:
parent
a796ce4f66
commit
53b53dd8c2
@ -20,6 +20,7 @@ struct box_colors {
|
||||
*/
|
||||
struct config {
|
||||
char *status_command;
|
||||
bool plaintext_markup;
|
||||
uint32_t position;
|
||||
char *font;
|
||||
char *sep_symbol;
|
||||
|
@ -116,6 +116,7 @@ struct bar_config {
|
||||
enum desktop_shell_panel_position position;
|
||||
list_t *bindings;
|
||||
char *status_command;
|
||||
bool plaintext_markup;
|
||||
char *swaybar_command;
|
||||
char *font;
|
||||
int height; // -1 not defined
|
||||
|
@ -103,6 +103,7 @@ static sway_cmd bar_cmd_id;
|
||||
static sway_cmd bar_cmd_position;
|
||||
static sway_cmd bar_cmd_separator_symbol;
|
||||
static sway_cmd bar_cmd_status_command;
|
||||
static sway_cmd bar_cmd_plaintext_markup;
|
||||
static sway_cmd bar_cmd_strip_workspace_numbers;
|
||||
static sway_cmd bar_cmd_swaybar_command;
|
||||
static sway_cmd bar_cmd_tray_output;
|
||||
@ -2757,6 +2758,29 @@ static struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
static struct cmd_results *bar_cmd_plaintext_markup(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "plaintext_markup", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!config->current_bar) {
|
||||
return cmd_results_new(CMD_FAILURE, "plaintext_markup", "No bar defined.");
|
||||
}
|
||||
|
||||
if (strcasecmp("pango", argv[0]) == 0) {
|
||||
config->current_bar->plaintext_markup = true;
|
||||
sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id);
|
||||
} else if (strcasecmp("none", argv[0]) == 0) {
|
||||
config->current_bar->plaintext_markup = false;
|
||||
sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id);
|
||||
} else {
|
||||
error = cmd_results_new(CMD_INVALID, "plaintext_markup", "Invalid value %s", argv[0]);
|
||||
return error;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) {
|
||||
@ -2861,6 +2885,7 @@ static struct cmd_handler bar_handlers[] = {
|
||||
{ "mode", bar_cmd_mode },
|
||||
{ "modifier", bar_cmd_modifier },
|
||||
{ "output", bar_cmd_output },
|
||||
{ "plaintext_markup", bar_cmd_plaintext_markup },
|
||||
{ "position", bar_cmd_position },
|
||||
{ "separator_symbol", bar_cmd_separator_symbol },
|
||||
{ "status_command", bar_cmd_status_command },
|
||||
|
@ -1022,6 +1022,7 @@ struct bar_config *default_bar_config(void) {
|
||||
bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
|
||||
bar->bindings = create_list();
|
||||
bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done");
|
||||
bar->plaintext_markup = true;
|
||||
bar->swaybar_command = NULL;
|
||||
bar->font = NULL;
|
||||
bar->height = -1;
|
||||
|
@ -21,6 +21,9 @@ Commands
|
||||
**status_command** <status command>::
|
||||
Executes the bar _status command_ with _sh -c_.
|
||||
|
||||
**plaintext_markup** <pango|none>::
|
||||
Enables or disables pango markup for plaintext statuslines.
|
||||
|
||||
**id** <bar_id>::
|
||||
Sets the ID of the bar.
|
||||
|
||||
|
@ -46,6 +46,7 @@ char *parse_font(const char *font) {
|
||||
struct config *init_config() {
|
||||
struct config *config = calloc(1, sizeof(struct config));
|
||||
config->status_command = NULL;
|
||||
config->plaintext_markup = true;
|
||||
config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
|
||||
config->font = strdup("monospace 10");
|
||||
config->mode = NULL;
|
||||
|
@ -280,7 +280,7 @@ void render(struct output *output, struct config *config, struct status_line *li
|
||||
if (line->protocol == TEXT) {
|
||||
get_text_size(window->cairo, window->font, &width, &height, true, "%s", line->text_line);
|
||||
cairo_move_to(cairo, window->width - margin - width, margin);
|
||||
pango_printf(window->cairo, window->font, true, "%s", line->text_line);
|
||||
pango_printf(window->cairo, window->font, config->plaintext_markup, "%s", line->text_line);
|
||||
} else if (line->protocol == I3BAR && line->block_line) {
|
||||
double pos = window->width - 0.5;
|
||||
bool edge = true;
|
||||
|
Loading…
Reference in New Issue
Block a user