Skip to content

Commit

Permalink
implement #245
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Apr 10, 2023
1 parent 18454bc commit 8c732f9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ let startMainWindow app opts =
(mainwinVM.WindowState.ToString())
(backgroundCompositionToString states.background_composition)
mainwinVM.CustomTitleBar
mainwinVM.NoTitleBar
0

let startCrashReportWindow app ex =
Expand Down
33 changes: 28 additions & 5 deletions ViewModels/FrameViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV

let mutable m_windowState = WindowState.Normal
let mutable m_customTitleBar = false
let mutable m_noTitleBar = false
let mutable m_fullscreen = false
let mutable m_title = "FVim"

Expand Down Expand Up @@ -94,6 +95,9 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV
match cfg.Mainwin.CustomTitleBar with
| Some true -> m_customTitleBar <- true
| _ -> ()
match cfg.Mainwin.NoTitleBar with
| Some true -> m_noTitleBar <- true
| _ -> ()
| _, Some grid ->
this.Height <- grid.BufferHeight
this.Width <- grid.BufferWidth
Expand All @@ -103,11 +107,15 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV
match cfg.Mainwin.CustomTitleBar with
| Some true -> m_customTitleBar <- true
| _ -> ()
match cfg.Mainwin.NoTitleBar with
| Some true -> m_noTitleBar <- true
| _ -> ()
| _ -> ()
| _ -> ()
this.Watch [
rpc.register.notify "ToggleFullScreen" (fun _ -> toggleFullScreen())
rpc.register.notify "CustomTitleBar" (fun [| Bool(v) |] -> this.CustomTitleBar <- v )
rpc.register.notify "NoTitleBar" (fun [| Bool(v) |] -> this.NoTitleBar <- v )
rpc.register.watch "background.image" (fun _ -> updateBackgroundImage())
]
match _maingrid with
Expand Down Expand Up @@ -141,21 +149,35 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV

member this.CustomTitleBarHeight
with get() =
if this.CustomTitleBar && (not this.Fullscreen) then GridLength 26.0
else GridLength 0.0
GridLength <|
if this.CustomTitleBar && (not this.Fullscreen) && (not this.NoTitleBar) then 26.0
else 0.0

member this.BorderSize
with get() =
if this.CustomTitleBar && (not this.Fullscreen) && (this.WindowState <> WindowState.Maximized)
then GridLength 1.0
else GridLength 0.0
GridLength <|
if (this.NoSystemTitleBar) && (not this.Fullscreen) && (this.WindowState <> WindowState.Maximized)
then 1.0
else 0.0

member this.CustomTitleBar
with get() = m_customTitleBar
and set(v) =
ignore <| this.RaiseAndSetIfChanged(&m_customTitleBar, v)
this.RaisePropertyChanged("CustomTitleBarHeight")
this.RaisePropertyChanged("BorderSize")
this.RaisePropertyChanged("NoSystemTitleBar")

member this.NoTitleBar
with get() = m_noTitleBar
and set(v) =
ignore <| this.RaiseAndSetIfChanged(&m_noTitleBar, v)
this.RaisePropertyChanged("CustomTitleBarHeight")
this.RaisePropertyChanged("BorderSize")
this.RaisePropertyChanged("NoSystemTitleBar")

member __.NoSystemTitleBar
with get() = m_customTitleBar || m_noTitleBar

member __.BackgroundImage with get(): IBitmap = m_bgimg_src :> IBitmap
member __.BackgroundImageHAlign with get(): HorizontalAlignment = m_bgimg_halign
Expand All @@ -174,6 +196,7 @@ type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridV
member __.Sync(_other: IFrame) =
let that = _other :?> FrameViewModel
m_customTitleBar <- that.CustomTitleBar
m_noTitleBar <- that.NoTitleBar
m_bgimg_src <- that.BackgroundImage :?> Bitmap
m_bgimg_halign <- that.BackgroundImageHAlign
m_bgimg_valign <- that.BackgroundImageVAlign
Expand Down
10 changes: 5 additions & 5 deletions Views/Frame.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ type Frame() as this =
let setCursor c =
this.Cursor <- c

let toggleTitleBar(custom) =
this.SystemDecorations <- if custom then SystemDecorations.BorderOnly else SystemDecorations.Full
let toggleTitleBar(noTitleBar) =
this.SystemDecorations <- if noTitleBar then SystemDecorations.BorderOnly else SystemDecorations.Full

let toggleFullscreen(v) =
if not v then
this.WindowState <- m_saved_state
this.PlatformImpl.Resize(m_saved_size)
this.Position <- m_saved_pos
toggleTitleBar this.ViewModel.CustomTitleBar
toggleTitleBar this.ViewModel.NoSystemTitleBar
else
// The order of actions is very important.
// 1. Remove decorations
Expand Down Expand Up @@ -180,7 +180,7 @@ type Frame() as this =
override this.OnDataContextChanged _ =
let ctx = this.DataContext :?> FrameViewModel
this.ViewModel <- ctx
toggleTitleBar ctx.CustomTitleBar
toggleTitleBar ctx.NoSystemTitleBar

if ctx.MainGrid.Id = 1 then
let pos = PixelPoint(int ctx.X, int ctx.Y)
Expand Down Expand Up @@ -227,5 +227,5 @@ type Frame() as this =
m_bgcolor <- c.Value
configBackground())
ctx.ObservableForProperty((fun x -> x.Fullscreen), skipInitial=true).Subscribe(fun v -> toggleFullscreen <| v.GetValue())
ctx.ObservableForProperty((fun x -> x.CustomTitleBar), skipInitial=true).Subscribe(fun v -> toggleTitleBar <| v.GetValue())
ctx.ObservableForProperty((fun x -> x.NoSystemTitleBar), skipInitial=true).Subscribe(fun v -> toggleTitleBar <| v.GetValue())
]
7 changes: 4 additions & 3 deletions config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let sample_config = """
"h": 600,
"state": "Normal",
"BackgroundComposition": "acrylic",
"CustomTitleBar": false
"CustomTitleBar": false,
"NoTitleBar": false
}
},
{
Expand Down Expand Up @@ -67,10 +68,10 @@ let save
(cfg: ConfigObject.Root)
(x: int) (y: int) (w: int) (h: int)
(def_w: int) (def_h: int)
(state: string) (composition: string) (customTitleBar: bool) =
(state: string) (composition: string) (customTitleBar: bool) (noTitleBar: bool) =
let dict = cfg.Workspace |> Array.map (fun ws -> (ws.Path, ws)) |> Map.ofArray
let cwd = Environment.CurrentDirectory |> Path.GetFullPath
let ws = ConfigObject.Workspace(cwd, ConfigObject.Mainwin(x, y, w, h, state, Some composition, Some customTitleBar))
let ws = ConfigObject.Workspace(cwd, ConfigObject.Mainwin(x, y, w, h, state, Some composition, Some customTitleBar, Some noTitleBar))
let wss = dict.Add(cwd, ws)
let defaults = ConfigObject.Default(def_w, def_h)
let cfg = ConfigObject.Root(wss |> Map.toArray |> Array.map snd, cfg.Logging, Some defaults)
Expand Down
1 change: 1 addition & 0 deletions fvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ command! -complete=expression -nargs=1 FVimUIWildMenu call rpcnotify(g:fvim_chan

command! -complete=expression -nargs=1 FVimDrawFPS call rpcnotify(g:fvim_channel, 'DrawFPS', <args>)
command! -complete=expression -nargs=1 FVimCustomTitleBar call rpcnotify(g:fvim_channel, 'CustomTitleBar', <args>)
command! -complete=expression -nargs=1 FVimNoTitleBar call rpcnotify(g:fvim_channel, 'NoTitleBar', <args>)

command! -complete=expression -nargs=1 FVimBackgroundOpacity call rpcnotify(g:fvim_channel, 'background.opacity', <args>)
command! -complete=expression -nargs=1 FVimBackgroundComposition call rpcnotify(g:fvim_channel, 'background.composition', <args>)
Expand Down

0 comments on commit 8c732f9

Please sign in to comment.