Skip to content

Commit

Permalink
Removed the "jittering" when the sidebar is setting its position with…
Browse files Browse the repository at this point in the history
… "Reserve Space" enabled. Also added cycle edge and screen hotkeys.
  • Loading branch information
ArcadeRenegade committed Feb 13, 2016
1 parent faabecf commit cdd8c79
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 64 deletions.
4 changes: 2 additions & 2 deletions SidebarDiagnostics/Dummy.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Dummy()
InitializeComponent();
}

public void Position()
public void Reposition()
{
int _screen;
DockEdge _edge;
Expand All @@ -33,7 +33,7 @@ public void Position()

private void Window_Loaded(object sender, RoutedEventArgs e)
{
Position();
Reposition();
}
}
}
10 changes: 10 additions & 0 deletions SidebarDiagnostics/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@
<RowDefinition Height="38px"></RowDefinition>
<RowDefinition Height="38px"></RowDefinition>
<RowDefinition Height="38px"></RowDefinition>
<RowDefinition Height="38px"></RowDefinition>
<RowDefinition Height="38px"></RowDefinition>
</Grid.RowDefinitions>

<Label Grid.Column="0" Grid.Row="0" Content="Toggle" />
Expand All @@ -340,6 +342,14 @@
<Label Grid.Column="0" Grid.Row="4" Content="Close" />
<ToggleButton Grid.Column="1" Grid.Row="4" Click="BindClose_Click" LostFocus="BindButton_LostFocus" Style="{StaticResource HotkeyToggle}" />
<TextBox Grid.Column="2" Grid.Row="4" Text="{Binding Path=CloseKey, Mode=OneWay, Converter={StaticResource HotkeyConverter}}" Style="{StaticResource HotkeyLabel}" />

<Label Grid.Column="0" Grid.Row="5" Content="Cycle Edge" />
<ToggleButton Grid.Column="1" Grid.Row="5" Click="BindCycleEdge_Click" LostFocus="BindButton_LostFocus" Style="{StaticResource HotkeyToggle}" />
<TextBox Grid.Column="2" Grid.Row="5" Text="{Binding Path=CycleEdgeKey, Mode=OneWay, Converter={StaticResource HotkeyConverter}}" Style="{StaticResource HotkeyLabel}" />

<Label Grid.Column="0" Grid.Row="6" Content="Cycle Screen" />
<ToggleButton Grid.Column="1" Grid.Row="6" Click="BindCycleScreen_Click" LostFocus="BindButton_LostFocus" Style="{StaticResource HotkeyToggle}" />
<TextBox Grid.Column="2" Grid.Row="6" Text="{Binding Path=CycleScreenKey, Mode=OneWay, Converter={StaticResource HotkeyConverter}}" Style="{StaticResource HotkeyLabel}" />
</Grid>
</TabItem>
</TabControl>
Expand Down
36 changes: 36 additions & 0 deletions SidebarDiagnostics/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,34 @@ private void BindClose_Click(object sender, RoutedEventArgs e)
}
}

private void BindCycleEdge_Click(object sender, RoutedEventArgs e)
{
_keybinder = (ToggleButton)sender;

if (_keybinder.IsChecked == true)
{
BeginBind(Hotkey.KeyAction.CycleEdge);
}
else
{
EndBind();
}
}

private void BindCycleScreen_Click(object sender, RoutedEventArgs e)
{
_keybinder = (ToggleButton)sender;

if (_keybinder.IsChecked == true)
{
BeginBind(Hotkey.KeyAction.CycleScreen);
}
else
{
EndBind();
}
}

private void BeginBind(Hotkey.KeyAction action)
{
_hotkey = new Hotkey();
Expand Down Expand Up @@ -224,6 +252,14 @@ private void EndBind()
case Hotkey.KeyAction.Close:
Model.CloseKey = _hotkey;
break;

case Hotkey.KeyAction.CycleEdge:
Model.CycleEdgeKey = _hotkey;
break;

case Hotkey.KeyAction.CycleScreen:
Model.CycleScreenKey = _hotkey;
break;
}

_keybinder.IsChecked = false;
Expand Down
48 changes: 44 additions & 4 deletions SidebarDiagnostics/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,12 @@ select config
if (Framework.Settings.Instance.Hotkeys != null)
{
ToggleKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Toggle);

ShowKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Show);

HideKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Hide);

ReloadKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Reload);

CloseKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Close);
CycleEdgeKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.CycleEdge);
CycleScreenKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.CycleScreen);
}

IsChanged = false;
Expand Down Expand Up @@ -170,6 +168,16 @@ public void Save()
_hotkeys.Add(CloseKey);
}

if (CycleEdgeKey != null)
{
_hotkeys.Add(CycleEdgeKey);
}

if (CycleScreenKey != null)
{
_hotkeys.Add(CycleScreenKey);
}

Framework.Settings.Instance.Hotkeys = _hotkeys.ToArray();

Framework.Settings.Instance.Save();
Expand Down Expand Up @@ -774,6 +782,38 @@ public Hotkey CloseKey
NotifyPropertyChanged("CloseKey");
}
}

private Hotkey _cycleEdgeKey { get; set; }

public Hotkey CycleEdgeKey
{
get
{
return _cycleEdgeKey;
}
set
{
_cycleEdgeKey = value;

NotifyPropertyChanged("CycleEdgeKey");
}
}

private Hotkey _cycleScreenKey { get; set; }

public Hotkey CycleScreenKey
{
get
{
return _cycleScreenKey;
}
set
{
_cycleScreenKey = value;

NotifyPropertyChanged("CycleScreenKey");
}
}
}

public class ScreenItem
Expand Down
4 changes: 2 additions & 2 deletions SidebarDiagnostics/Setup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void Yes_Click(object sender, RoutedEventArgs e)

case Page.BeginHighDPI:
Framework.Settings.Instance.HighDPISupport = true;
Sidebar.Position();
Sidebar.Reposition();
ShowPage(Page.EndHighDPI);
return;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ private void OffsetSlider_ValueChanged(object sender, RoutedPropertyChangedEvent
Framework.Settings.Instance.XOffset = (int)XOffsetSlider.Value;
Framework.Settings.Instance.YOffset = (int)YOffsetSlider.Value;

Sidebar.Position();
Sidebar.Reposition();
}));

_cancelReposition = null;
Expand Down
58 changes: 38 additions & 20 deletions SidebarDiagnostics/Sidebar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public void Reset(bool enableHotkeys)
new BindModelHandler(BindModel).BeginInvoke(null, null);
}

public void Reposition()
{
if (!Ready)
{
return;
}

Ready = false;

BindPosition(() => Ready = true);
}

private void Initialize()
{
Ready = false;
Expand All @@ -66,26 +78,7 @@ private void Initialize()

private void BindSettings(bool enableHotkeys)
{
int _screen;
DockEdge _edge;
WorkArea _windowWA;
WorkArea _appbarWA;

Monitor.GetWorkArea(this, out _screen, out _edge, out _windowWA, out _appbarWA);

Left = _windowWA.Left;
Top = _windowWA.Top;
Width = _windowWA.Width;
Height = _windowWA.Height;

if (Framework.Settings.Instance.UseAppBar)
{
SetAppBar(_screen, _edge, _windowWA, _appbarWA);
}
else
{
ClearAppBar();
}
BindPosition(null);

if (Framework.Settings.Instance.AlwaysTop)
{
Expand Down Expand Up @@ -113,6 +106,31 @@ private void BindSettings(bool enableHotkeys)
}
}

private void BindPosition(Action callback)
{
if (IsAppBar)
{
ClearAppBar();
}

int _screen;
DockEdge _edge;
WorkArea _windowWA;
WorkArea _appbarWA;

Monitor.GetWorkArea(this, out _screen, out _edge, out _windowWA, out _appbarWA);

Left = _windowWA.Left;
Top = _windowWA.Top;
Width = _windowWA.Width;
Height = _windowWA.Height;

if (Framework.Settings.Instance.UseAppBar)
{
SetAppBar(_screen, _edge, _windowWA, _appbarWA, callback);
}
}

private delegate void BindModelHandler();

private void BindModel()
Expand Down
Loading

0 comments on commit cdd8c79

Please sign in to comment.