Skip to content

Commit

Permalink
implement default window size. fix #178
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Mar 29, 2022
1 parent 220f87b commit c43c0c6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ let startMainWindow app opts =
>>= fun comp -> parseBackgroundComposition(box comp)
>>= fun comp -> states.background_composition <- comp; None
|> ignore
cfg.Default
>>= fun defs -> states.default_height <- defs.H; states.default_width <- defs.W; None
|> ignore

model.CreateFrame <- fun _gridui ->
let gridui = _gridui :?> GridViewModel
Expand Down Expand Up @@ -74,7 +77,13 @@ let startMainWindow app opts =
app <| mainwin
boundcheck()
let x, y, w, h = (int mainwinVM.X), (int mainwinVM.Y), (int mainwinVM.Width), (int mainwinVM.Height)
config.save cfg x y w h (mainwinVM.WindowState.ToString()) (backgroundCompositionToString states.background_composition) mainwinVM.CustomTitleBar
let def_w, def_h = states.default_width, states.default_height
config.save cfg
x y w h
def_w def_h
(mainwinVM.WindowState.ToString())
(backgroundCompositionToString states.background_composition)
mainwinVM.CustomTitleBar
0

let startCrashReportWindow app ex =
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ FVimKeyDisableShiftSpace v:true " disable unsupported sequence <S-Space>
FVimKeyAutoIme v:true " Automatic input method engagement in Insert mode
FVimKeyAltGr v:true " Recognize AltGr. Side effect is that <C-A-Key> is then impossible
" Default options (workspace-agnostic)
FVimDefaultWindowWidth 1600 " Default window size in a new workspace
FVimDefaultWindowHeight 900
" Detach from a remote session without killing the server
" If this command is executed on a standalone instance,
" the embedded process will be terminated anyway.
Expand Down
2 changes: 1 addition & 1 deletion ViewModels/FrameViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ open Avalonia.Layout
/// the frame should organize the grids.
/// </summary>
type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridViewModel) as this =
inherit ThemableViewModelBase(Some 300.0, Some 300.0, Some 800.0, Some 600.0)
inherit ThemableViewModelBase(Some 300.0, Some 300.0, Some states.default_width, Some states.default_height)

let mainGrid =
if _maingrid.IsNone then GridViewModel(1)
Expand Down
15 changes: 12 additions & 3 deletions config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ let sample_config = """
"Logging": {
"EchoOnConsole": false,
"LogToFile": ""
},
"Default": {
"w": 800,
"h": 600
}
},
{}
Expand All @@ -59,11 +63,16 @@ let load() =
cfg
with _ -> ConfigObject.Parse("{}")

let save (cfg: ConfigObject.Root) (x: int) (y: int) (w: int) (h: int) (state: string) (composition: string) (customTitleBar: bool) =
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) =
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 dict = dict.Add(cwd, ws)
let cfg = ConfigObject.Root(dict |> Map.toArray |> Array.map snd, cfg.Logging)
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)
try File.WriteAllText(configfile, cfg.ToString())
with _ -> ()
3 changes: 3 additions & 0 deletions fvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ command! -complete=expression -nargs=1 FVimBackgroundImageStretch call rpcnotify
command! -complete=expression -nargs=1 FVimBackgroundImageHAlign call rpcnotify(g:fvim_channel, 'background.image.halign', <args>)
command! -complete=expression -nargs=1 FVimBackgroundImageVAlign call rpcnotify(g:fvim_channel, 'background.image.valign', <args>)

command! -complete=expression -nargs=1 FVimDefaultWindowWidth call rpcnotify(g:fvim_channel, 'default.width', <args>)
command! -complete=expression -nargs=1 FVimDefaultWindowHeight call rpcnotify(g:fvim_channel, 'default.height', <args>)

function! s:fvim_on_bufwinenter()
let l:bufnr=expand("<abuf>")
let l:wins=win_findbuf(l:bufnr)
Expand Down
4 changes: 4 additions & 0 deletions model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ module rpc =

let bool = prop<bool> (|Bool|_|)
let string = prop<string> (|String|_|)
let int = prop<int> (|Integer32|_|)
let float = prop<float> (function
| Integer32 x -> Some(float x)
| :? float as x -> Some x
Expand Down Expand Up @@ -384,6 +385,9 @@ let Start (serveropts, norc, remote) =
rpc.register.prop<HorizontalAlignment> parseHorizontalAlignment "background.image.halign"
rpc.register.prop<VerticalAlignment> parseVerticalAlignment "background.image.valign"

rpc.register.int "default.width"
rpc.register.int "default.height"


List.iter ignore [
ev_uiopt.Publish
Expand Down
3 changes: 3 additions & 0 deletions states.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ let mutable background_image_stretch = Stretch.None
let mutable background_image_halign = HorizontalAlignment.Left
let mutable background_image_valign = VerticalAlignment.Top

// defaults
let mutable default_width = 800
let mutable default_height = 600

/// !Note does not include rgb and ext_linegrid
let PopulateUIOptions (opts: hashmap<_,_>) =
Expand Down

0 comments on commit c43c0c6

Please sign in to comment.