-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from AvaloniaUI/features/screens-implementation
Screen API
- Loading branch information
Showing
12 changed files
with
132 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "common.h" | ||
|
||
class Screens : public ComSingleObject<IAvnScreens, &IID_IAvnScreens> | ||
{ | ||
public: | ||
|
||
virtual HRESULT GetScreenCount (int* ret) | ||
{ | ||
*ret = (int)[NSScreen screens].count; | ||
|
||
return S_OK; | ||
} | ||
|
||
virtual HRESULT GetScreen (int index, AvnScreen* ret) | ||
{ | ||
if(index < 0 || index >= [NSScreen screens].count) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
auto screen = [[NSScreen screens] objectAtIndex:index]; | ||
|
||
ret->Bounds.X = [screen frame].origin.x; | ||
ret->Bounds.Y = [screen frame].origin.y; | ||
ret->Bounds.Height = [screen frame].size.height; | ||
ret->Bounds.Width = [screen frame].size.width; | ||
|
||
ret->WorkingArea.X = [screen visibleFrame].origin.x; | ||
ret->WorkingArea.Y = [screen visibleFrame].origin.y; | ||
ret->WorkingArea.Height = [screen visibleFrame].size.height; | ||
ret->WorkingArea.Width = [screen visibleFrame].size.width; | ||
|
||
ret->Primary = index == 0; | ||
|
||
return S_OK; | ||
} | ||
}; | ||
|
||
extern IAvnScreens* CreateScreens() | ||
{ | ||
return new Screens(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using Avalonia.Native.Interop; | ||
using Avalonia.Platform; | ||
|
||
namespace Avalonia.Native | ||
{ | ||
class ScreenImpl : IScreenImpl, IDisposable | ||
{ | ||
private IAvnScreens _native; | ||
|
||
public ScreenImpl(IAvnScreens native) | ||
{ | ||
_native = native; | ||
} | ||
|
||
public int ScreenCount => _native.GetScreenCount(); | ||
|
||
public Screen[] AllScreens | ||
{ | ||
get | ||
{ | ||
var count = ScreenCount; | ||
var result = new Screen[count]; | ||
|
||
for(int i = 0; i < count; i++) | ||
{ | ||
var screen = _native.GetScreen(i); | ||
|
||
result[i] = new Screen(screen.Bounds.ToAvaloniaRect(), screen.WorkingArea.ToAvaloniaRect(), screen.Primary); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
||
public void Dispose () | ||
{ | ||
_native.Dispose(); | ||
_native = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters