Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pango markup config #601

Merged
merged 5 commits into from
Apr 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/bar/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct box_colors {
*/
struct config {
char *status_command;
bool pango_markup;
uint32_t position;
char *font;
char *sep_symbol;
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct bar_config {
enum desktop_shell_panel_position position;
list_t *bindings;
char *status_command;
bool pango_markup;
char *swaybar_command;
char *font;
int height; // -1 not defined
Expand Down
25 changes: 25 additions & 0 deletions sway/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_pango_markup;
static sway_cmd bar_cmd_strip_workspace_numbers;
static sway_cmd bar_cmd_swaybar_command;
static sway_cmd bar_cmd_tray_output;
Expand Down Expand Up @@ -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_pango_markup(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) {
return error;
}

if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined.");
}

if (strcasecmp("enabled", argv[0]) == 0) {
config->current_bar->pango_markup = true;
sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id);
} else if (strcasecmp("disabled", argv[0]) == 0) {
config->current_bar->pango_markup = false;
sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id);
} else {
error = cmd_results_new(CMD_INVALID, "pango_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))) {
Expand Down Expand Up @@ -2861,6 +2885,7 @@ static struct cmd_handler bar_handlers[] = {
{ "mode", bar_cmd_mode },
{ "modifier", bar_cmd_modifier },
{ "output", bar_cmd_output },
{ "pango_markup", bar_cmd_pango_markup },
{ "position", bar_cmd_position },
{ "separator_symbol", bar_cmd_separator_symbol },
{ "status_command", bar_cmd_status_command },
Expand Down
1 change: 1 addition & 0 deletions sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->pango_markup = true;
bar->swaybar_command = NULL;
bar->font = NULL;
bar->height = -1;
Expand Down
1 change: 1 addition & 0 deletions sway/ipc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers));
json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator));
json_object_object_add(json, "verbose", json_object_new_boolean(bar->verbose));
json_object_object_add(json, "pango_markup", json_object_new_boolean(bar->pango_markup));

json_object *colors = json_object_new_object();
json_object_object_add(colors, "background", json_object_new_string(bar->colors.background));
Expand Down
3 changes: 3 additions & 0 deletions sway/sway-bar.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Commands
**status_command** <status command>::
Executes the bar _status command_ with _sh -c_.

**pango_markup** <enabled|disabled>::
Enables or disables pango markup for plaintext statuslines.

**id** <bar_id>::
Sets the ID of the bar.

Expand Down
1 change: 1 addition & 0 deletions swaybar/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->pango_markup = true;
config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
config->font = strdup("monospace 10");
config->mode = NULL;
Expand Down
6 changes: 6 additions & 0 deletions swaybar/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static void ipc_parse_config(struct config *config, const char *payload) {
json_object *tray_output, *mode, *hidden_bar, *position, *status_command;
json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers;
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
json_object *markup;
json_object_object_get_ex(bar_config, "tray_output", &tray_output);
json_object_object_get_ex(bar_config, "mode", &mode);
json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar);
Expand All @@ -26,6 +27,7 @@ static void ipc_parse_config(struct config *config, const char *payload) {
json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol);
json_object_object_get_ex(bar_config, "colors", &colors);
json_object_object_get_ex(bar_config, "outputs", &outputs);
json_object_object_get_ex(bar_config, "pango_markup", &markup);

if (status_command) {
free(config->status_command);
Expand Down Expand Up @@ -62,6 +64,10 @@ static void ipc_parse_config(struct config *config, const char *payload) {
config->height = json_object_get_int(bar_height);
}

if (markup) {
config->pango_markup = json_object_get_boolean(markup);
}

// free previous outputs list
int i;
for (i = 0; i < config->outputs->length; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions swaybar/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ void render(struct output *output, struct config *config, struct status_line *li
int width, height;

if (line->protocol == TEXT) {
get_text_size(window->cairo, window->font, &width, &height, true, "%s", line->text_line);
get_text_size(window->cairo, window->font, &width, &height, config->pango_markup, "%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->pango_markup, "%s", line->text_line);
} else if (line->protocol == I3BAR && line->block_line) {
double pos = window->width - 0.5;
bool edge = true;
Expand Down