Browse Source

[X11] Prevent possible blocking calls to XNextEvent

pull/2255/head
Nikita Tsukanov 8 years ago
parent
commit
6badd34c6a
  1. 42
      src/Avalonia.X11/X11PlatformThreading.cs

42
src/Avalonia.X11/X11PlatformThreading.cs

@ -164,39 +164,33 @@ namespace Avalonia.X11
void HandleX11(CancellationToken cancellationToken) void HandleX11(CancellationToken cancellationToken)
{ {
while (true) while (XPending(_display) != 0)
{ {
var pending = XPending(_display); if (cancellationToken.IsCancellationRequested)
if (pending == 0) return;
break; XNextEvent(_display, out var xev);
while (pending > 0) if (xev.type == XEventName.GenericEvent)
XGetEventData(_display, &xev.GenericEventCookie);
try
{ {
if (cancellationToken.IsCancellationRequested)
return;
XNextEvent(_display, out var xev);
if (xev.type == XEventName.GenericEvent) if (xev.type == XEventName.GenericEvent)
XGetEventData(_display, &xev.GenericEventCookie);
pending--;
try
{ {
if (xev.type == XEventName.GenericEvent) if (_platform.XI2 != null && _platform.Info.XInputOpcode ==
xev.GenericEventCookie.extension)
{ {
if (_platform.XI2 != null && _platform.Info.XInputOpcode == _platform.XI2.OnEvent((XIEvent*)xev.GenericEventCookie.data);
xev.GenericEventCookie.extension)
{
_platform.XI2.OnEvent((XIEvent*)xev.GenericEventCookie.data);
}
} }
else if (_eventHandlers.TryGetValue(xev.AnyEvent.window, out var handler))
handler(xev);
}
finally
{
if (xev.type == XEventName.GenericEvent && xev.GenericEventCookie.data != null)
XFreeEventData(_display, &xev.GenericEventCookie);
} }
else if (_eventHandlers.TryGetValue(xev.AnyEvent.window, out var handler))
handler(xev);
}
finally
{
if (xev.type == XEventName.GenericEvent && xev.GenericEventCookie.data != null)
XFreeEventData(_display, &xev.GenericEventCookie);
} }
} }
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
} }

Loading…
Cancel
Save