diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-07-28 23:15:12 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-08-01 22:47:54 -0400 |
commit | a6145914c60351d8e541192c7fe35556f8e02507 (patch) | |
tree | 8bb5cacc6e91ed4483c8a4fd0b903aacb76abf15 | |
parent | swaynag: split config into own file and fix optind (diff) | |
download | sway-a6145914c60351d8e541192c7fe35556f8e02507.tar.gz sway-a6145914c60351d8e541192c7fe35556f8e02507.tar.zst sway-a6145914c60351d8e541192c7fe35556f8e02507.zip |
swaynag: refactor {sway_,}nagbar to swaynag
-rw-r--r-- | include/swaynag/config.h | 12 | ||||
-rw-r--r-- | include/swaynag/render.h | 7 | ||||
-rw-r--r-- | include/swaynag/swaynag.h (renamed from include/swaynag/nagbar.h) | 66 | ||||
-rw-r--r-- | include/swaynag/types.h | 18 | ||||
-rw-r--r-- | swaynag/config.c | 80 | ||||
-rw-r--r-- | swaynag/main.c | 78 | ||||
-rw-r--r-- | swaynag/meson.build | 2 | ||||
-rw-r--r-- | swaynag/render.c | 256 | ||||
-rw-r--r-- | swaynag/swaynag.c (renamed from swaynag/nagbar.c) | 283 | ||||
-rw-r--r-- | swaynag/types.c | 30 |
10 files changed, 418 insertions, 414 deletions
diff --git a/include/swaynag/config.h b/include/swaynag/config.h index caa32710..3fd5b3ce 100644 --- a/include/swaynag/config.h +++ b/include/swaynag/config.h | |||
@@ -1,13 +1,13 @@ | |||
1 | #ifndef _SWAY_NAGBAR_CONFIG_H | 1 | #ifndef _SWAYNAG_CONFIG_H |
2 | #define _SWAY_NAGBAR_CONFIG_H | 2 | #define _SWAYNAG_CONFIG_H |
3 | #include "swaynag/nagbar.h" | 3 | #include "swaynag/swaynag.h" |
4 | #include "list.h" | 4 | #include "list.h" |
5 | 5 | ||
6 | int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, | 6 | int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, |
7 | list_t *types, char **config, bool *debug); | 7 | list_t *types, char **config, bool *debug); |
8 | 8 | ||
9 | char *nagbar_get_config_path(void); | 9 | char *swaynag_get_config_path(void); |
10 | 10 | ||
11 | int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types); | 11 | int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types); |
12 | 12 | ||
13 | #endif | 13 | #endif |
diff --git a/include/swaynag/render.h b/include/swaynag/render.h index d9429f7f..d09e5929 100644 --- a/include/swaynag/render.h +++ b/include/swaynag/render.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _SWAY_NAGBAR_RENDER_H | 1 | #ifndef _SWAYNAG_RENDER_H |
2 | #define _SWAY_NAGBAR_RENDER_H | 2 | #define _SWAYNAG_RENDER_H |
3 | #include "swaynag/swaynag.h" | ||
3 | 4 | ||
4 | void render_frame(struct sway_nagbar *nagbar); | 5 | void render_frame(struct swaynag *swaynag); |
5 | 6 | ||
6 | #endif | 7 | #endif |
diff --git a/include/swaynag/nagbar.h b/include/swaynag/swaynag.h index 4ef101e9..6a56f14f 100644 --- a/include/swaynag/nagbar.h +++ b/include/swaynag/swaynag.h | |||
@@ -1,5 +1,5 @@ | |||
1 | #ifndef _SWAY_NAGBAR_NAGBAR_H | 1 | #ifndef _SWAYNAG_SWAYNAG_H |
2 | #define _SWAY_NAGBAR_NAGBAR_H | 2 | #define _SWAYNAG_SWAYNAG_H |
3 | #include <stdint.h> | 3 | #include <stdint.h> |
4 | #include <strings.h> | 4 | #include <strings.h> |
5 | #include "list.h" | 5 | #include "list.h" |
@@ -7,24 +7,24 @@ | |||
7 | #include "swaynag/types.h" | 7 | #include "swaynag/types.h" |
8 | #include "xdg-output-unstable-v1-client-protocol.h" | 8 | #include "xdg-output-unstable-v1-client-protocol.h" |
9 | 9 | ||
10 | #define NAGBAR_BAR_BORDER_THICKNESS 2 | 10 | #define SWAYNAG_BAR_BORDER_THICKNESS 2 |
11 | #define NAGBAR_MESSAGE_PADDING 8 | 11 | #define SWAYNAG_MESSAGE_PADDING 8 |
12 | #define NAGBAR_DETAILS_BORDER_THICKNESS 3 | 12 | #define SWAYNAG_DETAILS_BORDER_THICKNESS 3 |
13 | #define NAGBAR_BUTTON_BORDER_THICKNESS 3 | 13 | #define SWAYNAG_BUTTON_BORDER_THICKNESS 3 |
14 | #define NAGBAR_BUTTON_GAP 20 | 14 | #define SWAYNAG_BUTTON_GAP 20 |
15 | #define NAGBAR_BUTTON_GAP_CLOSE 15 | 15 | #define SWAYNAG_BUTTON_GAP_CLOSE 15 |
16 | #define NAGBAR_BUTTON_MARGIN_RIGHT 2 | 16 | #define SWAYNAG_BUTTON_MARGIN_RIGHT 2 |
17 | #define NAGBAR_BUTTON_PADDING 3 | 17 | #define SWAYNAG_BUTTON_PADDING 3 |
18 | 18 | ||
19 | #define NAGBAR_MAX_HEIGHT 500 | 19 | #define SWAYNAG_MAX_HEIGHT 500 |
20 | 20 | ||
21 | enum sway_nagbar_action_type { | 21 | enum swaynag_action_type { |
22 | NAGBAR_ACTION_DISMISS, | 22 | SWAYNAG_ACTION_DISMISS, |
23 | NAGBAR_ACTION_EXPAND, | 23 | SWAYNAG_ACTION_EXPAND, |
24 | NAGBAR_ACTION_COMMAND, | 24 | SWAYNAG_ACTION_COMMAND, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | struct sway_nagbar_pointer { | 27 | struct swaynag_pointer { |
28 | struct wl_pointer *pointer; | 28 | struct wl_pointer *pointer; |
29 | struct wl_cursor_theme *cursor_theme; | 29 | struct wl_cursor_theme *cursor_theme; |
30 | struct wl_cursor_image *cursor_image; | 30 | struct wl_cursor_image *cursor_image; |
@@ -33,15 +33,15 @@ struct sway_nagbar_pointer { | |||
33 | int y; | 33 | int y; |
34 | }; | 34 | }; |
35 | 35 | ||
36 | struct sway_nagbar_output { | 36 | struct swaynag_output { |
37 | char *name; | 37 | char *name; |
38 | struct wl_output *wl_output; | 38 | struct wl_output *wl_output; |
39 | uint32_t wl_name; | 39 | uint32_t wl_name; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | struct sway_nagbar_button { | 42 | struct swaynag_button { |
43 | char *text; | 43 | char *text; |
44 | enum sway_nagbar_action_type type; | 44 | enum swaynag_action_type type; |
45 | char *action; | 45 | char *action; |
46 | int x; | 46 | int x; |
47 | int y; | 47 | int y; |
@@ -49,7 +49,7 @@ struct sway_nagbar_button { | |||
49 | int height; | 49 | int height; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | struct sway_nagbar_details { | 52 | struct swaynag_details { |
53 | bool visible; | 53 | bool visible; |
54 | char *message; | 54 | char *message; |
55 | 55 | ||
@@ -61,12 +61,12 @@ struct sway_nagbar_details { | |||
61 | int offset; | 61 | int offset; |
62 | int visible_lines; | 62 | int visible_lines; |
63 | int total_lines; | 63 | int total_lines; |
64 | struct sway_nagbar_button button_details; | 64 | struct swaynag_button button_details; |
65 | struct sway_nagbar_button button_up; | 65 | struct swaynag_button button_up; |
66 | struct sway_nagbar_button button_down; | 66 | struct swaynag_button button_down; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | struct sway_nagbar { | 69 | struct swaynag { |
70 | bool run_display; | 70 | bool run_display; |
71 | int querying_outputs; | 71 | int querying_outputs; |
72 | 72 | ||
@@ -74,9 +74,9 @@ struct sway_nagbar { | |||
74 | struct wl_compositor *compositor; | 74 | struct wl_compositor *compositor; |
75 | struct wl_seat *seat; | 75 | struct wl_seat *seat; |
76 | struct wl_shm *shm; | 76 | struct wl_shm *shm; |
77 | struct sway_nagbar_pointer pointer; | 77 | struct swaynag_pointer pointer; |
78 | struct zxdg_output_manager_v1 *xdg_output_manager; | 78 | struct zxdg_output_manager_v1 *xdg_output_manager; |
79 | struct sway_nagbar_output output; | 79 | struct swaynag_output output; |
80 | struct zwlr_layer_shell_v1 *layer_shell; | 80 | struct zwlr_layer_shell_v1 *layer_shell; |
81 | struct zwlr_layer_surface_v1 *layer_surface; | 81 | struct zwlr_layer_surface_v1 *layer_surface; |
82 | struct wl_surface *surface; | 82 | struct wl_surface *surface; |
@@ -87,18 +87,18 @@ struct sway_nagbar { | |||
87 | struct pool_buffer buffers[2]; | 87 | struct pool_buffer buffers[2]; |
88 | struct pool_buffer *current_buffer; | 88 | struct pool_buffer *current_buffer; |
89 | 89 | ||
90 | struct sway_nagbar_type *type; | 90 | struct swaynag_type *type; |
91 | uint32_t anchors; | 91 | uint32_t anchors; |
92 | char *message; | 92 | char *message; |
93 | char *font; | 93 | char *font; |
94 | list_t *buttons; | 94 | list_t *buttons; |
95 | struct sway_nagbar_details details; | 95 | struct swaynag_details details; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | void nagbar_setup(struct sway_nagbar *nagbar); | 98 | void swaynag_setup(struct swaynag *swaynag); |
99 | 99 | ||
100 | void nagbar_run(struct sway_nagbar *nagbar); | 100 | void swaynag_run(struct swaynag *swaynag); |
101 | 101 | ||
102 | void nagbar_destroy(struct sway_nagbar *nagbar); | 102 | void swaynag_destroy(struct swaynag *swaynag); |
103 | 103 | ||
104 | #endif | 104 | #endif |
diff --git a/include/swaynag/types.h b/include/swaynag/types.h index 32056514..af83bd83 100644 --- a/include/swaynag/types.h +++ b/include/swaynag/types.h | |||
@@ -1,7 +1,7 @@ | |||
1 | #ifndef _SWAY_NAGBAR_TYPES_H | 1 | #ifndef _SWAYNAG_TYPES_H |
2 | #define _SWAY_NAGBAR_TYPES_H | 2 | #define _SWAYNAG_TYPES_H |
3 | 3 | ||
4 | struct sway_nagbar_type { | 4 | struct swaynag_type { |
5 | char *name; | 5 | char *name; |
6 | uint32_t button_background; | 6 | uint32_t button_background; |
7 | uint32_t background; | 7 | uint32_t background; |
@@ -10,16 +10,16 @@ struct sway_nagbar_type { | |||
10 | uint32_t border_bottom; | 10 | uint32_t border_bottom; |
11 | }; | 11 | }; |
12 | 12 | ||
13 | void nagbar_types_add_default(list_t *types); | 13 | void swaynag_types_add_default(list_t *types); |
14 | 14 | ||
15 | struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name); | 15 | struct swaynag_type *swaynag_type_get(list_t *types, char *name); |
16 | 16 | ||
17 | struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type); | 17 | struct swaynag_type *swaynag_type_clone(struct swaynag_type *type); |
18 | 18 | ||
19 | void nagbar_type_free(struct sway_nagbar_type *type); | 19 | void swaynag_type_free(struct swaynag_type *type); |
20 | 20 | ||
21 | void nagbar_types_free(list_t *types); | 21 | void swaynag_types_free(list_t *types); |
22 | 22 | ||
23 | int nagbar_parse_type(int argc, char **argv, struct sway_nagbar_type *type); | 23 | int swaynag_parse_type(int argc, char **argv, struct swaynag_type *type); |
24 | 24 | ||
25 | #endif | 25 | #endif |
diff --git a/swaynag/config.c b/swaynag/config.c index 4e7edf2e..289fc82a 100644 --- a/swaynag/config.c +++ b/swaynag/config.c | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "log.h" | 6 | #include "log.h" |
7 | #include "list.h" | 7 | #include "list.h" |
8 | #include "readline.h" | 8 | #include "readline.h" |
9 | #include "swaynag/nagbar.h" | 9 | #include "swaynag/swaynag.h" |
10 | #include "swaynag/types.h" | 10 | #include "swaynag/types.h" |
11 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 11 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
12 | 12 | ||
@@ -36,7 +36,7 @@ static char *read_from_stdin() { | |||
36 | return buffer; | 36 | return buffer; |
37 | } | 37 | } |
38 | 38 | ||
39 | int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, | 39 | int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, |
40 | list_t *types, char **config, bool *debug) { | 40 | list_t *types, char **config, bool *debug) { |
41 | static struct option opts[] = { | 41 | static struct option opts[] = { |
42 | {"button", required_argument, NULL, 'b'}, | 42 | {"button", required_argument, NULL, 'b'}, |
@@ -81,17 +81,17 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, | |||
81 | } | 81 | } |
82 | switch (c) { | 82 | switch (c) { |
83 | case 'b': // Button | 83 | case 'b': // Button |
84 | if (nagbar) { | 84 | if (swaynag) { |
85 | if (optind >= argc) { | 85 | if (optind >= argc) { |
86 | fprintf(stderr, "Missing action for button %s\n", optarg); | 86 | fprintf(stderr, "Missing action for button %s\n", optarg); |
87 | return EXIT_FAILURE; | 87 | return EXIT_FAILURE; |
88 | } | 88 | } |
89 | struct sway_nagbar_button *button; | 89 | struct swaynag_button *button; |
90 | button = calloc(sizeof(struct sway_nagbar_button), 1); | 90 | button = calloc(sizeof(struct swaynag_button), 1); |
91 | button->text = strdup(optarg); | 91 | button->text = strdup(optarg); |
92 | button->type = NAGBAR_ACTION_COMMAND; | 92 | button->type = SWAYNAG_ACTION_COMMAND; |
93 | button->action = strdup(argv[optind]); | 93 | button->action = strdup(argv[optind]); |
94 | list_add(nagbar->buttons, button); | 94 | list_add(swaynag->buttons, button); |
95 | } | 95 | } |
96 | optind++; | 96 | optind++; |
97 | break; | 97 | break; |
@@ -106,13 +106,13 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, | |||
106 | } | 106 | } |
107 | break; | 107 | break; |
108 | case 'e': // Edge | 108 | case 'e': // Edge |
109 | if (nagbar) { | 109 | if (swaynag) { |
110 | if (strcmp(optarg, "top") == 0) { | 110 | if (strcmp(optarg, "top") == 0) { |
111 | nagbar->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | 111 | swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
112 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | 112 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
113 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | 113 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; |
114 | } else if (strcmp(optarg, "bottom") == 0) { | 114 | } else if (strcmp(optarg, "bottom") == 0) { |
115 | nagbar->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | 115 | swaynag->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
116 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | 116 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
117 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | 117 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; |
118 | } else { | 118 | } else { |
@@ -122,49 +122,49 @@ int nagbar_parse_options(int argc, char **argv, struct sway_nagbar *nagbar, | |||
122 | } | 122 | } |
123 | break; | 123 | break; |
124 | case 'f': // Font | 124 | case 'f': // Font |
125 | if (nagbar) { | 125 | if (swaynag) { |
126 | free(nagbar->font); | 126 | free(swaynag->font); |
127 | nagbar->font = strdup(optarg); | 127 | swaynag->font = strdup(optarg); |
128 | } | 128 | } |
129 | break; | 129 | break; |
130 | case 'l': // Detailed Message | 130 | case 'l': // Detailed Message |
131 | if (nagbar) { | 131 | if (swaynag) { |
132 | free(nagbar->details.message); | 132 | free(swaynag->details.message); |
133 | nagbar->details.message = read_from_stdin(); | 133 | swaynag->details.message = read_from_stdin(); |
134 | nagbar->details.button_up.text = strdup("â–²"); | 134 | swaynag->details.button_up.text = strdup("â–²"); |
135 | nagbar->details.button_down.text = strdup("â–¼"); | 135 | swaynag->details.button_down.text = strdup("â–¼"); |
136 | } | 136 | } |
137 | break; | 137 | break; |
138 | case 'L': // Detailed Button Text | 138 | case 'L': // Detailed Button Text |
139 | if (nagbar) { | 139 | if (swaynag) { |
140 | free(nagbar->details.button_details.text); | 140 | free(swaynag->details.button_details.text); |
141 | nagbar->details.button_details.text = strdup(optarg); | 141 | swaynag->details.button_details.text = strdup(optarg); |
142 | } | 142 | } |
143 | break; | 143 | break; |
144 | case 'm': // Message | 144 | case 'm': // Message |
145 | if (nagbar) { | 145 | if (swaynag) { |
146 | free(nagbar->message); | 146 | free(swaynag->message); |
147 | nagbar->message = strdup(optarg); | 147 | swaynag->message = strdup(optarg); |
148 | } | 148 | } |
149 | break; | 149 | break; |
150 | case 'o': // Output | 150 | case 'o': // Output |
151 | if (nagbar) { | 151 | if (swaynag) { |
152 | free(nagbar->output.name); | 152 | free(swaynag->output.name); |
153 | nagbar->output.name = strdup(optarg); | 153 | swaynag->output.name = strdup(optarg); |
154 | } | 154 | } |
155 | break; | 155 | break; |
156 | case 's': // Dismiss Button Text | 156 | case 's': // Dismiss Button Text |
157 | if (nagbar) { | 157 | if (swaynag) { |
158 | struct sway_nagbar_button *button_close; | 158 | struct swaynag_button *button_close; |
159 | button_close = nagbar->buttons->items[0]; | 159 | button_close = swaynag->buttons->items[0]; |
160 | free(button_close->text); | 160 | free(button_close->text); |
161 | button_close->text = strdup(optarg); | 161 | button_close->text = strdup(optarg); |
162 | } | 162 | } |
163 | break; | 163 | break; |
164 | case 't': // Type | 164 | case 't': // Type |
165 | if (nagbar) { | 165 | if (swaynag) { |
166 | nagbar->type = nagbar_type_get(types, optarg); | 166 | swaynag->type = swaynag_type_get(types, optarg); |
167 | if (!nagbar->type) { | 167 | if (!swaynag->type) { |
168 | fprintf(stderr, "Unknown type %s\n", optarg); | 168 | fprintf(stderr, "Unknown type %s\n", optarg); |
169 | return EXIT_FAILURE; | 169 | return EXIT_FAILURE; |
170 | } | 170 | } |
@@ -186,7 +186,7 @@ static bool file_exists(const char *path) { | |||
186 | return path && access(path, R_OK) != -1; | 186 | return path && access(path, R_OK) != -1; |
187 | } | 187 | } |
188 | 188 | ||
189 | char *nagbar_get_config_path(void) { | 189 | char *swaynag_get_config_path(void) { |
190 | static const char *config_paths[] = { | 190 | static const char *config_paths[] = { |
191 | "$HOME/.swaynag/config", | 191 | "$HOME/.swaynag/config", |
192 | "$XDG_CONFIG_HOME/swaynag/config", | 192 | "$XDG_CONFIG_HOME/swaynag/config", |
@@ -223,13 +223,13 @@ char *nagbar_get_config_path(void) { | |||
223 | return NULL; | 223 | return NULL; |
224 | } | 224 | } |
225 | 225 | ||
226 | int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) { | 226 | int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) { |
227 | FILE *config = fopen(path, "r"); | 227 | FILE *config = fopen(path, "r"); |
228 | if (!config) { | 228 | if (!config) { |
229 | fprintf(stderr, "Failed to read config. Running without it.\n"); | 229 | fprintf(stderr, "Failed to read config. Running without it.\n"); |
230 | return 0; | 230 | return 0; |
231 | } | 231 | } |
232 | struct sway_nagbar_type *type = NULL; | 232 | struct swaynag_type *type = NULL; |
233 | char *line; | 233 | char *line; |
234 | int line_number = 0; | 234 | int line_number = 0; |
235 | while (!feof(config)) { | 235 | while (!feof(config)) { |
@@ -259,9 +259,9 @@ int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) { | |||
259 | } | 259 | } |
260 | char *name = calloc(1, close - line); | 260 | char *name = calloc(1, close - line); |
261 | strncat(name, line + 1, close - line - 1); | 261 | strncat(name, line + 1, close - line - 1); |
262 | type = nagbar_type_get(types, name); | 262 | type = swaynag_type_get(types, name); |
263 | if (!type) { | 263 | if (!type) { |
264 | type = calloc(1, sizeof(struct sway_nagbar_type)); | 264 | type = calloc(1, sizeof(struct swaynag_type)); |
265 | type->name = strdup(name); | 265 | type->name = strdup(name); |
266 | list_add(types, type); | 266 | list_add(types, type); |
267 | } | 267 | } |
@@ -272,9 +272,9 @@ int nagbar_load_config(char *path, struct sway_nagbar *nagbar, list_t *types) { | |||
272 | char *argv[] = {"swaynag", flag}; | 272 | char *argv[] = {"swaynag", flag}; |
273 | int result; | 273 | int result; |
274 | if (type) { | 274 | if (type) { |
275 | result = nagbar_parse_type(2, argv, type); | 275 | result = swaynag_parse_type(2, argv, type); |
276 | } else { | 276 | } else { |
277 | result = nagbar_parse_options(2, argv, nagbar, types, | 277 | result = swaynag_parse_options(2, argv, swaynag, types, |
278 | NULL, NULL); | 278 | NULL, NULL); |
279 | } | 279 | } |
280 | if (result != 0) { | 280 | if (result != 0) { |
diff --git a/swaynag/main.c b/swaynag/main.c index 5c97e12a..0493c1f0 100644 --- a/swaynag/main.c +++ b/swaynag/main.c | |||
@@ -3,19 +3,19 @@ | |||
3 | #include "log.h" | 3 | #include "log.h" |
4 | #include "list.h" | 4 | #include "list.h" |
5 | #include "swaynag/config.h" | 5 | #include "swaynag/config.h" |
6 | #include "swaynag/nagbar.h" | 6 | #include "swaynag/swaynag.h" |
7 | #include "swaynag/types.h" | 7 | #include "swaynag/types.h" |
8 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 8 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
9 | 9 | ||
10 | static struct sway_nagbar nagbar; | 10 | static struct swaynag swaynag; |
11 | 11 | ||
12 | void sig_handler(int signal) { | 12 | void sig_handler(int signal) { |
13 | nagbar_destroy(&nagbar); | 13 | swaynag_destroy(&swaynag); |
14 | exit(EXIT_FAILURE); | 14 | exit(EXIT_FAILURE); |
15 | } | 15 | } |
16 | 16 | ||
17 | void sway_terminate(int code) { | 17 | void sway_terminate(int code) { |
18 | nagbar_destroy(&nagbar); | 18 | swaynag_destroy(&swaynag); |
19 | exit(code); | 19 | exit(code); |
20 | } | 20 | } |
21 | 21 | ||
@@ -23,28 +23,28 @@ int main(int argc, char **argv) { | |||
23 | int exit_code = EXIT_SUCCESS; | 23 | int exit_code = EXIT_SUCCESS; |
24 | 24 | ||
25 | list_t *types = create_list(); | 25 | list_t *types = create_list(); |
26 | nagbar_types_add_default(types); | 26 | swaynag_types_add_default(types); |
27 | 27 | ||
28 | memset(&nagbar, 0, sizeof(nagbar)); | 28 | memset(&swaynag, 0, sizeof(swaynag)); |
29 | nagbar.anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | 29 | swaynag.anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
30 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | 30 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
31 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | 31 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; |
32 | nagbar.font = strdup("pango:monospace 10"); | 32 | swaynag.font = strdup("pango:monospace 10"); |
33 | nagbar.buttons = create_list(); | 33 | swaynag.buttons = create_list(); |
34 | 34 | ||
35 | struct sway_nagbar_button *button_close = | 35 | struct swaynag_button *button_close = |
36 | calloc(sizeof(struct sway_nagbar_button), 1); | 36 | calloc(sizeof(struct swaynag_button), 1); |
37 | button_close->text = strdup("X"); | 37 | button_close->text = strdup("X"); |
38 | button_close->type = NAGBAR_ACTION_DISMISS; | 38 | button_close->type = SWAYNAG_ACTION_DISMISS; |
39 | list_add(nagbar.buttons, button_close); | 39 | list_add(swaynag.buttons, button_close); |
40 | 40 | ||
41 | nagbar.details.button_details.text = strdup("Toggle Details"); | 41 | swaynag.details.button_details.text = strdup("Toggle Details"); |
42 | nagbar.details.button_details.type = NAGBAR_ACTION_EXPAND; | 42 | swaynag.details.button_details.type = SWAYNAG_ACTION_EXPAND; |
43 | 43 | ||
44 | 44 | ||
45 | char *config_path = NULL; | 45 | char *config_path = NULL; |
46 | bool debug = false; | 46 | bool debug = false; |
47 | int launch_status = nagbar_parse_options(argc, argv, NULL, NULL, | 47 | int launch_status = swaynag_parse_options(argc, argv, NULL, NULL, |
48 | &config_path, &debug); | 48 | &config_path, &debug); |
49 | if (launch_status != 0) { | 49 | if (launch_status != 0) { |
50 | exit_code = launch_status; | 50 | exit_code = launch_status; |
@@ -53,11 +53,11 @@ int main(int argc, char **argv) { | |||
53 | wlr_log_init(debug ? WLR_DEBUG : WLR_ERROR, NULL); | 53 | wlr_log_init(debug ? WLR_DEBUG : WLR_ERROR, NULL); |
54 | 54 | ||
55 | if (!config_path) { | 55 | if (!config_path) { |
56 | config_path = nagbar_get_config_path(); | 56 | config_path = swaynag_get_config_path(); |
57 | } | 57 | } |
58 | if (config_path) { | 58 | if (config_path) { |
59 | wlr_log(WLR_DEBUG, "Loading config file: %s", config_path); | 59 | wlr_log(WLR_DEBUG, "Loading config file: %s", config_path); |
60 | int config_status = nagbar_load_config(config_path, &nagbar, types); | 60 | int config_status = swaynag_load_config(config_path, &swaynag, types); |
61 | free(config_path); | 61 | free(config_path); |
62 | if (config_status != 0) { | 62 | if (config_status != 0) { |
63 | exit_code = config_status; | 63 | exit_code = config_status; |
@@ -66,7 +66,7 @@ int main(int argc, char **argv) { | |||
66 | } | 66 | } |
67 | 67 | ||
68 | if (argc > 1) { | 68 | if (argc > 1) { |
69 | int result = nagbar_parse_options(argc, argv, &nagbar, types, | 69 | int result = swaynag_parse_options(argc, argv, &swaynag, types, |
70 | NULL, NULL); | 70 | NULL, NULL); |
71 | if (result != 0) { | 71 | if (result != 0) { |
72 | exit_code = result; | 72 | exit_code = result; |
@@ -74,46 +74,46 @@ int main(int argc, char **argv) { | |||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | if (!nagbar.message) { | 77 | if (!swaynag.message) { |
78 | wlr_log(WLR_ERROR, "No message passed. Please provide --message/-m"); | 78 | wlr_log(WLR_ERROR, "No message passed. Please provide --message/-m"); |
79 | exit_code = EXIT_FAILURE; | 79 | exit_code = EXIT_FAILURE; |
80 | goto cleanup; | 80 | goto cleanup; |
81 | } | 81 | } |
82 | 82 | ||
83 | if (!nagbar.type) { | 83 | if (!swaynag.type) { |
84 | nagbar.type = nagbar_type_get(types, "error"); | 84 | swaynag.type = swaynag_type_get(types, "error"); |
85 | } | 85 | } |
86 | 86 | ||
87 | nagbar.type = nagbar_type_clone(nagbar.type); | 87 | swaynag.type = swaynag_type_clone(swaynag.type); |
88 | nagbar_types_free(types); | 88 | swaynag_types_free(types); |
89 | 89 | ||
90 | if (nagbar.details.message) { | 90 | if (swaynag.details.message) { |
91 | list_add(nagbar.buttons, &nagbar.details.button_details); | 91 | list_add(swaynag.buttons, &swaynag.details.button_details); |
92 | } else { | 92 | } else { |
93 | free(nagbar.details.button_details.text); | 93 | free(swaynag.details.button_details.text); |
94 | } | 94 | } |
95 | 95 | ||
96 | wlr_log(WLR_DEBUG, "Output: %s", nagbar.output.name); | 96 | wlr_log(WLR_DEBUG, "Output: %s", swaynag.output.name); |
97 | wlr_log(WLR_DEBUG, "Anchors: %d", nagbar.anchors); | 97 | wlr_log(WLR_DEBUG, "Anchors: %d", swaynag.anchors); |
98 | wlr_log(WLR_DEBUG, "Type: %s", nagbar.type->name); | 98 | wlr_log(WLR_DEBUG, "Type: %s", swaynag.type->name); |
99 | wlr_log(WLR_DEBUG, "Message: %s", nagbar.message); | 99 | wlr_log(WLR_DEBUG, "Message: %s", swaynag.message); |
100 | wlr_log(WLR_DEBUG, "Font: %s", nagbar.font); | 100 | wlr_log(WLR_DEBUG, "Font: %s", swaynag.font); |
101 | wlr_log(WLR_DEBUG, "Buttons"); | 101 | wlr_log(WLR_DEBUG, "Buttons"); |
102 | for (int i = 0; i < nagbar.buttons->length; i++) { | 102 | for (int i = 0; i < swaynag.buttons->length; i++) { |
103 | struct sway_nagbar_button *button = nagbar.buttons->items[i]; | 103 | struct swaynag_button *button = swaynag.buttons->items[i]; |
104 | wlr_log(WLR_DEBUG, "\t[%s] `%s`", button->text, button->action); | 104 | wlr_log(WLR_DEBUG, "\t[%s] `%s`", button->text, button->action); |
105 | } | 105 | } |
106 | 106 | ||
107 | signal(SIGTERM, sig_handler); | 107 | signal(SIGTERM, sig_handler); |
108 | 108 | ||
109 | nagbar_setup(&nagbar); | 109 | swaynag_setup(&swaynag); |
110 | nagbar_run(&nagbar); | 110 | swaynag_run(&swaynag); |
111 | return exit_code; | 111 | return exit_code; |
112 | 112 | ||
113 | cleanup: | 113 | cleanup: |
114 | nagbar_types_free(types); | 114 | swaynag_types_free(types); |
115 | free(nagbar.details.button_details.text); | 115 | free(swaynag.details.button_details.text); |
116 | nagbar_destroy(&nagbar); | 116 | swaynag_destroy(&swaynag); |
117 | return exit_code; | 117 | return exit_code; |
118 | } | 118 | } |
119 | 119 | ||
diff --git a/swaynag/meson.build b/swaynag/meson.build index b2425504..f67c10ff 100644 --- a/swaynag/meson.build +++ b/swaynag/meson.build | |||
@@ -2,8 +2,8 @@ executable( | |||
2 | 'swaynag', [ | 2 | 'swaynag', [ |
3 | 'config.c', | 3 | 'config.c', |
4 | 'main.c', | 4 | 'main.c', |
5 | 'nagbar.c', | ||
6 | 'render.c', | 5 | 'render.c', |
6 | 'swaynag.c', | ||
7 | 'types.c', | 7 | 'types.c', |
8 | ], | 8 | ], |
9 | include_directories: [sway_inc], | 9 | include_directories: [sway_inc], |
diff --git a/swaynag/render.c b/swaynag/render.c index ef0f72a8..67e26eaf 100644 --- a/swaynag/render.c +++ b/swaynag/render.c | |||
@@ -3,99 +3,100 @@ | |||
3 | #include "log.h" | 3 | #include "log.h" |
4 | #include "pango.h" | 4 | #include "pango.h" |
5 | #include "pool-buffer.h" | 5 | #include "pool-buffer.h" |
6 | #include "swaynag/nagbar.h" | 6 | #include "swaynag/swaynag.h" |
7 | #include "swaynag/types.h" | 7 | #include "swaynag/types.h" |
8 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 8 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
9 | 9 | ||
10 | static uint32_t render_message(cairo_t *cairo, struct sway_nagbar *nagbar) { | 10 | static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) { |
11 | uint32_t height = nagbar->height * nagbar->scale; | 11 | uint32_t height = swaynag->height * swaynag->scale; |
12 | height -= NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; | 12 | height -= SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale; |
13 | 13 | ||
14 | int text_width, text_height; | 14 | int text_width, text_height; |
15 | get_text_size(cairo, nagbar->font, &text_width, &text_height, | 15 | get_text_size(cairo, swaynag->font, &text_width, &text_height, |
16 | nagbar->scale, true, "%s", nagbar->message); | 16 | swaynag->scale, true, "%s", swaynag->message); |
17 | 17 | ||
18 | int padding = NAGBAR_MESSAGE_PADDING * nagbar->scale; | 18 | int padding = SWAYNAG_MESSAGE_PADDING * swaynag->scale; |
19 | 19 | ||
20 | uint32_t ideal_height = text_height + padding * 2; | 20 | uint32_t ideal_height = text_height + padding * 2; |
21 | uint32_t ideal_surface_height = ideal_height / nagbar->scale; | 21 | uint32_t ideal_surface_height = ideal_height / swaynag->scale; |
22 | if (nagbar->height < ideal_surface_height) { | 22 | if (swaynag->height < ideal_surface_height) { |
23 | return ideal_surface_height; | 23 | return ideal_surface_height; |
24 | } | 24 | } |
25 | 25 | ||
26 | cairo_set_source_u32(cairo, nagbar->type->text); | 26 | cairo_set_source_u32(cairo, swaynag->type->text); |
27 | cairo_move_to(cairo, padding, (int)(ideal_height - text_height) / 2); | 27 | cairo_move_to(cairo, padding, (int)(ideal_height - text_height) / 2); |
28 | pango_printf(cairo, nagbar->font, nagbar->scale, false, "%s", | 28 | pango_printf(cairo, swaynag->font, swaynag->scale, false, "%s", |
29 | nagbar->message); | 29 | swaynag->message); |
30 | 30 | ||
31 | return ideal_height; | 31 | return ideal_height; |
32 | } | 32 | } |
33 | 33 | ||
34 | static void render_details_scroll_button(cairo_t *cairo, | 34 | static void render_details_scroll_button(cairo_t *cairo, |
35 | struct sway_nagbar *nagbar, struct sway_nagbar_button *button) { | 35 | struct swaynag *swaynag, struct swaynag_button *button) { |
36 | int text_width, text_height; | 36 | int text_width, text_height; |
37 | get_text_size(cairo, nagbar->font, &text_width, &text_height, | 37 | get_text_size(cairo, swaynag->font, &text_width, &text_height, |
38 | nagbar->scale, true, "%s", button->text); | 38 | swaynag->scale, true, "%s", button->text); |
39 | 39 | ||
40 | int border = NAGBAR_BUTTON_BORDER_THICKNESS * nagbar->scale; | 40 | int border = SWAYNAG_BUTTON_BORDER_THICKNESS * swaynag->scale; |
41 | int padding = NAGBAR_BUTTON_PADDING * nagbar->scale; | 41 | int padding = SWAYNAG_BUTTON_PADDING * swaynag->scale; |
42 | 42 | ||
43 | cairo_set_source_u32(cairo, nagbar->type->border); | 43 | cairo_set_source_u32(cairo, swaynag->type->border); |
44 | cairo_rectangle(cairo, button->x, button->y, | 44 | cairo_rectangle(cairo, button->x, button->y, |
45 | button->width, button->height); | 45 | button->width, button->height); |
46 | cairo_fill(cairo); | 46 | cairo_fill(cairo); |
47 | 47 | ||
48 | cairo_set_source_u32(cairo, nagbar->type->button_background); | 48 | cairo_set_source_u32(cairo, swaynag->type->button_background); |
49 | cairo_rectangle(cairo, button->x + border, button->y + border, | 49 | cairo_rectangle(cairo, button->x + border, button->y + border, |
50 | button->width - (border * 2), button->height - (border * 2)); | 50 | button->width - (border * 2), button->height - (border * 2)); |
51 | cairo_fill(cairo); | 51 | cairo_fill(cairo); |
52 | 52 | ||
53 | cairo_set_source_u32(cairo, nagbar->type->text); | 53 | cairo_set_source_u32(cairo, swaynag->type->text); |
54 | cairo_move_to(cairo, button->x + border + padding, | 54 | cairo_move_to(cairo, button->x + border + padding, |
55 | button->y + border + (button->height - text_height) / 2); | 55 | button->y + border + (button->height - text_height) / 2); |
56 | pango_printf(cairo, nagbar->font, nagbar->scale, true, "%s", button->text); | 56 | pango_printf(cairo, swaynag->font, swaynag->scale, true, |
57 | "%s", button->text); | ||
57 | } | 58 | } |
58 | 59 | ||
59 | static int get_detailed_scroll_button_width(cairo_t *cairo, | 60 | static int get_detailed_scroll_button_width(cairo_t *cairo, |
60 | struct sway_nagbar *nagbar) { | 61 | struct swaynag *swaynag) { |
61 | int up_width, down_width, temp_height; | 62 | int up_width, down_width, temp_height; |
62 | get_text_size(cairo, nagbar->font, &up_width, &temp_height, | 63 | get_text_size(cairo, swaynag->font, &up_width, &temp_height, |
63 | nagbar->scale, true, "%s", nagbar->details.button_up.text); | 64 | swaynag->scale, true, "%s", swaynag->details.button_up.text); |
64 | get_text_size(cairo, nagbar->font, &down_width, &temp_height, | 65 | get_text_size(cairo, swaynag->font, &down_width, &temp_height, |
65 | nagbar->scale, true, "%s", nagbar->details.button_down.text); | 66 | swaynag->scale, true, "%s", swaynag->details.button_down.text); |
66 | 67 | ||
67 | int text_width = up_width > down_width ? up_width : down_width; | 68 | int text_width = up_width > down_width ? up_width : down_width; |
68 | int border = NAGBAR_BUTTON_BORDER_THICKNESS * nagbar->scale; | 69 | int border = SWAYNAG_BUTTON_BORDER_THICKNESS * swaynag->scale; |
69 | int padding = NAGBAR_BUTTON_PADDING * nagbar->scale; | 70 | int padding = SWAYNAG_BUTTON_PADDING * swaynag->scale; |
70 | 71 | ||
71 | return text_width + border * 2 + padding * 2; | 72 | return text_width + border * 2 + padding * 2; |
72 | } | 73 | } |
73 | 74 | ||
74 | static uint32_t render_detailed(cairo_t *cairo, struct sway_nagbar *nagbar, | 75 | static uint32_t render_detailed(cairo_t *cairo, struct swaynag *swaynag, |
75 | uint32_t y) { | 76 | uint32_t y) { |
76 | uint32_t width = nagbar->width * nagbar->scale; | 77 | uint32_t width = swaynag->width * swaynag->scale; |
77 | uint32_t height = nagbar->height * nagbar->scale; | 78 | uint32_t height = swaynag->height * swaynag->scale; |
78 | height -= NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; | 79 | height -= SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale; |
79 | 80 | ||
80 | int border = NAGBAR_DETAILS_BORDER_THICKNESS * nagbar->scale; | 81 | int border = SWAYNAG_DETAILS_BORDER_THICKNESS * swaynag->scale; |
81 | int padding = NAGBAR_MESSAGE_PADDING * nagbar->scale; | 82 | int padding = SWAYNAG_MESSAGE_PADDING * swaynag->scale; |
82 | int decor = padding + border; | 83 | int decor = padding + border; |
83 | 84 | ||
84 | nagbar->details.x = decor; | 85 | swaynag->details.x = decor; |
85 | nagbar->details.y = y + decor; | 86 | swaynag->details.y = y + decor; |
86 | nagbar->details.width = width - decor * 2; | 87 | swaynag->details.width = width - decor * 2; |
87 | 88 | ||
88 | PangoLayout *layout = get_pango_layout(cairo, nagbar->font, | 89 | PangoLayout *layout = get_pango_layout(cairo, swaynag->font, |
89 | nagbar->details.message, nagbar->scale, false); | 90 | swaynag->details.message, swaynag->scale, false); |
90 | pango_layout_set_width(layout, | 91 | pango_layout_set_width(layout, |
91 | (nagbar->details.width - padding * 2) * PANGO_SCALE); | 92 | (swaynag->details.width - padding * 2) * PANGO_SCALE); |
92 | pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); | 93 | pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
93 | pango_layout_set_single_paragraph_mode(layout, false); | 94 | pango_layout_set_single_paragraph_mode(layout, false); |
94 | pango_cairo_update_layout(cairo, layout); | 95 | pango_cairo_update_layout(cairo, layout); |
95 | nagbar->details.total_lines = pango_layout_get_line_count(layout); | 96 | swaynag->details.total_lines = pango_layout_get_line_count(layout); |
96 | 97 | ||
97 | PangoLayoutLine *line; | 98 | PangoLayoutLine *line; |
98 | line = pango_layout_get_line_readonly(layout, nagbar->details.offset); | 99 | line = pango_layout_get_line_readonly(layout, swaynag->details.offset); |
99 | gint offset = line->start_index; | 100 | gint offset = line->start_index; |
100 | const char *text = pango_layout_get_text(layout); | 101 | const char *text = pango_layout_get_text(layout); |
101 | pango_layout_set_text(layout, text + offset, strlen(text) - offset); | 102 | 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, | |||
104 | pango_cairo_update_layout(cairo, layout); | 105 | pango_cairo_update_layout(cairo, layout); |
105 | pango_layout_get_pixel_size(layout, &text_width, &text_height); | 106 | pango_layout_get_pixel_size(layout, &text_width, &text_height); |
106 | 107 | ||
107 | bool show_buttons = nagbar->details.offset > 0; | 108 | bool show_buttons = swaynag->details.offset > 0; |
108 | int button_width = get_detailed_scroll_button_width(cairo, nagbar); | 109 | int button_width = get_detailed_scroll_button_width(cairo, swaynag); |
109 | if (show_buttons) { | 110 | if (show_buttons) { |
110 | nagbar->details.width -= button_width; | 111 | swaynag->details.width -= button_width; |
111 | pango_layout_set_width(layout, | 112 | pango_layout_set_width(layout, |
112 | (nagbar->details.width - padding * 2) * PANGO_SCALE); | 113 | (swaynag->details.width - padding * 2) * PANGO_SCALE); |
113 | } | 114 | } |
114 | 115 | ||
115 | uint32_t ideal_height; | 116 | uint32_t ideal_height; |
116 | do { | 117 | do { |
117 | ideal_height = nagbar->details.y + text_height + decor + padding * 2; | 118 | ideal_height = swaynag->details.y + text_height + decor + padding * 2; |
118 | if (ideal_height > NAGBAR_MAX_HEIGHT) { | 119 | if (ideal_height > SWAYNAG_MAX_HEIGHT) { |
119 | ideal_height = NAGBAR_MAX_HEIGHT; | 120 | ideal_height = SWAYNAG_MAX_HEIGHT; |
120 | 121 | ||
121 | if (!show_buttons) { | 122 | if (!show_buttons) { |
122 | show_buttons = true; | 123 | show_buttons = true; |
123 | nagbar->details.width -= button_width; | 124 | swaynag->details.width -= button_width; |
124 | pango_layout_set_width(layout, | 125 | pango_layout_set_width(layout, |
125 | (nagbar->details.width - padding * 2) * PANGO_SCALE); | 126 | (swaynag->details.width - padding * 2) * PANGO_SCALE); |
126 | } | 127 | } |
127 | } | 128 | } |
128 | 129 | ||
129 | nagbar->details.height = ideal_height - nagbar->details.y - decor; | 130 | swaynag->details.height = ideal_height - swaynag->details.y - decor; |
130 | pango_layout_set_height(layout, | 131 | pango_layout_set_height(layout, |
131 | (nagbar->details.height - padding * 2) * PANGO_SCALE); | 132 | (swaynag->details.height - padding * 2) * PANGO_SCALE); |
132 | pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); | 133 | pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
133 | pango_cairo_update_layout(cairo, layout); | 134 | pango_cairo_update_layout(cairo, layout); |
134 | pango_layout_get_pixel_size(layout, &text_width, &text_height); | 135 | pango_layout_get_pixel_size(layout, &text_width, &text_height); |
135 | } while (text_height != (nagbar->details.height - padding * 2)); | 136 | } while (text_height != (swaynag->details.height - padding * 2)); |
136 | 137 | ||
137 | nagbar->details.visible_lines = pango_layout_get_line_count(layout); | 138 | swaynag->details.visible_lines = pango_layout_get_line_count(layout); |
138 | 139 | ||
139 | if (show_buttons) { | 140 | if (show_buttons) { |
140 | nagbar->details.button_up.x = | 141 | swaynag->details.button_up.x = |
141 | nagbar->details.x + nagbar->details.width; | 142 | swaynag->details.x + swaynag->details.width; |
142 | nagbar->details.button_up.y = nagbar->details.y; | 143 | swaynag->details.button_up.y = swaynag->details.y; |
143 | nagbar->details.button_up.width = button_width; | 144 | swaynag->details.button_up.width = button_width; |
144 | nagbar->details.button_up.height = nagbar->details.height / 2; | 145 | swaynag->details.button_up.height = swaynag->details.height / 2; |
145 | render_details_scroll_button(cairo, nagbar, | 146 | render_details_scroll_button(cairo, swaynag, |
146 | &nagbar->details.button_up); | 147 | &swaynag->details.button_up); |
147 | 148 | ||
148 | nagbar->details.button_down.x = | 149 | swaynag->details.button_down.x = |
149 | nagbar->details.x + nagbar->details.width; | 150 | swaynag->details.x + swaynag->details.width; |
150 | nagbar->details.button_down.y = | 151 | swaynag->details.button_down.y = |
151 | nagbar->details.button_up.y + nagbar->details.button_up.height; | 152 | swaynag->details.button_up.y + swaynag->details.button_up.height; |
152 | nagbar->details.button_down.width = button_width; | 153 | swaynag->details.button_down.width = button_width; |
153 | nagbar->details.button_down.height = nagbar->details.height / 2; | 154 | swaynag->details.button_down.height = swaynag->details.height / 2; |
154 | render_details_scroll_button(cairo, nagbar, | 155 | render_details_scroll_button(cairo, swaynag, |
155 | &nagbar->details.button_down); | 156 | &swaynag->details.button_down); |
156 | } | 157 | } |
157 | 158 | ||
158 | cairo_set_source_u32(cairo, nagbar->type->border); | 159 | cairo_set_source_u32(cairo, swaynag->type->border); |
159 | cairo_rectangle(cairo, nagbar->details.x, nagbar->details.y, | 160 | cairo_rectangle(cairo, swaynag->details.x, swaynag->details.y, |
160 | nagbar->details.width, nagbar->details.height); | 161 | swaynag->details.width, swaynag->details.height); |
161 | cairo_fill(cairo); | 162 | cairo_fill(cairo); |
162 | 163 | ||
163 | cairo_move_to(cairo, nagbar->details.x + padding, | 164 | cairo_move_to(cairo, swaynag->details.x + padding, |
164 | nagbar->details.y + padding); | 165 | swaynag->details.y + padding); |
165 | cairo_set_source_u32(cairo, nagbar->type->text); | 166 | cairo_set_source_u32(cairo, swaynag->type->text); |
166 | pango_cairo_show_layout(cairo, layout); | 167 | pango_cairo_show_layout(cairo, layout); |
167 | g_object_unref(layout); | 168 | g_object_unref(layout); |
168 | 169 | ||
169 | return ideal_height; | 170 | return ideal_height; |
170 | } | 171 | } |
171 | 172 | ||
172 | static uint32_t render_button(cairo_t *cairo, struct sway_nagbar *nagbar, | 173 | static uint32_t render_button(cairo_t *cairo, struct swaynag *swaynag, |
173 | int button_index, int *x) { | 174 | int button_index, int *x) { |
174 | uint32_t height = nagbar->height * nagbar->scale; | 175 | uint32_t height = swaynag->height * swaynag->scale; |
175 | height -= NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; | 176 | height -= SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale; |
176 | struct sway_nagbar_button *button = nagbar->buttons->items[button_index]; | 177 | struct swaynag_button *button = swaynag->buttons->items[button_index]; |
177 | 178 | ||
178 | int text_width, text_height; | 179 | int text_width, text_height; |
179 | get_text_size(cairo, nagbar->font, &text_width, &text_height, | 180 | get_text_size(cairo, swaynag->font, &text_width, &text_height, |
180 | nagbar->scale, true, "%s", button->text); | 181 | swaynag->scale, true, "%s", button->text); |
181 | 182 | ||
182 | int border = NAGBAR_BUTTON_BORDER_THICKNESS * nagbar->scale; | 183 | int border = SWAYNAG_BUTTON_BORDER_THICKNESS * swaynag->scale; |
183 | int padding = NAGBAR_BUTTON_PADDING * nagbar->scale; | 184 | int padding = SWAYNAG_BUTTON_PADDING * swaynag->scale; |
184 | 185 | ||
185 | uint32_t ideal_height = text_height + padding * 2 + border * 2; | 186 | uint32_t ideal_height = text_height + padding * 2 + border * 2; |
186 | uint32_t ideal_surface_height = ideal_height / nagbar->scale; | 187 | uint32_t ideal_surface_height = ideal_height / swaynag->scale; |
187 | if (nagbar->height < ideal_surface_height) { | 188 | if (swaynag->height < ideal_surface_height) { |
188 | return ideal_surface_height; | 189 | return ideal_surface_height; |
189 | } | 190 | } |
190 | 191 | ||
@@ -193,64 +194,65 @@ static uint32_t render_button(cairo_t *cairo, struct sway_nagbar *nagbar, | |||
193 | button->width = text_width + padding * 2; | 194 | button->width = text_width + padding * 2; |
194 | button->height = text_height + padding * 2; | 195 | button->height = text_height + padding * 2; |
195 | 196 | ||
196 | cairo_set_source_u32(cairo, nagbar->type->border); | 197 | cairo_set_source_u32(cairo, swaynag->type->border); |
197 | cairo_rectangle(cairo, button->x - border, button->y - border, | 198 | cairo_rectangle(cairo, button->x - border, button->y - border, |
198 | button->width + border * 2, button->height + border * 2); | 199 | button->width + border * 2, button->height + border * 2); |
199 | cairo_fill(cairo); | 200 | cairo_fill(cairo); |
200 | 201 | ||
201 | cairo_set_source_u32(cairo, nagbar->type->button_background); | 202 | cairo_set_source_u32(cairo, swaynag->type->button_background); |
202 | cairo_rectangle(cairo, button->x, button->y, | 203 | cairo_rectangle(cairo, button->x, button->y, |
203 | button->width, button->height); | 204 | button->width, button->height); |
204 | cairo_fill(cairo); | 205 | cairo_fill(cairo); |
205 | 206 | ||
206 | cairo_set_source_u32(cairo, nagbar->type->text); | 207 | cairo_set_source_u32(cairo, swaynag->type->text); |
207 | cairo_move_to(cairo, button->x + padding, button->y + padding); | 208 | cairo_move_to(cairo, button->x + padding, button->y + padding); |
208 | pango_printf(cairo, nagbar->font, nagbar->scale, true, "%s", button->text); | 209 | pango_printf(cairo, swaynag->font, swaynag->scale, true, |
210 | "%s", button->text); | ||
209 | 211 | ||
210 | *x = button->x - border; | 212 | *x = button->x - border; |
211 | 213 | ||
212 | return ideal_height; | 214 | return ideal_height; |
213 | } | 215 | } |
214 | 216 | ||
215 | static uint32_t render_to_cairo(cairo_t *cairo, struct sway_nagbar *nagbar) { | 217 | static uint32_t render_to_cairo(cairo_t *cairo, struct swaynag *swaynag) { |
216 | uint32_t max_height = 0; | 218 | uint32_t max_height = 0; |
217 | 219 | ||
218 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); | 220 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); |
219 | cairo_set_source_u32(cairo, nagbar->type->background); | 221 | cairo_set_source_u32(cairo, swaynag->type->background); |
220 | cairo_paint(cairo); | 222 | cairo_paint(cairo); |
221 | 223 | ||
222 | uint32_t h = render_message(cairo, nagbar); | 224 | uint32_t h = render_message(cairo, swaynag); |
223 | max_height = h > max_height ? h : max_height; | 225 | max_height = h > max_height ? h : max_height; |
224 | 226 | ||
225 | int x = (nagbar->width - NAGBAR_BUTTON_MARGIN_RIGHT) * nagbar->scale; | 227 | int x = (swaynag->width - SWAYNAG_BUTTON_MARGIN_RIGHT) * swaynag->scale; |
226 | for (int i = 0; i < nagbar->buttons->length; i++) { | 228 | for (int i = 0; i < swaynag->buttons->length; i++) { |
227 | h = render_button(cairo, nagbar, i, &x); | 229 | h = render_button(cairo, swaynag, i, &x); |
228 | max_height = h > max_height ? h : max_height; | 230 | max_height = h > max_height ? h : max_height; |
229 | x -= NAGBAR_BUTTON_GAP * nagbar->scale; | 231 | x -= SWAYNAG_BUTTON_GAP * swaynag->scale; |
230 | if (i == 0) { | 232 | if (i == 0) { |
231 | x -= NAGBAR_BUTTON_GAP_CLOSE * nagbar->scale; | 233 | x -= SWAYNAG_BUTTON_GAP_CLOSE * swaynag->scale; |
232 | } | 234 | } |
233 | } | 235 | } |
234 | 236 | ||
235 | if (nagbar->details.visible) { | 237 | if (swaynag->details.visible) { |
236 | h = render_detailed(cairo, nagbar, max_height); | 238 | h = render_detailed(cairo, swaynag, max_height); |
237 | max_height = h > max_height ? h : max_height; | 239 | max_height = h > max_height ? h : max_height; |
238 | } | 240 | } |
239 | 241 | ||
240 | int border = NAGBAR_BAR_BORDER_THICKNESS * nagbar->scale; | 242 | int border = SWAYNAG_BAR_BORDER_THICKNESS * swaynag->scale; |
241 | if (max_height > nagbar->height) { | 243 | if (max_height > swaynag->height) { |
242 | max_height += border; | 244 | max_height += border; |
243 | } | 245 | } |
244 | cairo_set_source_u32(cairo, nagbar->type->border_bottom); | 246 | cairo_set_source_u32(cairo, swaynag->type->border_bottom); |
245 | cairo_rectangle(cairo, 0, nagbar->height * nagbar->scale - border, | 247 | cairo_rectangle(cairo, 0, swaynag->height * swaynag->scale - border, |
246 | nagbar->width * nagbar->scale, border); | 248 | swaynag->width * swaynag->scale, border); |
247 | cairo_fill(cairo); | 249 | cairo_fill(cairo); |
248 | 250 | ||
249 | return max_height; | 251 | return max_height; |
250 | } | 252 | } |
251 | 253 | ||
252 | void render_frame(struct sway_nagbar *nagbar) { | 254 | void render_frame(struct swaynag *swaynag) { |
253 | if (!nagbar->run_display) { | 255 | if (!swaynag->run_display) { |
254 | return; | 256 | return; |
255 | } | 257 | } |
256 | 258 | ||
@@ -261,24 +263,24 @@ void render_frame(struct sway_nagbar *nagbar) { | |||
261 | cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); | 263 | cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); |
262 | cairo_paint(cairo); | 264 | cairo_paint(cairo); |
263 | cairo_restore(cairo); | 265 | cairo_restore(cairo); |
264 | uint32_t height = render_to_cairo(cairo, nagbar); | 266 | uint32_t height = render_to_cairo(cairo, swaynag); |
265 | if (height != nagbar->height) { | 267 | if (height != swaynag->height) { |
266 | zwlr_layer_surface_v1_set_size(nagbar->layer_surface, 0, height); | 268 | zwlr_layer_surface_v1_set_size(swaynag->layer_surface, 0, height); |
267 | zwlr_layer_surface_v1_set_exclusive_zone(nagbar->layer_surface, | 269 | zwlr_layer_surface_v1_set_exclusive_zone(swaynag->layer_surface, |
268 | height); | 270 | height); |
269 | wl_surface_commit(nagbar->surface); | 271 | wl_surface_commit(swaynag->surface); |
270 | wl_display_roundtrip(nagbar->display); | 272 | wl_display_roundtrip(swaynag->display); |
271 | } else { | 273 | } else { |
272 | nagbar->current_buffer = get_next_buffer(nagbar->shm, | 274 | swaynag->current_buffer = get_next_buffer(swaynag->shm, |
273 | nagbar->buffers, | 275 | swaynag->buffers, |
274 | nagbar->width * nagbar->scale, | 276 | swaynag->width * swaynag->scale, |
275 | nagbar->height * nagbar->scale); | 277 | swaynag->height * swaynag->scale); |
276 | if (!nagbar->current_buffer) { | 278 | if (!swaynag->current_buffer) { |
277 | wlr_log(WLR_DEBUG, "Failed to get buffer. Skipping frame."); | 279 | wlr_log(WLR_DEBUG, "Failed to get buffer. Skipping frame."); |
278 | goto cleanup; | 280 | goto cleanup; |
279 | } | 281 | } |
280 | 282 | ||
281 | cairo_t *shm = nagbar->current_buffer->cairo; | 283 | cairo_t *shm = swaynag->current_buffer->cairo; |
282 | cairo_save(shm); | 284 | cairo_save(shm); |
283 | cairo_set_operator(shm, CAIRO_OPERATOR_CLEAR); | 285 | cairo_set_operator(shm, CAIRO_OPERATOR_CLEAR); |
284 | cairo_paint(shm); | 286 | cairo_paint(shm); |
@@ -286,13 +288,13 @@ void render_frame(struct sway_nagbar *nagbar) { | |||
286 | cairo_set_source_surface(shm, recorder, 0.0, 0.0); | 288 | cairo_set_source_surface(shm, recorder, 0.0, 0.0); |
287 | cairo_paint(shm); | 289 | cairo_paint(shm); |
288 | 290 | ||
289 | wl_surface_set_buffer_scale(nagbar->surface, nagbar->scale); | 291 | wl_surface_set_buffer_scale(swaynag->surface, swaynag->scale); |
290 | wl_surface_attach(nagbar->surface, | 292 | wl_surface_attach(swaynag->surface, |
291 | nagbar->current_buffer->buffer, 0, 0); | 293 | swaynag->current_buffer->buffer, 0, 0); |
292 | wl_surface_damage(nagbar->surface, 0, 0, | 294 | wl_surface_damage(swaynag->surface, 0, 0, |
293 | nagbar->width, nagbar->height); | 295 | swaynag->width, swaynag->height); |
294 | wl_surface_commit(nagbar->surface); | 296 | wl_surface_commit(swaynag->surface); |
295 | wl_display_roundtrip(nagbar->display); | 297 | wl_display_roundtrip(swaynag->display); |
296 | } | 298 | } |
297 | 299 | ||
298 | cleanup: | 300 | cleanup: |
diff --git a/swaynag/nagbar.c b/swaynag/swaynag.c index e451a53a..367e0854 100644 --- a/swaynag/nagbar.c +++ b/swaynag/swaynag.c | |||
@@ -6,8 +6,8 @@ | |||
6 | #include <wayland-cursor.h> | 6 | #include <wayland-cursor.h> |
7 | #include "log.h" | 7 | #include "log.h" |
8 | #include "list.h" | 8 | #include "list.h" |
9 | #include "swaynag/nagbar.h" | ||
10 | #include "swaynag/render.h" | 9 | #include "swaynag/render.h" |
10 | #include "swaynag/swaynag.h" | ||
11 | #include "swaynag/types.h" | 11 | #include "swaynag/types.h" |
12 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 12 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
13 | 13 | ||
@@ -32,14 +32,14 @@ static bool terminal_execute(char *terminal, char *command) { | |||
32 | return true; | 32 | return true; |
33 | } | 33 | } |
34 | 34 | ||
35 | static void nagbar_button_execute(struct sway_nagbar *nagbar, | 35 | static void swaynag_button_execute(struct swaynag *swaynag, |
36 | struct sway_nagbar_button *button) { | 36 | struct swaynag_button *button) { |
37 | wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action); | 37 | wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action); |
38 | if (button->type == NAGBAR_ACTION_DISMISS) { | 38 | if (button->type == SWAYNAG_ACTION_DISMISS) { |
39 | nagbar->run_display = false; | 39 | swaynag->run_display = false; |
40 | } else if (button->type == NAGBAR_ACTION_EXPAND) { | 40 | } else if (button->type == SWAYNAG_ACTION_EXPAND) { |
41 | nagbar->details.visible = !nagbar->details.visible; | 41 | swaynag->details.visible = !swaynag->details.visible; |
42 | render_frame(nagbar); | 42 | render_frame(swaynag); |
43 | } else { | 43 | } else { |
44 | if (fork() == 0) { | 44 | if (fork() == 0) { |
45 | // Child process. Will be used to prevent zombie processes | 45 | // Child process. Will be used to prevent zombie processes |
@@ -50,7 +50,7 @@ static void nagbar_button_execute(struct sway_nagbar *nagbar, | |||
50 | if (terminal && strlen(terminal)) { | 50 | if (terminal && strlen(terminal)) { |
51 | wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal); | 51 | wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal); |
52 | if (!terminal_execute(terminal, button->action)) { | 52 | if (!terminal_execute(terminal, button->action)) { |
53 | nagbar_destroy(nagbar); | 53 | swaynag_destroy(swaynag); |
54 | exit(EXIT_FAILURE); | 54 | exit(EXIT_FAILURE); |
55 | } | 55 | } |
56 | } else { | 56 | } else { |
@@ -67,17 +67,17 @@ static void nagbar_button_execute(struct sway_nagbar *nagbar, | |||
67 | static void layer_surface_configure(void *data, | 67 | static void layer_surface_configure(void *data, |
68 | struct zwlr_layer_surface_v1 *surface, | 68 | struct zwlr_layer_surface_v1 *surface, |
69 | uint32_t serial, uint32_t width, uint32_t height) { | 69 | uint32_t serial, uint32_t width, uint32_t height) { |
70 | struct sway_nagbar *nagbar = data; | 70 | struct swaynag *swaynag = data; |
71 | nagbar->width = width; | 71 | swaynag->width = width; |
72 | nagbar->height = height; | 72 | swaynag->height = height; |
73 | zwlr_layer_surface_v1_ack_configure(surface, serial); | 73 | zwlr_layer_surface_v1_ack_configure(surface, serial); |
74 | render_frame(nagbar); | 74 | render_frame(swaynag); |
75 | } | 75 | } |
76 | 76 | ||
77 | static void layer_surface_closed(void *data, | 77 | static void layer_surface_closed(void *data, |
78 | struct zwlr_layer_surface_v1 *surface) { | 78 | struct zwlr_layer_surface_v1 *surface) { |
79 | struct sway_nagbar *nagbar = data; | 79 | struct swaynag *swaynag = data; |
80 | nagbar_destroy(nagbar); | 80 | swaynag_destroy(swaynag); |
81 | } | 81 | } |
82 | 82 | ||
83 | static struct zwlr_layer_surface_v1_listener layer_surface_listener = { | 83 | static struct zwlr_layer_surface_v1_listener layer_surface_listener = { |
@@ -88,67 +88,67 @@ static struct zwlr_layer_surface_v1_listener layer_surface_listener = { | |||
88 | static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | 88 | static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, |
89 | uint32_t serial, struct wl_surface *surface, | 89 | uint32_t serial, struct wl_surface *surface, |
90 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | 90 | wl_fixed_t surface_x, wl_fixed_t surface_y) { |
91 | struct sway_nagbar *nagbar = data; | 91 | struct swaynag *swaynag = data; |
92 | struct sway_nagbar_pointer *pointer = &nagbar->pointer; | 92 | struct swaynag_pointer *pointer = &swaynag->pointer; |
93 | wl_surface_set_buffer_scale(pointer->cursor_surface, nagbar->scale); | 93 | wl_surface_set_buffer_scale(pointer->cursor_surface, swaynag->scale); |
94 | wl_surface_attach(pointer->cursor_surface, | 94 | wl_surface_attach(pointer->cursor_surface, |
95 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); | 95 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); |
96 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, | 96 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, |
97 | pointer->cursor_image->hotspot_x / nagbar->scale, | 97 | pointer->cursor_image->hotspot_x / swaynag->scale, |
98 | pointer->cursor_image->hotspot_y / nagbar->scale); | 98 | pointer->cursor_image->hotspot_y / swaynag->scale); |
99 | wl_surface_commit(pointer->cursor_surface); | 99 | wl_surface_commit(pointer->cursor_surface); |
100 | } | 100 | } |
101 | 101 | ||
102 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | 102 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, |
103 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | 103 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { |
104 | struct sway_nagbar *nagbar = data; | 104 | struct swaynag *swaynag = data; |
105 | nagbar->pointer.x = wl_fixed_to_int(surface_x); | 105 | swaynag->pointer.x = wl_fixed_to_int(surface_x); |
106 | nagbar->pointer.y = wl_fixed_to_int(surface_y); | 106 | swaynag->pointer.y = wl_fixed_to_int(surface_y); |
107 | } | 107 | } |
108 | 108 | ||
109 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | 109 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, |
110 | uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { | 110 | uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { |
111 | struct sway_nagbar *nagbar = data; | 111 | struct swaynag *swaynag = data; |
112 | 112 | ||
113 | if (state != WL_POINTER_BUTTON_STATE_PRESSED) { | 113 | if (state != WL_POINTER_BUTTON_STATE_PRESSED) { |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | 116 | ||
117 | double x = nagbar->pointer.x * nagbar->scale; | 117 | double x = swaynag->pointer.x * swaynag->scale; |
118 | double y = nagbar->pointer.y * nagbar->scale; | 118 | double y = swaynag->pointer.y * swaynag->scale; |
119 | for (int i = 0; i < nagbar->buttons->length; i++) { | 119 | for (int i = 0; i < swaynag->buttons->length; i++) { |
120 | struct sway_nagbar_button *nagbutton = nagbar->buttons->items[i]; | 120 | struct swaynag_button *nagbutton = swaynag->buttons->items[i]; |
121 | if (x >= nagbutton->x | 121 | if (x >= nagbutton->x |
122 | && y >= nagbutton->y | 122 | && y >= nagbutton->y |
123 | && x < nagbutton->x + nagbutton->width | 123 | && x < nagbutton->x + nagbutton->width |
124 | && y < nagbutton->y + nagbutton->height) { | 124 | && y < nagbutton->y + nagbutton->height) { |
125 | nagbar_button_execute(nagbar, nagbutton); | 125 | swaynag_button_execute(swaynag, nagbutton); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | if (nagbar->details.visible && | 130 | if (swaynag->details.visible && |
131 | nagbar->details.total_lines != nagbar->details.visible_lines) { | 131 | swaynag->details.total_lines != swaynag->details.visible_lines) { |
132 | struct sway_nagbar_button button_up = nagbar->details.button_up; | 132 | struct swaynag_button button_up = swaynag->details.button_up; |
133 | if (x >= button_up.x | 133 | if (x >= button_up.x |
134 | && y >= button_up.y | 134 | && y >= button_up.y |
135 | && x < button_up.x + button_up.width | 135 | && x < button_up.x + button_up.width |
136 | && y < button_up.y + button_up.height | 136 | && y < button_up.y + button_up.height |
137 | && nagbar->details.offset > 0) { | 137 | && swaynag->details.offset > 0) { |
138 | nagbar->details.offset--; | 138 | swaynag->details.offset--; |
139 | render_frame(nagbar); | 139 | render_frame(swaynag); |
140 | return; | 140 | return; |
141 | } | 141 | } |
142 | 142 | ||
143 | struct sway_nagbar_button button_down = nagbar->details.button_down; | 143 | struct swaynag_button button_down = swaynag->details.button_down; |
144 | int bot = nagbar->details.total_lines - nagbar->details.visible_lines; | 144 | int bot = swaynag->details.total_lines - swaynag->details.visible_lines; |
145 | if (x >= button_down.x | 145 | if (x >= button_down.x |
146 | && y >= button_down.y | 146 | && y >= button_down.y |
147 | && x < button_down.x + button_down.width | 147 | && x < button_down.x + button_down.width |
148 | && y < button_down.y + button_down.height | 148 | && y < button_down.y + button_down.height |
149 | && nagbar->details.offset < bot) { | 149 | && swaynag->details.offset < bot) { |
150 | nagbar->details.offset++; | 150 | swaynag->details.offset++; |
151 | render_frame(nagbar); | 151 | render_frame(swaynag); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | } | 154 | } |
@@ -156,25 +156,25 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
156 | 156 | ||
157 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | 157 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, |
158 | uint32_t time, uint32_t axis, wl_fixed_t value) { | 158 | uint32_t time, uint32_t axis, wl_fixed_t value) { |
159 | struct sway_nagbar *nagbar = data; | 159 | struct swaynag *swaynag = data; |
160 | if (!nagbar->details.visible | 160 | if (!swaynag->details.visible |
161 | || nagbar->pointer.x < nagbar->details.x | 161 | || swaynag->pointer.x < swaynag->details.x |
162 | || nagbar->pointer.y < nagbar->details.y | 162 | || swaynag->pointer.y < swaynag->details.y |
163 | || nagbar->pointer.x >= nagbar->details.x + nagbar->details.width | 163 | || swaynag->pointer.x >= swaynag->details.x + swaynag->details.width |
164 | || nagbar->pointer.y >= nagbar->details.y + nagbar->details.height | 164 | || swaynag->pointer.y >= swaynag->details.y + swaynag->details.height |
165 | || nagbar->details.total_lines == nagbar->details.visible_lines) { | 165 | || swaynag->details.total_lines == swaynag->details.visible_lines) { |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | 168 | ||
169 | int direction = wl_fixed_to_int(value); | 169 | int direction = wl_fixed_to_int(value); |
170 | int bot = nagbar->details.total_lines - nagbar->details.visible_lines; | 170 | int bot = swaynag->details.total_lines - swaynag->details.visible_lines; |
171 | if (direction < 0 && nagbar->details.offset > 0) { | 171 | if (direction < 0 && swaynag->details.offset > 0) { |
172 | nagbar->details.offset--; | 172 | swaynag->details.offset--; |
173 | } else if (direction > 0 && nagbar->details.offset < bot) { | 173 | } else if (direction > 0 && swaynag->details.offset < bot) { |
174 | nagbar->details.offset++; | 174 | swaynag->details.offset++; |
175 | } | 175 | } |
176 | 176 | ||
177 | render_frame(nagbar); | 177 | render_frame(swaynag); |
178 | } | 178 | } |
179 | 179 | ||
180 | static struct wl_pointer_listener pointer_listener = { | 180 | static struct wl_pointer_listener pointer_listener = { |
@@ -191,11 +191,11 @@ static struct wl_pointer_listener pointer_listener = { | |||
191 | 191 | ||
192 | static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, | 192 | static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, |
193 | enum wl_seat_capability caps) { | 193 | enum wl_seat_capability caps) { |
194 | struct sway_nagbar *nagbar = data; | 194 | struct swaynag *swaynag = data; |
195 | if ((caps & WL_SEAT_CAPABILITY_POINTER)) { | 195 | if ((caps & WL_SEAT_CAPABILITY_POINTER)) { |
196 | nagbar->pointer.pointer = wl_seat_get_pointer(wl_seat); | 196 | swaynag->pointer.pointer = wl_seat_get_pointer(wl_seat); |
197 | wl_pointer_add_listener(nagbar->pointer.pointer, &pointer_listener, | 197 | wl_pointer_add_listener(swaynag->pointer.pointer, &pointer_listener, |
198 | nagbar); | 198 | swaynag); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
@@ -206,9 +206,9 @@ const struct wl_seat_listener seat_listener = { | |||
206 | 206 | ||
207 | static void output_scale(void *data, struct wl_output *output, | 207 | static void output_scale(void *data, struct wl_output *output, |
208 | int32_t factor) { | 208 | int32_t factor) { |
209 | struct sway_nagbar *nagbar = data; | 209 | struct swaynag *swaynag = data; |
210 | nagbar->scale = factor; | 210 | swaynag->scale = factor; |
211 | render_frame(nagbar); | 211 | render_frame(swaynag); |
212 | } | 212 | } |
213 | 213 | ||
214 | static struct wl_output_listener output_listener = { | 214 | static struct wl_output_listener output_listener = { |
@@ -222,27 +222,27 @@ struct output_state { | |||
222 | struct wl_output *wl_output; | 222 | struct wl_output *wl_output; |
223 | uint32_t wl_name; | 223 | uint32_t wl_name; |
224 | struct zxdg_output_v1 *xdg_output; | 224 | struct zxdg_output_v1 *xdg_output; |
225 | struct sway_nagbar *nagbar; | 225 | struct swaynag *swaynag; |
226 | }; | 226 | }; |
227 | 227 | ||
228 | static void xdg_output_handle_name(void *data, | 228 | static void xdg_output_handle_name(void *data, |
229 | struct zxdg_output_v1 *xdg_output, const char *name) { | 229 | struct zxdg_output_v1 *xdg_output, const char *name) { |
230 | struct output_state *state = data; | 230 | struct output_state *state = data; |
231 | char *outname = state->nagbar->output.name; | 231 | char *outname = state->swaynag->output.name; |
232 | wlr_log(WLR_DEBUG, "Checking against output %s for %s", name, outname); | 232 | wlr_log(WLR_DEBUG, "Checking against output %s for %s", name, outname); |
233 | if (outname && !state->nagbar->output.wl_output) { | 233 | if (outname && !state->swaynag->output.wl_output) { |
234 | wlr_log(WLR_DEBUG, "Using output %s", name); | 234 | wlr_log(WLR_DEBUG, "Using output %s", name); |
235 | state->nagbar->output.wl_output = state->wl_output; | 235 | state->swaynag->output.wl_output = state->wl_output; |
236 | state->nagbar->output.wl_name = state->wl_name; | 236 | state->swaynag->output.wl_name = state->wl_name; |
237 | wl_output_add_listener(state->nagbar->output.wl_output, | 237 | wl_output_add_listener(state->swaynag->output.wl_output, |
238 | &output_listener, state->nagbar); | 238 | &output_listener, state->swaynag); |
239 | wl_display_roundtrip(state->nagbar->display); | 239 | wl_display_roundtrip(state->swaynag->display); |
240 | zxdg_output_v1_destroy(state->xdg_output); | 240 | zxdg_output_v1_destroy(state->xdg_output); |
241 | } else { | 241 | } else { |
242 | zxdg_output_v1_destroy(state->xdg_output); | 242 | zxdg_output_v1_destroy(state->xdg_output); |
243 | wl_output_destroy(state->wl_output); | 243 | wl_output_destroy(state->wl_output); |
244 | } | 244 | } |
245 | state->nagbar->querying_outputs--; | 245 | state->swaynag->querying_outputs--; |
246 | free(state); | 246 | free(state); |
247 | } | 247 | } |
248 | 248 | ||
@@ -256,35 +256,35 @@ static struct zxdg_output_v1_listener xdg_output_listener = { | |||
256 | 256 | ||
257 | static void handle_global(void *data, struct wl_registry *registry, | 257 | static void handle_global(void *data, struct wl_registry *registry, |
258 | uint32_t name, const char *interface, uint32_t version) { | 258 | uint32_t name, const char *interface, uint32_t version) { |
259 | struct sway_nagbar *nagbar = data; | 259 | struct swaynag *swaynag = data; |
260 | if (strcmp(interface, wl_compositor_interface.name) == 0) { | 260 | if (strcmp(interface, wl_compositor_interface.name) == 0) { |
261 | nagbar->compositor = wl_registry_bind(registry, name, | 261 | swaynag->compositor = wl_registry_bind(registry, name, |
262 | &wl_compositor_interface, 3); | 262 | &wl_compositor_interface, 3); |
263 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { | 263 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { |
264 | nagbar->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1); | 264 | swaynag->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1); |
265 | wl_seat_add_listener(nagbar->seat, &seat_listener, nagbar); | 265 | wl_seat_add_listener(swaynag->seat, &seat_listener, swaynag); |
266 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { | 266 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { |
267 | nagbar->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); | 267 | swaynag->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); |
268 | } else if (strcmp(interface, wl_output_interface.name) == 0) { | 268 | } else if (strcmp(interface, wl_output_interface.name) == 0) { |
269 | if (!nagbar->output.wl_output && nagbar->xdg_output_manager) { | 269 | if (!swaynag->output.wl_output && swaynag->xdg_output_manager) { |
270 | nagbar->querying_outputs++; | 270 | swaynag->querying_outputs++; |
271 | struct output_state *state = | 271 | struct output_state *state = |
272 | calloc(1, sizeof(struct output_state)); | 272 | calloc(1, sizeof(struct output_state)); |
273 | state->nagbar = nagbar; | 273 | state->swaynag = swaynag; |
274 | state->wl_output = wl_registry_bind(registry, name, | 274 | state->wl_output = wl_registry_bind(registry, name, |
275 | &wl_output_interface, 3); | 275 | &wl_output_interface, 3); |
276 | state->wl_name = name; | 276 | state->wl_name = name; |
277 | state->xdg_output = zxdg_output_manager_v1_get_xdg_output( | 277 | state->xdg_output = zxdg_output_manager_v1_get_xdg_output( |
278 | nagbar->xdg_output_manager, state->wl_output); | 278 | swaynag->xdg_output_manager, state->wl_output); |
279 | zxdg_output_v1_add_listener(state->xdg_output, | 279 | zxdg_output_v1_add_listener(state->xdg_output, |
280 | &xdg_output_listener, state); | 280 | &xdg_output_listener, state); |
281 | } | 281 | } |
282 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { | 282 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { |
283 | nagbar->layer_shell = wl_registry_bind( | 283 | swaynag->layer_shell = wl_registry_bind( |
284 | registry, name, &zwlr_layer_shell_v1_interface, 1); | 284 | registry, name, &zwlr_layer_shell_v1_interface, 1); |
285 | } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 | 285 | } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 |
286 | && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { | 286 | && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { |
287 | nagbar->xdg_output_manager = wl_registry_bind(registry, name, | 287 | swaynag->xdg_output_manager = wl_registry_bind(registry, name, |
288 | &zxdg_output_manager_v1_interface, | 288 | &zxdg_output_manager_v1_interface, |
289 | ZXDG_OUTPUT_V1_NAME_SINCE_VERSION); | 289 | ZXDG_OUTPUT_V1_NAME_SINCE_VERSION); |
290 | } | 290 | } |
@@ -292,9 +292,9 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
292 | 292 | ||
293 | static void handle_global_remove(void *data, struct wl_registry *registry, | 293 | static void handle_global_remove(void *data, struct wl_registry *registry, |
294 | uint32_t name) { | 294 | uint32_t name) { |
295 | struct sway_nagbar *nagbar = data; | 295 | struct swaynag *swaynag = data; |
296 | if (nagbar->output.wl_name == name) { | 296 | if (swaynag->output.wl_name == name) { |
297 | nagbar->run_display = false; | 297 | swaynag->run_display = false; |
298 | } | 298 | } |
299 | } | 299 | } |
300 | 300 | ||
@@ -303,110 +303,111 @@ static const struct wl_registry_listener registry_listener = { | |||
303 | .global_remove = handle_global_remove, | 303 | .global_remove = handle_global_remove, |
304 | }; | 304 | }; |
305 | 305 | ||
306 | void nagbar_setup(struct sway_nagbar *nagbar) { | 306 | void swaynag_setup(struct swaynag *swaynag) { |
307 | nagbar->display = wl_display_connect(NULL); | 307 | swaynag->display = wl_display_connect(NULL); |
308 | assert(nagbar->display); | 308 | assert(swaynag->display); |
309 | 309 | ||
310 | nagbar->scale = 1; | 310 | swaynag->scale = 1; |
311 | 311 | ||
312 | struct wl_registry *registry = wl_display_get_registry(nagbar->display); | 312 | struct wl_registry *registry = wl_display_get_registry(swaynag->display); |
313 | wl_registry_add_listener(registry, ®istry_listener, nagbar); | 313 | wl_registry_add_listener(registry, ®istry_listener, swaynag); |
314 | wl_display_roundtrip(nagbar->display); | 314 | wl_display_roundtrip(swaynag->display); |
315 | assert(nagbar->compositor && nagbar->layer_shell && nagbar->shm); | 315 | assert(swaynag->compositor && swaynag->layer_shell && swaynag->shm); |
316 | 316 | ||
317 | while (nagbar->querying_outputs > 0) { | 317 | while (swaynag->querying_outputs > 0) { |
318 | wl_display_roundtrip(nagbar->display); | 318 | wl_display_roundtrip(swaynag->display); |
319 | } | 319 | } |
320 | 320 | ||
321 | if (!nagbar->output.wl_output && nagbar->output.name) { | 321 | if (!swaynag->output.wl_output && swaynag->output.name) { |
322 | wlr_log(WLR_ERROR, "Output '%s' not found", nagbar->output.name); | 322 | wlr_log(WLR_ERROR, "Output '%s' not found", swaynag->output.name); |
323 | nagbar_destroy(nagbar); | 323 | swaynag_destroy(swaynag); |
324 | exit(EXIT_FAILURE); | 324 | exit(EXIT_FAILURE); |
325 | } | 325 | } |
326 | 326 | ||
327 | struct sway_nagbar_pointer *pointer = &nagbar->pointer; | 327 | struct swaynag_pointer *pointer = &swaynag->pointer; |
328 | int scale = nagbar->scale < 1 ? 1 : nagbar->scale; | 328 | int scale = swaynag->scale < 1 ? 1 : swaynag->scale; |
329 | pointer->cursor_theme = wl_cursor_theme_load( | 329 | pointer->cursor_theme = wl_cursor_theme_load( |
330 | NULL, 24 * scale, nagbar->shm); | 330 | NULL, 24 * scale, swaynag->shm); |
331 | assert(pointer->cursor_theme); | 331 | assert(pointer->cursor_theme); |
332 | struct wl_cursor *cursor = | 332 | struct wl_cursor *cursor = |
333 | wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); | 333 | wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); |
334 | assert(cursor); | 334 | assert(cursor); |
335 | pointer->cursor_image = cursor->images[0]; | 335 | pointer->cursor_image = cursor->images[0]; |
336 | pointer->cursor_surface = wl_compositor_create_surface(nagbar->compositor); | 336 | pointer->cursor_surface = wl_compositor_create_surface(swaynag->compositor); |
337 | assert(pointer->cursor_surface); | 337 | assert(pointer->cursor_surface); |
338 | 338 | ||
339 | nagbar->surface = wl_compositor_create_surface(nagbar->compositor); | 339 | swaynag->surface = wl_compositor_create_surface(swaynag->compositor); |
340 | assert(nagbar->surface); | 340 | assert(swaynag->surface); |
341 | nagbar->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | 341 | swaynag->layer_surface = zwlr_layer_shell_v1_get_layer_surface( |
342 | nagbar->layer_shell, nagbar->surface, nagbar->output.wl_output, | 342 | swaynag->layer_shell, swaynag->surface, swaynag->output.wl_output, |
343 | ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag"); | 343 | ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag"); |
344 | assert(nagbar->layer_surface); | 344 | assert(swaynag->layer_surface); |
345 | zwlr_layer_surface_v1_add_listener(nagbar->layer_surface, | 345 | zwlr_layer_surface_v1_add_listener(swaynag->layer_surface, |
346 | &layer_surface_listener, nagbar); | 346 | &layer_surface_listener, swaynag); |
347 | zwlr_layer_surface_v1_set_anchor(nagbar->layer_surface, nagbar->anchors); | 347 | zwlr_layer_surface_v1_set_anchor(swaynag->layer_surface, swaynag->anchors); |
348 | 348 | ||
349 | wl_registry_destroy(registry); | 349 | wl_registry_destroy(registry); |
350 | } | 350 | } |
351 | 351 | ||
352 | void nagbar_run(struct sway_nagbar *nagbar) { | 352 | void swaynag_run(struct swaynag *swaynag) { |
353 | nagbar->run_display = true; | 353 | swaynag->run_display = true; |
354 | render_frame(nagbar); | 354 | render_frame(swaynag); |
355 | while (nagbar->run_display && wl_display_dispatch(nagbar->display) != -1) { | 355 | while (swaynag->run_display |
356 | && wl_display_dispatch(swaynag->display) != -1) { | ||
356 | // This is intentionally left blank | 357 | // This is intentionally left blank |
357 | } | 358 | } |
358 | } | 359 | } |
359 | 360 | ||
360 | void nagbar_destroy(struct sway_nagbar *nagbar) { | 361 | void swaynag_destroy(struct swaynag *swaynag) { |
361 | nagbar->run_display = false; | 362 | swaynag->run_display = false; |
362 | 363 | ||
363 | free(nagbar->message); | 364 | free(swaynag->message); |
364 | free(nagbar->font); | 365 | free(swaynag->font); |
365 | while (nagbar->buttons->length) { | 366 | while (swaynag->buttons->length) { |
366 | struct sway_nagbar_button *button = nagbar->buttons->items[0]; | 367 | struct swaynag_button *button = swaynag->buttons->items[0]; |
367 | list_del(nagbar->buttons, 0); | 368 | list_del(swaynag->buttons, 0); |
368 | free(button->text); | 369 | free(button->text); |
369 | free(button->action); | 370 | free(button->action); |
370 | free(button); | 371 | free(button); |
371 | } | 372 | } |
372 | list_free(nagbar->buttons); | 373 | list_free(swaynag->buttons); |
373 | free(nagbar->details.message); | 374 | free(swaynag->details.message); |
374 | free(nagbar->details.button_up.text); | 375 | free(swaynag->details.button_up.text); |
375 | free(nagbar->details.button_down.text); | 376 | free(swaynag->details.button_down.text); |
376 | 377 | ||
377 | if (nagbar->type) { | 378 | if (swaynag->type) { |
378 | nagbar_type_free(nagbar->type); | 379 | swaynag_type_free(swaynag->type); |
379 | } | 380 | } |
380 | 381 | ||
381 | if (nagbar->layer_surface) { | 382 | if (swaynag->layer_surface) { |
382 | zwlr_layer_surface_v1_destroy(nagbar->layer_surface); | 383 | zwlr_layer_surface_v1_destroy(swaynag->layer_surface); |
383 | } | 384 | } |
384 | 385 | ||
385 | if (nagbar->surface) { | 386 | if (swaynag->surface) { |
386 | wl_surface_destroy(nagbar->surface); | 387 | wl_surface_destroy(swaynag->surface); |
387 | } | 388 | } |
388 | 389 | ||
389 | if (nagbar->output.wl_output) { | 390 | if (swaynag->output.wl_output) { |
390 | wl_output_destroy(nagbar->output.wl_output); | 391 | wl_output_destroy(swaynag->output.wl_output); |
391 | } | 392 | } |
392 | 393 | ||
393 | if (&nagbar->buffers[0]) { | 394 | if (&swaynag->buffers[0]) { |
394 | destroy_buffer(&nagbar->buffers[0]); | 395 | destroy_buffer(&swaynag->buffers[0]); |
395 | } | 396 | } |
396 | 397 | ||
397 | if (&nagbar->buffers[1]) { | 398 | if (&swaynag->buffers[1]) { |
398 | destroy_buffer(&nagbar->buffers[1]); | 399 | destroy_buffer(&swaynag->buffers[1]); |
399 | } | 400 | } |
400 | 401 | ||
401 | if (nagbar->compositor) { | 402 | if (swaynag->compositor) { |
402 | wl_compositor_destroy(nagbar->compositor); | 403 | wl_compositor_destroy(swaynag->compositor); |
403 | } | 404 | } |
404 | 405 | ||
405 | if (nagbar->shm) { | 406 | if (swaynag->shm) { |
406 | wl_shm_destroy(nagbar->shm); | 407 | wl_shm_destroy(swaynag->shm); |
407 | } | 408 | } |
408 | 409 | ||
409 | if (nagbar->display) { | 410 | if (swaynag->display) { |
410 | wl_display_disconnect(nagbar->display); | 411 | wl_display_disconnect(swaynag->display); |
411 | } | 412 | } |
412 | } | 413 | } |
diff --git a/swaynag/types.c b/swaynag/types.c index dbc841f7..c92d0e89 100644 --- a/swaynag/types.c +++ b/swaynag/types.c | |||
@@ -10,9 +10,9 @@ | |||
10 | #include "swaynag/types.h" | 10 | #include "swaynag/types.h" |
11 | #include "util.h" | 11 | #include "util.h" |
12 | 12 | ||
13 | void nagbar_types_add_default(list_t *types) { | 13 | void swaynag_types_add_default(list_t *types) { |
14 | struct sway_nagbar_type *type_error; | 14 | struct swaynag_type *type_error; |
15 | type_error = calloc(1, sizeof(struct sway_nagbar_type)); | 15 | type_error = calloc(1, sizeof(struct swaynag_type)); |
16 | type_error->name = strdup("error"); | 16 | type_error->name = strdup("error"); |
17 | type_error->button_background = 0x680A0AFF; | 17 | type_error->button_background = 0x680A0AFF; |
18 | type_error->background = 0x900000FF; | 18 | type_error->background = 0x900000FF; |
@@ -21,8 +21,8 @@ void nagbar_types_add_default(list_t *types) { | |||
21 | type_error->border_bottom = 0x470909FF; | 21 | type_error->border_bottom = 0x470909FF; |
22 | list_add(types, type_error); | 22 | list_add(types, type_error); |
23 | 23 | ||
24 | struct sway_nagbar_type *type_warning; | 24 | struct swaynag_type *type_warning; |
25 | type_warning = calloc(1, sizeof(struct sway_nagbar_type)); | 25 | type_warning = calloc(1, sizeof(struct swaynag_type)); |
26 | type_warning->name = strdup("warning"); | 26 | type_warning->name = strdup("warning"); |
27 | type_warning->button_background = 0xFFC100FF; | 27 | type_warning->button_background = 0xFFC100FF; |
28 | type_warning->background = 0xFFA800FF; | 28 | type_warning->background = 0xFFA800FF; |
@@ -32,9 +32,9 @@ void nagbar_types_add_default(list_t *types) { | |||
32 | list_add(types, type_warning); | 32 | list_add(types, type_warning); |
33 | } | 33 | } |
34 | 34 | ||
35 | struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name) { | 35 | struct swaynag_type *swaynag_type_get(list_t *types, char *name) { |
36 | for (int i = 0; i < types->length; i++) { | 36 | for (int i = 0; i < types->length; i++) { |
37 | struct sway_nagbar_type *type = types->items[i]; | 37 | struct swaynag_type *type = types->items[i]; |
38 | if (strcasecmp(type->name, name) == 0) { | 38 | if (strcasecmp(type->name, name) == 0) { |
39 | return type; | 39 | return type; |
40 | } | 40 | } |
@@ -42,9 +42,9 @@ struct sway_nagbar_type *nagbar_type_get(list_t *types, char *name) { | |||
42 | return NULL; | 42 | return NULL; |
43 | } | 43 | } |
44 | 44 | ||
45 | struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type) { | 45 | struct swaynag_type *swaynag_type_clone(struct swaynag_type *type) { |
46 | struct sway_nagbar_type *clone; | 46 | struct swaynag_type *clone; |
47 | clone = calloc(1, sizeof(struct sway_nagbar_type)); | 47 | clone = calloc(1, sizeof(struct swaynag_type)); |
48 | clone->name = strdup(type->name); | 48 | clone->name = strdup(type->name); |
49 | clone->button_background = type->button_background; | 49 | clone->button_background = type->button_background; |
50 | clone->background = type->background; | 50 | clone->background = type->background; |
@@ -54,21 +54,21 @@ struct sway_nagbar_type *nagbar_type_clone(struct sway_nagbar_type *type) { | |||
54 | return clone; | 54 | return clone; |
55 | } | 55 | } |
56 | 56 | ||
57 | void nagbar_type_free(struct sway_nagbar_type *type) { | 57 | void swaynag_type_free(struct swaynag_type *type) { |
58 | free(type->name); | 58 | free(type->name); |
59 | free(type); | 59 | free(type); |
60 | } | 60 | } |
61 | 61 | ||
62 | void nagbar_types_free(list_t *types) { | 62 | void swaynag_types_free(list_t *types) { |
63 | while (types->length) { | 63 | while (types->length) { |
64 | struct sway_nagbar_type *type = types->items[0]; | 64 | struct swaynag_type *type = types->items[0]; |
65 | nagbar_type_free(type); | 65 | swaynag_type_free(type); |
66 | list_del(types, 0); | 66 | list_del(types, 0); |
67 | } | 67 | } |
68 | list_free(types); | 68 | list_free(types); |
69 | } | 69 | } |
70 | 70 | ||
71 | int nagbar_parse_type(int argc, char **argv, struct sway_nagbar_type *type) { | 71 | int swaynag_parse_type(int argc, char **argv, struct swaynag_type *type) { |
72 | enum color_option { | 72 | enum color_option { |
73 | COLOR_BACKGROUND, | 73 | COLOR_BACKGROUND, |
74 | COLOR_BORDER, | 74 | COLOR_BORDER, |