1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-19 11:21:39 +03:00
Commit Graph

191 Commits

Author SHA1 Message Date
Wez Furlong
8015791dd0 fixup initial pty dimensions to account for font/dpi size
refs: https://github.com/wez/wezterm/issues/563
2021-03-20 13:17:32 -07:00
Wez Furlong
3d0f3eaeec gui: avoid doing work when WM sends spurious resize events
refs: #557
2021-03-19 08:11:39 -07:00
Wez Furlong
ba7add140e Attach gui window invalidation to pty output event
I'm not convinced that this is 100% good, but @fanzeyi reported
some latency when using tmux to mirror two sessions.  The session
that was accepting interactive input responded quickly, but the
mirroring session was laggy.

This change connects the mux pane output event to window invalidation,
which should cause repaints to happen more often.

I couldn't reproduce the scenario above on my M1 mac, but that may
just be because M1 has dark magicks.
2021-03-17 20:20:08 -07:00
Wez Furlong
5681cd9b64 gui: update windows dep to 0.4 2021-03-14 15:25:33 -07:00
Wez Furlong
04b7cedd02 fix animated gif playback
A casualty of b8dcfba9a4 was that
the decoded gif would get reset each time the texture filled up.

Take care to move that cached into the newly minted glyphcache.
2021-03-14 10:29:02 -07:00
Wez Furlong
09081d2189 improve texture upload performance, part 2
Continuing along the same lines as the prior commit, the goal
of this commit is to remove the buffer transformation that was
part of uploading the texture to the GPU provided surface.

In order to do so:

* The sense of our local textures needs to change from bgra32 to rgba32.
  bgra32 was a hangover from earlier versions of our window crate that
  allowed direct-to-fb writes in software mode.  We had to pick bgra32
  for that for the broadest OS compatibility.  I believe that that
  constraint has been totally removed, although there is a chance that
  this will flip the colors on macos.
* There was an additional linear-to-srgb conversion inlined in that
  buffer transformation.  I have no idea where that is needed because
  the source data is carefully constructed as SRGB.  I don't yet know
  how to signal that, but for now I've moved that gamma correction
  into the shader when we sample the texture.

With this change, timg playback now has vtparse as the hottest
region of code.

refs: #537
2021-03-14 09:14:30 -07:00
Wez Furlong
b8dcfba9a4 improve texture upload performance
Two issues highlighted by profiling:

* Clearing the texture takes a non-trivial percentage of the profile.
  The docs suggest that it is better to create a new texture than
  to update large portions of a texture, so add some plumbing so
  that we can do that in the first texture-full case.

* Next on the list is the code that translates from linear BGRA to
  SRGBA.  This is present for reasons that I believe are now legacy,
  but for the moment: those two primitives now have faster and
  easier implementations, so simplify to those.

This improves the timg video playback performance by ~10% for me.

refs: #537
2021-03-13 23:18:15 -08:00
Wez Furlong
693a717db2 improve output parsing performance and throughput
I've been meaning to do this for a while; this commit moves
the escape sequence parsing into the thread that reads the
pty output which achieves two goals:

* Large escape sequences (eg: image protocols) that span multiple
  4k buffers can be processed without ping-ponging between the
  reader thread and the main gui thread
* That parsing can happen in the reader thread, keeping the gui
  thread more responsive.

These changes free up the CPU during intensive operations such
as timg video playback.

This is a slight layering violation, in that this processing
really belongs to local pane (or any pane that embeds Terminal),
rather than generically at the Mux layer, but it's not any
worse a violation than `advance_bytes` already was.

refs: https://github.com/wez/wezterm/issues/537
2021-03-13 19:19:05 -08:00
Wez Furlong
333f5f9750 fix a rounding issue when computing block glyphs
The leftmost pixel was being set to at least 1 by the scale
function.

Fix that up by computing the x coordinate without calling
the scale function.

refs: https://github.com/wez/wezterm/issues/536
2021-03-13 11:29:57 -08:00
Wez Furlong
3d642461f8 fixup pty pixel size calculation
Derive the pixels from the rows/cols rather than the available space.

refs: https://github.com/wez/wezterm/issues/535
2021-03-13 09:31:13 -08:00
Wez Furlong
f4105cb42f avoid excess capacity when dealing with iterm2 image protocol
Using a boxed slice means that we hold exactly the memory required
for the file data, rather than the next-power-of-two, which can
be wasteful when a large number of images are being sent to
the terminal.

This is a API breaking change for termwiz, so bump its version.

refs: #534
2021-03-13 08:10:48 -08:00
Wez Furlong
dd5db065dc remove stray debug print 2021-03-13 08:06:03 -08:00
Wez Furlong
9be7b8f6ec and fixup the test build
refs: #534
2021-03-13 01:03:04 -08:00
Wez Furlong
26f9d91e43 set an upper bound on the image/frame caches
While adding gif support I let this become unbounded.
This commit resolves that by categorizing images as either
single frame or animations.

Single frame images are decoded and held entirely in the texture
atlas, so occupy no additional space beyond the image file contents
and their sprite region in the texture atlas.

Animations are decoded into a set of frame bitmaps.  There can be
up to 16 animations (each with their full set of frames) cached.
The individual frames may also exist within the texture atlas
if space permits.

refs: #534
2021-03-13 00:47:38 -08:00
Wez Furlong
48a3674c9a wayland: fix a panic during initialization 2021-03-12 22:48:37 -08:00
Wez Furlong
4ec48b1245 gifs: start at frame 0, not 1!
This fixes the panic that @mborejdo reported in
<https://matrix.to/#/!PirwUBcuIlTXwNveYz:matrix.org/$skjhC1EgMG5x0Wte0i6JquMHkQK2mST2zJoB_qrLMRc?via=matrix.org>
2021-03-12 08:39:53 -08:00
Wez Furlong
1097f329cf fixup x position for new tab button 2021-03-11 21:25:54 -08:00
Wez Furlong
eb4323ee59 add config for customizing the tabs and new tab button
```lua
local wezterm = require 'wezterm';

-- The filled in variant of the < symbol
local SOLID_LEFT_ARROW = utf8.char(0xe0b2)

-- The filled in variant of the > symbol
local SOLID_RIGHT_ARROW = utf8.char(0xe0b0)

return {
  tab_bar_style = {
    active_tab_left = wezterm.format({
      {Background={Color="#0b0022"}},
      {Foreground={Color="#2b2042"}},
      {Text=SOLID_LEFT_ARROW},
    }),
    active_tab_right = wezterm.format({
      {Background={Color="#0b0022"}},
      {Foreground={Color="#2b2042"}},
      {Text=SOLID_RIGHT_ARROW},
    }),
    inactive_tab_left = wezterm.format({
      {Background={Color="#0b0022"}},
      {Foreground={Color="#1b1032"}},
      {Text=SOLID_LEFT_ARROW},
    }),
    inactive_tab_right = wezterm.format({
      {Background={Color="#0b0022"}},
      {Foreground={Color="#1b1032"}},
      {Text=SOLID_RIGHT_ARROW},
    }),
  }
}
```
2021-03-11 21:22:10 -08:00
Wez Furlong
62d1d11eaf fall back to single frame gif parse if animated mode fails
At least we'll show something if we have a malformed gif.
2021-03-11 19:54:41 -08:00
Wez Furlong
9b3d35623f handle image decoding errors and return a placeholder
https://i.giphy.com/media/3owvKqP4VSydZE4pvq/200w.gif cannot
be decoded as an animated gif due to this error: `No end code in lzw stream`

Ensure that we don't completely fail to process the render phase
as a result.
2021-03-11 19:45:48 -08:00
Wez Furlong
b8390b3f7a animated images: now schedule repaint based on next frame time
Previously, invalidation for animation was driven by the cursor
blink rate, which meant that animated gifs/pngs could not play
faster than 5fps (default blink interval is 200ms).

This commit calculates the next invalidation time based on the
closes next frame time of all animated cells in the viewport.
2021-03-11 08:14:39 -08:00
Wez Furlong
c5cb0ef66d Added support for animated gifs and pngs
This is first draft; the animation rate is currently tied
to the cursor_blink_rate setting, so if the gif has frames that
are intended to display more frequently than that, they will
animate more slowly.

Animation is only carried out while the window has focus.
Animation increases the load on the GPU and thus uses more power.

It's kinda fun to stick one of these animated pixel gifs in the background:
https://imgur.com/gallery/F9DAH
2021-03-11 00:41:54 -08:00
Wez Furlong
182a4d068b ensure that we only use the default size when spawning new windows 2021-03-10 00:19:50 -08:00
Wez Furlong
83e9d672a4 spawning a new window should use the size from the config
rather than the size of the current window.
2021-03-10 00:15:26 -08:00
Wez Furlong
18cb179227 x11: query Xft.dpi from the root window
We should now be using the root window specified default dpi
if the dpi is left unspecified in the wezterm configuration.

refs: #515
2021-03-08 22:19:44 -08:00
Wez Furlong
5f1bb0a1bc "de-bounce" lua event callbacks
During a live resize, we could queue up a lot of `window-resized`
events, which is undesirable.

This commit introduces a simple but effective mechanism to manage this;
a given event can have at most one executing and one pending copy.

So if we get a burst of resize events (eg: during a live window resize)
that might have previously queued hundreds of discrete events, we now
get a more manageable situation with 1 executing and 1 queued.

With this change, a given event can only have 1 executing instance at a
time (with the exception that the open-uri event doesn't go through this
mechanism).

refs: https://github.com/wez/wezterm/issues/291
2021-03-07 18:11:27 -08:00
Wez Furlong
9c19fa1929 Add window-config-reloaded event
refs: #291
2021-03-07 15:06:04 -08:00
Benoit de Chezelles
683d8e96e8 windows: Add option to treat left ctrl-alt as altgr
The previous behavior was to always treat ctrl-alt as altgr on Windows,
this has been done to better support altgr through a VNC session,
but this is very unintuitive when you don't need this behavior.

ref: #472
2021-03-07 12:52:03 -08:00
Wez Furlong
ba5d50ba9e add window-resized event
This is to support <https://github.com/wez/wezterm/issues/291>.

The window resized event happens asynchronously wrt. processing
a window resize, triggering at the end of the normal window
resize handling.

This commit introduces the notion of whether we are in full screen
mode or not in the underlying event callback, which is useful to
gate the desired feature, which is: when in full screen mode,
increase the padding for the window to center its content.

While poking around at this, I noticed that we weren't passing
the per-window config down to the code that computes the quad
locations for the window.

This commit also changes the font size increase/decrease behavior
so that in full screen mode it doesn't try to resize the window.

```lua
local wezterm = require 'wezterm';

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

  if not window_dims.is_full_screen then
    if not overrides.window_padding then
      -- not changing anything
      return;
    end
    overrides.window_padding = nil;
  else
    -- Use only the middle 33%
    local third = math.floor(window_dims.pixel_width / 3)
    local new_padding = {
      left = third,
      right = third,
      top = 0,
      bottom = 0
    };
    if overrides.window_padding and new_padding.left == overrides.window_padding.left then
      -- padding is same, avoid triggering further changes
      return
    end
    overrides.window_padding = new_padding

  end
  window:set_config_overrides(overrides)
end);

return {
}
```
2021-03-07 11:54:15 -08:00
Wez Furlong
336f209ede Revert and gate shaping changes
I'm calling it a temporary defeat on the shaping changes;
this commit effectively reverts the series of changes made
to support slicing up ligatures like `->` when the cursor
moves through them.

They've introduced so many issues and I've spent hours
that haven't resulted in a complete solution, so I've
disabled those changes by putting them behind a boolean
option.

I'll revisit them after I've cut the next release.

refs: https://github.com/wez/wezterm/issues/478
2021-03-06 23:49:37 -08:00
Wez Furlong
dcb6fec28f don't kill pane when closing copy or search mode overlays
I recently introduced this bug when tidying up reaping overlay panes.
2021-03-06 13:46:30 -08:00
Wez Furlong
30144ef964 more guesswork to compensate for shaping weirdness 2021-03-06 13:38:38 -08:00
Wez Furlong
ac3ac43c2b warn instead of panic if there's already something assigned
I saw this trigger and couldn't repro; I want to understand it
better when it next occurs.
2021-03-06 12:56:36 -08:00
Wez Furlong
9cfa93bf8b tidy up some of the texture atlas invalidation
There was a bit of redundancy with things that happen
inside some of these calls, so centralize and clarify it.
2021-03-06 10:25:39 -08:00
Wez Furlong
f0527f646c simplify shape preprocessing
Manual test scenario:

```
wezterm -n --config adjust_window_size_when_changing_font_size=false --config 'exit_behavior="Hold"' start -- sh -c "echo '(...)'"
```

then CTRL +/- to change font size; the first cell of the `...` was
previously random garbage, now is more consistent.

refs: https://github.com/wez/wezterm/issues/478
2021-03-06 10:19:59 -08:00
Wez Furlong
cfed798e79 window: allow window layer to hold per-window config
This is to allow for eg: hotkey to change window decorations
(https://wezfurlong.org/wezterm/config/lua/window/set_config_overrides.html)

So far only macos actually keeps a per-window config.
Hopefully this still compiles for windows and x11.
2021-03-04 23:05:44 -08:00
Wez Furlong
1178639a22 windows: implement decoration setting, change to bitfield
Can now set `window_decorations = "TITLE|RESIZE"` or variations
on those flags.  `NONE` is a shortcut for no flags.
2021-03-04 09:40:38 -08:00
Wez Furlong
3356a3a149 don't trigger status bar update after each paint or mouse move
mouse move events in the tab bar, and paint events, could cause
the title bar state to be recomputed.

Make sure that we don't trigger the status event to trigger for those.

refs: https://github.com/wez/wezterm/issues/500
2021-03-03 23:53:09 -08:00
Wez Furlong
7e1d16e671 Add SUPER+Drag to drag the window 2021-03-03 23:45:02 -08:00
Wez Furlong
5a5d08080c gui: allow dragging the window by non-tab areas in tab bar
I've only tested this on macos, but it should be cross platform,
with the caveat that Wayland doesn't let a window position itself,
so this won't work there.
2021-03-03 23:29:18 -08:00
Wez Furlong
4834a29791 macos: support disabling the titlebar
This isn't fully baked yet, so I'm not documenting it yet.
2021-03-03 22:47:31 -08:00
Wez Furlong
783f445c57 allow changing status_update_interval dynamically
We were using the value that was active when the window was created,
and never updating it.

This commit sweeps the interval check into the existing periodic
window maintenance routine.

refs: https://github.com/wez/wezterm/issues/500
2021-03-03 19:58:46 -08:00
Wez Furlong
c305abdcd7 trigger the status event when the title is updated, too
This makes it quicker to respond to things like eg: the cwd
in the pane changing.

refs: https://github.com/wez/wezterm/issues/500
2021-03-02 22:36:39 -08:00
Wez Furlong
9ac230876c Add status_update_interval option for status updates
The status event is triggered at window creation, and
then every `status_update_interval` milliseconds.

refs: https://github.com/wez/wezterm/issues/500
2021-03-02 20:44:08 -08:00
Wez Furlong
99a0b044a0 experimental: add right-status concept and event
The API isn't finalized; this is proof of concept for putting something
in the area to the right of the new tab button.

The info will be right aligned to the tab area.

```lua
local wezterm = require 'wezterm';

wezterm.on("update-right-status", function(window, pane)
  -- demonstrates shelling out to get some external status.
  -- wezterm will parse escape sequences output by the
  -- child process and include them in the status area, too.
  local success, date, stderr = wezterm.run_child_process({"date"})

  -- Make it italic and underlined
  window:set_right_status(wezterm.format({
    {Attribute={Underline="Single"}},
    {Attribute={Italic=true}},
    {Text="Hello "..date},
  }));
end)

return {
}
```

refs: https://github.com/wez/wezterm/issues/500
2021-03-02 09:52:54 -08:00
Wez Furlong
48f5fccb86 block glyphs: fix quad rendering
The line drawing routine takes inclusive start/end coordinates,
so if we're feeding the start/end from Range (which is exclusive),
then we need to reduce by 1.

refs: https://github.com/wez/wezterm/issues/433#issuecomment-787640338
2021-03-01 09:52:25 -08:00
Wez Furlong
d56c5178da shaping: add test for FiraCode
Adds a test and seemingly a fix for https://github.com/wez/wezterm/issues/478#issuecomment-787520977

Fira Code is OFL-1.1 licensed like the other fonts we include,
however, I'm not distributing Fira Code with wezterm.
2021-02-28 13:35:00 -08:00
Wez Furlong
b4b92a68f7 block glyphs: handle very small sizes better!
refs: #433
2021-02-28 10:06:00 -08:00
Wez Furlong
0597684ebd Render custom block glyphs
As explained in the docs included in this commit, ideally this
wouldn't be needed, but due to a long-standing hinting bug in
freetype <https://gitlab.freedesktop.org/freetype/freetype/-/issues/761>
it seems most expedient to just render our own block glyphs,
so that's what this does!

refs: #433
2021-02-28 09:43:26 -08:00
Wez Furlong
a3b25324b2 build fixes for macos, windows 2021-02-28 07:39:49 -08:00