public WindowBaseImpl(GtkWindow gtkWidget) { GtkWidget = gtkWidget; Disposables.Add(gtkWidget); _framebuffer = new FramebufferManager(this); _imContext = Native.GtkImMulticontextNew(); Disposables.Add(_imContext); Native.GtkWidgetSetEvents(gtkWidget, 0xFFFFFE); Disposables.Add(Signal.Connect <Native.D.signal_commit>(_imContext, "commit", OnCommit)); Connect <Native.D.signal_widget_draw>("draw", OnDraw); Connect <Native.D.signal_generic>("realize", OnRealized); ConnectEvent("configure-event", OnConfigured); ConnectEvent("button-press-event", OnButton); ConnectEvent("button-release-event", OnButton); ConnectEvent("motion-notify-event", OnMotion); ConnectEvent("scroll-event", OnScroll); ConnectEvent("window-state-event", OnStateChanged); ConnectEvent("key-press-event", OnKeyEvent); ConnectEvent("key-release-event", OnKeyEvent); ConnectEvent("leave-notify-event", OnLeaveNotifyEvent); Connect <Native.D.signal_generic>("destroy", OnDestroy); Native.GtkWidgetRealize(gtkWidget); _lastSize = ClientSize; GlibTimeout.Add(0, 16, () => { Invalidate(default(Rect)); return(true); }); if (Gtk3Platform.UseDeferredRendering) { Native.GtkWidgetSetDoubleBuffered(gtkWidget, false); _gcHandle = GCHandle.Alloc(this); Native.GtkWidgetAddTickCallback(GtkWidget, PinnedStaticCallback, GCHandle.ToIntPtr(_gcHandle), IntPtr.Zero); } }
public void Signal() { lock (_lock) if (!_signaled) { _signaled = true; GlibTimeout.Add(0, () => { lock (_lock) { _signaled = false; } Signaled?.Invoke(); return(false); }); } }
public void Signal(DispatcherPriority prio) { var idx = (int)prio; lock (_lock) if (!_signaled[idx]) { _signaled[idx] = true; GlibTimeout.Add(GlibPriority.FromDispatcherPriority(prio), 0, () => { lock (_lock) { _signaled[idx] = false; } Signaled?.Invoke(prio); return(false); }); } }
Task <T> RunOnGtkThread <T>(Func <T> action) { var tcs = new TaskCompletionSource <T>(); GlibTimeout.Add(0, 0, () => { try { tcs.SetResult(action()); } catch (Exception e) { tcs.TrySetException(e); } return(false); }); return(tcs.Task); }