From f7ebaf4c8a30d62a364e6f9a8d9fe4872320de9a Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 1 Feb 2017 16:29:16 +0300 Subject: [PATCH] Various fixes --- src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs | 2 +- src/Gtk/Avalonia.Gtk3/Interop/Native.cs | 4 ++++ src/Gtk/Avalonia.Gtk3/PopupImpl.cs | 4 +++- src/Gtk/Avalonia.Gtk3/SystemDialogs.cs | 4 +--- src/Gtk/Avalonia.Gtk3/TopLevelImpl.cs | 20 +++++++++----------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs index 68583da480..b5235c7eb5 100644 --- a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs +++ b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs @@ -36,7 +36,7 @@ namespace Avalonia.Gtk3 .Bind().ToConstant(Mouse) .Bind().ToConstant(Instance) .Bind().ToConstant(Instance) - .Bind().ToSingleton() + .Bind().ToSingleton() .Bind().ToConstant(new DefaultRenderLoop(60)) .Bind().ToConstant(new PlatformIconLoader()); diff --git a/src/Gtk/Avalonia.Gtk3/Interop/Native.cs b/src/Gtk/Avalonia.Gtk3/Interop/Native.cs index be7a4e5117..34abe89f76 100644 --- a/src/Gtk/Avalonia.Gtk3/Interop/Native.cs +++ b/src/Gtk/Avalonia.Gtk3/Interop/Native.cs @@ -168,6 +168,9 @@ namespace Avalonia.Gtk3.Interop [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)] public delegate void gdk_window_begin_resize_drag(IntPtr window, WindowEdge edge, gint button, gint root_x, gint root_y, guint32 timestamp); + [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)] + public delegate void gdk_event_request_motions(IntPtr ev); + [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)] public delegate IntPtr gtk_clipboard_get_for_display(IntPtr display, IntPtr atom); @@ -299,6 +302,7 @@ namespace Avalonia.Gtk3.Interop public static D.gdk_window_get_pointer GdkWindowGetPointer; public static D.gdk_window_begin_move_drag GdkWindowBeginMoveDrag; public static D.gdk_window_begin_resize_drag GdkWindowBeginResizeDrag; + public static D.gdk_event_request_motions GdkEventRequestMotions; public static D.gdk_pixbuf_new_from_file GdkPixbufNewFromFile; public static D.gtk_icon_theme_get_default GtkIconThemeGetDefault; diff --git a/src/Gtk/Avalonia.Gtk3/PopupImpl.cs b/src/Gtk/Avalonia.Gtk3/PopupImpl.cs index 3f76960e8f..e14403f25b 100644 --- a/src/Gtk/Avalonia.Gtk3/PopupImpl.cs +++ b/src/Gtk/Avalonia.Gtk3/PopupImpl.cs @@ -37,7 +37,9 @@ namespace Avalonia.Gtk3 return; Native.GtkWindowSetDefaultSize(GtkWidget, (int)value.Width, (int)value.Height); base.ClientSize = value; - var size = ClientSize; + if (Native.GtkWidgetGetWindow(GtkWidget) == IntPtr.Zero) + Native.GtkWidgetRealize(GtkWidget); + Native.GdkWindowResize(Native.GtkWidgetGetWindow(GtkWidget), (int)value.Width, (int)value.Height); } } } diff --git a/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs b/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs index 19d135492a..04c224ff5b 100644 --- a/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs +++ b/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs @@ -9,11 +9,9 @@ using Avalonia.Gtk3.Interop; using Avalonia.Input.Platform; using Avalonia.Platform; -//TODO: This file should be empty once everything is implemented - namespace Avalonia.Gtk3 { - class SystemDialogStub : ISystemDialogImpl + class SystemDialog : ISystemDialogImpl { unsafe static Task ShowDialog(string title, GtkWindow parent, GtkFileChooserAction action, diff --git a/src/Gtk/Avalonia.Gtk3/TopLevelImpl.cs b/src/Gtk/Avalonia.Gtk3/TopLevelImpl.cs index 3884b19ae3..52feafa99d 100644 --- a/src/Gtk/Avalonia.Gtk3/TopLevelImpl.cs +++ b/src/Gtk/Avalonia.Gtk3/TopLevelImpl.cs @@ -31,7 +31,7 @@ namespace Avalonia.Gtk3 _framebuffer = new FramebufferManager(this); _imContext = Native.GtkImMulticontextNew(); Disposables.Add(_imContext); - Native.GtkWidgetSetEvents(gtkWidget, uint.MaxValue); + Native.GtkWidgetSetEvents(gtkWidget, 0xFFFFFE); Disposables.Add(Signal.Connect(_imContext, "commit", OnCommit)); Connect("draw", OnDraw); Connect("realize", OnRealized); @@ -111,7 +111,7 @@ namespace Avalonia.Gtk3 : evnt->button == 3 ? RawMouseEventType.RightButtonDown : RawMouseEventType.MiddleButtonDown, new Point(evnt->x, evnt->y), GetModifierKeys(evnt->state)); Input?.Invoke(e); - return false; + return true; } private unsafe bool OnStateChanged(IntPtr w, IntPtr pev, IntPtr userData) @@ -131,8 +131,7 @@ namespace Avalonia.Gtk3 { var evnt = (GdkEventMotion*)ev; var position = new Point(evnt->x, evnt->y); - - + Native.GdkEventRequestMotions(ev); var e = new RawMouseEventArgs( Gtk3Platform.Mouse, evnt->time, @@ -140,7 +139,8 @@ namespace Avalonia.Gtk3 RawMouseEventType.Move, position, GetModifierKeys(evnt->state)); Input(e); - return false; + + return true; } private unsafe bool OnScroll(IntPtr w, IntPtr ev, IntPtr userdata) { @@ -156,12 +156,13 @@ namespace Avalonia.Gtk3 else if (evnt->direction == GdkScrollDirection.Left) delta = new Vector(step, 0); else if (evnt->direction == GdkScrollDirection.Smooth) - delta = new Vector(evnt->delta_x, evnt->delta_y); - + { + delta = new Vector(-evnt->delta_x, -evnt->delta_y); + } var e = new RawMouseWheelEventArgs(Gtk3Platform.Mouse, evnt->time, _inputRoot, new Point(evnt->x, evnt->y), delta, GetModifierKeys(evnt->state)); Input(e); - return false; + return true; } private unsafe bool OnKeyEvent(IntPtr w, IntPtr pev, IntPtr userData) @@ -303,9 +304,6 @@ namespace Avalonia.Gtk3 if (GtkWidget.IsClosed) return; Native.GtkWindowResize(GtkWidget, (int)value.Width, (int)value.Height); - if (Native.GtkWidgetGetWindow(GtkWidget) == IntPtr.Zero) - Native.GtkWidgetRealize(GtkWidget); - Native.GdkWindowResize(Native.GtkWidgetGetWindow(GtkWidget), (int)value.Width, (int)value.Height); } }