aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-10-27 14:57:23 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-10-27 14:57:23 +0000
commit942ff566a2e8f9f4dc866b74ba10bce838a0d606 (patch)
treecec7fc2c0341cb4dea4e0a9def1a69e5c2bf5454
parentwayland: move wayland struct definitions to a separate file (diff)
wayland: implement wayl_destroy()
-rw-r--r--main.c62
-rw-r--r--meson.build2
-rw-r--r--wayland.c66
-rw-r--r--wayland.h7
4 files changed, 85 insertions, 52 deletions
diff --git a/main.c b/main.c
index 78a70fe4..7487705f 100644
--- a/main.c
+++ b/main.c
@@ -1152,47 +1152,26 @@ out:
shm_fini();
tll_free(term.window.on_outputs);
- tll_foreach(term.wl.monitors, it) {
- free(it->item.name);
- if (it->item.xdg != NULL)
- zxdg_output_v1_destroy(it->item.xdg);
- if (it->item.output != NULL)
- wl_output_destroy(it->item.output);
- tll_remove(term.wl.monitors, it);
- }
-
- if (term.wl.xdg_output_manager != NULL)
- zxdg_output_manager_v1_destroy(term.wl.xdg_output_manager);
-
- free(term.wl.pointer.theme_name);
- if (term.wl.pointer.theme != NULL)
- wl_cursor_theme_destroy(term.wl.pointer.theme);
- if (term.wl.pointer.pointer != NULL)
- wl_pointer_destroy(term.wl.pointer.pointer);
- if (term.wl.pointer.surface != NULL)
- wl_surface_destroy(term.wl.pointer.surface);
- if (term.wl.keyboard != NULL)
- wl_keyboard_destroy(term.wl.keyboard);
if (term.selection.clipboard.data_source != NULL)
wl_data_source_destroy(term.selection.clipboard.data_source);
if (term.selection.clipboard.data_offer != NULL)
wl_data_offer_destroy(term.selection.clipboard.data_offer);
free(term.selection.clipboard.text);
- if (term.wl.data_device != NULL)
- wl_data_device_destroy(term.wl.data_device);
- if (term.wl.data_device_manager != NULL)
- wl_data_device_manager_destroy(term.wl.data_device_manager);
if (term.selection.primary.data_source != NULL)
zwp_primary_selection_source_v1_destroy(term.selection.primary.data_source);
if (term.selection.primary.data_offer != NULL)
zwp_primary_selection_offer_v1_destroy(term.selection.primary.data_offer);
free(term.selection.primary.text);
- if (term.wl.primary_selection_device != NULL)
- zwp_primary_selection_device_v1_destroy(term.wl.primary_selection_device);
- if (term.wl.primary_selection_device_manager != NULL)
- zwp_primary_selection_device_manager_v1_destroy(term.wl.primary_selection_device_manager);
- if (term.wl.seat != NULL)
- wl_seat_destroy(term.wl.seat);
+ if (term.kbd.xkb_compose_state != NULL)
+ xkb_compose_state_unref(term.kbd.xkb_compose_state);
+ if (term.kbd.xkb_compose_table != NULL)
+ xkb_compose_table_unref(term.kbd.xkb_compose_table);
+ if (term.kbd.xkb_keymap != NULL)
+ xkb_keymap_unref(term.kbd.xkb_keymap);
+ if (term.kbd.xkb_state != NULL)
+ xkb_state_unref(term.kbd.xkb_state);
+ if (term.kbd.xkb != NULL)
+ xkb_context_unref(term.kbd.xkb);
if (term.window.search_sub_surface != NULL)
wl_subsurface_destroy(term.window.search_sub_surface);
if (term.window.search_surface != NULL)
@@ -1211,26 +1190,7 @@ out:
xdg_wm_base_destroy(term.window.shell);
if (term.window.surface != NULL)
wl_surface_destroy(term.window.surface);
- if (term.wl.shm != NULL)
- wl_shm_destroy(term.wl.shm);
- if (term.wl.sub_compositor != NULL)
- wl_subcompositor_destroy(term.wl.sub_compositor);
- if (term.wl.compositor != NULL)
- wl_compositor_destroy(term.wl.compositor);
- if (term.wl.registry != NULL)
- wl_registry_destroy(term.wl.registry);
- if (term.wl.display != NULL)
- wl_display_disconnect(term.wl.display);
- if (term.kbd.xkb_compose_state != NULL)
- xkb_compose_state_unref(term.kbd.xkb_compose_state);
- if (term.kbd.xkb_compose_table != NULL)
- xkb_compose_table_unref(term.kbd.xkb_compose_table);
- if (term.kbd.xkb_keymap != NULL)
- xkb_keymap_unref(term.kbd.xkb_keymap);
- if (term.kbd.xkb_state != NULL)
- xkb_state_unref(term.kbd.xkb_state);
- if (term.kbd.xkb != NULL)
- xkb_context_unref(term.kbd.xkb);
+ wayl_destroy(&term.wl);
free(term.vt.osc.data);
for (int row = 0; row < term.normal.num_rows; row++)
diff --git a/meson.build b/meson.build
index 62fceb6e..da91ff91 100644
--- a/meson.build
+++ b/meson.build
@@ -84,7 +84,7 @@ executable(
'tokenize.c', 'tokenize.h',
'tllist.h',
'vt.c', 'vt.h',
- 'wayland.h',
+ 'wayland.c', 'wayland.h',
wl_proto_src + wl_proto_headers, version,
dependencies: [threads, math, freetype, fontconfig, pixman, wayland_client, wayland_cursor, xkb],
install: true)
diff --git a/wayland.c b/wayland.c
new file mode 100644
index 00000000..4a8ad23f
--- /dev/null
+++ b/wayland.c
@@ -0,0 +1,66 @@
+#include "wayland.h"
+
+#include <wayland-client.h>
+#include <wayland-cursor.h>
+#include <xdg-shell.h>
+#include <xkbcommon/xkbcommon-compose.h>
+
+#include <xdg-output-unstable-v1.h>
+#include <xdg-decoration-unstable-v1.h>
+
+#define LOG_MODULE "wayland"
+#define LOG_ENABLE_DBG 0
+#include "log.h"
+
+#include "tllist.h"
+
+void
+wayl_init(struct wayland *wayl)
+{
+}
+
+void
+wayl_destroy(struct wayland *wayl)
+{
+ tll_foreach(wayl->monitors, it) {
+ free(it->item.name);
+ if (it->item.xdg != NULL)
+ zxdg_output_v1_destroy(it->item.xdg);
+ if (it->item.output != NULL)
+ wl_output_destroy(it->item.output);
+ tll_remove(wayl->monitors, it);
+ }
+
+ if (wayl->xdg_output_manager != NULL)
+ zxdg_output_manager_v1_destroy(wayl->xdg_output_manager);
+
+ free(wayl->pointer.theme_name);
+ if (wayl->pointer.theme != NULL)
+ wl_cursor_theme_destroy(wayl->pointer.theme);
+ if (wayl->pointer.pointer != NULL)
+ wl_pointer_destroy(wayl->pointer.pointer);
+ if (wayl->pointer.surface != NULL)
+ wl_surface_destroy(wayl->pointer.surface);
+ if (wayl->keyboard != NULL)
+ wl_keyboard_destroy(wayl->keyboard);
+ if (wayl->data_device != NULL)
+ wl_data_device_destroy(wayl->data_device);
+ if (wayl->data_device_manager != NULL)
+ wl_data_device_manager_destroy(wayl->data_device_manager);
+ if (wayl->primary_selection_device != NULL)
+ zwp_primary_selection_device_v1_destroy(wayl->primary_selection_device);
+ if (wayl->primary_selection_device_manager != NULL)
+ zwp_primary_selection_device_manager_v1_destroy(wayl->primary_selection_device_manager);
+ if (wayl->seat != NULL)
+ wl_seat_destroy(wayl->seat);
+ if (wayl->shm != NULL)
+ wl_shm_destroy(wayl->shm);
+ if (wayl->sub_compositor != NULL)
+ wl_subcompositor_destroy(wayl->sub_compositor);
+ if (wayl->compositor != NULL)
+ wl_compositor_destroy(wayl->compositor);
+ if (wayl->registry != NULL)
+ wl_registry_destroy(wayl->registry);
+ if (wayl->display != NULL)
+ wl_display_disconnect(wayl->display);
+}
diff --git a/wayland.h b/wayland.h
index 970cb8cf..81d622fe 100644
--- a/wayland.h
+++ b/wayland.h
@@ -3,6 +3,9 @@
#include <stdint.h>
#include <stdbool.h>
+#include <wayland-client.h>
+#include <primary-selection-unstable-v1.h>
+
#include "tllist.h"
struct monitor {
@@ -72,3 +75,7 @@ struct wayland {
bool have_argb8888;
tll(struct monitor) monitors; /* All available outputs */
};
+
+/* TODO: return allocated pointer */
+void wayl_init(struct wayland *wayl);
+void wayl_destroy(struct wayland *wayl);