swaynag: refactor {sway_,}nagbar to swaynag

This commit is contained in:
Brian Ashworth 2018-07-28 23:15:12 -04:00
parent 6124d0f9a2
commit a6145914c6
10 changed files with 415 additions and 411 deletions

View File

@ -1,13 +1,13 @@
#ifndef _SWAY_NAGBAR_CONFIG_H #ifndef _SWAYNAG_CONFIG_H
#define _SWAY_NAGBAR_CONFIG_H #define _SWAYNAG_CONFIG_H
#include "swaynag/nagbar.h" #include "swaynag/swaynag.h"
#include "list.h" #include "list.h"
int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
list_t *types, char **config, bool *debug); list_t *types, char **config, bool *debug);
char *nagbar_get_config_path(void); char *swaynag_get_config_path(void);
int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types); int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types);
#endif #endif

View File

@ -1,6 +1,7 @@
#ifndef _SWAY_NAGBAR_RENDER_H #ifndef _SWAYNAG_RENDER_H
#define _SWAY_NAGBAR_RENDER_H #define _SWAYNAG_RENDER_H
#include "swaynag/swaynag.h"
void render_frame(struct sway_nagbar *nagbar); void render_frame(struct swaynag *swaynag);
#endif #endif

View File

@ -1,5 +1,5 @@
#ifndef _SWAY_NAGBAR_NAGBAR_H #ifndef _SWAYNAG_SWAYNAG_H
#define _SWAY_NAGBAR_NAGBAR_H #define _SWAYNAG_SWAYNAG_H
#include <stdint.h> #include <stdint.h>
#include <strings.h> #include <strings.h>
#include "list.h" #include "list.h"
@ -7,24 +7,24 @@
#include "swaynag/types.h" #include "swaynag/types.h"
#include "xdg-output-unstable-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h"
#define NAGBAR_BAR_BORDER_THICKNESS 2 #define SWAYNAG_BAR_BORDER_THICKNESS 2
#define NAGBAR_MESSAGE_PADDING 8 #define SWAYNAG_MESSAGE_PADDING 8
#define NAGBAR_DETAILS_BORDER_THICKNESS 3 #define SWAYNAG_DETAILS_BORDER_THICKNESS 3
#define NAGBAR_BUTTON_BORDER_THICKNESS 3 #define SWAYNAG_BUTTON_BORDER_THICKNESS 3
#define NAGBAR_BUTTON_GAP 20 #define SWAYNAG_BUTTON_GAP 20
#define NAGBAR_BUTTON_GAP_CLOSE 15 #define SWAYNAG_BUTTON_GAP_CLOSE 15
#define NAGBAR_BUTTON_MARGIN_RIGHT 2 #define SWAYNAG_BUTTON_MARGIN_RIGHT 2
#define NAGBAR_BUTTON_PADDING 3 #define SWAYNAG_BUTTON_PADDING 3
#define NAGBAR_MAX_HEIGHT 500 #define SWAYNAG_MAX_HEIGHT 500
enum sway_nagbar_action_type { enum swaynag_action_type {
NAGBAR_ACTION_DISMISS, SWAYNAG_ACTION_DISMISS,
NAGBAR_ACTION_EXPAND, SWAYNAG_ACTION_EXPAND,
NAGBAR_ACTION_COMMAND, SWAYNAG_ACTION_COMMAND,
}; };
struct sway_nagbar_pointer { struct swaynag_pointer {
struct wl_pointer *pointer; struct wl_pointer *pointer;
struct wl_cursor_theme *cursor_theme; struct wl_cursor_theme *cursor_theme;
struct wl_cursor_image *cursor_image; struct wl_cursor_image *cursor_image;
@ -33,15 +33,15 @@ struct sway_nagbar_pointer {
int y; int y;
}; };
struct sway_nagbar_output { struct swaynag_output {
char *name; char *name;
struct wl_output *wl_output; struct wl_output *wl_output;
uint32_t wl_name; uint32_t wl_name;
}; };
struct sway_nagbar_button { struct swaynag_button {
char *text; char *text;
enum sway_nagbar_action_type type; enum swaynag_action_type type;
char *action; char *action;
int x; int x;
int y; int y;
@ -49,7 +49,7 @@ struct sway_nagbar_button {
int height; int height;
}; };
struct sway_nagbar_details { struct swaynag_details {
bool visible; bool visible;
char *message; char *message;
@ -61,12 +61,12 @@ struct sway_nagbar_details {
int offset; int offset;
int visible_lines; int visible_lines;
int total_lines; int total_lines;
struct sway_nagbar_button button_details; struct swaynag_button button_details;
struct sway_nagbar_button button_up; struct swaynag_button button_up;
struct sway_nagbar_button button_down; struct swaynag_button button_down;
}; };
struct sway_nagbar { struct swaynag {
bool run_display; bool run_display;
int querying_outputs; int querying_outputs;
@ -74,9 +74,9 @@ struct sway_nagbar {
struct wl_compositor *compositor; struct wl_compositor *compositor;
struct wl_seat *seat; struct wl_seat *seat;
struct wl_shm *shm; struct wl_shm *shm;
struct sway_nagbar_pointer pointer; struct swaynag_pointer pointer;
struct zxdg_output_manager_v1 *xdg_output_manager; struct zxdg_output_manager_v1 *xdg_output_manager;
struct sway_nagbar_output output; struct swaynag_output output;
struct zwlr_layer_shell_v1 *layer_shell; struct zwlr_layer_shell_v1 *layer_shell;
struct zwlr_layer_surface_v1 *layer_surface; struct zwlr_layer_surface_v1 *layer_surface;
struct wl_surface *surface; struct wl_surface *surface;
@ -87,18 +87,18 @@ struct sway_nagbar {
struct pool_buffer buffers[2]; struct pool_buffer buffers[2];
struct pool_buffer *current_buffer; struct pool_buffer *current_buffer;
struct sway_nagbar_type *type; struct swaynag_type *type;
uint32_t anchors; uint32_t anchors;
char *message; char *message;
char *font; char *font;
list_t *buttons; list_t *buttons;
struct sway_nagbar_details details; struct swaynag_details details;
}; };
void nagbar_setup(struct sway_nagbar *nagbar); void swaynag_setup(struct swaynag *swaynag);
void nagbar_run(struct sway_nagbar *nagbar); void swaynag_run(struct swaynag *swaynag);
void nagbar_destroy(struct sway_nagbar *nagbar); void swaynag_destroy(struct swaynag *swaynag);
#endif #endif

View File

@ -1,7 +1,7 @@
#ifndef _SWAY_NAGBAR_TYPES_H #ifndef _SWAYNAG_TYPES_H
#define _SWAY_NAGBAR_TYPES_H #define _SWAYNAG_TYPES_H
struct sway_nagbar_type { struct swaynag_type {
char *name; char *name;
uint32_t button_background; uint32_t button_background;
uint32_t background; uint32_t background;
@ -10,16 +10,16 @@ struct sway_nagbar_type {
uint32_t border_bottom; uint32_t border_bottom;
}; };
void nagbar_types_add_default(list_t *types); void swaynag_types_add_default(list_t *types);
struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name); struct swaynag_type *swaynag_type_get(list_t *types, char *name);
struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type); struct swaynag_type *swaynag_type_clone(struct swaynag_type *type);
void nagbar_type_free(struct sway_nagbar_type *type); void swaynag_type_free(struct swaynag_type *type);
void nagbar_types_free(list_t *types); void swaynag_types_free(list_t *types);
int nagbar_parse_type(int argc, char **argv, struct sway_nagbar_type *type); int swaynag_parse_type(int argc, char **argv, struct swaynag_type *type);
#endif #endif

View File

@ -6,7 +6,7 @@
#include "log.h" #include "log.h"
#include "list.h" #include "list.h"
#include "readline.h" #include "readline.h"
#include "swaynag/nagbar.h" #include "swaynag/swaynag.h"
#include "swaynag/types.h" #include "swaynag/types.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h"
@ -36,7 +36,7 @@ static char *read_from_stdin() {
return buffer; return buffer;
} }
int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
list_t *types, char **config, bool *debug) { list_t *types, char **config, bool *debug) {
static struct option opts[] = { static struct option opts[] = {
{"button", required_argument, NULL, 'b'}, {"button", required_argument, NULL, 'b'},
@ -81,17 +81,17 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar,
} }
switch (c) { switch (c) {
case 'b': // Button case 'b': // Button
if (nagbar) { if (swaynag) {
if (optind >= argc) { if (optind >= argc) {
fprintf(stderr, "Missing action for button %s\n", optarg); fprintf(stderr, "Missing action for button %s\n", optarg);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
struct sway_nagbar_button *button; struct swaynag_button *button;
button = calloc(sizeof(struct sway_nagbar_button), 1); button = calloc(sizeof(struct swaynag_button), 1);
button->text = strdup(optarg); button->text = strdup(optarg);
button->type = NAGBAR_ACTION_COMMAND; button->type = SWAYNAG_ACTION_COMMAND;
button->action = strdup(argv[optind]); button->action = strdup(argv[optind]);
list_add(nagbar->buttons, button); list_add(swaynag->buttons, button);
} }
optind++; optind++;
break; break;
@ -106,13 +106,13 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar,
} }
break; break;
case 'e': // Edge case 'e': // Edge
if (nagbar) { if (swaynag) {
if (strcmp(optarg, "top") == 0) { if (strcmp(optarg, "top") == 0) {
nagbar->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
} else if (strcmp(optarg, "bottom") == 0) { } else if (strcmp(optarg, "bottom") == 0) {
nagbar->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
} else { } else {
@ -122,49 +122,49 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar,
} }
break; break;
case 'f': // Font case 'f': // Font
if (nagbar) { if (swaynag) {
free(nagbar->font); free(swaynag->font);
nagbar->font = strdup(optarg); swaynag->font = strdup(optarg);
} }
break; break;
case 'l': // Detailed Message case 'l': // Detailed Message
if (nagbar) { if (swaynag) {
free(nagbar->details.message); free(swaynag->details.message);
nagbar->details.message = read_from_stdin(); swaynag->details.message = read_from_stdin();
nagbar->details.button_up.text = strdup(""); swaynag->details.button_up.text = strdup("");
nagbar->details.button_down.text = strdup(""); swaynag->details.button_down.text = strdup("");
} }
break; break;
case 'L': // Detailed Button Text case 'L': // Detailed Button Text
if (nagbar) { if (swaynag) {
free(nagbar->details.button_details.text); free(swaynag->details.button_details.text);
nagbar->details.button_details.text = strdup(optarg); swaynag->details.button_details.text = strdup(optarg);
} }
break; break;
case 'm': // Message case 'm': // Message
if (nagbar) { if (swaynag) {
free(nagbar->message); free(swaynag->message);
nagbar->message = strdup(optarg); swaynag->message = strdup(optarg);
} }
break; break;
case 'o': // Output case 'o': // Output
if (nagbar) { if (swaynag) {
free(nagbar->output.name); free(swaynag->output.name);
nagbar->output.name = strdup(optarg); swaynag->output.name = strdup(optarg);
} }
break; break;
case 's': // Dismiss Button Text case 's': // Dismiss Button Text
if (nagbar) { if (swaynag) {
struct sway_nagbar_button *button_close; struct swaynag_button *button_close;
button_close = nagbar->buttons->items[0]; button_close = swaynag->buttons->items[0];
free(button_close->text); free(button_close->text);
button_close->text = strdup(optarg); button_close->text = strdup(optarg);
} }
break; break;
case 't': // Type case 't': // Type
if (nagbar) { if (swaynag) {
nagbar->type = nagbar_type_get(types, optarg); swaynag->type = swaynag_type_get(types, optarg);
if (!nagbar->type) { if (!swaynag->type) {
fprintf(stderr, "Unknown type %s\n", optarg); fprintf(stderr, "Unknown type %s\n", optarg);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -186,7 +186,7 @@ static bool file_exists(const char *path) {
return path && access(path, R_OK) != -1; return path && access(path, R_OK) != -1;
} }
char *nagbar_get_config_path(void) { char *swaynag_get_config_path(void) {
static const char *config_paths[] = { static const char *config_paths[] = {
"$HOME/.swaynag/config", "$HOME/.swaynag/config",
"$XDG_CONFIG_HOME/swaynag/config", "$XDG_CONFIG_HOME/swaynag/config",
@ -223,13 +223,13 @@ char *nagbar_get_config_path(void) {
return NULL; return NULL;
} }
int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) { int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
FILE *config = fopen(path, "r"); FILE *config = fopen(path, "r");
if (!config) { if (!config) {
fprintf(stderr, "Failed to read config. Running without it.\n"); fprintf(stderr, "Failed to read config. Running without it.\n");
return 0; return 0;
} }
struct sway_nagbar_type *type = NULL; struct swaynag_type *type = NULL;
char *line; char *line;
int line_number = 0; int line_number = 0;
while (!feof(config)) { while (!feof(config)) {
@ -259,9 +259,9 @@ int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) {
} }
char *name = calloc(1, close - line); char *name = calloc(1, close - line);
strncat(name, line + 1, close - line - 1); strncat(name, line + 1, close - line - 1);
type = nagbar_type_get(types, name); type = swaynag_type_get(types, name);
if (!type) { if (!type) {
type = calloc(1, sizeof(struct sway_nagbar_type)); type = calloc(1, sizeof(struct swaynag_type));
type->name = strdup(name); type->name = strdup(name);
list_add(types, type); list_add(types, type);
} }
@ -272,9 +272,9 @@ int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) {
char *argv[] = {"swaynag", flag}; char *argv[] = {"swaynag", flag};
int result; int result;
if (type) { if (type) {
result = nagbar_parse_type(2, argv, type); result = swaynag_parse_type(2, argv, type);
} else { } else {
result = nagbar_parse_options(2, argv, nagbar, types, result = swaynag_parse_options(2, argv, swaynag, types,
NULL, NULL); NULL, NULL);
} }
if (result != 0) { if (result != 0) {

View File

@ -3,19 +3,19 @@
#include "log.h" #include "log.h"
#include "list.h" #include "list.h"
#include "swaynag/config.h" #include "swaynag/config.h"
#include "swaynag/nagbar.h" #include "swaynag/swaynag.h"
#include "swaynag/types.h" #include "swaynag/types.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h"
static struct sway_nagbar nagbar; static struct swaynag swaynag;
void sig_handler(int signal) { void sig_handler(int signal) {
nagbar_destroy(&nagbar); swaynag_destroy(&swaynag);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
void sway_terminate(int code) { void sway_terminate(int code) {
nagbar_destroy(&nagbar); swaynag_destroy(&swaynag);
exit(code); exit(code);
} }
@ -23,28 +23,28 @@ int main(int argc, char **argv) {
int exit_code = EXIT_SUCCESS; int exit_code = EXIT_SUCCESS;
list_t *types = create_list(); list_t *types = create_list();
nagbar_types_add_default(types); swaynag_types_add_default(types);
memset(&nagbar, 0, sizeof(nagbar)); memset(&swaynag, 0, sizeof(swaynag));
nagbar.anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP swaynag.anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
nagbar.font = strdup("pango:monospace 10"); swaynag.font = strdup("pango:monospace 10");
nagbar.buttons = create_list(); swaynag.buttons = create_list();
struct sway_nagbar_button *button_close = struct swaynag_button *button_close =
calloc(sizeof(struct sway_nagbar_button), 1); calloc(sizeof(struct swaynag_button), 1);
button_close->text = strdup("X"); button_close->text = strdup("X");
button_close->type = NAGBAR_ACTION_DISMISS; button_close->type = SWAYNAG_ACTION_DISMISS;
list_add(nagbar.buttons, button_close); list_add(swaynag.buttons, button_close);
nagbar.details.button_details.text = strdup("Toggle Details"); swaynag.details.button_details.text = strdup("Toggle Details");
nagbar.details.button_details.type = NAGBAR_ACTION_EXPAND; swaynag.details.button_details.type = SWAYNAG_ACTION_EXPAND;
char *config_path = NULL; char *config_path = NULL;
bool debug = false; bool debug = false;
int launch_status = nagbar_parse_options(argc, argv, NULL, NULL, int launch_status = swaynag_parse_options(argc, argv, NULL, NULL,
&config_path, &debug); &config_path, &debug);
if (launch_status != 0) { if (launch_status != 0) {
exit_code = launch_status; exit_code = launch_status;
@ -53,11 +53,11 @@ int main(int argc, char **argv) {
wlr_log_init(debug ? WLR_DEBUG : WLR_ERROR, NULL); wlr_log_init(debug ? WLR_DEBUG : WLR_ERROR, NULL);
if (!config_path) { if (!config_path) {
config_path = nagbar_get_config_path(); config_path = swaynag_get_config_path();
} }
if (config_path) { if (config_path) {
wlr_log(WLR_DEBUG, "Loading config file: %s", config_path); wlr_log(WLR_DEBUG, "Loading config file: %s", config_path);
int config_status = nagbar_load_config(config_path, &nagbar, types); int config_status = swaynag_load_config(config_path, &swaynag, types);
free(config_path); free(config_path);
if (config_status != 0) { if (config_status != 0) {
exit_code = config_status; exit_code = config_status;
@ -66,7 +66,7 @@ int main(int argc, char **argv) {
} }
if (argc > 1) { if (argc > 1) {
int result = nagbar_parse_options(argc, argv, &nagbar, types, int result = swaynag_parse_options(argc, argv, &swaynag, types,
NULL, NULL); NULL, NULL);
if (result != 0) { if (result != 0) {
exit_code = result; exit_code = result;
@ -74,46 +74,46 @@ int main(int argc, char **argv) {
} }
} }
if (!nagbar.message) { if (!swaynag.message) {
wlr_log(WLR_ERROR, "No message passed. Please provide --message/-m"); wlr_log(WLR_ERROR, "No message passed. Please provide --message/-m");
exit_code = EXIT_FAILURE; exit_code = EXIT_FAILURE;
goto cleanup; goto cleanup;
} }
if (!nagbar.type) { if (!swaynag.type) {
nagbar.type = nagbar_type_get(types, "error"); swaynag.type = swaynag_type_get(types, "error");
} }
nagbar.type = nagbar_type_clone(nagbar.type); swaynag.type = swaynag_type_clone(swaynag.type);
nagbar_types_free(types); swaynag_types_free(types);
if (nagbar.details.message) { if (swaynag.details.message) {
list_add(nagbar.buttons, &nagbar.details.button_details); list_add(swaynag.buttons, &swaynag.details.button_details);
} else { } else {
free(nagbar.details.button_details.text); free(swaynag.details.button_details.text);
} }
wlr_log(WLR_DEBUG, "Output: %s", nagbar.output.name); wlr_log(WLR_DEBUG, "Output: %s", swaynag.output.name);
wlr_log(WLR_DEBUG, "Anchors: %d", nagbar.anchors); wlr_log(WLR_DEBUG, "Anchors: %d", swaynag.anchors);
wlr_log(WLR_DEBUG, "Type: %s", nagbar.type->name); wlr_log(WLR_DEBUG, "Type: %s", swaynag.type->name);
wlr_log(WLR_DEBUG, "Message: %s", nagbar.message); wlr_log(WLR_DEBUG, "Message: %s", swaynag.message);
wlr_log(WLR_DEBUG, "Font: %s", nagbar.font); wlr_log(WLR_DEBUG, "Font: %s", swaynag.font);
wlr_log(WLR_DEBUG, "Buttons"); wlr_log(WLR_DEBUG, "Buttons");
for (int i = 0; i < nagbar.buttons->length; i++) { for (int i = 0; i < swaynag.buttons->length; i++) {
struct sway_nagbar_button *button = nagbar.buttons->items[i]; struct swaynag_button *button = swaynag.buttons->items[i];
wlr_log(WLR_DEBUG, "\t[%s] `%s`", button->text, button->action); wlr_log(WLR_DEBUG, "\t[%s] `%s`", button->text, button->action);
} }
signal(SIGTERM, sig_handler); signal(SIGTERM, sig_handler);
nagbar_setup(&nagbar); swaynag_setup(&swaynag);
nagbar_run(&nagbar); swaynag_run(&swaynag);
return exit_code; return exit_code;
cleanup: cleanup:
nagbar_types_free(types); swaynag_types_free(types);
free(nagbar.details.button_details.text); free(swaynag.details.button_details.text);
nagbar_destroy(&nagbar); swaynag_destroy(&swaynag);
return exit_code; return exit_code;
} }

View File

@ -2,8 +2,8 @@ executable(
'swaynag', [ 'swaynag', [
'config.c', 'config.c',
'main.c', 'main.c',
'nagbar.c',
'render.c', 'render.c',
'swaynag.c',
'types.c', 'types.c',
], ],
include_directories: [sway_inc], include_directories: [sway_inc],

View File

@ -3,99 +3,100 @@
#include "log.h" #include "log.h"
#include "pango.h" #include "pango.h"
#include "pool-buffer.h" #include "pool-buffer.h"
#include "swaynag/nagbar.h" #include "swaynag/swaynag.h"
#include "swaynag/types.h" #include "swaynag/types.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h"
static uint32_t render_message(cairo_t *cairo, struct sway_nagbar *nagbar) { static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) {
uint32_t height = nagbar->height * nagbar->scale; uint32_t height = swaynag->height * swaynag->scale;
height -= NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; height -= SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale;
int text_width, text_height; int text_width, text_height;
get_text_size(cairo, nagbar->font, &text_width, &text_height, get_text_size(cairo, swaynag->font, &text_width, &text_height,
nagbar->scale, true, "%s", nagbar->message); swaynag->scale, true, "%s", swaynag->message);
int padding = NAGBAR_MESSAGE_PADDING * nagbar->scale; int padding = SWAYNAG_MESSAGE_PADDING * swaynag->scale;
uint32_t ideal_height = text_height + padding * 2; uint32_t ideal_height = text_height + padding * 2;
uint32_t ideal_surface_height = ideal_height / nagbar->scale; uint32_t ideal_surface_height = ideal_height / swaynag->scale;
if (nagbar->height < ideal_surface_height) { if (swaynag->height < ideal_surface_height) {
return ideal_surface_height; return ideal_surface_height;
} }
cairo_set_source_u32(cairo, nagbar->type->text); cairo_set_source_u32(cairo, swaynag->type->text);
cairo_move_to(cairo, padding, (int)(ideal_height - text_height) / 2); cairo_move_to(cairo, padding, (int)(ideal_height - text_height) / 2);
pango_printf(cairo, nagbar->font, nagbar->scale, false, "%s", pango_printf(cairo, swaynag->font, swaynag->scale, false, "%s",
nagbar->message); swaynag->message);
return ideal_height; return ideal_height;
} }
static void render_details_scroll_button(cairo_t *cairo, static void render_details_scroll_button(cairo_t *cairo,
struct sway_nagbar *nagbar, struct sway_nagbar_button *button) { struct swaynag *swaynag, struct swaynag_button *button) {
int text_width, text_height; int text_width, text_height;
get_text_size(cairo, nagbar->font, &text_width, &text_height, get_text_size(cairo, swaynag->font, &text_width, &text_height,
nagbar->scale, true, "%s", button->text); swaynag->scale, true, "%s", button->text);
int border = NAGBAR_BUTTON_BORDER_THICKNESS * nagbar->scale; int border = SWAYNAG_BUTTON_BORDER_THICKNESS * swaynag->scale;
int padding = NAGBAR_BUTTON_PADDING * nagbar->scale; int padding = SWAYNAG_BUTTON_PADDING * swaynag->scale;
cairo_set_source_u32(cairo, nagbar->type->border); cairo_set_source_u32(cairo, swaynag->type->border);
cairo_rectangle(cairo, button->x, button->y, cairo_rectangle(cairo, button->x, button->y,
button->width, button->height); button->width, button->height);
cairo_fill(cairo); cairo_fill(cairo);
cairo_set_source_u32(cairo, nagbar->type->button_background); cairo_set_source_u32(cairo, swaynag->type->button_background);
cairo_rectangle(cairo, button->x + border, button->y + border, cairo_rectangle(cairo, button->x + border, button->y + border,
button->width - (border * 2), button->height - (border * 2)); button->width - (border * 2), button->height - (border * 2));
cairo_fill(cairo); cairo_fill(cairo);
cairo_set_source_u32(cairo, nagbar->type->text); cairo_set_source_u32(cairo, swaynag->type->text);
cairo_move_to(cairo, button->x + border + padding, cairo_move_to(cairo, button->x + border + padding,
button->y + border + (button->height - text_height) / 2); button->y + border + (button->height - text_height) / 2);
pango_printf(cairo, nagbar->font, nagbar->scale, true, "%s", button->text); pango_printf(cairo, swaynag->font, swaynag->scale, true,
"%s", button->text);
} }
static int get_detailed_scroll_button_width(cairo_t *cairo, static int get_detailed_scroll_button_width(cairo_t *cairo,
struct sway_nagbar *nagbar) { struct swaynag *swaynag) {
int up_width, down_width, temp_height; int up_width, down_width, temp_height;
get_text_size(cairo, nagbar->font, &up_width, &temp_height, get_text_size(cairo, swaynag->font, &up_width, &temp_height,
nagbar->scale, true, "%s", nagbar->details.button_up.text); swaynag->scale, true, "%s", swaynag->details.button_up.text);
get_text_size(cairo, nagbar->font, &down_width, &temp_height, get_text_size(cairo, swaynag->font, &down_width, &temp_height,
nagbar->scale, true, "%s", nagbar->details.button_down.text); swaynag->scale, true, "%s", swaynag->details.button_down.text);
int text_width = up_width > down_width ? up_width : down_width; int text_width = up_width > down_width ? up_width : down_width;
int border = NAGBAR_BUTTON_BORDER_THICKNESS * nagbar->scale; int border = SWAYNAG_BUTTON_BORDER_THICKNESS * swaynag->scale;
int padding = NAGBAR_BUTTON_PADDING * nagbar->scale; int padding = SWAYNAG_BUTTON_PADDING * swaynag->scale;
return text_width + border * 2 + padding * 2; return text_width + border * 2 + padding * 2;
} }
static uint32_t render_detailed(cairo_t *cairo, struct sway_nagbar *nagbar, static uint32_t render_detailed(cairo_t *cairo, struct swaynag *swaynag,
uint32_t y) { uint32_t y) {
uint32_t width = nagbar->width * nagbar->scale; uint32_t width = swaynag->width * swaynag->scale;
uint32_t height = nagbar->height * nagbar->scale; uint32_t height = swaynag->height * swaynag->scale;
height -= NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; height -= SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale;
int border = NAGBAR_DETAILS_BORDER_THICKNESS * nagbar->scale; int border = SWAYNAG_DETAILS_BORDER_THICKNESS * swaynag->scale;
int padding = NAGBAR_MESSAGE_PADDING * nagbar->scale; int padding = SWAYNAG_MESSAGE_PADDING * swaynag->scale;
int decor = padding + border; int decor = padding + border;
nagbar->details.x = decor; swaynag->details.x = decor;
nagbar->details.y = y + decor; swaynag->details.y = y + decor;
nagbar->details.width = width - decor * 2; swaynag->details.width = width - decor * 2;
PangoLayout *layout = get_pango_layout(cairo, nagbar->font, PangoLayout *layout = get_pango_layout(cairo, swaynag->font,
nagbar->details.message, nagbar->scale, false); swaynag->details.message, swaynag->scale, false);
pango_layout_set_width(layout, pango_layout_set_width(layout,
(nagbar->details.width - padding * 2) * PANGO_SCALE); (swaynag->details.width - padding * 2) * PANGO_SCALE);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_single_paragraph_mode(layout, false); pango_layout_set_single_paragraph_mode(layout, false);
pango_cairo_update_layout(cairo, layout); pango_cairo_update_layout(cairo, layout);
nagbar->details.total_lines = pango_layout_get_line_count(layout); swaynag->details.total_lines = pango_layout_get_line_count(layout);
PangoLayoutLine *line; PangoLayoutLine *line;
line = pango_layout_get_line_readonly(layout, nagbar->details.offset); line = pango_layout_get_line_readonly(layout, swaynag->details.offset);
gint offset = line->start_index; gint offset = line->start_index;
const char *text = pango_layout_get_text(layout); const char *text = pango_layout_get_text(layout);
pango_layout_set_text(layout, text + offset, strlen(text) - offset); pango_layout_set_text(layout, text + offset, strlen(text) - offset);
@ -104,87 +105,87 @@ static uint32_t render_detailed(cairo_t *cairo, struct sway_nagbar *nagbar,
pango_cairo_update_layout(cairo, layout); pango_cairo_update_layout(cairo, layout);
pango_layout_get_pixel_size(layout, &text_width, &text_height); pango_layout_get_pixel_size(layout, &text_width, &text_height);
bool show_buttons = nagbar->details.offset > 0; bool show_buttons = swaynag->details.offset > 0;
int button_width = get_detailed_scroll_button_width(cairo, nagbar); int button_width = get_detailed_scroll_button_width(cairo, swaynag);
if (show_buttons) { if (show_buttons) {
nagbar->details.width -= button_width; swaynag->details.width -= button_width;
pango_layout_set_width(layout, pango_layout_set_width(layout,
(nagbar->details.width - padding * 2) * PANGO_SCALE); (swaynag->details.width - padding * 2) * PANGO_SCALE);
} }
uint32_t ideal_height; uint32_t ideal_height;
do { do {
ideal_height = nagbar->details.y + text_height + decor + padding * 2; ideal_height = swaynag->details.y + text_height + decor + padding * 2;
if (ideal_height > NAGBAR_MAX_HEIGHT) { if (ideal_height > SWAYNAG_MAX_HEIGHT) {
ideal_height = NAGBAR_MAX_HEIGHT; ideal_height = SWAYNAG_MAX_HEIGHT;
if (!show_buttons) { if (!show_buttons) {
show_buttons = true; show_buttons = true;
nagbar->details.width -= button_width; swaynag->details.width -= button_width;
pango_layout_set_width(layout, pango_layout_set_width(layout,
(nagbar->details.width - padding * 2) * PANGO_SCALE); (swaynag->details.width - padding * 2) * PANGO_SCALE);
} }
} }
nagbar->details.height = ideal_height - nagbar->details.y - decor; swaynag->details.height = ideal_height - swaynag->details.y - decor;
pango_layout_set_height(layout, pango_layout_set_height(layout,
(nagbar->details.height - padding * 2) * PANGO_SCALE); (swaynag->details.height - padding * 2) * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
pango_cairo_update_layout(cairo, layout); pango_cairo_update_layout(cairo, layout);
pango_layout_get_pixel_size(layout, &text_width, &text_height); pango_layout_get_pixel_size(layout, &text_width, &text_height);
} while (text_height != (nagbar->details.height - padding * 2)); } while (text_height != (swaynag->details.height - padding * 2));
nagbar->details.visible_lines = pango_layout_get_line_count(layout); swaynag->details.visible_lines = pango_layout_get_line_count(layout);
if (show_buttons) { if (show_buttons) {
nagbar->details.button_up.x = swaynag->details.button_up.x =
nagbar->details.x + nagbar->details.width; swaynag->details.x + swaynag->details.width;
nagbar->details.button_up.y = nagbar->details.y; swaynag->details.button_up.y = swaynag->details.y;
nagbar->details.button_up.width = button_width; swaynag->details.button_up.width = button_width;
nagbar->details.button_up.height = nagbar->details.height / 2; swaynag->details.button_up.height = swaynag->details.height / 2;
render_details_scroll_button(cairo, nagbar, render_details_scroll_button(cairo, swaynag,
&nagbar->details.button_up); &swaynag->details.button_up);
nagbar->details.button_down.x = swaynag->details.button_down.x =
nagbar->details.x + nagbar->details.width; swaynag->details.x + swaynag->details.width;
nagbar->details.button_down.y = swaynag->details.button_down.y =
nagbar->details.button_up.y + nagbar->details.button_up.height; swaynag->details.button_up.y + swaynag->details.button_up.height;
nagbar->details.button_down.width = button_width; swaynag->details.button_down.width = button_width;
nagbar->details.button_down.height = nagbar->details.height / 2; swaynag->details.button_down.height = swaynag->details.height / 2;
render_details_scroll_button(cairo, nagbar, render_details_scroll_button(cairo, swaynag,
&nagbar->details.button_down); &swaynag->details.button_down);
} }
cairo_set_source_u32(cairo, nagbar->type->border); cairo_set_source_u32(cairo, swaynag->type->border);
cairo_rectangle(cairo, nagbar->details.x, nagbar->details.y, cairo_rectangle(cairo, swaynag->details.x, swaynag->details.y,
nagbar->details.width, nagbar->details.height); swaynag->details.width, swaynag->details.height);
cairo_fill(cairo); cairo_fill(cairo);
cairo_move_to(cairo, nagbar->details.x + padding, cairo_move_to(cairo, swaynag->details.x + padding,
nagbar->details.y + padding); swaynag->details.y + padding);
cairo_set_source_u32(cairo, nagbar->type->text); cairo_set_source_u32(cairo, swaynag->type->text);
pango_cairo_show_layout(cairo, layout); pango_cairo_show_layout(cairo, layout);
g_object_unref(layout); g_object_unref(layout);
return ideal_height; return ideal_height;
} }
static uint32_t render_button(cairo_t *cairo, struct sway_nagbar *nagbar, static uint32_t render_button(cairo_t *cairo, struct swaynag *swaynag,
int button_index, int *x) { int button_index, int *x) {
uint32_t height = nagbar->height * nagbar->scale; uint32_t height = swaynag->height * swaynag->scale;
height -= NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; height -= SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale;
struct sway_nagbar_button *button = nagbar->buttons->items[button_index]; struct swaynag_button *button = swaynag->buttons->items[button_index];
int text_width, text_height; int text_width, text_height;
get_text_size(cairo, nagbar->font, &text_width, &text_height, get_text_size(cairo, swaynag->font, &text_width, &text_height,
nagbar->scale, true, "%s", button->text); swaynag->scale, true, "%s", button->text);
int border = NAGBAR_BUTTON_BORDER_THICKNESS * nagbar->scale; int border = SWAYNAG_BUTTON_BORDER_THICKNESS * swaynag->scale;
int padding = NAGBAR_BUTTON_PADDING * nagbar->scale; int padding = SWAYNAG_BUTTON_PADDING * swaynag->scale;
uint32_t ideal_height = text_height + padding * 2 + border * 2; uint32_t ideal_height = text_height + padding * 2 + border * 2;
uint32_t ideal_surface_height = ideal_height / nagbar->scale; uint32_t ideal_surface_height = ideal_height / swaynag->scale;
if (nagbar->height < ideal_surface_height) { if (swaynag->height < ideal_surface_height) {
return ideal_surface_height; return ideal_surface_height;
} }
@ -193,64 +194,65 @@ static uint32_t render_button(cairo_t *cairo, struct sway_nagbar *nagbar,
button->width = text_width + padding * 2; button->width = text_width + padding * 2;
button->height = text_height + padding * 2; button->height = text_height + padding * 2;
cairo_set_source_u32(cairo, nagbar->type->border); cairo_set_source_u32(cairo, swaynag->type->border);
cairo_rectangle(cairo, button->x - border, button->y - border, cairo_rectangle(cairo, button->x - border, button->y - border,
button->width + border * 2, button->height + border * 2); button->width + border * 2, button->height + border * 2);
cairo_fill(cairo); cairo_fill(cairo);
cairo_set_source_u32(cairo, nagbar->type->button_background); cairo_set_source_u32(cairo, swaynag->type->button_background);
cairo_rectangle(cairo, button->x, button->y, cairo_rectangle(cairo, button->x, button->y,
button->width, button->height); button->width, button->height);
cairo_fill(cairo); cairo_fill(cairo);
cairo_set_source_u32(cairo, nagbar->type->text); cairo_set_source_u32(cairo, swaynag->type->text);
cairo_move_to(cairo, button->x + padding, button->y + padding); cairo_move_to(cairo, button->x + padding, button->y + padding);
pango_printf(cairo, nagbar->font, nagbar->scale, true, "%s", button->text); pango_printf(cairo, swaynag->font, swaynag->scale, true,
"%s", button->text);
*x = button->x - border; *x = button->x - border;
return ideal_height; return ideal_height;
} }
static uint32_t render_to_cairo(cairo_t *cairo, struct sway_nagbar *nagbar) { static uint32_t render_to_cairo(cairo_t *cairo, struct swaynag *swaynag) {
uint32_t max_height = 0; uint32_t max_height = 0;
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
cairo_set_source_u32(cairo, nagbar->type->background); cairo_set_source_u32(cairo, swaynag->type->background);
cairo_paint(cairo); cairo_paint(cairo);
uint32_t h = render_message(cairo, nagbar); uint32_t h = render_message(cairo, swaynag);
max_height = h > max_height ? h : max_height; max_height = h > max_height ? h : max_height;
int x = (nagbar->width - NAGBAR_BUTTON_MARGIN_RIGHT) * nagbar->scale; int x = (swaynag->width - SWAYNAG_BUTTON_MARGIN_RIGHT) * swaynag->scale;
for (int i = 0; i < nagbar->buttons->length; i++) { for (int i = 0; i < swaynag->buttons->length; i++) {
h = render_button(cairo, nagbar, i, &x); h = render_button(cairo, swaynag, i, &x);
max_height = h > max_height ? h : max_height; max_height = h > max_height ? h : max_height;
x -= NAGBAR_BUTTON_GAP * nagbar->scale; x -= SWAYNAG_BUTTON_GAP * swaynag->scale;
if (i == 0) { if (i == 0) {
x -= NAGBAR_BUTTON_GAP_CLOSE * nagbar->scale; x -= SWAYNAG_BUTTON_GAP_CLOSE * swaynag->scale;
} }
} }
if (nagbar->details.visible) { if (swaynag->details.visible) {
h = render_detailed(cairo, nagbar, max_height); h = render_detailed(cairo, swaynag, max_height);
max_height = h > max_height ? h : max_height; max_height = h > max_height ? h : max_height;
} }
int border = NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; int border = SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale;
if (max_height > nagbar->height) { if (max_height > swaynag->height) {
max_height += border; max_height += border;
} }
cairo_set_source_u32(cairo, nagbar->type->border_bottom); cairo_set_source_u32(cairo, swaynag->type->border_bottom);
cairo_rectangle(cairo, 0, nagbar->height * nagbar->scale - border, cairo_rectangle(cairo, 0, swaynag->height * swaynag->scale - border,
nagbar->width * nagbar->scale, border); swaynag->width * swaynag->scale, border);
cairo_fill(cairo); cairo_fill(cairo);
return max_height; return max_height;
} }
void render_frame(struct sway_nagbar *nagbar) { void render_frame(struct swaynag *swaynag) {
if (!nagbar->run_display) { if (!swaynag->run_display) {
return; return;
} }
@ -261,24 +263,24 @@ void render_frame(struct sway_nagbar *nagbar) {
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
cairo_paint(cairo); cairo_paint(cairo);
cairo_restore(cairo); cairo_restore(cairo);
uint32_t height = render_to_cairo(cairo, nagbar); uint32_t height = render_to_cairo(cairo, swaynag);
if (height != nagbar->height) { if (height != swaynag->height) {
zwlr_layer_surface_v1_set_size(nagbar->layer_surface, 0, height); zwlr_layer_surface_v1_set_size(swaynag->layer_surface, 0, height);
zwlr_layer_surface_v1_set_exclusive_zone(nagbar->layer_surface, zwlr_layer_surface_v1_set_exclusive_zone(swaynag->layer_surface,
height); height);
wl_surface_commit(nagbar->surface); wl_surface_commit(swaynag->surface);
wl_display_roundtrip(nagbar->display); wl_display_roundtrip(swaynag->display);
} else { } else {
nagbar->current_buffer = get_next_buffer(nagbar->shm, swaynag->current_buffer = get_next_buffer(swaynag->shm,
nagbar->buffers, swaynag->buffers,
nagbar->width * nagbar->scale, swaynag->width * swaynag->scale,
nagbar->height * nagbar->scale); swaynag->height * swaynag->scale);
if (!nagbar->current_buffer) { if (!swaynag->current_buffer) {
wlr_log(WLR_DEBUG, "Failed to get buffer. Skipping frame."); wlr_log(WLR_DEBUG, "Failed to get buffer. Skipping frame.");
goto cleanup; goto cleanup;
} }
cairo_t *shm = nagbar->current_buffer->cairo; cairo_t *shm = swaynag->current_buffer->cairo;
cairo_save(shm); cairo_save(shm);
cairo_set_operator(shm, CAIRO_OPERATOR_CLEAR); cairo_set_operator(shm, CAIRO_OPERATOR_CLEAR);
cairo_paint(shm); cairo_paint(shm);
@ -286,13 +288,13 @@ void render_frame(struct sway_nagbar *nagbar) {
cairo_set_source_surface(shm, recorder, 0.0, 0.0); cairo_set_source_surface(shm, recorder, 0.0, 0.0);
cairo_paint(shm); cairo_paint(shm);
wl_surface_set_buffer_scale(nagbar->surface, nagbar->scale); wl_surface_set_buffer_scale(swaynag->surface, swaynag->scale);
wl_surface_attach(nagbar->surface, wl_surface_attach(swaynag->surface,
nagbar->current_buffer->buffer, 0, 0); swaynag->current_buffer->buffer, 0, 0);
wl_surface_damage(nagbar->surface, 0, 0, wl_surface_damage(swaynag->surface, 0, 0,
nagbar->width, nagbar->height); swaynag->width, swaynag->height);
wl_surface_commit(nagbar->surface); wl_surface_commit(swaynag->surface);
wl_display_roundtrip(nagbar->display); wl_display_roundtrip(swaynag->display);
} }
cleanup: cleanup:

View File

@ -6,8 +6,8 @@
#include <wayland-cursor.h> #include <wayland-cursor.h>
#include "log.h" #include "log.h"
#include "list.h" #include "list.h"
#include "swaynag/nagbar.h"
#include "swaynag/render.h" #include "swaynag/render.h"
#include "swaynag/swaynag.h"
#include "swaynag/types.h" #include "swaynag/types.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h"
@ -32,14 +32,14 @@ static bool terminal_execute(char *terminal, char *command) {
return true; return true;
} }
static void nagbar_button_execute(struct sway_nagbar *nagbar, static void swaynag_button_execute(struct swaynag *swaynag,
struct sway_nagbar_button *button) { struct swaynag_button *button) {
wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action); wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action);
if (button->type == NAGBAR_ACTION_DISMISS) { if (button->type == SWAYNAG_ACTION_DISMISS) {
nagbar->run_display = false; swaynag->run_display = false;
} else if (button->type == NAGBAR_ACTION_EXPAND) { } else if (button->type == SWAYNAG_ACTION_EXPAND) {
nagbar->details.visible = !nagbar->details.visible; swaynag->details.visible = !swaynag->details.visible;
render_frame(nagbar); render_frame(swaynag);
} else { } else {
if (fork() == 0) { if (fork() == 0) {
// Child process. Will be used to prevent zombie processes // Child process. Will be used to prevent zombie processes
@ -50,7 +50,7 @@ static void nagbar_button_execute(struct sway_nagbar *nagbar,
if (terminal && strlen(terminal)) { if (terminal && strlen(terminal)) {
wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal); wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal);
if (!terminal_execute(terminal, button->action)) { if (!terminal_execute(terminal, button->action)) {
nagbar_destroy(nagbar); swaynag_destroy(swaynag);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
@ -67,17 +67,17 @@ static void nagbar_button_execute(struct sway_nagbar *nagbar,
static void layer_surface_configure(void *data, static void layer_surface_configure(void *data,
struct zwlr_layer_surface_v1 *surface, struct zwlr_layer_surface_v1 *surface,
uint32_t serial, uint32_t width, uint32_t height) { uint32_t serial, uint32_t width, uint32_t height) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
nagbar->width = width; swaynag->width = width;
nagbar->height = height; swaynag->height = height;
zwlr_layer_surface_v1_ack_configure(surface, serial); zwlr_layer_surface_v1_ack_configure(surface, serial);
render_frame(nagbar); render_frame(swaynag);
} }
static void layer_surface_closed(void *data, static void layer_surface_closed(void *data,
struct zwlr_layer_surface_v1 *surface) { struct zwlr_layer_surface_v1 *surface) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
nagbar_destroy(nagbar); swaynag_destroy(swaynag);
} }
static struct zwlr_layer_surface_v1_listener layer_surface_listener = { static struct zwlr_layer_surface_v1_listener layer_surface_listener = {
@ -88,67 +88,67 @@ static struct zwlr_layer_surface_v1_listener layer_surface_listener = {
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface, uint32_t serial, struct wl_surface *surface,
wl_fixed_t surface_x, wl_fixed_t surface_y) { wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
struct sway_nagbar_pointer *pointer = &nagbar->pointer; struct swaynag_pointer *pointer = &swaynag->pointer;
wl_surface_set_buffer_scale(pointer->cursor_surface, nagbar->scale); wl_surface_set_buffer_scale(pointer->cursor_surface, swaynag->scale);
wl_surface_attach(pointer->cursor_surface, wl_surface_attach(pointer->cursor_surface,
wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface,
pointer->cursor_image->hotspot_x / nagbar->scale, pointer->cursor_image->hotspot_x / swaynag->scale,
pointer->cursor_image->hotspot_y / nagbar->scale); pointer->cursor_image->hotspot_y / swaynag->scale);
wl_surface_commit(pointer->cursor_surface); wl_surface_commit(pointer->cursor_surface);
} }
static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
nagbar->pointer.x = wl_fixed_to_int(surface_x); swaynag->pointer.x = wl_fixed_to_int(surface_x);
nagbar->pointer.y = wl_fixed_to_int(surface_y); swaynag->pointer.y = wl_fixed_to_int(surface_y);
} }
static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
if (state != WL_POINTER_BUTTON_STATE_PRESSED) { if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
return; return;
} }
double x = nagbar->pointer.x * nagbar->scale; double x = swaynag->pointer.x * swaynag->scale;
double y = nagbar->pointer.y * nagbar->scale; double y = swaynag->pointer.y * swaynag->scale;
for (int i = 0; i < nagbar->buttons->length; i++) { for (int i = 0; i < swaynag->buttons->length; i++) {
struct sway_nagbar_button *nagbutton = nagbar->buttons->items[i]; struct swaynag_button *nagbutton = swaynag->buttons->items[i];
if (x >= nagbutton->x if (x >= nagbutton->x
&& y >= nagbutton->y && y >= nagbutton->y
&& x < nagbutton->x + nagbutton->width && x < nagbutton->x + nagbutton->width
&& y < nagbutton->y + nagbutton->height) { && y < nagbutton->y + nagbutton->height) {
nagbar_button_execute(nagbar, nagbutton); swaynag_button_execute(swaynag, nagbutton);
return; return;
} }
} }
if (nagbar->details.visible && if (swaynag->details.visible &&
nagbar->details.total_lines != nagbar->details.visible_lines) { swaynag->details.total_lines != swaynag->details.visible_lines) {
struct sway_nagbar_button button_up = nagbar->details.button_up; struct swaynag_button button_up = swaynag->details.button_up;
if (x >= button_up.x if (x >= button_up.x
&& y >= button_up.y && y >= button_up.y
&& x < button_up.x + button_up.width && x < button_up.x + button_up.width
&& y < button_up.y + button_up.height && y < button_up.y + button_up.height
&& nagbar->details.offset > 0) { && swaynag->details.offset > 0) {
nagbar->details.offset--; swaynag->details.offset--;
render_frame(nagbar); render_frame(swaynag);
return; return;
} }
struct sway_nagbar_button button_down = nagbar->details.button_down; struct swaynag_button button_down = swaynag->details.button_down;
int bot = nagbar->details.total_lines - nagbar->details.visible_lines; int bot = swaynag->details.total_lines - swaynag->details.visible_lines;
if (x >= button_down.x if (x >= button_down.x
&& y >= button_down.y && y >= button_down.y
&& x < button_down.x + button_down.width && x < button_down.x + button_down.width
&& y < button_down.y + button_down.height && y < button_down.y + button_down.height
&& nagbar->details.offset < bot) { && swaynag->details.offset < bot) {
nagbar->details.offset++; swaynag->details.offset++;
render_frame(nagbar); render_frame(swaynag);
return; return;
} }
} }
@ -156,25 +156,25 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value) { uint32_t time, uint32_t axis, wl_fixed_t value) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
if (!nagbar->details.visible if (!swaynag->details.visible
|| nagbar->pointer.x < nagbar->details.x || swaynag->pointer.x < swaynag->details.x
|| nagbar->pointer.y < nagbar->details.y || swaynag->pointer.y < swaynag->details.y
|| nagbar->pointer.x >= nagbar->details.x + nagbar->details.width || swaynag->pointer.x >= swaynag->details.x + swaynag->details.width
|| nagbar->pointer.y >= nagbar->details.y + nagbar->details.height || swaynag->pointer.y >= swaynag->details.y + swaynag->details.height
|| nagbar->details.total_lines == nagbar->details.visible_lines) { || swaynag->details.total_lines == swaynag->details.visible_lines) {
return; return;
} }
int direction = wl_fixed_to_int(value); int direction = wl_fixed_to_int(value);
int bot = nagbar->details.total_lines - nagbar->details.visible_lines; int bot = swaynag->details.total_lines - swaynag->details.visible_lines;
if (direction < 0 && nagbar->details.offset > 0) { if (direction < 0 && swaynag->details.offset > 0) {
nagbar->details.offset--; swaynag->details.offset--;
} else if (direction > 0 && nagbar->details.offset < bot) { } else if (direction > 0 && swaynag->details.offset < bot) {
nagbar->details.offset++; swaynag->details.offset++;
} }
render_frame(nagbar); render_frame(swaynag);
} }
static struct wl_pointer_listener pointer_listener = { static struct wl_pointer_listener pointer_listener = {
@ -191,11 +191,11 @@ static struct wl_pointer_listener pointer_listener = {
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) { enum wl_seat_capability caps) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
if ((caps & WL_SEAT_CAPABILITY_POINTER)) { if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
nagbar->pointer.pointer = wl_seat_get_pointer(wl_seat); swaynag->pointer.pointer = wl_seat_get_pointer(wl_seat);
wl_pointer_add_listener(nagbar->pointer.pointer, &pointer_listener, wl_pointer_add_listener(swaynag->pointer.pointer, &pointer_listener,
nagbar); swaynag);
} }
} }
@ -206,9 +206,9 @@ const struct wl_seat_listener seat_listener = {
static void output_scale(void *data, struct wl_output *output, static void output_scale(void *data, struct wl_output *output,
int32_t factor) { int32_t factor) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
nagbar->scale = factor; swaynag->scale = factor;
render_frame(nagbar); render_frame(swaynag);
} }
static struct wl_output_listener output_listener = { static struct wl_output_listener output_listener = {
@ -222,27 +222,27 @@ struct output_state {
struct wl_output *wl_output; struct wl_output *wl_output;
uint32_t wl_name; uint32_t wl_name;
struct zxdg_output_v1 *xdg_output; struct zxdg_output_v1 *xdg_output;
struct sway_nagbar *nagbar; struct swaynag *swaynag;
}; };
static void xdg_output_handle_name(void *data, static void xdg_output_handle_name(void *data,
struct zxdg_output_v1 *xdg_output, const char *name) { struct zxdg_output_v1 *xdg_output, const char *name) {
struct output_state *state = data; struct output_state *state = data;
char *outname = state->nagbar->output.name; char *outname = state->swaynag->output.name;
wlr_log(WLR_DEBUG, "Checking against output %s for %s", name, outname); wlr_log(WLR_DEBUG, "Checking against output %s for %s", name, outname);
if (outname && !state->nagbar->output.wl_output) { if (outname && !state->swaynag->output.wl_output) {
wlr_log(WLR_DEBUG, "Using output %s", name); wlr_log(WLR_DEBUG, "Using output %s", name);
state->nagbar->output.wl_output = state->wl_output; state->swaynag->output.wl_output = state->wl_output;
state->nagbar->output.wl_name = state->wl_name; state->swaynag->output.wl_name = state->wl_name;
wl_output_add_listener(state->nagbar->output.wl_output, wl_output_add_listener(state->swaynag->output.wl_output,
&output_listener, state->nagbar); &output_listener, state->swaynag);
wl_display_roundtrip(state->nagbar->display); wl_display_roundtrip(state->swaynag->display);
zxdg_output_v1_destroy(state->xdg_output); zxdg_output_v1_destroy(state->xdg_output);
} else { } else {
zxdg_output_v1_destroy(state->xdg_output); zxdg_output_v1_destroy(state->xdg_output);
wl_output_destroy(state->wl_output); wl_output_destroy(state->wl_output);
} }
state->nagbar->querying_outputs--; state->swaynag->querying_outputs--;
free(state); free(state);
} }
@ -256,35 +256,35 @@ static struct zxdg_output_v1_listener xdg_output_listener = {
static void handle_global(void *data, struct wl_registry *registry, static void handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) { uint32_t name, const char *interface, uint32_t version) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
if (strcmp(interface, wl_compositor_interface.name) == 0) { if (strcmp(interface, wl_compositor_interface.name) == 0) {
nagbar->compositor = wl_registry_bind(registry, name, swaynag->compositor = wl_registry_bind(registry, name,
&wl_compositor_interface, 3); &wl_compositor_interface, 3);
} else if (strcmp(interface, wl_seat_interface.name) == 0) { } else if (strcmp(interface, wl_seat_interface.name) == 0) {
nagbar->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1); swaynag->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
wl_seat_add_listener(nagbar->seat, &seat_listener, nagbar); wl_seat_add_listener(swaynag->seat, &seat_listener, swaynag);
} else if (strcmp(interface, wl_shm_interface.name) == 0) { } else if (strcmp(interface, wl_shm_interface.name) == 0) {
nagbar->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); swaynag->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
} else if (strcmp(interface, wl_output_interface.name) == 0) { } else if (strcmp(interface, wl_output_interface.name) == 0) {
if (!nagbar->output.wl_output && nagbar->xdg_output_manager) { if (!swaynag->output.wl_output && swaynag->xdg_output_manager) {
nagbar->querying_outputs++; swaynag->querying_outputs++;
struct output_state *state = struct output_state *state =
calloc(1, sizeof(struct output_state)); calloc(1, sizeof(struct output_state));
state->nagbar = nagbar; state->swaynag = swaynag;
state->wl_output = wl_registry_bind(registry, name, state->wl_output = wl_registry_bind(registry, name,
&wl_output_interface, 3); &wl_output_interface, 3);
state->wl_name = name; state->wl_name = name;
state->xdg_output = zxdg_output_manager_v1_get_xdg_output( state->xdg_output = zxdg_output_manager_v1_get_xdg_output(
nagbar->xdg_output_manager, state->wl_output); swaynag->xdg_output_manager, state->wl_output);
zxdg_output_v1_add_listener(state->xdg_output, zxdg_output_v1_add_listener(state->xdg_output,
&xdg_output_listener, state); &xdg_output_listener, state);
} }
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
nagbar->layer_shell = wl_registry_bind( swaynag->layer_shell = wl_registry_bind(
registry, name, &zwlr_layer_shell_v1_interface, 1); registry, name, &zwlr_layer_shell_v1_interface, 1);
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0
&& version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
nagbar->xdg_output_manager = wl_registry_bind(registry, name, swaynag->xdg_output_manager = wl_registry_bind(registry, name,
&zxdg_output_manager_v1_interface, &zxdg_output_manager_v1_interface,
ZXDG_OUTPUT_V1_NAME_SINCE_VERSION); ZXDG_OUTPUT_V1_NAME_SINCE_VERSION);
} }
@ -292,9 +292,9 @@ static void handle_global(void *data, struct wl_registry *registry,
static void handle_global_remove(void *data, struct wl_registry *registry, static void handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name) { uint32_t name) {
struct sway_nagbar *nagbar = data; struct swaynag *swaynag = data;
if (nagbar->output.wl_name == name) { if (swaynag->output.wl_name == name) {
nagbar->run_display = false; swaynag->run_display = false;
} }
} }
@ -303,110 +303,111 @@ static const struct wl_registry_listener registry_listener = {
.global_remove = handle_global_remove, .global_remove = handle_global_remove,
}; };
void nagbar_setup(struct sway_nagbar *nagbar) { void swaynag_setup(struct swaynag *swaynag) {
nagbar->display = wl_display_connect(NULL); swaynag->display = wl_display_connect(NULL);
assert(nagbar->display); assert(swaynag->display);
nagbar->scale = 1; swaynag->scale = 1;
struct wl_registry *registry = wl_display_get_registry(nagbar->display); struct wl_registry *registry = wl_display_get_registry(swaynag->display);
wl_registry_add_listener(registry, &registry_listener, nagbar); wl_registry_add_listener(registry, &registry_listener, swaynag);
wl_display_roundtrip(nagbar->display); wl_display_roundtrip(swaynag->display);
assert(nagbar->compositor && nagbar->layer_shell && nagbar->shm); assert(swaynag->compositor && swaynag->layer_shell && swaynag->shm);
while (nagbar->querying_outputs > 0) { while (swaynag->querying_outputs > 0) {
wl_display_roundtrip(nagbar->display); wl_display_roundtrip(swaynag->display);
} }
if (!nagbar->output.wl_output && nagbar->output.name) { if (!swaynag->output.wl_output && swaynag->output.name) {
wlr_log(WLR_ERROR, "Output '%s' not found", nagbar->output.name); wlr_log(WLR_ERROR, "Output '%s' not found", swaynag->output.name);
nagbar_destroy(nagbar); swaynag_destroy(swaynag);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
struct sway_nagbar_pointer *pointer = &nagbar->pointer; struct swaynag_pointer *pointer = &swaynag->pointer;
int scale = nagbar->scale < 1 ? 1 : nagbar->scale; int scale = swaynag->scale < 1 ? 1 : swaynag->scale;
pointer->cursor_theme = wl_cursor_theme_load( pointer->cursor_theme = wl_cursor_theme_load(
NULL, 24 * scale, nagbar->shm); NULL, 24 * scale, swaynag->shm);
assert(pointer->cursor_theme); assert(pointer->cursor_theme);
struct wl_cursor *cursor = struct wl_cursor *cursor =
wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
assert(cursor); assert(cursor);
pointer->cursor_image = cursor->images[0]; pointer->cursor_image = cursor->images[0];
pointer->cursor_surface = wl_compositor_create_surface(nagbar->compositor); pointer->cursor_surface = wl_compositor_create_surface(swaynag->compositor);
assert(pointer->cursor_surface); assert(pointer->cursor_surface);
nagbar->surface = wl_compositor_create_surface(nagbar->compositor); swaynag->surface = wl_compositor_create_surface(swaynag->compositor);
assert(nagbar->surface); assert(swaynag->surface);
nagbar->layer_surface = zwlr_layer_shell_v1_get_layer_surface( swaynag->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
nagbar->layer_shell, nagbar->surface, nagbar->output.wl_output, swaynag->layer_shell, swaynag->surface, swaynag->output.wl_output,
ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag"); ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag");
assert(nagbar->layer_surface); assert(swaynag->layer_surface);
zwlr_layer_surface_v1_add_listener(nagbar->layer_surface, zwlr_layer_surface_v1_add_listener(swaynag->layer_surface,
&layer_surface_listener, nagbar); &layer_surface_listener, swaynag);
zwlr_layer_surface_v1_set_anchor(nagbar->layer_surface, nagbar->anchors); zwlr_layer_surface_v1_set_anchor(swaynag->layer_surface, swaynag->anchors);
wl_registry_destroy(registry); wl_registry_destroy(registry);
} }
void nagbar_run(struct sway_nagbar *nagbar) { void swaynag_run(struct swaynag *swaynag) {
nagbar->run_display = true; swaynag->run_display = true;
render_frame(nagbar); render_frame(swaynag);
while (nagbar->run_display && wl_display_dispatch(nagbar->display) != -1) { while (swaynag->run_display
&& wl_display_dispatch(swaynag->display) != -1) {
// This is intentionally left blank // This is intentionally left blank
} }
} }
void nagbar_destroy(struct sway_nagbar *nagbar) { void swaynag_destroy(struct swaynag *swaynag) {
nagbar->run_display = false; swaynag->run_display = false;
free(nagbar->message); free(swaynag->message);
free(nagbar->font); free(swaynag->font);
while (nagbar->buttons->length) { while (swaynag->buttons->length) {
struct sway_nagbar_button *button = nagbar->buttons->items[0]; struct swaynag_button *button = swaynag->buttons->items[0];
list_del(nagbar->buttons, 0); list_del(swaynag->buttons, 0);
free(button->text); free(button->text);
free(button->action); free(button->action);
free(button); free(button);
} }
list_free(nagbar->buttons); list_free(swaynag->buttons);
free(nagbar->details.message); free(swaynag->details.message);
free(nagbar->details.button_up.text); free(swaynag->details.button_up.text);
free(nagbar->details.button_down.text); free(swaynag->details.button_down.text);
if (nagbar->type) { if (swaynag->type) {
nagbar_type_free(nagbar->type); swaynag_type_free(swaynag->type);
} }
if (nagbar->layer_surface) { if (swaynag->layer_surface) {
zwlr_layer_surface_v1_destroy(nagbar->layer_surface); zwlr_layer_surface_v1_destroy(swaynag->layer_surface);
} }
if (nagbar->surface) { if (swaynag->surface) {
wl_surface_destroy(nagbar->surface); wl_surface_destroy(swaynag->surface);
} }
if (nagbar->output.wl_output) { if (swaynag->output.wl_output) {
wl_output_destroy(nagbar->output.wl_output); wl_output_destroy(swaynag->output.wl_output);
} }
if (&nagbar->buffers[0]) { if (&swaynag->buffers[0]) {
destroy_buffer(&nagbar->buffers[0]); destroy_buffer(&swaynag->buffers[0]);
} }
if (&nagbar->buffers[1]) { if (&swaynag->buffers[1]) {
destroy_buffer(&nagbar->buffers[1]); destroy_buffer(&swaynag->buffers[1]);
} }
if (nagbar->compositor) { if (swaynag->compositor) {
wl_compositor_destroy(nagbar->compositor); wl_compositor_destroy(swaynag->compositor);
} }
if (nagbar->shm) { if (swaynag->shm) {
wl_shm_destroy(nagbar->shm); wl_shm_destroy(swaynag->shm);
} }
if (nagbar->display) { if (swaynag->display) {
wl_display_disconnect(nagbar->display); wl_display_disconnect(swaynag->display);
} }
} }

View File

@ -10,9 +10,9 @@
#include "swaynag/types.h" #include "swaynag/types.h"
#include "util.h" #include "util.h"
void nagbar_types_add_default(list_t *types) { void swaynag_types_add_default(list_t *types) {
struct sway_nagbar_type *type_error; struct swaynag_type *type_error;
type_error = calloc(1, sizeof(struct sway_nagbar_type)); type_error = calloc(1, sizeof(struct swaynag_type));
type_error->name = strdup("error"); type_error->name = strdup("error");
type_error->button_background = 0x680A0AFF; type_error->button_background = 0x680A0AFF;
type_error->background = 0x900000FF; type_error->background = 0x900000FF;
@ -21,8 +21,8 @@ void nagbar_types_add_default(list_t *types) {
type_error->border_bottom = 0x470909FF; type_error->border_bottom = 0x470909FF;
list_add(types, type_error); list_add(types, type_error);
struct sway_nagbar_type *type_warning; struct swaynag_type *type_warning;
type_warning = calloc(1, sizeof(struct sway_nagbar_type)); type_warning = calloc(1, sizeof(struct swaynag_type));
type_warning->name = strdup("warning"); type_warning->name = strdup("warning");
type_warning->button_background = 0xFFC100FF; type_warning->button_background = 0xFFC100FF;
type_warning->background = 0xFFA800FF; type_warning->background = 0xFFA800FF;
@ -32,9 +32,9 @@ void nagbar_types_add_default(list_t *types) {
list_add(types, type_warning); list_add(types, type_warning);
} }
struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name) { struct swaynag_type *swaynag_type_get(list_t *types, char *name) {
for (int i = 0; i < types->length; i++) { for (int i = 0; i < types->length; i++) {
struct sway_nagbar_type *type = types->items[i]; struct swaynag_type *type = types->items[i];
if (strcasecmp(type->name, name) == 0) { if (strcasecmp(type->name, name) == 0) {
return type; return type;
} }
@ -42,9 +42,9 @@ struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name) {
return NULL; return NULL;
} }
struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type) { struct swaynag_type *swaynag_type_clone(struct swaynag_type *type) {
struct sway_nagbar_type *clone; struct swaynag_type *clone;
clone = calloc(1, sizeof(struct sway_nagbar_type)); clone = calloc(1, sizeof(struct swaynag_type));
clone->name = strdup(type->name); clone->name = strdup(type->name);
clone->button_background = type->button_background; clone->button_background = type->button_background;
clone->background = type->background; clone->background = type->background;
@ -54,21 +54,21 @@ struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type) {
return clone; return clone;
} }
void nagbar_type_free(struct sway_nagbar_type *type) { void swaynag_type_free(struct swaynag_type *type) {
free(type->name); free(type->name);
free(type); free(type);
} }
void nagbar_types_free(list_t *types) { void swaynag_types_free(list_t *types) {
while (types->length) { while (types->length) {
struct sway_nagbar_type *type = types->items[0]; struct swaynag_type *type = types->items[0];
nagbar_type_free(type); swaynag_type_free(type);
list_del(types, 0); list_del(types, 0);
} }
list_free(types); list_free(types);
} }
int nagbar_parse_type(int argc, char **argv, struct sway_nagbar_type *type) { int swaynag_parse_type(int argc, char **argv, struct swaynag_type *type) {
enum color_option { enum color_option {
COLOR_BACKGROUND, COLOR_BACKGROUND,
COLOR_BORDER, COLOR_BORDER,