The current algorithm for swapping icons on the taskbar requires overlap between the items. This leads to the following problem where if you go past the end without hitting the last icon, the icon you’re dragging won’t swap itself at the end of the list.
The correct algorithm is supposed to be:
-
When the mouse moves, and we are dragging,
-
Take the GridLayout which has all the icons and create a copy without including the one which is being dragged.
-
Now, for(i) the length of the gridlayout, re-insert the item at the given (i)
-
Layout the copy so that every item is in it’s final ‘x’ positions.
-
Get the ‘x’ of the re-inserted element and compare it against the actual real draggingItemX
-
Whichever index resulted in the least distance between the two, is the index we have to swap with
-
-
Perform the element swap on the actual GridLayout, and animate items which moved.
A visualizer of the algorithm:
https://jmanc3.github.io/draggable-list-algorithm/
The actual swap algorithm source:
https://github.com/jmanc3/draggable-list-algorithm/blob/7947d135bf2946dbbd4c2f9e28267c0bdaa711f2/index.html#L179
The feel of dragging off the end of the list and having no swap occur, is really bad and needs to be fixed. The KDE panel cannot be the premier windows alternative and fail at the one things it’s supposed to do.