wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Center window contents

Open valpackett opened this issue 4 years ago • 6 comments

Is your feature request related to a problem? Please describe.

Unlike #291 I just want to be able to center the content in the window to avoid ugly asymmetrical padding on the bottom and right sides of the window. Or even align it to be horizontally centered but vertically always sticking to the bottom edge.

(BTW even if/when there would be snap-to-character-grid resizing, there would still be fullscreen/maximized mode…)

Describe the solution you'd like

It is sort of possible to achieve with scripting…

wezterm.on("window-resized", function(window, pane)
  local window_dims = window:get_dimensions();
  local overrides = window:get_config_overrides() or {}
  local new_padding = {
    left = math.floor((window_dims.pixel_width % 19) / 2),
    right = 0,
    top = math.floor((window_dims.pixel_height % 43) / 2),
    bottom = 0
  };
  overrides.window_padding = new_padding
  window:set_config_overrides(overrides)
end);

…but only with hardcoded cell size. So, I guess there should be a Lua call for getting character grid cell dimensions!

Describe alternatives you've considered

Or make this just a built-in mode (flag) to avoid having stuff in configs.

valpackett avatar Sep 08 '21 16:09 valpackett

I would also like this feature.

On st I used the anysize patch to center the content of the terminal window on my tiling wm.

Currently I am using:

local center_content = function(window, pane)
	local win_dim = window:get_dimensions()
	local tab_dim = pane:tab():get_size()
	local overrides = window:get_config_overrides() or {}
	local padding_left = (win_dim.pixel_width - tab_dim.pixel_width) / 2
	local padding_top = (win_dim.pixel_height - tab_dim.pixel_height) / 2
	local new_padding = {
		left = padding_left,
		right = 0,
		top = padding_top,
		bottom = 0,
	}
	if overrides.window_padding and new_padding.left == overrides.window_padding.left then
		return
	end
	overrides.window_padding = new_padding
	window:set_config_overrides(overrides)
end

wezterm.on('window-resized', center_content)
wezterm.on('window-config-reloaded', center_content)

bvtthead avatar Oct 10 '23 14:10 bvtthead

This is interesting. How would a use the above in my 3 pane setup (below) to add padding to my top right (terminal) split? Currently it's a bit far to the left and looks a bit out of place against my centred Neovim main pane and auto-sized Bottom right split

-- Startup using 3 panes, lvim, wezterm and btm
wezterm.on("gui-startup", function(cmd)
	local tab, pane, window = mux.spawn_window(cmd or {
		args = { "/opt/homebrew/bin/fish", "-c", "/Users/Karim/.local/bin/lvim" },
	})
	window:gui_window():toggle_fullscreen()
	-- Create a right side pane
	local right_pane = pane:split { direction = "Right", size = 0.4 }
	-- Split right pane into two, with new pane on bottom
	local bottom_pane = right_pane:split { direction = "Bottom", size = 0.9, args = { "/opt/homebrew/bin/btm" } }
	-- Activate primary left pane
	pane:activate()
end)
Screenshot 2024-01-27 at 08 32 36

karimlevallois avatar Jan 27 '24 08:01 karimlevallois

I really would like an option to "center" the terminal inside whatever padding you had set. Right now all the excess padding goes to the right and bottom. The idea way for this to work is you set your padding and then any extra padding is divided equally between opposite sides.

bartdorsey avatar Jan 29 '24 16:01 bartdorsey

FWIW, if you enable https://wezfurlong.org/wezterm/config/lua/config/use_resize_increments.html you will be less likely to have any excess padding. This works best under X11 and macOS, but has no effect on Windows.

wez avatar Jan 29 '24 16:01 wez

FWIW, if you enable https://wezfurlong.org/wezterm/config/lua/config/use_resize_increments.html you will be less likely to have any excess padding. This works best under X11 and macOS, but has no effect on Windows.

Thank you for this! Unfortunately, I usually work in a fullscreen terminal window, so this is not a 100% solution for me.

janbuchar avatar Jan 30 '24 10:01 janbuchar

I would like to note that on MacOS use_resize_increments interacts a bit weirdly with Raycast's "Maximize". It would appear that Raycast sets the window as large as possible, but this ends up being scaled back to some increment that fits an exact number of cells, which often leaves a small strip of the background peeking through along the bottom. This looks like intended behavior, but is annoying nonetheless.

ArchWand avatar Jun 12 '24 02:06 ArchWand

Right now all the excess padding goes to the right and bottom.

It'd be ideal to not left/top align by default. Center seems to be a thing people want, but that would be too restrictive as well. Ideally there would be a default alignment.

Right now, I'm doing this to get bottom/left alignment:

wezterm.on("window-resized", function(window, pane)
    local overrides = window:get_config_overrides() or {}

    local tabsz = window:active_tab():get_size()
    local cellheight = tabsz.pixel_height / tabsz.rows

    local window_height = window:get_dimensions().pixel_height
    local pane_height = math.floor(window_height / cellheight) * cellheight

    local new_padding = {
        left = 0,
        right = 0,
        top = window_height - pane_height,
        bottom = 0
    };
    if overrides.window_padding and new_padding.top == overrides.window_padding.top then
        return
    end
    overrides.window_padding = new_padding
    window:set_config_overrides(overrides)
end)

It jumps around and flickers, but it works. Ideally it could just do this before it renders wrong by having the alignment option.

Also, this doesn't really fix the situation when you are in fullscreen and change font size, because no "window-resized" event is fired

dannydulai avatar Nov 15 '24 13:11 dannydulai

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Mar 11 '25 03:03 github-actions[bot]