Remember size and position on startup
Is your feature request related to a problem? Please describe. I'm always frustrated when I close wezterm and when I start it back up it doesn't remember the size and location of where it last was
Describe the solution you'd like A default behavior of remembering the position of the window would be nice, not sure how to handle the size since it can be coded in the settings... which takes precedence?
.. as well as maximization/tiling mode
- unmaximized - the unmaximized sz/pos needs to be saved regardless of being set to tiling states
- maximized
- left tiled
- right tiled
The difficulty here will be how to make it so that it is OS/window-manager/compositor independent.
There's a lot of complexity here; as there can be multiple windows there would need to be a way to somehow identify each of them and remember their individual positions. I can see this feature being annoying if you had a lot of windows open and had them auto-restore.
Another aspect of this is that some people start one wezterm process per window and others run one wezterm process with multiple windows. I'm not sure this feature would be compatible with that workflow.
And finally: what would get restored in the windows? Each window can have multiple tabs running a variety of programs. Would those get restored? Restoration would be weird as there is no session resumption protocol for arbitrary programs, and some of those might be dangerous; say for example something spawned a new tab running rm -rf /some/dir. That would likely be dangerous or at best unwanted if that got run when you opened the terminal!
Such a headache!
Can we reduce the scope of this request? Would it be valid to offer startup positioning options in the config file? We already allow setting the default size. It doesn't seem unreasonable to add some positioning related options. For example, allow specifying x/y position in pixels and/or percentage of screen size, and likewise expand the size options to also allow pixels and percentage of screen size.
Can we reduce the scope of this request? Would it be valid to offer startup positioning options in the config file? We already allow setting the default size. It doesn't seem unreasonable to add some positioning related options. For example, allow specifying x/y position in pixels and/or percentage of screen size, and likewise expand the size options to also allow pixels and percentage of screen size.
Can you point to the doc (or tell me how) to change the default size in the config? Sorry of this is a bit of a derail, but I searched far and wide and only found this request that was somewhat close.
The docs are here: https://wezfurlong.org/wezterm/config/lua/config/initial_rows.html https://wezfurlong.org/wezterm/config/lua/config/initial_cols.html
Would you mind sharing what you searched for so that I can make this easier to find for others in the future?
In changelog: 20200406-151651-5b700e4 ( link ) Added initial_rows and initial_cols config options to set the starting size of new terminal windows
Keywords could be: terminal size, window size (though this means something different), terminal-rows, terminal-columns, rows, columns
The docs are here: https://wezfurlong.org/wezterm/config/lua/config/initial_rows.html https://wezfurlong.org/wezterm/config/lua/config/initial_cols.html
Would you mind sharing what you searched for so that I can make this easier to find for others in the future?
Thx! I searched for "Window Size" and didn't get anything that seemed clear up front.
I adjusted the text in those pages so that searches for "window size" now show them as matching results.
Here is another approach. What if the existing API is beefed up just a bit? The config file could "invoke" a layout. A layout might look something like this:
function layout_startup()
local win, tab, pane1 = SpawnWindow(0, 0, 0, 0, true) -- new window at x,y=(0,0) r,c=(0,0) and true is "maximized"
local pane2 = pane:SplitHorizontal( .6, .4 ) -- split, pane1 60% wide, pane2 40% wide
local pane3 = pane2:SplitVertical(.5, .5) -- split, pane2 50% high and pane3 50% high
local tab2 = win:SpawnTab()
-- more splits, etc.
local win, tab, pane1 = SpawnWindow(0, 0, r, 0, false) -- new window at x,y=(50,100) h,w=(24,80) and not "maximized"
-- more split, tab, windows
end
The beauty is that the API structure is in place. There is clearly some thinking on the params to each of the calls. And, this approach is in line with the Lua as a programming language config approach.
There might need to be additional APIs, perhaps something to StopDrawing and StartDrawing while the layout_startup Lua function is running.
Thanks for sharing the links to the configs (https://github.com/wez/wezterm/issues/256#issuecomment-794194416). I ran into this issue, too, because I searched for "width" and "height" on the config page and came up with nothing. I thought I had searched for "initial" too, but I guess I must not have. I had Googled for "wezterm initial window size" and came up with several forum posts but nothing authoritative. However, it got me here.
If possible, it'd be helpful to add these terms as parentheticals following the names/titles of those configurables' names in the index/list.
Thanks for the link to the docs indeed!
@wez May I suggest disabling/deprioritizing Changelog in the search results as currently, for example, when searching for new window height out of the top 7 you have 6(!) from Changelog and only one with the correct results initial_rows
I'm not sure if mdbook (the technology used to build the docs) allows for that kind of search result manipulation
An "initial_xpos" and "initial_ypos" would really solve all my problems with the missing the old "-geometry" option that old terminals have.
Together with the already present "inital_rows" and "initial_cols" and in my case "colors.background=#xxxxxx", i could switch to WezTerm and continue to use my start scripts that initially place multiple Terminal windows on my desktop with the right dimensions and background colors.
I think this very old issue got a bit derailed from the original request, and the simple positioning solution got buried.
Should i make a new simple request for "initial_xpos" and "initial_ypos", which is all i would need to place the windows with correct position and size?
Should i make a new simple request for "initial_xpos" and "initial_ypos", which is all i would need to place the windows with correct position and size?
Yeah; specifying the size/position via command line parameters to wezterm start is a more more constrained problem because it doesn't need to remember anything
In main and the currently available nightly builds, the following features tick off a number of boxes here, if you want the ability to control the startup layout:
- wezterm.on("gui-startup") gives you a hook where you can control which windows, tabs and panes are created in the internal multiplexer
- mux_window:gui_window() bridges from the internal multiplexer window to the corresponding gui window
- gui_window:set_position() and gui_window:set_inner_size() give control over gui window size and position
- gui_window:maximize() to set the maximized state
- wezterm.gui.screens() returns information about available screens for you to make decisions about placement/sizing.
Note that Wayland doesn't allow applications to control or even see their own positioning, but does allow control over sizing.
There isn't an ability to save these things and automatically restore them and I'm honestly hoping to avoid getting into that for the reasons I call out in https://github.com/wez/wezterm/issues/256#issuecomment-683319071 above.
The old thread Add config option to always open window in full screen/maximized · Issue #284 · wez/wezterm got closed. I could never figure out a native way to maximize the window without flickering. Managed to script it myself today. I thought that's quite relevant to this issue, as it's pretty much what I'm doing. Hope this helps out others.
local wezterm = require 'wezterm'
local mux = wezterm.mux
local cache_dir = os.getenv('HOME') .. '/.cache/wezterm/'
local window_size_cache_path = cache_dir .. 'window_size_cache.txt'
wezterm.on('gui-startup', function()
os.execute('mkdir ' .. cache_dir)
local window_size_cache_file = io.open(window_size_cache_path, 'r')
if window_size_cache_file ~= nil then
_, _, width, height = string.find(window_size_cache_file:read(), '(%d+),(%d+)')
mux.spawn_window{ width = tonumber(width), height = tonumber(height) }
window_size_cache_file:close()
else
local tab, pane, window = mux.spawn_window{}
window:gui_window():maximize()
end
end)
wezterm.on('window-resized', function(window, pane)
local window_size_cache_file = io.open(window_size_cache_path, 'r')
if window_size_cache_file == nil then
local tab_size = pane:tab():get_size()
cols = tab_size['cols']
rows = tab_size['rows'] + 2 -- Without adding the 2 here, the window doesn't maximize
contents = string.format('%d,%d', cols, rows)
window_size_cache_file = assert(io.open(window_size_cache_path, 'w'))
window_size_cache_file:write(contents)
window_size_cache_file:close()
end
end)
Can you point to the doc (or tell me how) to change the default size in the config? Sorry of this is a bit of a derail, but I searched far and wide and only found this request that was somewhat close.
https://wezfurlong.org/wezterm/config/lua/keyassignment/ResetFontAndWindowSize.html
I adjusted the text in those pages so that searches for "window size" now show them as matching results.
The link above shows up as the 2nd result if searching for "window size", but it's not that clear as it's under "ResResetFontAndWindowSize", perhaps a small addition or separation or direction to initial_rows and initial_cols would suffice this. I ended up here when looking for configuring my window size.
The old thread Add config option to always open window in full screen/maximized · Issue #284 · wez/wezterm got closed. I could never figure out a native way to maximize the window without flickering. Managed to script it myself today. I thought that's quite relevant to this issue, as it's pretty much what I'm doing. Hope this helps out others.
local wezterm = require 'wezterm' local mux = wezterm.mux local cache_dir = os.getenv('HOME') .. '/.cache/wezterm/' local window_size_cache_path = cache_dir .. 'window_size_cache.txt' wezterm.on('gui-startup', function() os.execute('mkdir ' .. cache_dir) local window_size_cache_file = io.open(window_size_cache_path, 'r') if window_size_cache_file ~= nil then _, _, width, height = string.find(window_size_cache_file:read(), '(%d+),(%d+)') mux.spawn_window{ width = tonumber(width), height = tonumber(height) } window_size_cache_file:close() else local tab, pane, window = mux.spawn_window{} window:gui_window():maximize() end end) wezterm.on('window-resized', function(window, pane) local window_size_cache_file = io.open(window_size_cache_path, 'r') if window_size_cache_file == nil then local tab_size = pane:tab():get_size() cols = tab_size['cols'] rows = tab_size['rows'] + 2 -- Without adding the 2 here, the window doesn't maximize contents = string.format('%d,%d', cols, rows) window_size_cache_file = assert(io.open(window_size_cache_path, 'w')) window_size_cache_file:write(contents) window_size_cache_file:close() end end)
Works like a charm!