Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Most native Windows multi-finger gestures work as "recognize a gesture → play
- **Three-finger swipe up · Window overview**: every window flies from where it is into the overview layout, with progress driven entirely by finger travel. Pause and the picture holds halfway; swipe back and it rewinds.
- **Three-finger swipe down · App windows view**: tiles only the current app's windows, with minimized ones in a separate row at the bottom, while other windows fade out in place. It follows your fingers the whole way, and a swipe up dismisses it (like macOS App Exposé). In the overview, clicking the title under a window switches to that app's view, and clicking again goes back to the overview.
- **Four-finger swipe down · Show desktop**: windows slide off the screen edges with your fingers to reveal the desktop; a four-finger swipe up pulls them back. When the desktop isn't showing, a four-finger swipe up opens the overview (as on macOS).
- **Desktop strip in the overview**: the top of the overview lists all virtual desktops. Hover over it and it expands into live thumbnails; click another desktop to switch right away and zoom from its thumbnail into that desktop. The "+" at the end adds a desktop and the "×" next to a name removes one. Drag a window onto a desktop to move it there, or onto "+" to create a new desktop and move it.
- **Desktop strip in the overview**: the top of the overview lists all virtual desktops. Hover over it and it expands into live thumbnails; click another desktop to switch right away and zoom from its thumbnail into that desktop. Drag thumbnails to reorder the actual desktops; four-finger swipes follow the new order too. The "+" at the end adds a desktop and the "×" next to a name removes one. Drag a window onto a desktop to move it there, or onto "+" to create a new desktop and move it.
- **Four-finger horizontal swipe inside the overview**: without leaving the overview, the window area slides sideways with your fingers to the neighboring desktop's page, with its windows already laid out.
- **Three-finger horizontal swipe · Switch windows**: a strip of windows pans with your fingers and, on release, snaps to the nearest window and brings it to the front. Alt+Tab uses the same switcher.
- **Four-finger horizontal swipe · Switch virtual desktops**: the neighboring desktop slides in with your fingers, with no dead zone at the start. The first and last desktops rubber-band, there is no flicker when the switch finishes, and window shadows match the system's.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Windows 原生的多指手势大多是「识别到手势 → 播放一段固定
- **三指上滑 · 窗口总览**:每个窗口从原位飞向总览布局,进度完全由手指位移驱动。停住,画面就停在半路;往回滑,画面就倒退。
- **三指下滑 · 应用窗口视图**:只把当前程序的窗口平铺出来,最小化的单独排在底部一排,其他窗口原地淡出;同样全程跟手,向上滑收起(macOS App Exposé)。总览里点某个窗口下面的标题,就直接换成那个程序的视图,再点一次回到总览。
- **四指下滑 · 显示桌面**:窗口跟着手指滑出屏幕边缘,露出桌面;再四指上滑把它们拉回来。桌面没显示时四指上滑打开总览(同 macOS)。
- **总览桌面条**:总览顶部列出所有虚拟桌面;指针移上去就展开成实时缩略图,点另一个桌面会立刻切过去,并从缩略图放大进入那个桌面。末尾的「+」新建桌面,名字旁的「×」删除桌面。把窗口拖到某个桌面上就移过去,拖到「+」上就新建桌面并移过去。
- **总览桌面条**:总览顶部列出所有虚拟桌面;指针移上去就展开成实时缩略图,点另一个桌面会立刻切过去,并从缩略图放大进入那个桌面。拖动缩略图可调整真实桌面顺序,四指横滑也按新顺序切换。末尾的「+」新建桌面,名字旁的「×」删除桌面。把窗口拖到某个桌面上就移过去,拖到「+」上就新建桌面并移过去。
- **总览里四指横滑**:不退出总览,窗口区域跟手横向滑到相邻桌面那一页,各桌面的窗口都已排好。
- **三指横滑 · 切换窗口**:窗口条随手指平移,松手吸附到最近的窗口并切到前台。Alt+Tab 也换成同一个切换条。
- **四指横滑 · 切换虚拟桌面**:相邻桌面跟着手指滑入,没有起滑死区。到首尾桌面时有橡皮筋,切换结束时没有闪烁,窗口阴影也与系统一致。
Expand Down
143 changes: 143 additions & 0 deletions src/GlideShell.Core/Overview/DesktopBar.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GlideShell.Core.Geometry;
using GlideShell.Core.Motion;

namespace GlideShell.Core.Overview;

Expand Down Expand Up @@ -31,6 +32,120 @@ public readonly record struct DesktopBarHit(DesktopBarPart Part, int Index)
public static DesktopBarHit Nothing => new(DesktopBarPart.None, -1);
}

/// <summary>一次桌面拖动排序:从原来的下标移到目标下标。</summary>
public readonly record struct DesktopBarMove(int From, int To);

/// <summary>桌面拖动排序的纯计算:所有桌面仍以原下标存储,只在画面上临时换到目标槽位。</summary>
public static class DesktopBarReorder
{
/// <summary>原下标 <paramref name="index"/> 的桌面在拖动预览里应占的槽位。</summary>
public static int Slot(int index, int from, int to, int count)
{
if (count <= 0 || index < 0 || index >= count || from < 0 || from >= count || to < 0 || to >= count || from == to) return index;
if (index == from) return to;
if (from < to && index > from && index <= to) return index - 1;
if (from > to && index >= to && index < from) return index + 1;
return index;
}

/// <summary>被拖桌面的中心越过其他槽位中心时,预览顺序随之改变。</summary>
public static int Target(DesktopBarGeometry bar, int from, double draggedCenterX)
{
if (from < 0 || from >= bar.Count) return -1;
int target = from;
if (draggedCenterX > bar.Thumbs[from].CenterX)
for (int i = from + 1; i < bar.Count && draggedCenterX > bar.Thumbs[i].CenterX; i++) target = i;
else
for (int i = from - 1; i >= 0 && draggedCenterX < bar.Thumbs[i].CenterX; i--) target = i;
return target;
}

/// <summary>
/// 拖动排序这一帧第 <paramref name="index"/> 个桌面的缩略图、收起时的桌面名条与展开后的桌面名位置(屏幕坐标):
/// 其余桌面在槽位之间滑动让位;被拖的跟着指针,松手后从松手处飞到它的槽位,桌面名始终跟着它的缩略图。
/// 合成层的缩略图与装饰(名字、框)都按它摆,两边不会错开。
/// </summary>
public static (RectD Thumb, RectD Pill, RectD Label) Layout(DesktopBarGeometry bar, in DesktopBarDragFrame drag, int index, double expansion)
{
double slot = drag.SlotOf(index, bar.Count);
var thumb = bar.ThumbRectAt(slot, expansion);
var pill = bar.PillAt(slot);
var label = bar.LabelAt(slot);
if (index != drag.Source) return (thumb, pill, label);
var follow = new RectD(drag.X - drag.GrabX * thumb.Width, drag.Y - drag.GrabY * thumb.Height, thumb.Width, thumb.Height);
var moved = drag.Fly < 0 ? follow : RectD.Lerp(follow, thumb, Math.Clamp(drag.Fly, 0, 1));
return (moved, pill, label.Offset(moved.Left - thumb.Left, moved.Top - thumb.Top));
}
}

/// <summary>
/// 桌面拖动排序的让位动画(不可变:UI 线程整体替换,渲染线程只取样)。每个桌面一个显示槽位(可带小数)的弹簧;
/// 预览顺序变化时,各桌面从此刻的位置与速度出发驶向新槽位,所以让位连续、可以随时改道。
/// </summary>
public sealed class DesktopReorderMotion
{
/// <summary>其余桌面让位 / 回原位的弹簧(与桌面条展开同一手感)。</summary>
public static readonly SpringParameters SlotSpring = new(0.28, 1.0);

/// <summary>松手后被拖的缩略图飞到槽位的弹簧(与拖窗口飞回同一手感)。</summary>
public static readonly SpringParameters FlySpring = new(0.3, 1.0);

private readonly SpringAnimation[] _slots;

private DesktopReorderMotion(SpringAnimation[] slots) => _slots = slots;

public int Count => _slots.Length;

/// <summary>所有桌面都在原位(刚开始拖)。</summary>
public static DesktopReorderMotion Identity(int count, long hostUs)
{
var slots = new SpringAnimation[Math.Max(0, count)];
for (int i = 0; i < slots.Length; i++) slots[i] = new SpringAnimation(SlotSpring, i, i, 0, hostUs);
return new DesktopReorderMotion(slots);
}

/// <summary>
/// 驶向「<paramref name="from"/> 移到 <paramref name="to"/>」的预览顺序(<paramref name="from"/> = <paramref name="to"/> 即原顺序)。
/// <paramref name="snap"/> 那个桌面直接到位:它正被拖着,画面上跟着指针,松手时要从它的目标槽位算起。
/// </summary>
public DesktopReorderMotion Retarget(int from, int to, long hostUs, int snap = -1)
{
var next = new SpringAnimation[_slots.Length];
for (int i = 0; i < next.Length; i++)
{
double target = DesktopBarReorder.Slot(i, from, to, next.Length);
var current = _slots[i];
if (i == snap) next[i] = new SpringAnimation(SlotSpring, target, target, 0, hostUs);
else if (current.Target == target) next[i] = current;
else
{
var (value, velocity, _) = current.Sample(hostUs);
next[i] = new SpringAnimation(SlotSpring, value, target, velocity, hostUs);
}
}
return new DesktopReorderMotion(next);
}

/// <summary>所有桌面直接停到目标槽位(落定动画被别的输入打断)。</summary>
public DesktopReorderMotion Snap(long hostUs)
{
var next = new SpringAnimation[_slots.Length];
for (int i = 0; i < next.Length; i++) next[i] = new SpringAnimation(SlotSpring, _slots[i].Target, _slots[i].Target, 0, hostUs);
return new DesktopReorderMotion(next);
}

/// <summary>第 <paramref name="index"/> 个桌面此刻的槽位(越界的按原位)。</summary>
public double SlotAt(int index, long hostUs) => index >= 0 && index < _slots.Length ? _slots[index].Sample(hostUs).Value : index;

/// <summary>此刻所有桌面都已停在目标槽位。</summary>
public bool IsSettled(long hostUs)
{
foreach (var slot in _slots)
if (!slot.Sample(hostUs).Settled) return false;
return true;
}
}

/// <summary>
/// 一块屏上桌面条的几何(物理像素)。macOS 调度中心的样子:平时顶部一排桌面名(收起),
/// 指针移到顶部时展开成一排桌面缩略图(壁纸 + 窗口),名字挪到缩略图下面;展开时下面的窗口区域整体往下缩,给它让位。
Expand Down Expand Up @@ -145,6 +260,34 @@ public RectD ThumbRect(int index, double expansion)
return RectD.Lerp(seed, full, Math.Clamp(expansion, 0, 1.05));
}

/// <summary>小数槽位 <paramref name="slot"/> 处(拖动排序让位途中)的缩略图:在相邻两个槽位之间插值(各槽位等宽等距)。</summary>
public RectD ThumbRectAt(double slot, double expansion)
{
var (lo, hi, t) = Split(slot);
return RectD.Lerp(ThumbRect(lo, expansion), ThumbRect(hi, expansion), t);
}

/// <summary>小数槽位处收起时的桌面名条。</summary>
public RectD PillAt(double slot)
{
var (lo, hi, t) = Split(slot);
return RectD.Lerp(Pills[lo], Pills[hi], t);
}

/// <summary>小数槽位处展开后的桌面名。</summary>
public RectD LabelAt(double slot)
{
var (lo, hi, t) = Split(slot);
return RectD.Lerp(Labels[lo], Labels[hi], t);
}

private (int Lo, int Hi, double T) Split(double slot)
{
double s = Math.Clamp(double.IsFinite(slot) ? slot : 0, 0, Math.Max(0, Count - 1));
int lo = (int)s;
return (lo, Math.Min(lo + 1, Math.Max(0, Count - 1)), s - lo);
}

/// <summary>屏幕上的矩形 <paramref name="source"/>(例如窗口原位)画在第 <paramref name="index"/> 个桌面缩略图里的位置。</summary>
public RectD InThumb(int index, RectD source, double expansion = 1)
{
Expand Down
Loading
Loading