Skip to content

Add support for reordering notification icons via drag-and-drop#1227

Draft
xoascf wants to merge 1 commit intodremin:masterfrom
xoascf:move-tray-icons
Draft

Add support for reordering notification icons via drag-and-drop#1227
xoascf wants to merge 1 commit intodremin:masterfrom
xoascf:move-tray-icons

Conversation

@xoascf
Copy link
Copy Markdown
Collaborator

@xoascf xoascf commented Aug 20, 2025

It should also save and restore the layout order.

Further testing is required. Since the code has not been reviewed, it may not adhere to best practices.

@xoascf xoascf requested a review from dremin August 20, 2025 01:04
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 20, 2025

@xoascf xoascf requested a review from Copilot August 21, 2025 18:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for reordering notification icons via drag-and-drop functionality and saves/restores the layout order. The implementation uses the GongSolutions.Wpf.DragDrop library to enable interactive reordering of notification icons in the system tray.

Key changes:

  • Added NotifyIconOrder property to Settings class to persist icon order
  • Created NotifyIconDropHandler class to handle drag-and-drop operations
  • Modified NotifyIconList to use ObservableCollections instead of CollectionViewSources and implement order persistence

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
RetroBar/Utilities/Settings.cs Adds NotifyIconOrder property to store icon ordering
RetroBar/Utilities/NotifyIconDropHandler.cs Implements IDropTarget interface for drag-and-drop handling
RetroBar/Controls/NotifyIconList.xaml.cs Refactors collection management and adds order persistence logic
RetroBar/Controls/NotifyIconList.xaml Enables drag-and-drop on NotifyIcons ItemsControl

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

.ToList();

// Sort icons according to saved order
var sortedIcons = icons.OrderBy(i => Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier())).ToList();
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using IndexOf for ordering will fail when icons are not in the saved order list. IndexOf returns -1 for missing items, which will cause all unknown icons to be sorted to the beginning with the same priority. Use a custom ordering logic that handles missing items by assigning them a default order value.

Suggested change
var sortedIcons = icons.OrderBy(i => Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier())).ToList();
var sortedIcons = icons.OrderBy(i =>
{
int idx = Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier());
return idx == -1 ? Settings.Instance.NotifyIconOrder.Count : idx;
}).ToList();

Copilot uses AI. Check for mistakes.
}
foreach (var icon in NotificationArea.PinnedIcons.Cast<ManagedShell.WindowsTray.NotifyIcon>().OrderBy(i => Settings.Instance.NotifyIconOrder.IndexOf(i.GetInvertIdentifier())))
{
pinnedNotifyIcons.Add(icon);
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same IndexOf issue as line 218. Missing icons from the saved order will all receive -1 and be grouped together at the beginning, losing their relative order.

Suggested change
pinnedNotifyIcons.Add(icon);
foreach (var tuple in NotificationArea.PinnedIcons.Cast<ManagedShell.WindowsTray.NotifyIcon>()
.Select((icon, idx) => new { icon, idx, orderIndex = Settings.Instance.NotifyIconOrder.IndexOf(icon.GetInvertIdentifier()) })
.OrderBy(t => t.orderIndex == -1 ? int.MaxValue : t.orderIndex)
.ThenBy(t => t.idx))
{
pinnedNotifyIcons.Add(tuple.icon);

Copilot uses AI. Check for mistakes.

public void SaveIconOrder()
{
var visibleIcons = new System.Collections.Generic.List<ManagedShell.WindowsTray.NotifyIcon>();
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the fully qualified type name 'System.Collections.Generic.List' is unnecessary since 'using System.Collections.Generic;' is already present. Use 'List<ManagedShell.WindowsTray.NotifyIcon>' instead.

Suggested change
var visibleIcons = new System.Collections.Generic.List<ManagedShell.WindowsTray.NotifyIcon>();
var visibleIcons = new List<ManagedShell.WindowsTray.NotifyIcon>();

Copilot uses AI. Check for mistakes.
@MatroskaBabushka
Copy link
Copy Markdown

@xoascf @dremin
Hello. So what is the state of this PR? Is this ready or does it need more work?
Thanks @xoascf for taking the time to make this feature, it is very usefull.

@kuku00GT
Copy link
Copy Markdown

kuku00GT commented Nov 6, 2025

Hi, will be this (drag-dropp icon ordering) finished soon and added to official release?

@supra107
Copy link
Copy Markdown

I've been merging and compiling this manually since it's the one feature that is missing the most from the main code for daily use for me, but it still has some ways to go.

Mainly the drag-and-drop behavior needs some work as some icons like Windows Defender will react just as when the left button is pressed down, meaning that when you try to drag it it will open Windows Defender. f.lux's tray icon shows the same behavior if an additional example is needed.

It does seem to maintain the icon order just fine however, as long as you don't run a version without this code, which leads to the icon order getting reset, which I think is worth mentioning for debugging purposes. It would be great to see this be ready for 1.22 and it's already working pretty well.

@MatroskaBabushka
Copy link
Copy Markdown

I've been merging and compiling this manually since it's the one feature that is missing the most from the main code for daily use for me, but it still has some ways to go.

Mainly the drag-and-drop behavior needs some work as some icons like Windows Defender will react just as when the left button is pressed down, meaning that when you try to drag it it will open Windows Defender. f.lux's tray icon shows the same behavior if an additional example is needed.

It does seem to maintain the icon order just fine however, as long as you don't run a version without this code, which leads to the icon order getting reset, which I think is worth mentioning for debugging purposes. It would be great to see this be ready for 1.22 and it's already working pretty well.

so basically we would need to change tray icon click behaviour from "leftMBpressed" to "leftMBreleased", and check "if leftMBpressed && iconDragged" to trigger drag events and "leftMBreleased && !iconDragged" to trigger the click events?
@dremin this would need to be done on managedshell side or can these check be done on retrobar side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] An ability to reorder tray icons with dragging Inability to save layout of tray items upon closing the software

5 participants