Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions RetroBar/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using ManagedShell;
using RetroBar.Utilities;
using System.Windows;
using ManagedShell;
using ManagedShell.Common.Enums;
using ManagedShell.Common.Helpers;
using ManagedShell.Common.Logging;
using ManagedShell.Interop;
using Application = System.Windows.Application;
using System.Windows.Interop;
using System.Windows.Media;
using ManagedShell.Common.Enums;
using RetroBar.Utilities;
using System;
using System.Diagnostics;
using System.Reflection;
using ManagedShell.Common.Logging;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using Application = System.Windows.Application;

namespace RetroBar
{
Expand Down Expand Up @@ -89,6 +89,10 @@ private void Settings_PropertyChanged(object sender, System.ComponentModel.Prope
{
setTaskIconSize();
}
else if (e.PropertyName == nameof(Settings.SortTaskbarByProgramName))
{
RestartApp();
}
}

private void loadTheme()
Expand Down
13 changes: 13 additions & 0 deletions RetroBar/Controls/TaskList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Collections;

namespace RetroBar.Controls
{
Expand All @@ -21,6 +23,7 @@ public partial class TaskList : UserControl
private double TaskButtonLeftMargin;
private double TaskButtonRightMargin;
private ICollectionView taskbarItems;
private ProgramNameTaskbarSorter programNameTaskbarSorter;

public static DependencyProperty ButtonWidthProperty = DependencyProperty.Register(nameof(ButtonWidth), typeof(double), typeof(TaskList), new PropertyMetadata(new double()));

Expand Down Expand Up @@ -49,6 +52,8 @@ public Taskbar Host
public TaskList()
{
InitializeComponent();
programNameTaskbarSorter = new ProgramNameTaskbarSorter();
programNameTaskbarSorter.setSortingList(Settings.Instance.TaskbarSortingFilter);
}

private void SetStyles()
Expand Down Expand Up @@ -85,6 +90,14 @@ private void SetTasksCollection()
{
taskbarItems.CollectionChanged += GroupedWindows_CollectionChanged;
taskbarItems.Filter = Tasks_Filter;

if (taskbarItems is ListCollectionView lcv)
{
/*lcv.CustomSort = (IComparer)(Settings.Instance.SortTaskbarByProgramName
? programNameTaskbarSorter
: null);*/
lcv.CustomSort = programNameTaskbarSorter;
}
}

TasksList.ItemsSource = taskbarItems;
Expand Down
12 changes: 12 additions & 0 deletions RetroBar/PropertiesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@
IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=ShowEndTaskButton, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{DynamicResource show_end_task_button}" />
</CheckBox>
<CheckBox IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=SortTaskbarByProgramName, UpdateSourceTrigger=PropertyChanged}">
<Label Content="Group taskbar buttons by program" />
</CheckBox>
<StackPanel Margin="0,0,0,10">
<Label Margin="0,0,0,5" Content="Grouping order filter (ie.: Brave.exe, Code.exe, ...):"/>
<TextBox Text="{Binding Source={x:Static Settings:Settings.Instance},
Path=TaskbarSortingFilter,
UpdateSourceTrigger=PropertyChanged}"
Width="400" Height="20"/>
</StackPanel>


<DockPanel>
<Label VerticalAlignment="Center"
Target="{Binding ElementName=cboWinNumHotkeysAction}">
Expand Down
58 changes: 58 additions & 0 deletions RetroBar/Utilities/ProgramNameTaskbarSorter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using ManagedShell.WindowsTasks;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using static ManagedShell.Interop.NativeMethods;

namespace RetroBar.Utilities
{
internal class ProgramNameTaskbarSorter : IComparer
{
private List<string> programs = null;
private bool alphabeticSorting = Settings.Instance.SortTaskbarByProgramName;

public void setSortingList(String list)
{
if (!String.IsNullOrEmpty(list) && list.Length > 3 && list.Contains(","))
{
string[] parts = list.Split(',');
parts = parts.Select(p => p.Trim()).ToArray();

programs = new List<string>(parts);
}
}

public int Compare(object x, object y)
{
var winA = x as ApplicationWindow;
var winB = y as ApplicationWindow;
if (winA == null || winB == null) return 0;

if (programs != null)
{
int wantedIndexA = programs.FindIndex(p => winA.WinFileName != null && p != null && winA.WinFileName.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0);
int wantedIndexB = programs.FindIndex(p => winB.WinFileName != null && p != null && winB.WinFileName.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0);

if (wantedIndexA == -1 && wantedIndexB == -1) { }
else if (wantedIndexA == -1) { return 1; }
else if (wantedIndexB == -1) { return -1; }
else if (wantedIndexA < wantedIndexB) { return -1; }
else if (wantedIndexA > wantedIndexB) { return 1; }
}

if (!alphabeticSorting) { return 1; }

// Use WinFileName as a substitute for ProcessName
int cmp = string.Compare(winA.WinFileName, winB.WinFileName, StringComparison.OrdinalIgnoreCase);
System.Diagnostics.Debug.WriteLine("wina: " + winA.WinFileName + "winb: " + winB.WinFileName + "ret cmp: " + cmp);
if (cmp != 0) return cmp;

// Fallback: sort by window title
return string.Compare(winA.Title, winB.Title, StringComparison.OrdinalIgnoreCase);
}
}
}
14 changes: 14 additions & 0 deletions RetroBar/Utilities/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ public bool AllowBlurBehind
get => _allowBlurBehind;
set => Set(ref _allowBlurBehind, value);
}

private bool _sortTaskbarByProgramName = false;
public bool SortTaskbarByProgramName
{
get => _sortTaskbarByProgramName;
set => Set(ref _sortTaskbarByProgramName, value);
}

private string _taskbarSortingFilter = "";
public string TaskbarSortingFilter
{
get => _taskbarSortingFilter;
set => Set(ref _taskbarSortingFilter, value);
}
#endregion

#region Old Properties
Expand Down