Browse Source

Merge pull request #3107 from AvaloniaUI/fix-nondecor-window-x11

Pass PointerPressed event to BeginModeDrag and BeginResizeDrag.
pull/3111/head
danwalmsley 7 years ago
committed by GitHub
parent
commit
3694e7115d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      samples/ControlCatalog/DecoratedWindow.xaml.cs
  2. 13
      src/Avalonia.Controls/Platform/IWindowImpl.cs
  3. 4
      src/Avalonia.Controls/Window.cs
  4. 5
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  5. 14
      src/Avalonia.DesignerSupport/Remote/Stubs.cs
  6. 4
      src/Avalonia.Native/WindowImplBase.cs
  7. 12
      src/Avalonia.X11/X11Window.cs
  8. 5
      src/Windows/Avalonia.Win32/WindowImpl.cs

8
samples/ControlCatalog/DecoratedWindow.xaml.cs

@ -18,18 +18,18 @@ namespace ControlCatalog
{ {
var ctl = this.FindControl<Control>(name); var ctl = this.FindControl<Control>(name);
ctl.Cursor = new Cursor(cursor); ctl.Cursor = new Cursor(cursor);
ctl.PointerPressed += delegate ctl.PointerPressed += (i, e) =>
{ {
PlatformImpl?.BeginResizeDrag(edge); PlatformImpl?.BeginResizeDrag(edge, e);
}; };
} }
private void InitializeComponent() private void InitializeComponent()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
this.FindControl<Control>("TitleBar").PointerPressed += delegate this.FindControl<Control>("TitleBar").PointerPressed += (i, e) =>
{ {
PlatformImpl?.BeginMoveDrag(); PlatformImpl?.BeginMoveDrag(e);
}; };
SetupSide("Left", StandardCursorType.LeftSide, WindowEdge.West); SetupSide("Left", StandardCursorType.LeftSide, WindowEdge.West);
SetupSide("Right", StandardCursorType.RightSide, WindowEdge.East); SetupSide("Right", StandardCursorType.RightSide, WindowEdge.East);

13
src/Avalonia.Controls/Platform/IWindowImpl.cs

@ -3,6 +3,7 @@
using System; using System;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input;
namespace Avalonia.Platform namespace Avalonia.Platform
{ {
@ -57,28 +58,28 @@ namespace Avalonia.Platform
/// Return true to prevent the underlying implementation from closing. /// Return true to prevent the underlying implementation from closing.
/// </summary> /// </summary>
Func<bool> Closing { get; set; } Func<bool> Closing { get; set; }
/// <summary> /// <summary>
/// Starts moving a window with left button being held. Should be called from left mouse button press event handler. /// Starts moving a window with left button being held. Should be called from left mouse button press event handler.
/// </summary> /// </summary>
void BeginMoveDrag(); void BeginMoveDrag(PointerPressedEventArgs e);
/// <summary> /// <summary>
/// Starts resizing a window. This function is used if an application has window resizing controls. /// Starts resizing a window. This function is used if an application has window resizing controls.
/// Should be called from left mouse button press event handler /// Should be called from left mouse button press event handler
/// </summary> /// </summary>
void BeginResizeDrag(WindowEdge edge); void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e);
/// <summary> /// <summary>
/// Sets the client size of the top level. /// Sets the client size of the top level.
/// </summary> /// </summary>
void Resize(Size clientSize); void Resize(Size clientSize);
/// <summary> /// <summary>
/// Sets the client size of the top level. /// Sets the client size of the top level.
/// </summary> /// </summary>
void Move(PixelPoint point); void Move(PixelPoint point);
/// <summary> /// <summary>
/// Minimum width of the window. /// Minimum width of the window.
/// </summary> /// </summary>

4
src/Avalonia.Controls/Window.cs

@ -261,13 +261,13 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Starts moving a window with left button being held. Should be called from left mouse button press event handler /// Starts moving a window with left button being held. Should be called from left mouse button press event handler
/// </summary> /// </summary>
public void BeginMoveDrag() => PlatformImpl?.BeginMoveDrag(); public void BeginMoveDrag(PointerPressedEventArgs e) => PlatformImpl?.BeginMoveDrag(e);
/// <summary> /// <summary>
/// Starts resizing a window. This function is used if an application has window resizing controls. /// Starts resizing a window. This function is used if an application has window resizing controls.
/// Should be called from left mouse button press event handler /// Should be called from left mouse button press event handler
/// </summary> /// </summary>
public void BeginResizeDrag(WindowEdge edge) => PlatformImpl?.BeginResizeDrag(edge); public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e) => PlatformImpl?.BeginResizeDrag(edge, e);
/// <summary> /// <summary>
/// Carries out the arrange pass of the window. /// Carries out the arrange pass of the window.

5
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@ -2,6 +2,7 @@
using System.Reactive.Disposables; using System.Reactive.Disposables;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Remote.Server; using Avalonia.Controls.Remote.Server;
using Avalonia.Input;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Remote.Protocol; using Avalonia.Remote.Protocol;
using Avalonia.Remote.Protocol.Viewport; using Avalonia.Remote.Protocol.Viewport;
@ -27,11 +28,11 @@ namespace Avalonia.DesignerSupport.Remote
{ {
} }
public void BeginMoveDrag() public void BeginMoveDrag(PointerPressedEventArgs e)
{ {
} }
public void BeginResizeDrag(WindowEdge edge) public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
{ {
} }

14
src/Avalonia.DesignerSupport/Remote/Stubs.cs

@ -46,7 +46,7 @@ namespace Avalonia.DesignerSupport.Remote
Resize(size); Resize(size);
})); }));
} }
public IRenderer CreateRenderer(IRenderRoot root) => new ImmediateRenderer(root); public IRenderer CreateRenderer(IRenderRoot root) => new ImmediateRenderer(root);
public void Dispose() public void Dispose()
{ {
@ -75,11 +75,11 @@ namespace Avalonia.DesignerSupport.Remote
{ {
} }
public void BeginMoveDrag() public void BeginMoveDrag(PointerPressedEventArgs e)
{ {
} }
public void BeginResizeDrag(WindowEdge edge) public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
{ {
} }
@ -93,7 +93,7 @@ namespace Avalonia.DesignerSupport.Remote
public void Move(PixelPoint point) public void Move(PixelPoint point)
{ {
} }
public IScreenImpl Screen { get; } = new ScreenStub(); public IScreenImpl Screen { get; } = new ScreenStub();
@ -153,7 +153,7 @@ namespace Avalonia.DesignerSupport.Remote
{ {
public void Save(Stream outputStream) public void Save(Stream outputStream)
{ {
} }
} }
@ -167,10 +167,10 @@ namespace Avalonia.DesignerSupport.Remote
class SystemDialogsStub : ISystemDialogImpl class SystemDialogsStub : ISystemDialogImpl
{ {
public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) => public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) =>
Task.FromResult((string[]) null); Task.FromResult((string[])null);
public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) => public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) =>
Task.FromResult((string) null); Task.FromResult((string)null);
} }
class ScreenStub : IScreenImpl class ScreenStub : IScreenImpl

4
src/Avalonia.Native/WindowImplBase.cs

@ -301,7 +301,7 @@ namespace Avalonia.Native
_native.Hide(); _native.Hide();
} }
public void BeginMoveDrag() public void BeginMoveDrag(PointerPressedEventArgs e)
{ {
_native.BeginMoveDrag(); _native.BeginMoveDrag();
} }
@ -343,7 +343,7 @@ namespace Avalonia.Native
_native.SetMinMaxSize(minSize.ToAvnSize(), maxSize.ToAvnSize()); _native.SetMinMaxSize(minSize.ToAvnSize(), maxSize.ToAvnSize());
} }
public void BeginResizeDrag(WindowEdge edge) public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
{ {
} }

12
src/Avalonia.X11/X11Window.cs

@ -878,21 +878,23 @@ namespace Avalonia.X11
} }
void BeginMoveResize(NetWmMoveResize side) void BeginMoveResize(NetWmMoveResize side, PointerPressedEventArgs e)
{ {
var pos = GetCursorPos(_x11); var pos = GetCursorPos(_x11);
XUngrabPointer(_x11.Display, new IntPtr(0)); XUngrabPointer(_x11.Display, new IntPtr(0));
SendNetWMMessage (_x11.Atoms._NET_WM_MOVERESIZE, (IntPtr) pos.x, (IntPtr) pos.y, SendNetWMMessage (_x11.Atoms._NET_WM_MOVERESIZE, (IntPtr) pos.x, (IntPtr) pos.y,
(IntPtr) side, (IntPtr) side,
(IntPtr) 1, (IntPtr)1); // left button (IntPtr) 1, (IntPtr)1); // left button
e.Pointer.Capture(null);
} }
public void BeginMoveDrag() public void BeginMoveDrag(PointerPressedEventArgs e)
{ {
BeginMoveResize(NetWmMoveResize._NET_WM_MOVERESIZE_MOVE); BeginMoveResize(NetWmMoveResize._NET_WM_MOVERESIZE_MOVE, e);
} }
public void BeginResizeDrag(WindowEdge edge) public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
{ {
var side = NetWmMoveResize._NET_WM_MOVERESIZE_CANCEL; var side = NetWmMoveResize._NET_WM_MOVERESIZE_CANCEL;
if (edge == WindowEdge.East) if (edge == WindowEdge.East)
@ -911,7 +913,7 @@ namespace Avalonia.X11
side = NetWmMoveResize._NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; side = NetWmMoveResize._NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
if (edge == WindowEdge.SouthWest) if (edge == WindowEdge.SouthWest)
side = NetWmMoveResize._NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; side = NetWmMoveResize._NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
BeginMoveResize(side); BeginMoveResize(side, e);
} }
public void SetTitle(string title) public void SetTitle(string title)

5
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -331,11 +331,12 @@ namespace Avalonia.Win32
ShowWindow(_showWindowState); ShowWindow(_showWindowState);
} }
public void BeginMoveDrag() public void BeginMoveDrag(PointerPressedEventArgs e)
{ {
WindowsMouseDevice.Instance.Capture(null); WindowsMouseDevice.Instance.Capture(null);
UnmanagedMethods.DefWindowProc(_hwnd, (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN, UnmanagedMethods.DefWindowProc(_hwnd, (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN,
new IntPtr((int)UnmanagedMethods.HitTestValues.HTCAPTION), IntPtr.Zero); new IntPtr((int)UnmanagedMethods.HitTestValues.HTCAPTION), IntPtr.Zero);
e.Pointer.Capture(null);
} }
static readonly Dictionary<WindowEdge, UnmanagedMethods.HitTestValues> EdgeDic = new Dictionary<WindowEdge, UnmanagedMethods.HitTestValues> static readonly Dictionary<WindowEdge, UnmanagedMethods.HitTestValues> EdgeDic = new Dictionary<WindowEdge, UnmanagedMethods.HitTestValues>
@ -350,7 +351,7 @@ namespace Avalonia.Win32
{WindowEdge.West, UnmanagedMethods.HitTestValues.HTLEFT} {WindowEdge.West, UnmanagedMethods.HitTestValues.HTLEFT}
}; };
public void BeginResizeDrag(WindowEdge edge) public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
{ {
#if USE_MANAGED_DRAG #if USE_MANAGED_DRAG
_managedDrag.BeginResizeDrag(edge, ScreenToClient(MouseDevice.Position)); _managedDrag.BeginResizeDrag(edge, ScreenToClient(MouseDevice.Position));

Loading…
Cancel
Save