diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-10-12 20:18:04 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-10-14 13:33:12 +0100 |
commit | 19f0bf38640f4da609782442c901366617aa27fa (patch) | |
tree | 0aa166b77546858f433237ff1533b7ea6b709feb | |
parent | swaybar: only subscribe to required events (diff) | |
download | sway-19f0bf38640f4da609782442c901366617aa27fa.tar.gz sway-19f0bf38640f4da609782442c901366617aa27fa.tar.zst sway-19f0bf38640f4da609782442c901366617aa27fa.zip |
swaybar: add free_hotspots helper function
-rw-r--r-- | include/swaybar/bar.h | 1 | ||||
-rw-r--r-- | swaybar/bar.c | 23 | ||||
-rw-r--r-- | swaybar/render.c | 9 |
3 files changed, 15 insertions, 18 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 3c1a236d..72e0ca75 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -102,6 +102,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path); | |||
102 | void bar_run(struct swaybar *bar); | 102 | void bar_run(struct swaybar *bar); |
103 | void bar_teardown(struct swaybar *bar); | 103 | void bar_teardown(struct swaybar *bar); |
104 | 104 | ||
105 | void free_hotspots(struct wl_list *list); | ||
105 | void free_workspaces(struct wl_list *list); | 106 | void free_workspaces(struct wl_list *list); |
106 | 107 | ||
107 | #endif | 108 | #endif |
diff --git a/swaybar/bar.c b/swaybar/bar.c index f2dab738..e6c5f2f1 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -35,6 +35,17 @@ static void bar_init(struct swaybar *bar) { | |||
35 | wl_list_init(&bar->outputs); | 35 | wl_list_init(&bar->outputs); |
36 | } | 36 | } |
37 | 37 | ||
38 | void free_hotspots(struct wl_list *list) { | ||
39 | struct swaybar_hotspot *hotspot, *tmp; | ||
40 | wl_list_for_each_safe(hotspot, tmp, list, link) { | ||
41 | wl_list_remove(&hotspot->link); | ||
42 | if (hotspot->destroy) { | ||
43 | hotspot->destroy(hotspot->data); | ||
44 | } | ||
45 | free(hotspot); | ||
46 | } | ||
47 | } | ||
48 | |||
38 | void free_workspaces(struct wl_list *list) { | 49 | void free_workspaces(struct wl_list *list) { |
39 | struct swaybar_workspace *ws, *tmp; | 50 | struct swaybar_workspace *ws, *tmp; |
40 | wl_list_for_each_safe(ws, tmp, list, link) { | 51 | wl_list_for_each_safe(ws, tmp, list, link) { |
@@ -59,14 +70,8 @@ static void swaybar_output_free(struct swaybar_output *output) { | |||
59 | wl_output_destroy(output->output); | 70 | wl_output_destroy(output->output); |
60 | destroy_buffer(&output->buffers[0]); | 71 | destroy_buffer(&output->buffers[0]); |
61 | destroy_buffer(&output->buffers[1]); | 72 | destroy_buffer(&output->buffers[1]); |
73 | free_hotspots(&output->hotspots); | ||
62 | free_workspaces(&output->workspaces); | 74 | free_workspaces(&output->workspaces); |
63 | struct swaybar_hotspot *hotspot, *hotspot_tmp; | ||
64 | wl_list_for_each_safe(hotspot, hotspot_tmp, &output->hotspots, link) { | ||
65 | if (hotspot->destroy) { | ||
66 | hotspot->destroy(hotspot->data); | ||
67 | } | ||
68 | free(hotspot); | ||
69 | } | ||
70 | wl_list_remove(&output->link); | 75 | wl_list_remove(&output->link); |
71 | free(output->name); | 76 | free(output->name); |
72 | free(output); | 77 | free(output); |
@@ -75,9 +80,7 @@ static void swaybar_output_free(struct swaybar_output *output) { | |||
75 | static void set_output_dirty(struct swaybar_output *output) { | 80 | static void set_output_dirty(struct swaybar_output *output) { |
76 | if (output->frame_scheduled) { | 81 | if (output->frame_scheduled) { |
77 | output->dirty = true; | 82 | output->dirty = true; |
78 | return; | 83 | } else if (output->surface) { |
79 | } | ||
80 | if (output->surface) { | ||
81 | render_frame(output); | 84 | render_frame(output); |
82 | } | 85 | } |
83 | } | 86 | } |
diff --git a/swaybar/render.c b/swaybar/render.c index dc31a5ea..2a06a79b 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -491,14 +491,7 @@ static const struct wl_callback_listener output_frame_listener = { | |||
491 | void render_frame(struct swaybar_output *output) { | 491 | void render_frame(struct swaybar_output *output) { |
492 | assert(output->surface != NULL); | 492 | assert(output->surface != NULL); |
493 | 493 | ||
494 | struct swaybar_hotspot *hotspot, *tmp; | 494 | free_hotspots(&output->hotspots); |
495 | wl_list_for_each_safe(hotspot, tmp, &output->hotspots, link) { | ||
496 | if (hotspot->destroy) { | ||
497 | hotspot->destroy(hotspot->data); | ||
498 | } | ||
499 | wl_list_remove(&hotspot->link); | ||
500 | free(hotspot); | ||
501 | } | ||
502 | 495 | ||
503 | cairo_surface_t *recorder = cairo_recording_surface_create( | 496 | cairo_surface_t *recorder = cairo_recording_surface_create( |
504 | CAIRO_CONTENT_COLOR_ALPHA, NULL); | 497 | CAIRO_CONTENT_COLOR_ALPHA, NULL); |