Browse Source

Cleaned up implementation of ShowTaskbarIcon

Created property in Window to enable/disable the taskbar icon
pull/1146/head
Jurjen Biewenga 9 years ago
parent
commit
a12c4649cb
  1. 7
      src/Avalonia.Controls/Platform/IWindowImpl.cs
  2. 24
      src/Avalonia.Controls/Window.cs
  3. 21
      src/Gtk/Avalonia.Gtk/WindowImpl.cs
  4. 6
      src/Gtk/Avalonia.Gtk3/WindowImpl.cs
  5. 1
      src/Windows/Avalonia.Win32/WindowImpl.cs

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

@ -31,7 +31,7 @@ namespace Avalonia.Platform
IDisposable ShowDialog(); IDisposable ShowDialog();
/// <summary> /// <summary>
/// Enables of disables system window decorations (title bar, buttons, etc) /// Enables or disables system window decorations (title bar, buttons, etc)
/// </summary> /// </summary>
void SetSystemDecorations(bool enabled); void SetSystemDecorations(bool enabled);
@ -40,8 +40,9 @@ namespace Avalonia.Platform
/// </summary> /// </summary>
void SetIcon(IWindowIconImpl icon); void SetIcon(IWindowIconImpl icon);
/// <summary>
/// Enables or disables the taskbar icon
/// </summary>
void ShowTaskbarIcon(bool value); void ShowTaskbarIcon(bool value);
} }
} }

24
src/Avalonia.Controls/Window.cs

@ -61,11 +61,17 @@ namespace Avalonia.Controls
AvaloniaProperty.Register<Window, SizeToContent>(nameof(SizeToContent)); AvaloniaProperty.Register<Window, SizeToContent>(nameof(SizeToContent));
/// <summary> /// <summary>
/// Enables of disables system window decorations (title bar, buttons, etc) /// Enables or disables system window decorations (title bar, buttons, etc)
/// </summary> /// </summary>
public static readonly StyledProperty<bool> HasSystemDecorationsProperty = public static readonly StyledProperty<bool> HasSystemDecorationsProperty =
AvaloniaProperty.Register<Window, bool>(nameof(HasSystemDecorations), true); AvaloniaProperty.Register<Window, bool>(nameof(HasSystemDecorations), true);
/// <summary>
/// Enables or disables the taskbar icon
/// </summary>
public static readonly StyledProperty<bool> HasTaskbarIconProperty =
AvaloniaProperty.Register<Window, bool>(nameof(HasTaskbarIcon), true);
/// <summary> /// <summary>
/// Defines the <see cref="Title"/> property. /// Defines the <see cref="Title"/> property.
/// </summary> /// </summary>
@ -92,6 +98,8 @@ namespace Avalonia.Controls
HasSystemDecorationsProperty.Changed.AddClassHandler<Window>( HasSystemDecorationsProperty.Changed.AddClassHandler<Window>(
(s, e) => s.PlatformImpl?.SetSystemDecorations((bool) e.NewValue)); (s, e) => s.PlatformImpl?.SetSystemDecorations((bool) e.NewValue));
HasTaskbarIconProperty.Changed.AddClassHandler<Window>((w, e) => w.PlatformImpl?.ShowTaskbarIcon((bool)e.NewValue));
IconProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl?.SetIcon(((WindowIcon)e.NewValue).PlatformImpl)); IconProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl?.SetIcon(((WindowIcon)e.NewValue).PlatformImpl));
} }
@ -152,7 +160,7 @@ namespace Avalonia.Controls
} }
/// <summary> /// <summary>
/// Enables of disables system window decorations (title bar, buttons, etc) /// Enables or disables system window decorations (title bar, buttons, etc)
/// </summary> /// </summary>
/// ///
public bool HasSystemDecorations public bool HasSystemDecorations
@ -160,6 +168,16 @@ namespace Avalonia.Controls
get { return GetValue(HasSystemDecorationsProperty); } get { return GetValue(HasSystemDecorationsProperty); }
set { SetValue(HasSystemDecorationsProperty, value); } set { SetValue(HasSystemDecorationsProperty, value); }
} }
/// <summary>
/// Enables or disables the taskbar icon
/// </summary>
///
public bool HasTaskbarIcon
{
get { return GetValue(HasTaskbarIconProperty); }
set { SetValue(HasTaskbarIconProperty, value); }
}
/// <summary> /// <summary>
/// Gets or sets the minimized/maximized state of the window. /// Gets or sets the minimized/maximized state of the window.

21
src/Gtk/Avalonia.Gtk/WindowImpl.cs

@ -6,11 +6,12 @@ using Gdk;
namespace Avalonia.Gtk namespace Avalonia.Gtk
{ {
using Gtk = global::Gtk; using Gtk = global::Gtk;
public class WindowImpl : TopLevelImpl, IWindowImpl public class WindowImpl : TopLevelImpl, IWindowImpl
{ {
private Gtk.Window _window; private Gtk.Window _window;
private Gtk.Window Window => _window ?? (_window = (Gtk.Window) Widget); private Gtk.Window Window => _window ?? (_window = (Gtk.Window)Widget);
public WindowImpl(Gtk.WindowType type) : base(new PlatformHandleAwareWindow(type)) public WindowImpl(Gtk.WindowType type) : base(new PlatformHandleAwareWindow(type))
{ {
Init(); Init();
@ -29,8 +30,10 @@ namespace Avalonia.Gtk
_lastClientSize = ClientSize; _lastClientSize = ClientSize;
_lastPosition = Position; _lastPosition = Position;
} }
private Size _lastClientSize; private Size _lastClientSize;
private Point _lastPosition; private Point _lastPosition;
void OnConfigureEvent(object o, Gtk.ConfigureEventArgs args) void OnConfigureEvent(object o, Gtk.ConfigureEventArgs args)
{ {
var evnt = args.Event; var evnt = args.Event;
@ -44,7 +47,7 @@ namespace Avalonia.Gtk
} }
var newPosition = new Point(evnt.X, evnt.Y); var newPosition = new Point(evnt.X, evnt.Y);
if (newPosition != _lastPosition) if (newPosition != _lastPosition)
{ {
PositionChanged(newPosition); PositionChanged(newPosition);
@ -107,10 +110,7 @@ namespace Avalonia.Gtk
Window.GetPosition(out x, out y); Window.GetPosition(out x, out y);
return new Point(x, y); return new Point(x, y);
} }
set set { Window.Move((int)value.X, (int)value.Y); }
{
Window.Move((int)value.X, (int)value.Y);
}
} }
public IDisposable ShowDialog() public IDisposable ShowDialog()
@ -128,9 +128,6 @@ namespace Avalonia.Gtk
Window.Icon = ((IconImpl)icon).Pixbuf; Window.Icon = ((IconImpl)icon).Pixbuf;
} }
public void ShowTaskbarIcon(bool value) public void ShowTaskbarIcon(bool value) => Window.SkipTaskbarHint = !value;
{
Window.SkipTaskbarHint = !value;
}
} }
} }

6
src/Gtk/Avalonia.Gtk3/WindowImpl.cs

@ -60,10 +60,8 @@ namespace Avalonia.Gtk3
//Why do we even have that? //Why do we even have that?
} }
public void ShowTaskbarIcon(bool value) public void ShowTaskbarIcon(bool value) => Native.GtkWindowSetSkipTaskbarHint(GtkWidget, !value);
{
Native.GtkWindowSetSkipTaskbarHint(GtkWidget, !value);
}
class EmptyDisposable : IDisposable class EmptyDisposable : IDisposable
{ {

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

@ -763,6 +763,7 @@ namespace Avalonia.Win32
else else
style &= ~(UnmanagedMethods.WindowStyles.WS_EX_APPWINDOW); style &= ~(UnmanagedMethods.WindowStyles.WS_EX_APPWINDOW);
//Toggle to make the styles stick
UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide); UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide);
UnmanagedMethods.SetWindowLong(_hwnd, -20, (uint)style); UnmanagedMethods.SetWindowLong(_hwnd, -20, (uint)style);
UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Show); UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Show);

Loading…
Cancel
Save