mirror of
https://cagebreak.project-repo.co/cagebreak.git
synced 2026-08-21 13:04:18 +02:00
Merge branch 'unsigned-enby-master' into development
This commit is contained in:
commit
b42a9f77cf
6 changed files with 88 additions and 20 deletions
|
|
@ -357,6 +357,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;
|
||||
|
||||
event_loop = wl_display_get_event_loop(server.wl_display);
|
||||
sigint_source =
|
||||
|
|
|
|||
|
|
@ -1615,6 +1615,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;
|
||||
}
|
||||
ipc_send_event(server, "{\"event_name\":\"configure_message\"}");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ definekey root <key> <command>
|
|||
Close current window - This may be useful for windows of
|
||||
applications which do not offer any method of closing them.
|
||||
|
||||
*configure_message [font <font description>|[f|b]g_color <r> <g> b> <a>|display_time <n>]*
|
||||
*configure_message [font <font description>|[f|b]g_color <r> <g> b> <a>|display_time <n>|align <alignment>]*
|
||||
Configure message characteristics -
|
||||
- font <font description> sets
|
||||
- <font description> is
|
||||
|
|
@ -61,6 +61,8 @@ definekey root <key> <command>
|
|||
- fg_color <r> <g> <b> <a> sets RGBA of foreground
|
||||
- bg_color <r> <g> <b> <a> sets RGBA of background
|
||||
- display_time <n> sets display time in seconds
|
||||
- anchor <position> sets the position of the message
|
||||
- <position> may be one of {top,bottom}_{left,center,right} or center
|
||||
|
||||
```
|
||||
# Set font
|
||||
|
|
|
|||
77
message.c
77
message.c
|
|
@ -176,11 +176,11 @@ 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"
|
||||
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" // NOLINT
|
||||
#endif
|
||||
void
|
||||
message_set_output(struct cg_output *output, const char *string,
|
||||
struct wlr_box *box, enum cg_message_align align) {
|
||||
struct wlr_box *box, enum cg_message_anchor anchor) {
|
||||
struct cg_message *message = malloc(sizeof(struct cg_message));
|
||||
if(!message) {
|
||||
wlr_log(WLR_ERROR, "Error allocating message structure");
|
||||
|
|
@ -202,26 +202,35 @@ message_set_output(struct cg_output *output, const char *string,
|
|||
int height = buf->base.height / scale;
|
||||
message->position->width = width;
|
||||
message->position->height = height;
|
||||
switch(align) {
|
||||
case CG_MESSAGE_TOP_RIGHT: {
|
||||
message->position->x -= width;
|
||||
switch(anchor) {
|
||||
case CG_MESSAGE_TOP_LEFT:
|
||||
message->position->x = 0;
|
||||
message->position->y = 0;
|
||||
break;
|
||||
}
|
||||
case CG_MESSAGE_BOTTOM_LEFT: {
|
||||
case CG_MESSAGE_TOP_CENTER:
|
||||
message->position->x -= width / 2;
|
||||
message->position->y = 0;
|
||||
break;
|
||||
case CG_MESSAGE_TOP_RIGHT:
|
||||
message->position->x -= width;
|
||||
message->position->y = 0;
|
||||
break;
|
||||
case CG_MESSAGE_BOTTOM_LEFT:
|
||||
message->position->x = 0;
|
||||
message->position->y -= height;
|
||||
break;
|
||||
}
|
||||
case CG_MESSAGE_BOTTOM_RIGHT: {
|
||||
case CG_MESSAGE_BOTTOM_CENTER:
|
||||
message->position->x -= width / 2;
|
||||
message->position->y -= height;
|
||||
break;
|
||||
case CG_MESSAGE_BOTTOM_RIGHT:
|
||||
message->position->x -= width;
|
||||
message->position->y -= height;
|
||||
break;
|
||||
}
|
||||
case CG_MESSAGE_CENTER: {
|
||||
case CG_MESSAGE_CENTER:
|
||||
message->position->x -= width / 2;
|
||||
message->position->y -= height / 2;
|
||||
break;
|
||||
}
|
||||
case CG_MESSAGE_TOP_LEFT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -262,12 +271,44 @@ message_printf(struct cg_output *output, const char *fmt, ...) {
|
|||
free(buffer);
|
||||
return;
|
||||
}
|
||||
box->x = output_get_layout_box(output).width;
|
||||
box->y = 0;
|
||||
struct wlr_box output_box=output_get_layout_box(output);
|
||||
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;
|
||||
case CG_MESSAGE_TOP_RIGHT:
|
||||
box->x = output_box.width;
|
||||
box->y = 0;
|
||||
break;
|
||||
case CG_MESSAGE_BOTTOM_LEFT:
|
||||
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_RIGHT:
|
||||
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;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
message_set_output(output, buffer, box, CG_MESSAGE_TOP_RIGHT);
|
||||
message_set_output(output, buffer, box,
|
||||
output->server->message_config.anchor);
|
||||
free(buffer);
|
||||
alarm(output->server->message_config.display_time);
|
||||
}
|
||||
|
|
@ -277,7 +318,7 @@ message_printf(struct cg_output *output, const char *fmt, ...) {
|
|||
|
||||
void
|
||||
message_printf_pos(struct cg_output *output, struct wlr_box *position,
|
||||
const enum cg_message_align align, const char *fmt, ...) {
|
||||
const enum cg_message_anchor anchor, const char *fmt, ...) {
|
||||
if(output->destroyed) {
|
||||
free(position);
|
||||
return;
|
||||
|
|
@ -290,7 +331,7 @@ message_printf_pos(struct cg_output *output, struct wlr_box *position,
|
|||
vsnprintf(buffer, buf_len, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
message_set_output(output, buffer, position, align);
|
||||
message_set_output(output, buffer, position, anchor);
|
||||
free(buffer);
|
||||
alarm(output->server->message_config.display_time);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,15 @@ struct cg_output;
|
|||
struct wlr_box;
|
||||
struct wlr_buffer;
|
||||
|
||||
enum cg_message_align {
|
||||
enum cg_message_anchor {
|
||||
CG_MESSAGE_TOP_LEFT,
|
||||
CG_MESSAGE_TOP_CENTER,
|
||||
CG_MESSAGE_TOP_RIGHT,
|
||||
CG_MESSAGE_BOTTOM_LEFT,
|
||||
CG_MESSAGE_BOTTOM_CENTER,
|
||||
CG_MESSAGE_BOTTOM_RIGHT,
|
||||
CG_MESSAGE_CENTER,
|
||||
CG_MESSAGE_NOPT
|
||||
};
|
||||
|
||||
struct cg_message_config {
|
||||
|
|
@ -24,6 +27,7 @@ struct cg_message_config {
|
|||
int display_time;
|
||||
float bg_color[4];
|
||||
float fg_color[4];
|
||||
enum cg_message_anchor anchor;
|
||||
};
|
||||
|
||||
struct cg_message {
|
||||
|
|
@ -37,7 +41,7 @@ void
|
|||
message_printf(struct cg_output *output, const char *fmt, ...);
|
||||
void
|
||||
message_printf_pos(struct cg_output *output, struct wlr_box *position,
|
||||
enum cg_message_align, const char *fmt, ...);
|
||||
enum cg_message_anchor, const char *fmt, ...);
|
||||
void
|
||||
message_clear(struct cg_output *output);
|
||||
|
||||
|
|
|
|||
17
parse.c
17
parse.c
|
|
@ -720,6 +720,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;
|
||||
|
||||
char *setting = strtok_r(NULL, " ", saveptr);
|
||||
if(setting == NULL) {
|
||||
|
|
@ -763,6 +764,22 @@ parse_message_config(char **saveptr, char **errstr) {
|
|||
goto error;
|
||||
}
|
||||
}
|
||||
} 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 {
|
||||
*errstr = log_error("Invalid option to command \"configure_message\"");
|
||||
goto error;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue