summaryrefslogtreecommitdiff
path: root/swaynag
diff options
context:
space:
mode:
authorReza Jelveh <[email protected]>2024-04-15 13:39:41 +0800
committerGitHub <[email protected]>2024-04-15 01:39:41 -0400
commitfb86ed6b0588dfdebfb66ce875bc63cfa0a897f6 (patch)
tree29857a1769107adc58696f08d379f608aa4e29a2 /swaynag
parenta5e79676c4bd22fc5902182acf0667907202a465 (diff)
feat: 1.9 merge (#277)
Co-authored-by: William McKinnon <[email protected]> Co-authored-by: Erik Reider <[email protected]>
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/config.c10
-rw-r--r--swaynag/main.c25
-rw-r--r--swaynag/swaynag.c42
-rw-r--r--swaynag/types.c8
4 files changed, 51 insertions, 34 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index db86c1b8..b355b153 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -166,7 +166,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
fprintf(stderr, "Missing action for button %s\n", optarg);
return EXIT_FAILURE;
}
- struct swaynag_button *button = calloc(sizeof(struct swaynag_button), 1);
+ struct swaynag_button *button = calloc(1, sizeof(struct swaynag_button));
if (!button) {
perror("calloc");
return EXIT_FAILURE;
@@ -226,10 +226,8 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
break;
case 'f': // Font
if (type) {
- free(type->font);
pango_font_description_free(type->font_description);
- type->font = strdup(optarg);
- type->font_description = pango_font_description_from_string(type->font);
+ type->font_description = pango_font_description_from_string(optarg);
}
break;
case 'l': // Detailed Message
@@ -245,8 +243,8 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
break;
case 'L': // Detailed Button Text
if (swaynag) {
- free(swaynag->details.button_details.text);
- swaynag->details.button_details.text = strdup(optarg);
+ free(swaynag->details.details_text);
+ swaynag->details.details_text = strdup(optarg);
}
break;
case 'm': // Message
diff --git a/swaynag/main.c b/swaynag/main.c
index 2ce37831..20390207 100644
--- a/swaynag/main.c
+++ b/swaynag/main.c
@@ -29,10 +29,12 @@ int main(int argc, char **argv) {
wl_list_init(&swaynag.outputs);
wl_list_init(&swaynag.seats);
- struct swaynag_button button_close = { 0 };
- button_close.text = strdup("X");
- button_close.type = SWAYNAG_ACTION_DISMISS;
- list_add(swaynag.buttons, &button_close);
+ struct swaynag_button *button_close = calloc(1, sizeof(struct swaynag_button));
+ button_close->text = strdup("X");
+ button_close->type = SWAYNAG_ACTION_DISMISS;
+ list_add(swaynag.buttons, button_close);
+
+ swaynag.details.details_text = strdup("Toggle details");
char *config_path = NULL;
bool debug = false;
@@ -54,8 +56,6 @@ int main(int argc, char **argv) {
}
}
- swaynag.details.button_details.text = strdup("Toggle details");
- swaynag.details.button_details.type = SWAYNAG_ACTION_EXPAND;
if (argc > 1) {
struct swaynag_type *type_args = swaynag_type_new("<args>");
@@ -88,17 +88,20 @@ int main(int argc, char **argv) {
swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
swaynag.type = type;
- swaynag_types_free(types);
-
if (swaynag.details.message) {
- list_add(swaynag.buttons, &swaynag.details.button_details);
+ swaynag.details.button_details = calloc(1, sizeof(struct swaynag_button));
+ swaynag.details.button_details->text = strdup(swaynag.details.details_text);
+ swaynag.details.button_details->type = SWAYNAG_ACTION_EXPAND;
+ list_add(swaynag.buttons, swaynag.details.button_details);
}
sway_log(SWAY_DEBUG, "Output: %s", swaynag.type->output);
sway_log(SWAY_DEBUG, "Anchors: %" PRIu32, swaynag.type->anchors);
sway_log(SWAY_DEBUG, "Type: %s", swaynag.type->name);
sway_log(SWAY_DEBUG, "Message: %s", swaynag.message);
- sway_log(SWAY_DEBUG, "Font: %s", swaynag.type->font);
+ char *font = pango_font_description_to_string(swaynag.type->font_description);
+ sway_log(SWAY_DEBUG, "Font: %s", font);
+ free(font);
sway_log(SWAY_DEBUG, "Buttons");
for (int i = 0; i < swaynag.buttons->length; i++) {
struct swaynag_button *button = swaynag.buttons->items[i];
@@ -109,11 +112,9 @@ int main(int argc, char **argv) {
swaynag_setup(&swaynag);
swaynag_run(&swaynag);
- return status;
cleanup:
swaynag_types_free(types);
- free(swaynag.details.button_details.text);
swaynag_destroy(&swaynag);
return status;
}
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c
index 5620155d..6ea739e3 100644
--- a/swaynag/swaynag.c
+++ b/swaynag/swaynag.c
@@ -153,8 +153,15 @@ static void update_cursor(struct swaynag_seat *seat) {
}
pointer->cursor_theme = wl_cursor_theme_load(
cursor_theme, cursor_size * swaynag->scale, swaynag->shm);
- struct wl_cursor *cursor =
- wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
+ if (!pointer->cursor_theme) {
+ sway_log(SWAY_ERROR, "Failed to load cursor theme");
+ return;
+ }
+ struct wl_cursor *cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "default");
+ if (!cursor) {
+ sway_log(SWAY_ERROR, "Failed to get default cursor from theme");
+ return;
+ }
pointer->cursor_image = cursor->images[0];
wl_surface_set_buffer_scale(pointer->cursor_surface,
swaynag->scale);
@@ -182,11 +189,22 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface,
wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct swaynag_seat *seat = data;
+
struct swaynag_pointer *pointer = &seat->pointer;
pointer->x = wl_fixed_to_int(surface_x);
pointer->y = wl_fixed_to_int(surface_y);
- pointer->serial = serial;
- update_cursor(seat);
+
+ if (seat->swaynag->cursor_shape_manager) {
+ struct wp_cursor_shape_device_v1 *device =
+ wp_cursor_shape_manager_v1_get_pointer(
+ seat->swaynag->cursor_shape_manager, wl_pointer);
+ wp_cursor_shape_device_v1_set_shape(device, serial,
+ WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
+ wp_cursor_shape_device_v1_destroy(device);
+ } else {
+ pointer->serial = serial;
+ update_cursor(seat);
+ }
}
static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
@@ -378,6 +396,9 @@ static void handle_global(void *data, struct wl_registry *registry,
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
swaynag->layer_shell = wl_registry_bind(
registry, name, &zwlr_layer_shell_v1_interface, 1);
+ } else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
+ swaynag->cursor_shape_manager = wl_registry_bind(
+ registry, name, &wp_cursor_shape_manager_v1_interface, 1);
}
}
@@ -456,7 +477,9 @@ void swaynag_setup(struct swaynag *swaynag) {
exit(EXIT_FAILURE);
}
- swaynag_setup_cursors(swaynag);
+ if (!swaynag->cursor_shape_manager) {
+ swaynag_setup_cursors(swaynag);
+ }
swaynag->surface = wl_compositor_create_surface(swaynag->compositor);
assert(swaynag->surface);
@@ -483,10 +506,6 @@ void swaynag_run(struct swaynag *swaynag) {
&& wl_display_dispatch(swaynag->display) != -1) {
// This is intentionally left blank
}
-
- if (swaynag->display) {
- wl_display_disconnect(swaynag->display);
- }
}
void swaynag_destroy(struct swaynag *swaynag) {
@@ -501,6 +520,7 @@ void swaynag_destroy(struct swaynag *swaynag) {
}
list_free(swaynag->buttons);
free(swaynag->details.message);
+ free(swaynag->details.details_text);
free(swaynag->details.button_up.text);
free(swaynag->details.button_down.text);
@@ -541,4 +561,8 @@ void swaynag_destroy(struct swaynag *swaynag) {
if (swaynag->shm) {
wl_shm_destroy(swaynag->shm);
}
+
+ if (swaynag->display) {
+ wl_display_disconnect(swaynag->display);
+ }
}
diff --git a/swaynag/types.c b/swaynag/types.c
index a46aacd5..409cc668 100644
--- a/swaynag/types.c
+++ b/swaynag/types.c
@@ -32,9 +32,8 @@ struct swaynag_type *swaynag_type_new(const char *name) {
void swaynag_types_add_default(list_t *types) {
struct swaynag_type *type_defaults = swaynag_type_new("<defaults>");
- type_defaults->font = strdup("pango:Monospace 10");
type_defaults->font_description =
- pango_font_description_from_string(type_defaults->font);
+ pango_font_description_from_string("pango:Monospace 10");
type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
@@ -92,10 +91,6 @@ void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) {
return;
}
- if (src->font) {
- dest->font = strdup(src->font);
- }
-
if (src->font_description) {
dest->font_description = pango_font_description_copy(src->font_description);
}
@@ -178,7 +173,6 @@ void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) {
void swaynag_type_free(struct swaynag_type *type) {
free(type->name);
- free(type->font);
pango_font_description_free(type->font_description);
free(type->output);
free(type);