Skip to content

Commit c43c0c6

Browse files
author
Yatao Li
committed
implement default window size. fix #178
1 parent 220f87b commit c43c0c6

File tree

7 files changed

+37
-5
lines changed

7 files changed

+37
-5
lines changed

Program.fs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ let startMainWindow app opts =
4141
>>= fun comp -> parseBackgroundComposition(box comp)
4242
>>= fun comp -> states.background_composition <- comp; None
4343
|> ignore
44+
cfg.Default
45+
>>= fun defs -> states.default_height <- defs.H; states.default_width <- defs.W; None
46+
|> ignore
4447

4548
model.CreateFrame <- fun _gridui ->
4649
let gridui = _gridui :?> GridViewModel
@@ -74,7 +77,13 @@ let startMainWindow app opts =
7477
app <| mainwin
7578
boundcheck()
7679
let x, y, w, h = (int mainwinVM.X), (int mainwinVM.Y), (int mainwinVM.Width), (int mainwinVM.Height)
77-
config.save cfg x y w h (mainwinVM.WindowState.ToString()) (backgroundCompositionToString states.background_composition) mainwinVM.CustomTitleBar
80+
let def_w, def_h = states.default_width, states.default_height
81+
config.save cfg
82+
x y w h
83+
def_w def_h
84+
(mainwinVM.WindowState.ToString())
85+
(backgroundCompositionToString states.background_composition)
86+
mainwinVM.CustomTitleBar
7887
0
7988

8089
let startCrashReportWindow app ex =

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ FVimKeyDisableShiftSpace v:true " disable unsupported sequence <S-Space>
155155
FVimKeyAutoIme v:true " Automatic input method engagement in Insert mode
156156
FVimKeyAltGr v:true " Recognize AltGr. Side effect is that <C-A-Key> is then impossible
157157
158+
" Default options (workspace-agnostic)
159+
FVimDefaultWindowWidth 1600 " Default window size in a new workspace
160+
FVimDefaultWindowHeight 900
161+
158162
" Detach from a remote session without killing the server
159163
" If this command is executed on a standalone instance,
160164
" the embedded process will be terminated anyway.

ViewModels/FrameViewModel.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open Avalonia.Layout
3636
/// the frame should organize the grids.
3737
/// </summary>
3838
type FrameViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid: GridViewModel) as this =
39-
inherit ThemableViewModelBase(Some 300.0, Some 300.0, Some 800.0, Some 600.0)
39+
inherit ThemableViewModelBase(Some 300.0, Some 300.0, Some states.default_width, Some states.default_height)
4040

4141
let mainGrid =
4242
if _maingrid.IsNone then GridViewModel(1)

config.fs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ let sample_config = """
3636
"Logging": {
3737
"EchoOnConsole": false,
3838
"LogToFile": ""
39+
},
40+
"Default": {
41+
"w": 800,
42+
"h": 600
3943
}
4044
},
4145
{}
@@ -59,11 +63,16 @@ let load() =
5963
cfg
6064
with _ -> ConfigObject.Parse("{}")
6165

62-
let save (cfg: ConfigObject.Root) (x: int) (y: int) (w: int) (h: int) (state: string) (composition: string) (customTitleBar: bool) =
66+
let save
67+
(cfg: ConfigObject.Root)
68+
(x: int) (y: int) (w: int) (h: int)
69+
(def_w: int) (def_h: int)
70+
(state: string) (composition: string) (customTitleBar: bool) =
6371
let dict = cfg.Workspace |> Array.map (fun ws -> (ws.Path, ws)) |> Map.ofArray
6472
let cwd = Environment.CurrentDirectory |> Path.GetFullPath
6573
let ws = ConfigObject.Workspace(cwd, ConfigObject.Mainwin(x, y, w, h, state, Some composition, Some customTitleBar))
66-
let dict = dict.Add(cwd, ws)
67-
let cfg = ConfigObject.Root(dict |> Map.toArray |> Array.map snd, cfg.Logging)
74+
let wss = dict.Add(cwd, ws)
75+
let defaults = ConfigObject.Default(def_w, def_h)
76+
let cfg = ConfigObject.Root(wss |> Map.toArray |> Array.map snd, cfg.Logging, Some defaults)
6877
try File.WriteAllText(configfile, cfg.ToString())
6978
with _ -> ()

fvim.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ command! -complete=expression -nargs=1 FVimBackgroundImageStretch call rpcnotify
5151
command! -complete=expression -nargs=1 FVimBackgroundImageHAlign call rpcnotify(g:fvim_channel, 'background.image.halign', <args>)
5252
command! -complete=expression -nargs=1 FVimBackgroundImageVAlign call rpcnotify(g:fvim_channel, 'background.image.valign', <args>)
5353

54+
command! -complete=expression -nargs=1 FVimDefaultWindowWidth call rpcnotify(g:fvim_channel, 'default.width', <args>)
55+
command! -complete=expression -nargs=1 FVimDefaultWindowHeight call rpcnotify(g:fvim_channel, 'default.height', <args>)
56+
5457
function! s:fvim_on_bufwinenter()
5558
let l:bufnr=expand("<abuf>")
5659
let l:wins=win_findbuf(l:bufnr)

model.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ module rpc =
313313

314314
let bool = prop<bool> (|Bool|_|)
315315
let string = prop<string> (|String|_|)
316+
let int = prop<int> (|Integer32|_|)
316317
let float = prop<float> (function
317318
| Integer32 x -> Some(float x)
318319
| :? float as x -> Some x
@@ -384,6 +385,9 @@ let Start (serveropts, norc, remote) =
384385
rpc.register.prop<HorizontalAlignment> parseHorizontalAlignment "background.image.halign"
385386
rpc.register.prop<VerticalAlignment> parseVerticalAlignment "background.image.valign"
386387

388+
rpc.register.int "default.width"
389+
rpc.register.int "default.height"
390+
387391

388392
List.iter ignore [
389393
ev_uiopt.Publish

states.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ let mutable background_image_stretch = Stretch.None
7171
let mutable background_image_halign = HorizontalAlignment.Left
7272
let mutable background_image_valign = VerticalAlignment.Top
7373

74+
// defaults
75+
let mutable default_width = 800
76+
let mutable default_height = 600
7477

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

0 commit comments

Comments
 (0)