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: 2 additions & 0 deletions Win32/DwmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public sealed class DwmApi
[DllImport("dwmapi.dll")]
public static extern int DwmRegisterThumbnail(IntPtr dest, IntPtr src, out IntPtr thumb);
[DllImport("dwmapi.dll")]
public static extern int DwmQueryThumbnailSourceSize(IntPtr thumb, out SIZE size);
[DllImport("dwmapi.dll")]
public static extern int DwmUpdateThumbnailProperties(IntPtr hThumbnail, ref DWM_THUMBNAIL_PROPERTIES props);
[DllImport("dwmapi.dll")]
public static extern int DwmUnregisterThumbnail(IntPtr hThumbnail);
Expand Down
321 changes: 273 additions & 48 deletions WtProgram/GroupEditor.fs

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions WtProgram/GroupEditorPreview.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace Bemo
open System
open System.Collections.Generic
open System.Drawing
open System.Windows.Forms

module GroupEditorPreview =
let height = 96
let width = 180
/// Clip the destination and source together so scrolling never stretches the picture.
let projection crop (source:Size) (target:Rectangle) (viewport:Rectangle) =
if source.Width<=0 || source.Height<=0 || target.Width<=0 || target.Height<=0 then None
else
let factor = if crop then float target.Width/float source.Width else min (float target.Width/float source.Width) (float target.Height/float source.Height)
let w,h = max 1 (int(float source.Width*factor)),max 1 (int(float source.Height*factor))
let dest = Rectangle(target.X+(target.Width-w)/2,target.Y+(if crop then 0 else (target.Height-h)/2),w,h)
let shown = Rectangle.Intersect(Rectangle.Intersect(dest,target),viewport)
if shown.Width<=0 || shown.Height<=0 then None
else
let sx = (shown.X-dest.X)*source.Width/dest.Width
let sy = (shown.Y-dest.Y)*source.Height/dest.Height
let sw = max 1 (shown.Width*source.Width/dest.Width)
let sh = max 1 (shown.Height*source.Height/dest.Height)
Some(shown,Rectangle(sx,sy,min sw (source.Width-sx),min sh (source.Height-sy)))

/// Only visible cards own DWM registrations; no screenshots or capture workers are needed.
type GroupEditorPreviews() =
let thumbnails = Dictionary<IntPtr,IntPtr>()
let release hwnd =
DwmApi.DwmUnregisterThumbnail(thumbnails.[hwnd]) |> ignore
thumbnails.Remove hwnd |> ignore
member _.Clear() = for hwnd in List.ofSeq thumbnails.Keys do release hwnd
member _.Count = thumbnails.Count
member _.Update(owner:IntPtr, crop:bool, viewport:Rectangle, cards:(IntPtr * Rectangle) list) =
let wanted = cards |> List.filter(fun (hwnd,r) -> r.IntersectsWith viewport && WinUserApi.IsWindow hwnd && not(WinUserApi.IsIconic hwnd))
for hwnd in List.ofSeq thumbnails.Keys do
if not(wanted |> List.exists(fun (h,_) -> h=hwnd)) then release hwnd
for hwnd,target in wanted do
let thumb =
match thumbnails.TryGetValue hwnd with
| true,value -> Some value
| _ ->
let mutable value = IntPtr.Zero
if DwmApi.DwmRegisterThumbnail(owner,hwnd,&value)=0 then
thumbnails.[hwnd] <- value
Some value
else None
thumb |> Option.iter(fun thumb ->
let mutable size = SIZE()
let projection =
if DwmApi.DwmQueryThumbnailSourceSize(thumb,&size)=0 then
GroupEditorPreview.projection crop (Size(size.cx,size.cy)) target viewport
else None
let mutable props = DWM_THUMBNAIL_PROPERTIES()
props.dwFlags <- 1 ||| 2 ||| 4 ||| 8
props.opacity <- 255uy
match projection with
| Some(dest,source) ->
props.rcDestination <- RECT.FromRectangle dest
props.rcSource <- RECT.FromRectangle source
props.fVisible <- 1
| None -> props.fVisible <- 0
DwmApi.DwmUpdateThumbnailProperties(thumb,&props) |> ignore)
interface IDisposable with
member this.Dispose() = this.Clear()
2 changes: 1 addition & 1 deletion WtProgram/ManagerViewService/Views/AppearanceView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ type AppearanceView(?settings:ISettings) =
let ts : TabStripSprite<int> = {
tabs=Map2(List2([1,info 1 (tr Strings.Settings.tabActiveBgColor.caption);2,info 2 (tr Strings.Settings.tabHighlightBgColor.caption);3,info 4 (tr Strings.Settings.tabNormalBgColor.caption)]))
lorder=List2([1;2;3]);zorder=List2([1;2;3]);size=Sz(tabs.Width,tabs.Height)
slide=None;direction=(if vertical then TabDown else TabUp);alignment=TabLeft;onlyIcons=((settings.getValue("showIconsOnly") :?> bool) || (vertical && preview.ColumnWidth=fst SettingsCatalog.columnWidthRange));transparent=true;held=None;position=None;rowSlide=None;showAddButton=TabAddButton.visible (settings.getValue("tabAddButton") :?> string) previewHovered; reserveAddButton=preview.ReserveAddButton; buttonScreen=None; windowRight=None; centerShift=0.0;blocked=[]; dock=preview.Position; scrollOffset=0
slide=None;direction=(if vertical then TabDown else TabUp);alignment=TabLeft;onlyIcons=((settings.getValue("showIconsOnly") :?> bool) || (vertical && preview.ColumnWidth=fst SettingsCatalog.columnWidthRange));transparent=true;held=None;position=None;rowSlide=None;showAddButton=TabAddButton.visible (settings.getValue("tabAddButton") :?> string) previewHovered; reserveAddButton=preview.ReserveAddButton; buttonScreen=None; windowRight=None; centerShift=0.0;blocked=[]; dock=preview.Position; scrollOffset=0; scrollExpansion=0.0f
appearance=appearance;hover=Some(2,TabBackground);captured=None }
use bitmap = ts.render.bitmap
previewButton <-
Expand Down
23 changes: 21 additions & 2 deletions WtProgram/ManagerViewService/Views/WorkspaceView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type WorkspaceRestoreDialog(first:WorkspaceRestoreResult, ?launch:WorkspaceResto
Margin=Padding(-Dpi.scale 3,0,(if i<shown.Length-1 then Dpi.scale 22 else 0),0)))
table.Controls.Add(counts)
// Titles are often file paths with no spaces, which a label would cut off rather than wrap.
let wrap (text:string) font = String.Join("\n",SettingsTextWrap.lines text font (width-indent-SystemInformation.VerticalScrollBarWidth))
let wrap (text:string) font = String.Join("\n",SettingsTextWrap.lines text font (width-indent-Dpi.scale 14))
let details = new FlowLayoutPanel(AutoSize=true,AutoSizeMode=AutoSizeMode.GrowAndShrink,FlowDirection=FlowDirection.TopDown,
WrapContents=false,Margin=Padding.Empty)
let section state (items:(string*string) list) (hint:LocalizedText option) =
Expand All @@ -113,8 +113,27 @@ type WorkspaceRestoreDialog(first:WorkspaceRestoreResult, ?launch:WorkspaceResto
let listed = details.Controls.Count>0
// The summary is centred; the list reads from the left and, empty, still
// keeps the dialog at its width.
let holder = new Panel(AutoScroll=true,Margin=Padding(0,(if listed then Dpi.scale 20 else 0),0,0))
let holder = new Panel(Margin=Padding(0,(if listed then Dpi.scale 20 else 0),0,0))
let scroll = new SettingsScrollBar(TabStop=false)
let mutable offset = 0
let maximum() = max 0 (details.Height-holder.ClientSize.Height)
let apply value =
offset <- max 0 (min (maximum()) value)
details.Top <- -offset
scroll.configure(maximum(),holder.ClientSize.Height,offset)
let smooth = new SmoothScroller((fun () -> offset),(fun n -> max 0 (min (maximum()) n)),apply)
holder.Controls.Add(details)
holder.Controls.Add(scroll)
scroll.BringToFront()
scroll.changed.Add(smooth.jump)
holder.SizeChanged.Add(fun _ ->
scroll.Bounds <- Rectangle(holder.ClientSize.Width-scroll.Width,0,scroll.Width,holder.ClientSize.Height)
apply offset)
details.SizeChanged.Add(fun _ -> apply offset)
holder.MouseWheel.Add(fun e ->
smooth.by(SmoothScroller.wheelStep e.Delta holder.ClientSize.Height)
match e with :? HandledMouseEventArgs as handled -> handled.Handled <- true | _ -> ())
holder.Disposed.Add(fun _ -> (smooth :> IDisposable).Dispose())
table.Controls.Add(holder)
let buttons = new FlowLayoutPanel(AutoSize=true,AutoSizeMode=AutoSizeMode.GrowAndShrink,WrapContents=false,
FlowDirection=FlowDirection.RightToLeft,Anchor=AnchorStyles.Right,Margin=Padding(0,Dpi.scale 24,0,0))
Expand Down
5 changes: 4 additions & 1 deletion WtProgram/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,10 @@ type Program(lifetime:LifetimeScope, ?settings:Settings) as this =
let draft = DesktopDraft.ofDesktop drafts loose
// Every row folded, the overview first; the popup opens on the screen of the window in front.
let front = if hwnd=IntPtr.Zero then None else Some(os.windowFromHwnd(hwnd).visibleBounds)
let editor = GroupEditorForm(draft,rows |> List.map fst,windows,None,?front=front)
let editor = GroupEditorForm(draft,rows |> List.map fst,windows,None,?front=front,previews=(Services.settings.getValue "groupEditorPreviews" :?> bool))
editor.PreviewChanged.Add(fun value -> Services.settings.setValue("groupEditorPreviews",box value))
let previewSubscription = Services.settings.notifyValue "groupEditorPreviews" (fun value -> editor.SetPreviews(unbox value))
editor.Ended.Add(fun () -> previewSubscription.Dispose())
editor.Ended.Add(fun () -> groupEditorCell.set None)
editor.Saved.Add(fun plan ->
if DesktopPlan.isEmpty plan then Notice.show (tr Strings.GroupEditor.title) (tr Strings.GroupEditor.nothingChanged)
Expand Down
2 changes: 2 additions & 0 deletions WtProgram/Settings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ type Settings(isStandAlone, ?saveDelay:int) as this =
enableCtrlScroll = settingsJson.getBool("enableCtrlScroll").def(SettingsCatalog.toggleDefault "enableCtrlScroll" hasExistingSettings)
enableMiddleClickClose = settingsJson.getBool("enableMiddleClickClose").def(SettingsCatalog.toggleDefault "enableMiddleClickClose" hasExistingSettings)
tabHoverPreview = settingsJson.getBool("tabHoverPreview").def(SettingsCatalog.toggleDefault "tabHoverPreview" hasExistingSettings)
groupEditorPreviews = settingsJson.getBool("groupEditorPreviews").def(SettingsCatalog.toggleDefault "groupEditorPreviews" hasExistingSettings)
pauseInFullScreen = settingsJson.getBool("pauseInFullScreen").def(SettingsCatalog.toggleDefault "pauseInFullScreen" hasExistingSettings)
recordResources = settingsJson.getBool("recordResources").def(SettingsCatalog.toggleDefault "recordResources" hasExistingSettings)
version = settingsJson.getString("version").def(String.Empty)
Expand Down Expand Up @@ -325,6 +326,7 @@ type Settings(isStandAlone, ?saveDelay:int) as this =
settingsJson.setBool("enableCtrlScroll", settings.enableCtrlScroll)
settingsJson.setBool("enableMiddleClickClose", settings.enableMiddleClickClose)
settingsJson.setBool("tabHoverPreview", settings.tabHoverPreview)
settingsJson.setBool("groupEditorPreviews", settings.groupEditorPreviews)
settingsJson.setBool("pauseInFullScreen", settings.pauseInFullScreen)
settingsJson.setBool("recordResources", settings.recordResources)
settingsJson.setString("tabPosition",settings.tabPosition)
Expand Down
1 change: 1 addition & 0 deletions WtProgram/Shared/ProgramTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type SettingsRec = {
enableMiddleClickClose: bool
/// A picture of a tab's window while the pointer rests on the tab.
tabHoverPreview: bool
groupEditorPreviews: bool
/// While a full-screen app is in front, shortcuts let go of their keys and notices wait.
pauseInFullScreen: bool
/// The Support page's charts: a reading every five seconds in the background, kept in memory.
Expand Down
1 change: 1 addition & 0 deletions WtProgram/Shared/SettingsCatalog.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module SettingsCatalog =
let opacityDefault = 100
let leaderKeyPresets = List.zip ["123456789";"QWERTYUIOP";"ASDFGHJKL;"] (Array.toList Strings.Settings.leaderKeyPresets)
let all = [
{ id="group-editor-previews"; page=GeneralSettings; text=Strings.GroupEditor.previewSetting; binding=Toggle("groupEditorPreviews",false,false) }
{ id="tab-color-mode"; page=AppearanceSettings; text=Strings.Settings.tabColorMode; binding=Choice("tabColorMode",["Off";"ByWindow";"ByApp"],"Off") }
{ id="tab-color-style"; page=AppearanceSettings; text=Strings.Settings.tabColorStyle; binding=Choice("tabColorStyle",["Fill";"Stripe"],"Fill") }
// Kept in the appearance, not under a key of its own: the palette lists the presets itself.
Expand Down
5 changes: 5 additions & 0 deletions WtProgram/Shared/Strings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ module Strings =
/// Written to the console a command line was given from.
/// The group editor's popup.
module GroupEditor =
let previews = { en="Window previews"; zh="窗口预览"; ja="ウィンドウのプレビュー"; ar="معاينات النوافذ"; ko="창 미리 보기" }
let previewSetting = {
caption={ en="Window previews in Edit groups"; zh="编辑分组中的窗口预览"; ja="グループ編集のウィンドウプレビュー"; ar="معاينات النوافذ في تحرير المجموعات"; ko="그룹 편집에서 창 미리 보기" }
description={ en="Show wrapping preview cards in the group editor."; zh="在分组编辑器中显示自动换行的预览卡片。"; ja="グループ編集で折り返すプレビューカードを表示します。"; ar="عرض بطاقات معاينة تلتف تلقائيًا في محرر المجموعات."; ko="그룹 편집기에서 줄 바꿈되는 미리 보기 카드를 표시합니다." }
keywords={ en="group editor thumbnail preview"; zh="分组编辑器 缩略图 预览"; ja="グループ 編集 サムネイル プレビュー"; ar="مجموعة محرر مصغرة معاينة"; ko="그룹 편집기 썸네일 미리 보기" } }
let title = { en="Edit groups"; zh="编辑分组"; ja="グループを編集"; ar="تحرير المجموعات"; ko="그룹 편집" }
let windows count =
{ en=(if count=1 then "1 window" else sprintf "%d windows" count); zh=sprintf "%d 个窗口" count; ja=sprintf "%d 個のウィンドウ" count; ar=sprintf "%d نافذة" count; ko=sprintf "창 %d개" count }
Expand Down
26 changes: 25 additions & 1 deletion WtProgram/TabStrip.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type TabStrip(monitor:ITabStripMonitor) as this =
| "Right" -> TabDockRight
| _ -> TabDockTop)
let scrollOffsetCell = Cell.create(0)
let scrollExpansionCell = Cell.create(0.0f)
let mutable scrollHover = false
let mutable scrollCollapseAt = DateTime.MinValue
let scrollAnimation = new Timer(Interval=15)
let dockChangedEvent = Event<unit>()
let layoutChangedEvent = Event<bool>()
let mutable columnWidthValue = Services.settings.getValue("tabColumnWidth") :?> int
Expand Down Expand Up @@ -237,6 +241,12 @@ type TabStrip(monitor:ITabStripMonitor) as this =
titleTimer.Tick.Add(fun _ -> titleTimer.Stop(); this.showTitle())
hoverOpenTimer.Tick.Add(fun _ -> this.stepHoverOpen())
hoverOpenAnimation.Tick.Add(fun _ -> this.stepHoverOpenAnimation())
scrollAnimation.Tick.Add(fun _ ->
let active = scrollHover || columnScroll.IsSome || DateTime.UtcNow<scrollCollapseAt
let value = scrollExpansionCell.value
let next = if active then min 1.0f (value+0.2f) else max 0.0f (value-0.12f)
if next<>value then scrollExpansionCell.set(next)
elif DateTime.UtcNow>=scrollCollapseAt then scrollAnimation.Stop())
captureWatch.Tick.Add(fun _ ->
if this.isVertical && WinUserApi.GetCapture()=IntPtr.Zero then
this.refreshHover(trackLeave=false)
Expand Down Expand Up @@ -347,6 +357,7 @@ type TabStrip(monitor:ITabStripMonitor) as this =
windowRight = windowRight
buttonScreen = this.buttonScreen
scrollOffset = scrollOffsetCell.value
scrollExpansion = scrollExpansionCell.value
held = heldLayoutCell.value
position = positionCell.value
rowSlide = rowSlideCell.value
Expand All @@ -372,10 +383,15 @@ type TabStrip(monitor:ITabStripMonitor) as this =
this.withUpdate(fun () ->
match mouse with
| MouseMove(pt) ->
let over = this.ts.scrollThumb.IsSome && this.ts.scrollTrack.containsPoint(pt)
if over<>scrollHover then
scrollHover <- over
if not over then scrollCollapseAt <- DateTime.UtcNow.AddMilliseconds(600.0)
scrollAnimation.Start()
pointerOverCell.set(true)
if this.window.hasCapture.not && defaultArg trackLeave true then
this.window.trackMouseLeave()
let hit = this.hitAt pt
let hit = if over then None else this.hitAt pt
hoverCell.set(hit)
let tabHit = hit |> Option.filter(fun (_,part) -> not part.isAddButton)
this.pointTitle(hit |> Option.map(fun (tab,part) -> if part.isAddButton then AddTabHint else TabTitle tab))
Expand Down Expand Up @@ -413,6 +429,9 @@ type TabStrip(monitor:ITabStripMonitor) as this =
if action=MouseUp then capturedCell.set(None)
if pointerOverCell.value then hoverCell.set(this.hitAt pt)
| MouseLeave ->
scrollHover <- false
scrollCollapseAt <- DateTime.UtcNow.AddMilliseconds(600.0)
scrollAnimation.Start()
tipTarget <- None
this.hideTitle()
this.closeHoverOpen()
Expand Down Expand Up @@ -616,6 +635,8 @@ type TabStrip(monitor:ITabStripMonitor) as this =
if btn=MouseLeft && (columnResize.IsSome || columnScroll.IsSome) then
columnResize <- None
columnScroll <- None
scrollCollapseAt <- DateTime.UtcNow.AddMilliseconds(600.0)
scrollAnimation.Start()
this.window.releaseCapture()
this.refreshHover()
elif btn=MouseRight && this.endRowDrag() then this.refreshHover()
Expand Down Expand Up @@ -978,6 +999,8 @@ type TabStrip(monitor:ITabStripMonitor) as this =
true
elif this.ts.scrollThumb.IsSome && this.ts.scrollTrack.containsPoint(pt) then
this.hideTitle()
scrollHover <- true
scrollAnimation.Start()
let thumb = this.ts.scrollThumb.Value
if thumb.containsPoint(pt) then
columnScroll <- Some(pt.y,scrollOffsetCell.value)
Expand Down Expand Up @@ -1485,6 +1508,7 @@ type TabStrip(monitor:ITabStripMonitor) as this =
titleTimer.Dispose()
hoverOpenTimer.Dispose()
hoverOpenAnimation.Dispose()
scrollAnimation.Dispose()
tipRequest <- tipRequest+1
tipTarget <- None
titleTip |> Option.iter(fun tip -> tip.Dispose())
Expand Down
Loading