diff --git a/cagebreak.c b/cagebreak.c index 6940db9..78d6fdb 100644 --- a/cagebreak.c +++ b/cagebreak.c @@ -356,7 +356,7 @@ main(int argc, char *argv[]) { server.message_config.display_time = 2; server.message_config.font = strdup("pango:Monospace 10"); - server.message_config.anchor = CG_MESSAGE_TOP_RIGHT; + server.message_config.anchor = CG_MESSAGE_TOP_RIGHT; event_loop = wl_display_get_event_loop(server.wl_display); sigint_source = diff --git a/keybinding.c b/keybinding.c index 38ba60b..64cacfb 100644 --- a/keybinding.c +++ b/keybinding.c @@ -1620,9 +1620,9 @@ keybinding_configure_message(struct cg_server *server, server->message_config.fg_color[2] = config->fg_color[2]; server->message_config.fg_color[3] = config->fg_color[3]; } - if(config->anchor != CG_MESSAGE_NOPT) { - server->message_config.anchor = config->anchor; - } + if(config->anchor != CG_MESSAGE_NOPT) { + server->message_config.anchor = config->anchor; + } ipc_send_event(server, "{\"event_name\":\"configure_message\"}"); } diff --git a/man/cagebreak-config.5.md b/man/cagebreak-config.5.md index 04536aa..dc3517b 100644 --- a/man/cagebreak-config.5.md +++ b/man/cagebreak-config.5.md @@ -61,8 +61,8 @@ definekey root - fg_color sets RGBA of foreground - bg_color sets RGBA of background - display_time sets display time in seconds - - anchor sets the position of the message - - may be one of {top,bottom}_{left,center,right} or center + - anchor sets the position of the message + - may be one of {top,bottom}_{left,center,right} or center ``` # Set font diff --git a/message.c b/message.c index 56a1111..04a3d55 100644 --- a/message.c +++ b/message.c @@ -177,7 +177,7 @@ create_message_texture(const char *string, const struct cg_output *output) { #if CG_HAS_FANALYZE #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" //NOLINT +#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" // NOLINT #endif void message_set_output(struct cg_output *output, const char *string, @@ -205,23 +205,23 @@ message_set_output(struct cg_output *output, const char *string, message->position->height = height; switch(anchor) { case CG_MESSAGE_TOP_LEFT: - message->position->x = 0; - message->position->y = 0; - break; + message->position->x = 0; + message->position->y = 0; + break; case CG_MESSAGE_TOP_CENTER: - message->position->x -= width / 2; - message->position->y = 0; - break; + message->position->x -= width / 2; + message->position->y = 0; + break; case CG_MESSAGE_TOP_RIGHT: message->position->x -= width; - message->position->y = 0; + message->position->y = 0; break; case CG_MESSAGE_BOTTOM_LEFT: - message->position->x = 0; + message->position->x = 0; message->position->y -= height; break; case CG_MESSAGE_BOTTOM_CENTER: - message->position->x -= width / 2; + message->position->x -= width / 2; message->position->y -= height; break; case CG_MESSAGE_BOTTOM_RIGHT: @@ -274,43 +274,44 @@ message_printf(struct cg_output *output, const char *fmt, ...) { struct wlr_box output_box; wlr_output_layout_get_box(output->server->output_layout, output->wlr_output, &output_box); - - box->width = 0; + + box->width = 0; box->height = 0; switch(output->server->message_config.anchor) { case CG_MESSAGE_TOP_LEFT: - box->x = 0; - box->y = 0; - break; - case CG_MESSAGE_TOP_CENTER: - box->x = output_box.width /2; - box->y = 0; - break; + box->x = 0; + box->y = 0; + break; + case CG_MESSAGE_TOP_CENTER: + box->x = output_box.width / 2; + box->y = 0; + break; case CG_MESSAGE_TOP_RIGHT: - box->x = output_box.width; - box->y = 0; + box->x = output_box.width; + box->y = 0; break; case CG_MESSAGE_BOTTOM_LEFT: - box->x = 0; - box->y = output_box.height; + box->x = 0; + box->y = output_box.height; + break; + case CG_MESSAGE_BOTTOM_CENTER: + box->x = output_box.width / 2; + box->y = output_box.height; break; - case CG_MESSAGE_BOTTOM_CENTER: - box->x = output_box.width /2; - box->y = output_box.height; - break; case CG_MESSAGE_BOTTOM_RIGHT: - box->x = output_box.width; - box->y = output_box.height; + box->x = output_box.width; + box->y = output_box.height; break; case CG_MESSAGE_CENTER: - box->x = output_box.width / 2; - box->y = output_box.height / 2; + box->x = output_box.width / 2; + box->y = output_box.height / 2; break; default: break; } - - message_set_output(output, buffer, box, output->server->message_config.anchor); + + message_set_output(output, buffer, box, + output->server->message_config.anchor); free(buffer); alarm(output->server->message_config.display_time); } diff --git a/message.h b/message.h index 715fde3..1eb6664 100644 --- a/message.h +++ b/message.h @@ -13,13 +13,13 @@ struct wlr_buffer; enum cg_message_anchor { CG_MESSAGE_TOP_LEFT, - CG_MESSAGE_TOP_CENTER, + CG_MESSAGE_TOP_CENTER, CG_MESSAGE_TOP_RIGHT, CG_MESSAGE_BOTTOM_LEFT, - CG_MESSAGE_BOTTOM_CENTER, + CG_MESSAGE_BOTTOM_CENTER, CG_MESSAGE_BOTTOM_RIGHT, CG_MESSAGE_CENTER, - CG_MESSAGE_NOPT + CG_MESSAGE_NOPT }; struct cg_message_config { @@ -27,7 +27,7 @@ struct cg_message_config { int display_time; float bg_color[4]; float fg_color[4]; - enum cg_message_anchor anchor; + enum cg_message_anchor anchor; }; struct cg_message { diff --git a/parse.c b/parse.c index 70d2724..63d88f4 100644 --- a/parse.c +++ b/parse.c @@ -702,7 +702,7 @@ parse_message_config(char **saveptr, char **errstr) { cfg->fg_color[0] = -1; cfg->display_time = -1; cfg->font = NULL; - cfg->anchor = CG_MESSAGE_NOPT; + cfg->anchor = CG_MESSAGE_NOPT; char *setting = strtok_r(NULL, " ", saveptr); if(setting == NULL) { @@ -747,20 +747,22 @@ parse_message_config(char **saveptr, char **errstr) { } } } else if(strcmp(setting, "anchor") == 0) { - char* anchors[] = {"top_left", "top_center", "top_right", "bottom_left", "bottom_center", "bottom_right", "center"}; - for(int i = 0; i < 7; ++i) { - if(strcmp(*saveptr, anchors[i]) == 0) { - cfg->anchor = i; - break; - } - } - if(cfg->anchor == CG_MESSAGE_NOPT) { - *errstr = log_error( - "Error parsing command \"configure_message anchor\", " - "the given anchor value is not a valid option"); - goto error; - } - } else { + char *anchors[] = {"top_left", "top_center", "top_right", + "bottom_left", "bottom_center", "bottom_right", + "center"}; + for(int i = 0; i < 7; ++i) { + if(strcmp(*saveptr, anchors[i]) == 0) { + cfg->anchor = i; + break; + } + } + if(cfg->anchor == CG_MESSAGE_NOPT) { + *errstr = + log_error("Error parsing command \"configure_message anchor\", " + "the given anchor value is not a valid option"); + goto error; + } + } else { *errstr = log_error("Invalid option to command \"configure_message\""); goto error; }