New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Screen implementation #1150
Closed
Closed
Screen implementation #1150
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
3e9bbb3
Added Win32 screen implementation
JurjenBiewenga d76ddc9
Forgot saving these
JurjenBiewenga 4e55faf
Started work on GTK implementation
JurjenBiewenga 87b74d5
Created a working implementation for Gtk3
JurjenBiewenga 72844f4
Added logging for testing
JurjenBiewenga 693b09d
Added gtk implementation
JurjenBiewenga abe48b4
Added equals, gethashcode, performance improvements
JurjenBiewenga b565e70
Resolving conflicts
JurjenBiewenga 1af896a
Merge branch 'master' into Screen
JurjenBiewenga 4e146c8
Replaced GetScreen with GetDefaultScreen
JurjenBiewenga 1432b0d
Merge
JurjenBiewenga 01f21c2
ScreenCount is now cached in gtk3
JurjenBiewenga 0d5b7d1
Forgot to commit the name changed interface
JurjenBiewenga b3c0f53
Renamed GtkScreen to GdkScreen
JurjenBiewenga 3624041
Created UnownedGdkScreen class
JurjenBiewenga 58e0140
Added constructor to gdkscreen
JurjenBiewenga a9d8b80
Moved Screen data to its own class
JurjenBiewenga 7433858
Screen no longer override Equals
JurjenBiewenga eb12e9f
Forcing recompile
JurjenBiewenga b00f027
Created platform specific Screen implementations
JurjenBiewenga 57b1681
Merge
JurjenBiewenga 4249db6
Revert "Merge"
JurjenBiewenga d458bc5
Added files to project
JurjenBiewenga e11fdc8
Merge branch 'master' into Screen
JurjenBiewenga 5671f73
Added basic mac implementation
JurjenBiewenga 28778dc
Cached allScreens
JurjenBiewenga 562381e
Added caching to win32 implementation
JurjenBiewenga a505cd5
Changed formatting of privates
JurjenBiewenga 47c35e5
Changed primary screen on osx to the screen with the menu bar
JurjenBiewenga 2fc4e09
Mac/win32 implementation now use the AllScreens property to find the …
JurjenBiewenga 305db08
Moved callback registration to constructor
JurjenBiewenga 8cf6c86
Fixed helper functions
JurjenBiewenga 7943590
Added Control.Catalog page
JurjenBiewenga aaa3a83
Moved things around
JurjenBiewenga 188e7c2
Android PopupImpl now has a null Screens variable
JurjenBiewenga a3697dc
Moved Screens to Window
JurjenBiewenga 2a8ab01
Removed remnant of Screens variable
JurjenBiewenga 5b3862d
Added bounds to screen implementation
JurjenBiewenga b510d9c
Merge branch 'master' into Screen
JurjenBiewenga 3c231f2
Moved a ScreenFromBounds and Primary to Screens class
JurjenBiewenga ae957e5
Restored draw dirty rects
JurjenBiewenga 1ce1ec7
Added ScreenFromPoint and ScreenFromVisual
JurjenBiewenga 60629d1
Merge branch 'master' into Screen
JurjenBiewenga 1f52f8b
Fixed indentation
JurjenBiewenga 319c0b8
Screens.Primary is now consistent with the other properties
JurjenBiewenga f92dc0c
Merge branch 'Screen' of https://github.com/JurjenBiewenga/Avalonia i…
JurjenBiewenga 6fb5823
Merge
JurjenBiewenga 03e633d
Merge branch 'master' into Screen
JurjenBiewenga a6007b6
Screens is now properly cached
JurjenBiewenga File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -13,11 +13,20 @@ public MainView() | |
{ | ||
this.InitializeComponent(); | ||
if (AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().IsDesktop) | ||
((IList) this.FindControl<TabControl>("Sidebar").Items).Add(new TabItem() | ||
{ | ||
Header = "Dialogs", | ||
Content = new DialogsPage() | ||
}); | ||
{ | ||
IList tabItems = ((IList)this.FindControl<TabControl>("Sidebar").Items); | ||
tabItems.Add(new TabItem() | ||
{ | ||
Header = "Dialogs", | ||
Content = new DialogsPage() | ||
}); | ||
tabItems.Add(new TabItem() | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also seems unusually indented |
||
Header = "Screens", | ||
Content = new ScreenPage() | ||
}); | ||
|
||
} | ||
} | ||
|
||
private void InitializeComponent() | ||
|
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,3 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui"> | ||
|
||
</UserControl> |
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,72 @@ | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Media; | ||
using Avalonia.Platform; | ||
|
||
namespace ControlCatalog.Pages | ||
{ | ||
public class ScreenPage : UserControl | ||
{ | ||
private double leftMost; | ||
|
||
public ScreenPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) | ||
{ | ||
base.OnAttachedToVisualTree(e); | ||
Window w = (Window)VisualRoot; | ||
w.PositionChanged += (sender, args) => InvalidateVisual(); | ||
} | ||
|
||
public override void Render(DrawingContext context) | ||
{ | ||
base.Render(context); | ||
Window w = (Window)VisualRoot; | ||
Screen[] screens = w.Screens.All; | ||
|
||
Pen p = new Pen(Brushes.Black); | ||
if (screens != null) | ||
foreach (Screen screen in screens) | ||
{ | ||
if (screen.Bounds.X / 10f < leftMost) | ||
{ | ||
leftMost = screen.Bounds.X / 10f; | ||
InvalidateVisual(); | ||
return; | ||
} | ||
|
||
Rect boundsRect = new Rect(screen.Bounds.X / 10f + Math.Abs(leftMost), screen.Bounds.Y / 10f, screen.Bounds.Width / 10f, | ||
screen.Bounds.Height / 10f); | ||
Rect workingAreaRect = new Rect(screen.WorkingArea.X / 10f + Math.Abs(leftMost), screen.WorkingArea.Y / 10f, screen.WorkingArea.Width / 10f, | ||
screen.WorkingArea.Height / 10f); | ||
context.DrawRectangle(p, boundsRect); | ||
context.DrawRectangle(p, workingAreaRect); | ||
|
||
FormattedText text = new FormattedText(); | ||
text.Text = $"Bounds: {screen.Bounds.Width}:{screen.Bounds.Height}"; | ||
context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height), text); | ||
|
||
text.Text = $"WorkArea: {screen.WorkingArea.Width}:{screen.WorkingArea.Height}"; | ||
context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height + 20), text); | ||
|
||
text.Text = $"Primary: {screen.Primary}"; | ||
context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height + 40), text); | ||
|
||
text.Text = $"Current: {screen.Equals(w.Screens.ScreenFromBounds(new Rect(w.Position, w.Bounds.Size)))}"; | ||
context.DrawText(Brushes.Black, boundsRect.Position.WithY(boundsRect.Size.Height + 60), text); | ||
} | ||
|
||
context.DrawRectangle(p, new Rect(w.Position.X / 10f + Math.Abs(leftMost), w.Position.Y / 10, w.Bounds.Width / 10, w.Bounds.Height / 10)); | ||
} | ||
} | ||
} |
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,9 @@ | ||
namespace Avalonia.Platform | ||
{ | ||
public interface IScreenImpl | ||
{ | ||
int ScreenCount { get; } | ||
|
||
Screen[] AllScreens { get; } | ||
} | ||
} |
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,18 @@ | ||
namespace Avalonia.Platform | ||
{ | ||
public class Screen | ||
{ | ||
public Rect Bounds { get; } | ||
|
||
public Rect WorkingArea { get; } | ||
|
||
public bool Primary { get; } | ||
|
||
public Screen(Rect bounds, Rect workingArea, bool primary) | ||
{ | ||
this.Bounds = bounds; | ||
this.WorkingArea = workingArea; | ||
this.Primary = primary; | ||
} | ||
} | ||
} |
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,54 @@ | ||
using System.Linq; | ||
using Avalonia.Platform; | ||
using Avalonia.Utilities; | ||
using Avalonia.VisualTree; | ||
|
||
namespace Avalonia.Controls | ||
{ | ||
public class Screens | ||
{ | ||
private readonly IScreenImpl _iScreenImpl; | ||
|
||
public int ScreenCount => _iScreenImpl.ScreenCount; | ||
public Screen[] All => _iScreenImpl?.AllScreens; | ||
public Screen Primary => All.FirstOrDefault(x => x.Primary); | ||
|
||
public Screens(IScreenImpl iScreenImpl) | ||
{ | ||
_iScreenImpl = iScreenImpl; | ||
} | ||
|
||
public Screen ScreenFromBounds(Rect bounds){ | ||
|
||
Screen currMaxScreen = null; | ||
double maxAreaSize = 0; | ||
foreach (Screen screen in All) | ||
{ | ||
double left = MathUtilities.Clamp(bounds.X, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width); | ||
double top = MathUtilities.Clamp(bounds.Y, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height); | ||
double right = MathUtilities.Clamp(bounds.X + bounds.Width, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width); | ||
double bottom = MathUtilities.Clamp(bounds.Y + bounds.Height, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height); | ||
double area = (right - left) * (bottom - top); | ||
if (area > maxAreaSize) | ||
{ | ||
maxAreaSize = area; | ||
currMaxScreen = screen; | ||
} | ||
} | ||
|
||
return currMaxScreen; | ||
} | ||
|
||
public Screen SceenFromPoint(Point point) | ||
{ | ||
return All.FirstOrDefault(x=>x.Bounds.Contains(point)); | ||
} | ||
|
||
public Screen ScreenFromVisual(IVisual visual) | ||
{ | ||
Point tl = visual.PointToScreen(visual.Bounds.TopLeft); | ||
Point br = visual.PointToScreen(visual.Bounds.BottomRight); | ||
return ScreenFromBounds(new Rect(tl,br)); | ||
} | ||
} | ||
} |
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.Controls; | ||
using Avalonia.Platform; | ||
using Avalonia.Utilities; | ||
using Gdk; | ||
using Screen = Avalonia.Platform.Screen; | ||
using Window = Gtk.Window; | ||
|
||
namespace Avalonia.Gtk | ||
{ | ||
internal class ScreenImpl : IScreenImpl | ||
{ | ||
private Window window; | ||
|
||
public int ScreenCount | ||
{ | ||
get => window.Display.DefaultScreen.NMonitors; | ||
} | ||
public Screen[] AllScreens { | ||
get | ||
{ | ||
Screen[] screens = new Screen[ScreenCount]; | ||
var screen = window.Display.DefaultScreen; | ||
|
||
for (short i = 0; i < screens.Length; i++) | ||
{ | ||
Rectangle geometry = screen.GetMonitorGeometry(i); | ||
Rect geometryRect = new Rect(geometry.X, geometry.Y, geometry.Width, geometry.Height); | ||
Screen s = new Screen(geometryRect, geometryRect, false); | ||
screens[i] = s; | ||
} | ||
|
||
return screens; | ||
} | ||
} | ||
|
||
public ScreenImpl(Window window) | ||
{ | ||
this.window = window; | ||
} | ||
} | ||
} |
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,24 @@ | ||
using Avalonia.Platform; | ||
|
||
namespace Avalonia.Gtk3 | ||
{ | ||
public class GtkScreen : Screen | ||
{ | ||
private readonly int _screenId; | ||
|
||
public GtkScreen(Rect bounds, Rect workingArea, bool primary, int screenId) : base(bounds, workingArea, primary) | ||
{ | ||
this._screenId = screenId; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return _screenId; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return (obj is GtkScreen screen) ? this._screenId == screen._screenId : base.Equals(obj); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to be indented this far?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how Rider does it, it indents to the same column. I prefer it this way but I don't mind changing it back.