annotate dep/animia/src/win/wayland.cc @ 199:9f3534f6b8c4

dep/animia: initial Wayland support, drop non-working kvm fd plugin
author Paper <mrpapersonic@gmail.com>
date Tue, 02 Jan 2024 02:34:27 -0500
parents
children 8a482049b968
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
199
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "animia/win/wayland.h"
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include "animia/win.h"
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 #include "animia.h"
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include <iostream>
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include <cstring>
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include "animia/win/wayland/ext-foreign-toplevel-list-v1.h"
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include <wayland-client.h>
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 namespace animia::internal::wayland {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 static void noop() {}
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 /* ext_foreign_handle stuff */
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 static void ext_foreign_handle_handle_app_id(void* data, struct ext_foreign_toplevel_handle_v1* handle, const char* app_id) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 if (app_id)
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 reinterpret_cast<Window*>(data)->class_name = app_id;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 static void ext_foreign_handle_handle_title(void* data, struct ext_foreign_toplevel_handle_v1* handle, const char* title) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 if (title)
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 reinterpret_cast<Window*>(data)->text = title;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 static void ext_foreign_handle_handle_done(void* data, struct ext_foreign_toplevel_handle_v1* handle) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 if (handle)
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 ext_foreign_toplevel_handle_v1_destroy(handle);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 static void ext_foreign_handle_handle_closed(void*, struct ext_foreign_toplevel_handle_v1*) {}
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 static void ext_foreign_handle_handle_identifier(void*, ext_foreign_toplevel_handle_v1*, const char*) {}
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 static const struct ext_foreign_toplevel_handle_v1_listener ext_handle_listener = {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 .closed = ext_foreign_handle_handle_closed,
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 .done = ext_foreign_handle_handle_done,
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 .title = ext_foreign_handle_handle_title,
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 .app_id = ext_foreign_handle_handle_app_id,
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 .identifier = ext_foreign_handle_handle_identifier // for now
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 };
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 static void ext_toplevel_list_handle_toplevel(void* data, struct ext_foreign_toplevel_list_v1* list, struct ext_foreign_toplevel_handle_v1* handle) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 std::vector<Window>* windows = reinterpret_cast<std::vector<Window>*>(data);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 if (!windows)
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 return;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47 windows->push_back({0});
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 ext_foreign_toplevel_handle_v1_add_listener(handle, &ext_handle_listener, &*windows->end());
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 static void ext_toplevel_list_handle_finished(void*, ext_foreign_toplevel_list_v1*) {}
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 static const struct ext_foreign_toplevel_list_v1_listener ext_toplevel_list_listener = {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 .toplevel = ext_toplevel_list_handle_toplevel,
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55 .finished = ext_toplevel_list_handle_finished
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 };
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 /* -- Global data -- */
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 struct global_data {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 struct ext_foreign_toplevel_list_v1* ext_toplevel_list;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61 std::vector<Window> windows;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 };
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 static void registry_handle_global(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65 struct global_data* global = reinterpret_cast<struct global_data*>(data);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 if (!std::strcmp(interface, ext_foreign_toplevel_list_v1_interface.name)) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 // bind to ext-foreign-toplevel-list-v1
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 global->ext_toplevel_list = reinterpret_cast<struct ext_foreign_toplevel_list_v1*>(wl_registry_bind(registry, name, &ext_foreign_toplevel_list_v1_interface, 1));
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70 ext_foreign_toplevel_list_v1_add_listener(global->ext_toplevel_list, &ext_toplevel_list_listener, &global->windows);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 static void registry_handle_global_remove(void*, wl_registry*, uint32_t) {}
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76 static const struct wl_registry_listener registry_listener = {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 .global = registry_handle_global,
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78 .global_remove = registry_handle_global_remove
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
79 };
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
80
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
81 /* BAH! humbug... */
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82 struct sync_data {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 bool loop = true;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84 int sync = 0;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86 struct global_data global = {0};
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 struct wl_callback* callback = nullptr;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 struct wl_display* display = nullptr;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90 };
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92 static void sync_handle_done (void* data, struct wl_callback* callback, uint32_t other_data);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93 static const struct wl_callback_listener sync_callback_listener = {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94 .done = sync_handle_done,
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
95 };
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97 static void sync_handle_done (void* data, struct wl_callback* callback, uint32_t other_data) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
98 struct sync_data* sync = reinterpret_cast<struct sync_data*>(data);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
99
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 wl_callback_destroy(callback);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101 sync->callback = nullptr;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 if (sync->sync == 0) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 if (!sync->global.ext_toplevel_list) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105 std::cerr << "animia/wayland: Wayland server doesn't support ext-foreign-toplevel-list-v1!" << std::endl;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106 sync->loop = false;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 return;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110 sync->sync++;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111 sync->callback = wl_display_sync(sync->display);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
112 wl_callback_add_listener(sync->callback, &sync_callback_listener, sync);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
113
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
114 /* we may need another sync here if there are protocol extensions for
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
115 * ext_foreign_toplevel_list.
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
116 *
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
117 * more info: https://git.sr.ht/~leon_plickat/lswt/tree/toplevel-info/item/lswt.c
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
118 */
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
119 } else {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
120 /* we've received everything we need! */
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
121 sync->loop = false;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
123 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
124
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
125 /* here comes the actual function we can use */
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 bool EnumerateWindows(window_proc_t window_proc) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
127 struct sync_data sync = {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
128 .display = wl_display_connect(NULL)
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 };
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131 if (!sync.display) {
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
132 std::cerr << "animia/wayland: Can't connect to display" << std::endl;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133 return false;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
134 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136 struct global_data global;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
137
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
138 struct wl_registry* registry = wl_display_get_registry(sync.display);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
139 wl_registry_add_listener(registry, &registry_listener, &sync.global);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
141 sync.callback = wl_display_sync(sync.display);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
142 wl_callback_add_listener(sync.callback, &sync_callback_listener, &sync);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
143
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
144 while (sync.loop && wl_display_dispatch(sync.display));
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
145
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
146 for (const auto& window : global.windows)
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
147 if (!window_proc({0}, window))
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
148 return false;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
149
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
150 wl_display_disconnect(sync.display);
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
151
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
152 return true;
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
153 }
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
154
9f3534f6b8c4 dep/animia: initial Wayland support, drop non-working kvm fd plugin
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
155 }