Skip to content

Commit

Permalink
feat(notification): Banner positions (#1346)
Browse files Browse the repository at this point in the history
Fixes #242 
Fixes #1176 

* feat(notification): Banner positions

* Update SoundSwitch/Framework/Banner/BannerForm.cs

Co-authored-by: Antoine Aflalo <Belphemur@users.noreply.github.com>

---------

Co-authored-by: Antoine Aflalo <Belphemur@users.noreply.github.com>
  • Loading branch information
XangelMusic and Belphemur authored Dec 30, 2023
1 parent 9f7170f commit 40892fe
Show file tree
Hide file tree
Showing 21 changed files with 537 additions and 122 deletions.
27 changes: 24 additions & 3 deletions SoundSwitch/Framework/Banner/BannerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ public partial class BannerForm : Form
public BannerForm()
{
InitializeComponent();
var screen = AppModel.Instance.NotifyUsingPrimaryScreen ? Screen.PrimaryScreen : Screen.FromPoint(Cursor.Position);
var screen = GetScreen();
StartPosition = FormStartPosition.Manual;
Bounds = screen.Bounds;
TopMost = true;

Location = new Point(screen.Bounds.X + 50, screen.Bounds.Y + 60);
}

protected override bool ShowWithoutActivation => true;
Expand All @@ -66,6 +64,14 @@ public BannerForm()
// }
// }

/// <summary>
///
/// </summary>
private static Screen GetScreen()
{
return AppModel.Instance.NotifyUsingPrimaryScreen ? Screen.PrimaryScreen : Screen.FromPoint(Cursor.Position);
}

/// <summary>
/// Called internally to configure pass notification parameters
/// </summary>
Expand Down Expand Up @@ -104,6 +110,21 @@ internal void SetData(BannerData data)
lblTitle.Text = data.Text;
Region = Region.FromHrgn(RoundedCorner.CreateRoundRectRgn(0, 0, Width, Height , 20, 20));

var screen = GetScreen();
var positionLeft = screen.Bounds.X + 50;
var positionRight = screen.Bounds.Width - Width - positionLeft;
var positionTop = screen.Bounds.Y + 60;
var positionBottom = screen.Bounds.Height - Height - positionTop;

Location = AppModel.Instance.BannerPosition switch
{
BannerPositionEnum.TopLeft => new Point(positionLeft, positionTop),
BannerPositionEnum.TopRight => new Point(positionRight, positionTop),
BannerPositionEnum.BottomLeft => new Point(positionLeft, positionBottom),
BannerPositionEnum.BottomRight => new Point(positionRight, positionBottom),
_ => new Point(0, 0)
};

_timerHide.Enabled = true;

Show();
Expand Down
24 changes: 24 additions & 0 deletions SoundSwitch/Framework/Banner/BannerPositionEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

namespace SoundSwitch.Framework.Banner
{
public enum BannerPositionEnum
{
TopLeft = 0,
TopRight = 1,
BottomLeft = 2,
BottomRight = 3
}
}
38 changes: 38 additions & 0 deletions SoundSwitch/Framework/Banner/BannerPositionFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using System.Collections.Generic;
using System.Linq;
using SoundSwitch.Framework.Banner;
using SoundSwitch.Framework.Banner.Position;
using SoundSwitch.Framework.Factory;

namespace SoundSwitch.Framework.NotificationManager
{
public class BannerPositionFactory : AbstractFactory<BannerPositionEnum, IPosition>
{
private static readonly IEnumImplList<BannerPositionEnum, IPosition> Positions = new EnumImplList
<BannerPositionEnum, IPosition>
{
new PositionTopLeft(),
new PositionTopRight(),
new PositionBottomLeft(),
new PositionBottomRight()
};

public BannerPositionFactory() : base(Positions)
{
}
}
}
22 changes: 22 additions & 0 deletions SoundSwitch/Framework/Banner/Position/IPosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Framework.Factory;

namespace SoundSwitch.Framework.Banner.Position
{
public interface IPosition : IEnumImpl<BannerPositionEnum>
{
}
}
24 changes: 24 additions & 0 deletions SoundSwitch/Framework/Banner/Position/PositionBottomLeft.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Localization;

namespace SoundSwitch.Framework.Banner.Position
{
internal class PositionBottomLeft : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.BottomLeft;
public string Label => SettingsStrings.positionOptionBottomLeft;
}
}
24 changes: 24 additions & 0 deletions SoundSwitch/Framework/Banner/Position/PositionBottomRight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Localization;

namespace SoundSwitch.Framework.Banner.Position
{
internal class PositionBottomRight : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.BottomRight;
public string Label => SettingsStrings.positionOptionBottomRight;
}
}
24 changes: 24 additions & 0 deletions SoundSwitch/Framework/Banner/Position/PositionTopLeft.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Localization;

namespace SoundSwitch.Framework.Banner.Position
{
internal class PositionTopLeft : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.TopLeft;
public string Label => SettingsStrings.positionOptionTopLeft;
}
}
24 changes: 24 additions & 0 deletions SoundSwitch/Framework/Banner/Position/PositionTopRight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Localization;

namespace SoundSwitch.Framework.Banner.Position
{
internal class PositionTopRight : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.TopRight;
public string Label => SettingsStrings.positionOptionTopRight;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using SoundSwitch.Common.Framework.Audio.Device;
using SoundSwitch.Framework.Banner;
using SoundSwitch.Framework.DeviceCyclerManager;
using SoundSwitch.Framework.NotificationManager;
using SoundSwitch.Framework.Profile;
Expand Down Expand Up @@ -45,6 +46,7 @@ public interface ISoundSwitchConfiguration : IConfiguration
uint UpdateCheckInterval { get; set; }

NotificationTypeEnum NotificationSettings { get; set; }
BannerPositionEnum BannerPosition { get; set; }
bool IncludeBetaVersions { get; set; }
string CustomNotificationFilePath { get; set; }
UpdateMode UpdateMode { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Serilog;
using SoundSwitch.Audio.Manager;
using SoundSwitch.Common.Framework.Audio.Device;
using SoundSwitch.Framework.Banner;
using SoundSwitch.Framework.DeviceCyclerManager;
using SoundSwitch.Framework.NotificationManager;
using SoundSwitch.Framework.Profile;
Expand All @@ -44,7 +45,6 @@ public SoundSwitchConfiguration()

// Audio Settings
ChangeCommunications = false;
NotificationSettings = NotificationTypeEnum.BannerNotification;
TooltipInfo = TooltipInfoTypeEnum.Playback;
CyclerType = DeviceCyclerTypeEnum.Available;

Expand All @@ -61,6 +61,10 @@ public SoundSwitchConfiguration()
RecordingHotKey = new HotKey(Keys.F7, HotKey.ModifierKeys.Alt | HotKey.ModifierKeys.Control);
MuteRecordingHotKey = new HotKey(Keys.M, HotKey.ModifierKeys.Control | HotKey.ModifierKeys.Alt);

// Notification Settings
NotificationSettings = NotificationTypeEnum.BannerNotification;
BannerPosition = BannerPositionEnum.TopLeft;

AutoAddNewConnectedDevices = false;

SelectedDevices = new HashSet<DeviceInfo>();
Expand All @@ -83,6 +87,7 @@ public SoundSwitchConfiguration()
public TooltipInfoTypeEnum TooltipInfo { get; set; }
public DeviceCyclerTypeEnum CyclerType { get; set; }
public NotificationTypeEnum NotificationSettings { get; set; }
public BannerPositionEnum BannerPosition { get; set; }
public Language Language { get; set; }
public bool IncludeBetaVersions { get; set; }
public string CustomNotificationFilePath { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoundSwitch.Framework.NotificationManager
namespace SoundSwitch.Framework.NotificationManager
{
public enum NotificationCustomSoundEnum
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
********************************************************************/

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using SoundSwitch.Framework.Factory;
using SoundSwitch.Framework.NotificationManager.Notification;

Expand Down
3 changes: 1 addition & 2 deletions SoundSwitch/Framework/WinApi/Interop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using SoundSwitch.Audio.Manager.Interop.Com.User;

namespace SoundSwitch.Framework.WinApi
Expand Down
Loading

0 comments on commit 40892fe

Please sign in to comment.