@@ -117,6 +117,7 @@ class EventSource {
117
117
GSource source;
118
118
GPollFD pfd;
119
119
struct wl_display * display;
120
+ bool prepared;
120
121
};
121
122
122
123
GSourceFuncs EventSource::sourceFuncs = {
@@ -126,6 +127,9 @@ GSourceFuncs EventSource::sourceFuncs = {
126
127
auto * source = reinterpret_cast <EventSource*>(base);
127
128
struct wl_display * display = source->display ;
128
129
130
+ if (source->prepared )
131
+ return FALSE ;
132
+
129
133
*timeout = -1 ;
130
134
131
135
while (wl_display_prepare_read (display) != 0 ) {
@@ -136,6 +140,7 @@ GSourceFuncs EventSource::sourceFuncs = {
136
140
}
137
141
wl_display_flush (display);
138
142
143
+ source->prepared = true ;
139
144
return FALSE ;
140
145
},
141
146
// check
@@ -144,14 +149,19 @@ GSourceFuncs EventSource::sourceFuncs = {
144
149
auto * source = reinterpret_cast <EventSource*>(base);
145
150
struct wl_display * display = source->display ;
146
151
152
+ if (!source->prepared )
153
+ return FALSE ;
154
+
147
155
if (source->pfd .revents & G_IO_IN) {
148
156
if (wl_display_read_events (display) < 0 ) {
149
157
DEBUG_PRINT (" Wayland::Display: error in wayland read\n " );
150
158
return FALSE ;
151
159
}
160
+ source->prepared = false ;
152
161
return TRUE ;
153
162
} else {
154
163
wl_display_cancel_read (display);
164
+ source->prepared = false ;
155
165
return FALSE ;
156
166
}
157
167
},
@@ -213,8 +223,7 @@ Backend::Backend()
213
223
214
224
Backend::~Backend ()
215
225
{
216
- if (m_eventSource)
217
- g_source_destroy (m_eventSource);
226
+ invalidate ();
218
227
219
228
if (m_compositor)
220
229
wl_compositor_destroy (m_compositor);
@@ -227,6 +236,8 @@ Backend::~Backend()
227
236
void Backend::invalidate ()
228
237
{
229
238
if (m_eventSource) {
239
+ if (m_eventSource->prepared && m_display)
240
+ wl_display_cancel_read (m_display);
230
241
g_source_destroy (m_eventSource);
231
242
m_eventSource = nullptr ;
232
243
}
@@ -240,6 +251,7 @@ void Backend::initialize()
240
251
m_eventSource = g_source_new (&EventSource::sourceFuncs, sizeof (EventSource));
241
252
auto & source = *reinterpret_cast <EventSource*>(m_eventSource);
242
253
source.display = m_display;
254
+ source.prepared = false ;
243
255
244
256
source.pfd .fd = wl_display_get_fd (m_display);
245
257
source.pfd .events = G_IO_IN | G_IO_ERR | G_IO_HUP;
0 commit comments