Skip to content

Commit

Permalink
Merge pull request #962 from dremin/resize-vertical
Browse files Browse the repository at this point in the history
Allow resize of vertical taskbars as well
  • Loading branch information
dremin authored Nov 26, 2024
2 parents ef6fd0b + 0859264 commit 41f1c1d
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 75 deletions.
2 changes: 1 addition & 1 deletion RetroBar/Controls/StartButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void openFloatingStart()
{
bool useFloatingStartButton = Application.Current.FindResource("UseFloatingStartButton") as bool? ?? false;

if (!useFloatingStartButton || !Host.Screen.Primary) return;
if (!useFloatingStartButton || Host?.Screen.Primary != true) return;

if (floatingStartButton == null)
{
Expand Down
21 changes: 0 additions & 21 deletions RetroBar/Converters/EdgeIsHorizontalConverter.cs

This file was deleted.

27 changes: 27 additions & 0 deletions RetroBar/Converters/EdgeOrientationVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using ManagedShell.AppBar;
using System;
using System.Windows;
using System.Windows.Data;

namespace RetroBar.Converters
{
[ValueConversion(typeof(bool), typeof(Visibility))]
public class EdgeOrientationVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is AppBarEdge edge && parameter is string visibleOrientation)
{
return ((edge == AppBarEdge.Left || edge == AppBarEdge.Right) && visibleOrientation == "vertical") ||
((edge == AppBarEdge.Top || edge == AppBarEdge.Bottom) && visibleOrientation == "horizontal") ? Visibility.Visible : Visibility.Collapsed;
}

return Binding.DoNothing;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
}
}
8 changes: 1 addition & 7 deletions RetroBar/Languages/English.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
</x:Array>
<s:String x:Key="rowcount_text">Number of _rows:</s:String>
<s:String x:Key="rowcount_tip">The number of rows on the taskbar when on top or bottom.</s:String>
<x:Array x:Key="rowcount_options" Type="s:Int32">
<s:Int32>1</s:Int32>
<s:Int32>2</s:Int32>
<s:Int32>3</s:Int32>
<s:Int32>4</s:Int32>
<s:Int32>5</s:Int32>
</x:Array>
<s:String x:Key="taskbar_width">Taskba_r width:</s:String>
<s:String x:Key="allow_font_smoothing">_Allow font smoothing</s:String>
<s:String x:Key="collapse_tray_icons">Collapse _notification area icons</s:String>
<s:String x:Key="customize">_Customize...</s:String>
Expand Down
27 changes: 21 additions & 6 deletions RetroBar/PropertiesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<converters:CountToIndexConverter x:Key="countToIndexConverter" />
<converters:DoubleToPercentConverter x:Key="doubleToPercentConverter" />
<converters:EnumConverter x:Key="enumConverter" />
<converters:EdgeIsHorizontalConverter x:Key="isHorizontalConverter" />
<converters:EdgeOrientationVisibilityConverter x:Key="edgeOrientationVisibilityConverter" />
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment"
Value="Center" />
Expand Down Expand Up @@ -205,16 +205,31 @@
SelectedIndex="{Binding Source={x:Static Settings:Settings.Instance}, Path=Edge, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource enumConverter}}"
SelectionChanged="cboEdgeSelect_SelectionChanged" />
</DockPanel>
<DockPanel IsEnabled="{Binding Source={x:Static Settings:Settings.Instance}, Path=Edge, Converter={StaticResource isHorizontalConverter}}">
<DockPanel Visibility="{Binding Source={x:Static Settings:Settings.Instance}, Path=Edge, Converter={StaticResource edgeOrientationVisibilityConverter}, ConverterParameter='horizontal'}">
<Label VerticalAlignment="Center"
Target="{Binding ElementName=cbRowCount}">
Target="{Binding ElementName=cboRowCount}">
<AccessText Text="{DynamicResource rowcount_text}"
ToolTip="{DynamicResource rowcount_tip}" />
</Label>
<ComboBox x:Name="cbRowCount"
ItemsSource="{DynamicResource rowcount_options}"
<ComboBox x:Name="cboRowCount"
SelectedIndex="{Binding Source={x:Static Settings:Settings.Instance}, Path=RowCount, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource countToIndexConverter}}"
SelectionChanged="cbRowCount_SelectionChanged" />
SelectionChanged="cboRowCount_SelectionChanged" />
</DockPanel>
<DockPanel Visibility="{Binding Source={x:Static Settings:Settings.Instance}, Path=Edge, Converter={StaticResource edgeOrientationVisibilityConverter}, ConverterParameter='vertical'}">
<Label VerticalAlignment="Center"
Target="{Binding ElementName=sldTaskbarWidth}">
<AccessText Text="{DynamicResource taskbar_width}" />
</Label>
<Slider Name="sldTaskbarWidth"
Orientation="Horizontal"
IsSnapToTickEnabled="True"
Value="{Binding Source={x:Static Settings:Settings.Instance}, Path=TaskbarWidth, UpdateSourceTrigger=PropertyChanged}"
Minimum="1"
TickFrequency="1"
TickPlacement="BottomRight"
HorizontalAlignment="Right"
Margin="0,3,0,4"
Width="200" />
</DockPanel>
<CheckBox IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=AllowFontSmoothing, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{DynamicResource allow_font_smoothing}" />
Expand Down
27 changes: 24 additions & 3 deletions RetroBar/PropertiesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public bool IsLocked
get => Settings.Instance.LockTaskbar;
}

// Previews should never be scaled
public bool IsScaled
{
get => false;
}

// Previews should always assume 1 row
public int Rows
{
Expand All @@ -72,8 +78,10 @@ private PropertiesWindow(NotificationArea notificationArea, DictionaryManager di
LoadPreviewHeight();
LoadAutoStart();
LoadLanguages();
LoadRows();
LoadThemes();
LoadVersion();
LoadWidth();

Settings.Instance.PropertyChanged += Settings_PropertyChanged;
}
Expand Down Expand Up @@ -157,6 +165,14 @@ private void LoadLanguages()
}
}

private void LoadRows()
{
for (int i = 1; i <= Settings.Instance.RowLimit; i++)
{
cboRowCount.Items.Add(i.ToString());
}
}

private void LoadThemes()
{
foreach (var theme in _dictionaryManager.GetThemes())
Expand All @@ -170,6 +186,11 @@ private void LoadVersion()
txtVersion.Text = string.Format((string)FindResource("version"), System.Windows.Forms.Application.ProductVersion);
}

private void LoadWidth()
{
sldTaskbarWidth.Maximum = Settings.Instance.TaskbarWidthLimit;
}

private void UpdateWindowPosition()
{
switch (Settings.Instance.Edge)
Expand Down Expand Up @@ -290,11 +311,11 @@ private void cboMiddleMouseAction_SelectionChanged(object sender, System.Windows
}
}

private void cbRowCount_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
private void cboRowCount_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (cbRowCount.SelectedItem == null)
if (cboRowCount.SelectedItem == null)
{
cbRowCount.SelectedValue = cbRowCount.Items[Settings.Instance.RowCount - 1];
cboRowCount.SelectedValue = cboRowCount.Items[Settings.Instance.RowCount - 1];
}
}

Expand Down
97 changes: 62 additions & 35 deletions RetroBar/Taskbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,7 @@ public Taskbar(WindowManager windowManager, DictionaryManager dictionaryManager,
DataContext = _shellManager;
StartButton.StartMenuMonitor = startMenuMonitor;


_unlockedMargin = Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarUnlockedSize") as double? ?? 0);
DesiredRowHeight = Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarRowHeight") as double? ?? 0);
DesiredWidth = Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarWidth") as double? ?? 0);
DesiredHeight = (Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarHeight") as double? ?? 0)) + DesiredRowHeight * (Rows - 1);

if (AppBarMode == AppBarMode.AutoHide || !Settings.Instance.LockTaskbar)
{
DesiredHeight += _unlockedMargin;
DesiredWidth += _unlockedMargin;
}
RecalculateSize(false);

AllowsTransparency = mode == AppBarMode.AutoHide || (Application.Current.FindResource("AllowsTransparency") as bool? ?? false);

Expand Down Expand Up @@ -165,12 +155,11 @@ private void UpdateTrayPosition()
}
}

private void RecalculateSize()
private void RecalculateSize(bool performResize = true)
{
_unlockedMargin = Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarUnlockedSize") as double? ?? 0);
DesiredRowHeight = Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarRowHeight") as double? ?? 0);
double newWidth = Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarWidth") as double? ?? 0);

double newWidth = (Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarWidth") as double? ?? 0)) + DesiredRowHeight * (Settings.Instance.TaskbarWidth - 1);
double newHeight = (Settings.Instance.TaskbarScale * (Application.Current.FindResource("TaskbarHeight") as double? ?? 0)) + DesiredRowHeight * (Rows - 1);

if (AppBarMode == AppBarMode.AutoHide || !Settings.Instance.LockTaskbar)
Expand All @@ -185,15 +174,18 @@ private void RecalculateSize()
DesiredHeight = newHeight;
DesiredWidth = newWidth;

if (Orientation == Orientation.Horizontal && heightChanged)
if (performResize)
{
Height = DesiredHeight;
SetScreenPosition();
}
else if (Orientation == Orientation.Vertical && widthChanged)
{
Width = DesiredWidth;
SetScreenPosition();
if (Orientation == Orientation.Horizontal && heightChanged)
{
Height = DesiredHeight;
SetScreenPosition();
}
else if (Orientation == Orientation.Vertical && widthChanged)
{
Width = DesiredWidth;
SetScreenPosition();
}
}
}

Expand Down Expand Up @@ -282,9 +274,15 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
}
else if (e.PropertyName == nameof(Settings.RowCount))
{
PeekDuringAutoHide();
RecalculateSize();
OnPropertyChanged(nameof(Rows));
}
else if (e.PropertyName == nameof(Settings.TaskbarWidth))
{
PeekDuringAutoHide();
RecalculateSize();
}
}

private void Taskbar_OnLocationChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -568,23 +566,43 @@ private void MouseDragHook_LowLevelMouseEvent(object sender, LowLevelMouseHook.L
if (_mouseDragResize)
{
Dispatcher.BeginInvoke(() => {
int mouseX = e.HookStruct.pt.X;
int mouseY = e.HookStruct.pt.Y;
// Calculate where the resize edge should be, in case the actual resize operation is lagging behind the mouse
double taskbarEdge = AppBarEdge == AppBarEdge.Top ? Screen.Bounds.Top + (DesiredHeight * DpiScale) : Screen.Bounds.Bottom - (DesiredHeight * DpiScale);
double scaledRowHeight = DesiredRowHeight * DpiScale;
if ((AppBarEdge == AppBarEdge.Top && mouseY < taskbarEdge - SystemParameters.MinimumVerticalDragDistance ||
AppBarEdge == AppBarEdge.Bottom && mouseY > taskbarEdge + SystemParameters.MinimumVerticalDragDistance) &&
Settings.Instance.RowCount > 1)
if (Orientation == Orientation.Horizontal)
{
// If mouse is inside the taskbar and more than the minimum drag distance away, decrement size
Settings.Instance.RowCount -= 1;
double taskbarEdge = AppBarEdge == AppBarEdge.Top ? Screen.Bounds.Top + (DesiredHeight * DpiScale) : Screen.Bounds.Bottom - (DesiredHeight * DpiScale);
if ((AppBarEdge == AppBarEdge.Top && mouseY < taskbarEdge - SystemParameters.MinimumVerticalDragDistance ||
AppBarEdge == AppBarEdge.Bottom && mouseY > taskbarEdge + SystemParameters.MinimumVerticalDragDistance) &&
Settings.Instance.RowCount > 1)
{
// If mouse is inside the taskbar and more than the minimum drag distance away, decrement size
Settings.Instance.RowCount -= 1;
}
else if ((AppBarEdge == AppBarEdge.Top && mouseY >= taskbarEdge + scaledRowHeight ||
AppBarEdge == AppBarEdge.Bottom && mouseY <= taskbarEdge - scaledRowHeight) &&
Settings.Instance.RowCount < Settings.Instance.RowLimit)
{
// If mouse is outside the taskbar and at least one row height away, increment size
Settings.Instance.RowCount += 1;
}
}
else if ((AppBarEdge == AppBarEdge.Top && mouseY >= taskbarEdge + scaledRowHeight ||
AppBarEdge == AppBarEdge.Bottom && mouseY <= taskbarEdge - scaledRowHeight) &&
Settings.Instance.RowCount < 5)
else
{
// If mouse is outside the taskbar and at least one row height away, increment size
Settings.Instance.RowCount += 1;
double taskbarEdge = AppBarEdge == AppBarEdge.Left ? Screen.Bounds.Left + (DesiredWidth * DpiScale) : Screen.Bounds.Right - (DesiredWidth * DpiScale);
if ((AppBarEdge == AppBarEdge.Left && mouseX > taskbarEdge + scaledRowHeight ||
AppBarEdge == AppBarEdge.Right && mouseX < taskbarEdge - scaledRowHeight) &&
Settings.Instance.TaskbarWidth < Settings.Instance.TaskbarWidthLimit)
{
Settings.Instance.TaskbarWidth += 1;
}
else if ((AppBarEdge == AppBarEdge.Left && mouseX < taskbarEdge - SystemParameters.MinimumHorizontalDragDistance ||
AppBarEdge == AppBarEdge.Right && mouseX > taskbarEdge + SystemParameters.MinimumHorizontalDragDistance) &&
Settings.Instance.TaskbarWidth > 1)
{
Settings.Instance.TaskbarWidth -= 1;
}
}
});
return;
Expand Down Expand Up @@ -644,9 +662,10 @@ private void StopMouseDragHook()

private bool IsMouseInResizeArea()
{
if (IsLocked || Orientation == Orientation.Vertical) return false;
if (IsLocked) return false;

int resizeRegionSize = (int)((_unlockedMargin > 0 ? _unlockedMargin : SystemParameters.MinimumVerticalDragDistance * Settings.Instance.TaskbarScale) * DpiScale);
int mouseX = System.Windows.Forms.Cursor.Position.X;
int mouseY = System.Windows.Forms.Cursor.Position.Y;

if (AppBarEdge == AppBarEdge.Bottom && mouseY <= (int)(Top * DpiScale) + resizeRegionSize)
Expand All @@ -657,6 +676,14 @@ private bool IsMouseInResizeArea()
{
return true;
}
else if (AppBarEdge == AppBarEdge.Left && mouseX >= (int)((Left + Width) * DpiScale) - resizeRegionSize)
{
return true;
}
else if (AppBarEdge == AppBarEdge.Right && mouseX <= (int)(Left * DpiScale) + resizeRegionSize)
{
return true;
}

return false;
}
Expand All @@ -666,7 +693,7 @@ private void Taskbar_MouseMove(object sender, MouseEventArgs e)
// Show resize cursor for resizable taskbars
if (IsMouseInResizeArea() || _mouseDragResize)
{
Cursor = Cursors.SizeNS;
Cursor = Orientation == Orientation.Horizontal ? Cursors.SizeNS : Cursors.SizeWE;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion RetroBar/Themes/Windows Vista Aero.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@
<Setter Property="Background"
Value="Transparent" />
<Setter Property="HorizontalAlignment"
Value="Right" />
Value="Stretch" />
<Setter Property="FocusVisualStyle"
Value="{x:Null}" />
<Setter Property="Template">
Expand Down
2 changes: 1 addition & 1 deletion RetroBar/Themes/Windows XP Blue.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border x:Name="StartButtonBorder">
<Border x:Name="StartButtonBorder" HorizontalAlignment="Left">
<Border.Background>
<ImageBrush ImageSource="{DynamicResource StartButtonImage}"
ViewboxUnits="RelativeToBoundingBox"
Expand Down
Loading

0 comments on commit 41f1c1d

Please sign in to comment.