1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Linq ;
4
+ using System . Threading ;
3
5
using System . Windows . Forms ;
4
6
using SoundSwitch . UI . Forms . Components ;
7
+ using SoundSwitch . Util . Timer ;
5
8
6
9
namespace SoundSwitch . UI . Forms
7
10
{
8
11
public partial class DeviceSelectorMenu : Form
9
12
{
10
13
private readonly Dictionary < string , IconMenuItem . DataContainer > _currentPayloads = new ( ) ;
14
+ private readonly DebounceDispatcher _debounce = new ( ) ;
15
+ private bool _hiding = false ;
16
+ private readonly MethodInvoker _deleteMethod ;
11
17
protected override bool ShowWithoutActivation => true ;
12
18
13
19
/// <summary>
@@ -19,7 +25,7 @@ protected override CreateParams CreateParams
19
25
get
20
26
{
21
27
CreateParams p = base . CreateParams ;
22
- // p.ExStyle |= 0x08000000; // WS_EX_NOACTIVATE
28
+ // p.ExStyle |= 0x08000000; // WS_EX_NOACTIVATE
23
29
p . ExStyle |= 0x00000008 ; // WS_EX_TOPMOST
24
30
return p ;
25
31
}
@@ -28,10 +34,16 @@ protected override CreateParams CreateParams
28
34
public DeviceSelectorMenu ( )
29
35
{
30
36
InitializeComponent ( ) ;
37
+ ResetOpacity ( ) ;
38
+ _deleteMethod = Delete ;
31
39
}
32
40
33
41
public void SetData ( IEnumerable < IconMenuItem . DataContainer > payloads )
34
42
{
43
+ _hiding = false ;
44
+ _debounce . Debounce < object > ( TimeSpan . FromMilliseconds ( 1500 ) , _ => BeginInvoke ( _deleteMethod ) ) ;
45
+ ResetOpacity ( ) ;
46
+
35
47
var payloadsArray = payloads . ToArray ( ) ;
36
48
var newPayloads = payloadsArray . ToDictionary ( container => container . Id ) ;
37
49
var toRemove = _currentPayloads . Keys . Except ( newPayloads . Keys ) ;
@@ -79,6 +91,27 @@ public void SetData(IEnumerable<IconMenuItem.DataContainer> payloads)
79
91
SetLocationToCursor ( ) ;
80
92
}
81
93
94
+ private void Delete ( )
95
+ {
96
+ _hiding = true ;
97
+ while ( Opacity > 0.0 )
98
+ {
99
+ Thread . Sleep ( 50 ) ;
100
+
101
+ if ( ! _hiding )
102
+ break ;
103
+ Opacity -= 0.05 ;
104
+ }
105
+
106
+ Hide ( ) ;
107
+ Dispose ( ) ;
108
+ }
109
+
110
+ private void ResetOpacity ( )
111
+ {
112
+ Opacity = 0.7D ;
113
+ }
114
+
82
115
private void SetLocationToCursor ( )
83
116
{
84
117
SetDesktopLocation ( Cursor . Position . X , Cursor . Position . Y ) ;
0 commit comments