Skip to content

Commit

Permalink
Merge branch 'master' into fix-win32-right-modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
MarchingCube authored Dec 13, 2019
2 parents ff4e412 + a7ebcf8 commit 3f58f70
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 38 deletions.
24 changes: 16 additions & 8 deletions native/Avalonia.Native/src/OSX/gl.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common.h"
#include <OpenGL/gl.h>
#include <dlfcn.h>
#include "window.h"

template <typename T, size_t N> char (&ArrayCounter(T (&a)[N]))[N];
#define ARRAY_COUNT(a) (sizeof(ArrayCounter(a)))
Expand Down Expand Up @@ -181,12 +182,12 @@ virtual HRESULT ObtainImmediateContext(IAvnGlContext**retOut) override

class AvnGlRenderingSession : public ComSingleObject<IAvnGlSurfaceRenderingSession, &IID_IAvnGlSurfaceRenderingSession>
{
NSView* _view;
NSWindow* _window;
AvnView* _view;
AvnWindow* _window;
NSOpenGLContext* _context;
public:
FORWARD_IUNKNOWN()
AvnGlRenderingSession(NSWindow*window, NSView* view, NSOpenGLContext* context)
AvnGlRenderingSession(AvnWindow*window, AvnView* view, NSOpenGLContext* context)
{
_context = context;
_window = window;
Expand All @@ -195,14 +196,12 @@ virtual HRESULT ObtainImmediateContext(IAvnGlContext**retOut) override

virtual HRESULT GetPixelSize(AvnPixelSize* ret) override
{
auto fsize = [_view convertSizeToBacking: [_view frame].size];
ret->Width = (int)fsize.width;
ret->Height = (int)fsize.height;
*ret = [_view getPixelSize];
return S_OK;
}
virtual HRESULT GetScaling(double* ret) override
{
*ret = [_window backingScaleFactor];
*ret = [_window getScaling];
return S_OK;
}

Expand Down Expand Up @@ -234,8 +233,17 @@ virtual HRESULT BeginDrawing(IAvnGlSurfaceRenderingSession** ret) override
auto f = GetFeature();
if(f == NULL)
return E_FAIL;
if(![_view lockFocusIfCanDraw])

@try
{
if(![_view lockFocusIfCanDraw])
return E_ABORT;
}
@catch(NSException* exception)
{
return E_ABORT;
}


auto gl = _context;
CGLLockContext([_context CGLContextObj]);
Expand Down
2 changes: 2 additions & 0 deletions native/Avalonia.Native/src/OSX/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class WindowBaseImpl;
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
-(void) setSwRenderedFrame: (AvnFramebuffer* _Nonnull) fb dispose: (IUnknown* _Nonnull) dispose;
-(void) onClosed;
-(AvnPixelSize) getPixelSize;
@end

@interface AvnWindow : NSWindow <NSWindowDelegate>
Expand All @@ -22,6 +23,7 @@ class WindowBaseImpl;
-(void) restoreParentWindow;
-(bool) shouldTryToHandleEvents;
-(void) applyMenu:(NSMenu *)menu;
-(double) getScaling;
@end

struct INSWindowHolder
Expand Down
89 changes: 65 additions & 24 deletions native/Avalonia.Native/src/OSX/window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ virtual HRESULT Close() override
{
@autoreleasepool
{
[Window close];
if (Window != nullptr)
{
[Window close];
}

return S_OK;
}
}
Expand Down Expand Up @@ -291,7 +295,14 @@ virtual bool TryLock() override
{
@autoreleasepool
{
return [View lockFocusIfCanDraw] == YES;
@try
{
return [View lockFocusIfCanDraw] == YES;
}
@catch (NSException*)
{
return NO;
}
}
}

Expand Down Expand Up @@ -719,15 +730,33 @@ @implementation AvnView
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed, _isMouseOver;
NSEvent* _lastMouseDownEvent;
bool _lastKeyHandled;
AvnPixelSize _lastPixelSize;
}

- (void)dealloc
- (void)onClosed
{
@synchronized (self)
{
_parent = nullptr;
}
}

- (void)onClosed
- (BOOL)lockFocusIfCanDraw
{
@synchronized (self)
{
if(_parent == nullptr)
{
return NO;
}
}

return [super lockFocusIfCanDraw];
}

-(AvnPixelSize) getPixelSize
{
_parent = NULL;
return _lastPixelSize;
}

- (NSEvent*) lastMouseDownEvent
Expand All @@ -742,6 +771,8 @@ -(AvnView*) initWithParent: (WindowBaseImpl*) parent
[self setWantsLayer:YES];
_parent = parent;
_area = nullptr;
_lastPixelSize.Height = 100;
_lastPixelSize.Width = 100;
return self;
}

Expand Down Expand Up @@ -783,6 +814,10 @@ -(void)setFrameSize:(NSSize)newSize
[self addTrackingArea:_area];

_parent->UpdateCursor();

auto fsize = [self convertSizeToBacking: [self frame].size];
_lastPixelSize.Width = (int)fsize.width;
_lastPixelSize.Height = (int)fsize.height;

_parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height});
}
Expand Down Expand Up @@ -812,7 +847,13 @@ - (void) drawFb: (AvnFramebuffer*) fb

- (void)drawRect:(NSRect)dirtyRect
{
if (_parent == nullptr)
{
return;
}

_parent->BaseEvents->RunRenderPriorityJobs();

@synchronized (self) {
if(_swRenderedFrame != NULL)
{
Expand Down Expand Up @@ -879,7 +920,12 @@ - (AvnPoint)toAvnPoint:(CGPoint)p

- (void) viewDidChangeBackingProperties
{
auto fsize = [self convertSizeToBacking: [self frame].size];
_lastPixelSize.Width = (int)fsize.width;
_lastPixelSize.Height = (int)fsize.height;

_parent->BaseEvents->ScalingChanged([_parent->Window backingScaleFactor]);

[super viewDidChangeBackingProperties];
}

Expand Down Expand Up @@ -1161,6 +1207,12 @@ @implementation AvnWindow
bool _closed;
NSMenu* _menu;
bool _isAppMenuApplied;
double _lastScaling;
}

-(double) getScaling
{
return _lastScaling;
}

+(void)closeAll
Expand All @@ -1174,10 +1226,6 @@ +(void)closeAll
}
}

- (void)dealloc
{
}

- (void)pollModalSession:(nonnull NSModalSession)session
{
auto response = [NSApp runModalSession:session];
Expand Down Expand Up @@ -1232,6 +1280,9 @@ -(AvnWindow*) initWithParent: (WindowBaseImpl*) parent
[self setReleasedWhenClosed:false];
_parent = parent;
[self setDelegate:self];
_closed = false;

_lastScaling = [self backingScaleFactor];
return self;
}

Expand All @@ -1247,6 +1298,11 @@ - (BOOL)windowShouldClose:(NSWindow *)sender
return true;
}

- (void)windowDidChangeBackingProperties:(NSNotification *)notification
{
_lastScaling = [self backingScaleFactor];
}

- (void)windowWillClose:(NSNotification *)notification
{
_closed = true;
Expand All @@ -1257,9 +1313,6 @@ - (void)windowWillClose:(NSNotification *)notification
[self restoreParentWindow];
parent->BaseEvents->Closed();
[parent->View onClosed];
dispatch_async(dispatch_get_main_queue(), ^{
[self setContentView: nil];
});
}
}

Expand Down Expand Up @@ -1406,18 +1459,6 @@ - (void)windowDidMove:(NSNotification *)notification
_parent->GetPosition(&position);
_parent->BaseEvents->PositionChanged(position);
}

// TODO this breaks resizing.
/*- (void)windowDidResize:(NSNotification *)notification
{
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
if(parent != nullptr)
{
parent->WindowStateChanged();
}
}*/
@end

class PopupImpl : public virtual WindowBaseImpl, public IAvnPopup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static void ConfigurePosition(ref this PopupPositionerParameters position
if (placement == PlacementMode.Pointer)
{
positionerParameters.AnchorRectangle = new Rect(pointer, new Size(1, 1));
positionerParameters.Anchor = PopupPositioningEdge.BottomRight;
positionerParameters.Anchor = PopupPositioningEdge.TopLeft;
positionerParameters.Gravity = PopupPositioningEdge.BottomRight;
}
else
Expand Down
3 changes: 2 additions & 1 deletion src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private void Poll(long _)

var fProcMounts = File.ReadAllLines(ProcMountsDir)
.Select(x => x.Split(' '))
.Select(x => (x[0], x[1]));
.Select(x => (x[0], x[1]))
.Where(x => !x.Item2.StartsWith("/snap/", StringComparison.InvariantCultureIgnoreCase));

var labelDirEnum = Directory.Exists(DevByLabelDir) ?
new DirectoryInfo(DevByLabelDir).GetFiles() : Enumerable.Empty<FileInfo>();
Expand Down
5 changes: 5 additions & 0 deletions src/Avalonia.Native/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ public void SetTopmost(bool value)

public void SetCursor(IPlatformHandle cursor)
{
if (_native == null)
{
return;
}

var newCursor = cursor as AvaloniaNativeCursor;
newCursor = newCursor ?? (_cursorFactory.GetCursor(StandardCursorType.Arrow) as AvaloniaNativeCursor);
_native.Cursor = newCursor.Cursor;
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public Matrix Invert()
/// <summary>
/// Parses a <see cref="Matrix"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <param name="s">Six comma-delimited double values (m11, m12, m21, m22, offsetX, offsetY) that describe the new <see cref="Matrix"/></param>
/// <returns>The <see cref="Matrix"/>.</returns>
public static Matrix Parse(string s)
{
Expand Down
19 changes: 19 additions & 0 deletions src/Avalonia.Visuals/Media/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,31 @@ static Transform()
/// </summary>
public abstract Matrix Value { get; }

/// <summary>
/// Parses a <see cref="Transform"/> string.
/// </summary>
/// <param name="s">Six comma-delimited double values that describe the new <see cref="Transform"/>. For details check <see cref="Matrix.Parse(string)"/> </param>
/// <returns>The <see cref="Transform"/>.</returns>
public static Transform Parse(string s)
{
return new MatrixTransform(Matrix.Parse(s));
}

/// <summary>
/// Raises the <see cref="Changed"/> event.
/// </summary>
protected void RaiseChanged()
{
Changed?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Returns a String representing this transform matrix instance.
/// </summary>
/// <returns>The string representation.</returns>
public override string ToString()
{
return Value.ToString();
}
}
}
2 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static implicit operator Vector(Point p)
/// Parses a <see cref="Point"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <returns>The <see cref="Thickness"/>.</returns>
/// <returns>The <see cref="Point"/>.</returns>
public static Point Parse(string s)
{
using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Point."))
Expand Down
11 changes: 11 additions & 0 deletions src/Avalonia.Visuals/RelativePoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,16 @@ public static RelativePoint Parse(string s)
unit);
}
}

/// <summary>
/// Returns a String representing this RelativePoint instance.
/// </summary>
/// <returns>The string representation.</returns>
public override string ToString()
{
return _unit == RelativeUnit.Absolute ?
_point.ToString() :
string.Format(CultureInfo.InvariantCulture, "{0}%, {1}%", _point.X * 100, _point.Y * 100);
}
}
}
Loading

0 comments on commit 3f58f70

Please sign in to comment.