1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 12:23:46 +03:00
Commit Graph

322 Commits

Author SHA1 Message Date
Wez Furlong
627d21cbac cargo fmt 2020-10-23 09:07:11 -07:00
Wez Furlong
e2311aaa73 window: more fun with dead keys on Windows
This is a bit more involved than I'd like, but it seems more
deterministic than using `TranslateMessage` or `ToUnicode` in all cases.

This commit expands the depth of the keyboard layout probing that
is performed when we detect a changed keyboard layout.

We know detect starting `(Modifier, VK) -> char` for a dead key press,
as well as the map of terminating `(Modifier, VK) -> char` for valid
dead key presses.

This information allows us to simply lookup the mapping without
calling `ToUnicode`.  Avoiding `ToUnicode` is desirable because it
maintains a global state and it is unpredictable what else is
manipulating that same state.  In particular, for the ESP keyboard
layout where `~` is a dead key that is reached via `AltGr 4`, there
doesn't appear to be a reliable way to extract the correct mapping
from it when calling `ToUnicode` in response to the various KEYUP,
KEYDOWN messages.   We could get it if we always called
`TranslateMessage` and only looked at `WM_CHAR`, but that means that
we cannot decompose `WM_CHAR` back to the raw key events when we
need to.  Bleh!

Test Plan for this commit:

* With ENG layout active, check that CTRL, ALT and so on have the
  intended effect in the terminal; eg: CTRL-C, CTRL-W (in vim).
* Switch to pinyin layout, check that typing still invokes the
  IME and that it can insert text
* Switch to DEU.  Check that `AltGr m` produces a `mu` symbol.
  Check that grave (`\``) (a dead key) doesn't immediately output
  anything, then press `e`; that produces an `e` with a grave
  diacritic.  Grave followed by space emits grave.  Grave
  followed by grave emits a grave and holds the second grave; pressing
  `e` at this point now emits `e` with a grave diacritic.
  (This is a difference from the "normal" system behavior, which
  would just emit two graves in a row, then a regular `e`).
* Switch to ESP.  Check that `AltGr 4` (tilde) doesn't immediately
  output anything, then press `n`; that produces an `n` with the
  tilde diacritic.
* Change `use_dead_keys = false`.  Now verify in DEU that `grave`
  just emits grave.  In ESP, verify that `AltGr 4` just emits
  a tilde.
* Switch back to ENG.  Verify that `ALT-space` pops up the system
  menu.

refs: #275
refs: #305
2020-10-23 08:47:11 -07:00
Wez Furlong
f12df0be9b window: add cursors for resizing up/down left/right
Change the cursor to an appropriate one of these when hoving
over and dragging a split.

Fix an issue where we wouldn't always change the cursor when
hovering over a split when multiple splits are present.
2020-10-22 09:23:05 -07:00
Wez Furlong
aa660d5d06 wezterm: apply transparency tint to all background colors
refs: https://github.com/wez/wezterm/issues/141#issuecomment-711442986
2020-10-18 21:51:12 -07:00
Wez Furlong
191b047126 macos: implement opacity for CGL and Metal
There's a few different knobs to turn, but this
commit turns them and we're now able to respect
opacity settings for both OpenGL/CGL and Metal
renderers.

closes: #141
2020-10-18 14:00:06 -07:00
Wez Furlong
2364b0a20e Windows: enable window_background_opacity
This causes DWM to respect the alpha channel we set during rendering,
allowing the window opacity to be respected on Windows.

refs: #141
2020-10-18 11:13:34 -07:00
Wez Furlong
cac02b3bbb Windows: fix enabling dark mode
This got broken by a recentish windows update.
2020-10-17 19:48:43 -07:00
Wez Furlong
b7e303f39c Windows: prefer to use Direct3D11 via ANGLE
This is similar in spirit to the work in 4d71a7913a
but for Windows.

This commit adds ANGLE binaries built from
07ea804e62
to the repo.  The build and packaging will copy those into the same
directory as wezterm.exe so that they can be resolved at runtime.

By default, `prefer_egl = true`, which will cause the window
crate to first try to load an EGL implementation.  If that fails,
or if `prefer_egl = false`, then the window crate will perform
the usual WGL initialization.

The practical effect of this change is that Direct3D11 is used for the
underlying render, which avoids problematic OpenGL drivers and means
that the process can survive graphics drivers being updated.

It may also increase the chances that the GPU will really be used
in an RDP session rather than the pessimised use of the software
renderer.

The one downside that I've noticed is that the resize behavior feels a
little janky in comparison to WGL (frames can render with mismatched
surface/window sizes which makes the window contents feel like they're
zooming/rippling slightly as the window is live resized). I think this
is specific to the ANGLE D3D implementation as EGL on other platforms
feels more solid.

I'm a little on the fence about making this the default; I think
it makes sense to prefer something that won't quit unexpectedly
while a software update is in progress, so that's a strong plus
in favor of EGL as the default, but I'm not sure how much the
resize wobble is going to set people off.

If you prefer WGL and are fine with the risk of a drive update
killing wezterm, then you can set this in your config:

```lua
return {
  prefer_egl = false,
}
```

refs: https://github.com/wez/wezterm/issues/265
closes: https://github.com/wez/wezterm/issues/156
2020-10-17 19:08:16 -07:00
Wez Furlong
f6afec27f5 windows: lowercase the raw key
6c5a996423 was almost great...
the problem is that CTRL-W for example was generating a raw
uppercase W instead of a lowercase W which meant that CTRL-W
for split navigation in vim would trigger the close pane
key assignment.
2020-10-17 14:02:06 -07:00
Wez Furlong
6c5a996423 windows: set KeyEvent::raw_key in key processing
I noticed that the built-in CTRL-SHIFT-1 assignment had
stopped working because that key press was being recognized
as CTRL-SHIFT-! with the recent changes in handling keyboard
input.

This commit sets the raw key to the position-based fallback
that we'd use if ToUnicode didn't return the correct mapping.

This is sufficient for this sort of un-modified key assignment
because the key is based on the virtual key code and is ignorant
of how the keyboard layout might compose those keys with SHIFT;
that is exactly what we want in this situation.
2020-10-17 10:25:55 -07:00
Wez Furlong
4d71a7913a macOS: bundle and use MetalANGLE to enable Metal rendering
This commit adjusts the window layer to have it try to load EGL
implementations on macOS.  This is important as the system
provided OpenGL implementation is deprecated and I wanted to
have a path forward for when it is finally removed.

If EGL fails to initialize, we fall back to the CGL/OpenGL
implementation that we used previously.

I've included binaries built for 64-bit intel from the MetalANGLE
project; here's how I built them:

```
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --depth 1
git clone https://github.com/kakashidinho/metalangle --depth 1
cd metalangle
PATH=$PWD/../depot_tools:$PATH python scripts/bootstrap.py
PATH=$PWD/../depot_tools:$PATH gclient sync
PATH=$PWD/../depot_tools:$PATH gn --args="is_debug=false angle_enable_metal=true angle_enable_vulkan=false angle_enable_gl=false angle_build_all=false" gen out/Release
PATH=$PWD/../depot_tools:$PATH autoninja -C out/Release
```

Those steps are a little too long to want to put them directly
into the wezterm CI.

It is important for metalangle to be >= 8230df39a5
in order for scaling to be handled correctly when dragging windows
between monitors.

refs: https://github.com/kakashidinho/metalangle/issues/34
2020-10-17 09:34:01 -07:00
Wez Furlong
13cd24d9b5 Windows: improve ALT + dead key handling, part 2
This changes the ALT/dead key behavior a little bit more,
and in a way that is likely more useful to terminal users.

The default behavior is that system dead key processing is enabled.
For example, with DEU keyboard layout activated:

* `^` `<SPACE>` results in a single `^`
* `^` `e` result in those two characters combining into an e with a
  diacritic.

If the config sets `use_dead_keys = false` then the behavior changes;
wezterm probes the active keymap to determine which keys are marked
as dead keys and computes their single character expansion.  When
the dead key is pressed then that expansion is substituted instead.
So `^` is simply `^`.

In order to pull this off, the window layer needs to selectively
call `TranslateMessage` for the system dead key expansion case
instead of unconditionally in the global message loop.

As a result of *that*, it means that we don't perform the default ALT
key translation for every key press any more.  I looked to see how old
friend putty handles this and found that it only allows default system
processing for ALT-space and ALT-F4.  I was resistent to selectively
processing system shortcuts because the full set are effectively
unknowable to an application and I didn't want to try to replicate
a wide selection of varying keypresses.  I'm fine to only allow
these two, so this commit does that, and reverts the portion of
the prior commit that prevented passing general ALT key combinations
through.

refs: #275
refs: #296
2020-10-15 17:06:09 -07:00
Wez Furlong
5088c62954 Windows: improve ALT and dead key handling
For some definition of improve, at least.

On Windows, ALT is basically reserved by the Window management
layer for functions such as ALT-space, ALT-F4 and so on.
Windows doesn't provide a method by which an application can
test whether a given key would be processed by the default
window procedure so we're in a bit of a bind in terms of
allowing ALT+a keypress to do something meaningful in the
terminal.

What I've settled on for now is:

On Windows only, if ALT is pressed, allow matching key assignments that
include ALT to be matched.  If there are no key assignments, then DON'T
pass the key press to the active pane, and instead allow it to be passed
to DefWindowProc.  This allows ALT-space to be handled correctly,
provided the user hasn't defined an ALT-space key assignment of their
own.

This may have some unforeseen consequences.  For example, ALT-<number>
is a readline binding that repeats an argument a number of times.
This change "breaks" that, but the user can provide a key assignment
to `SendString` the equivalent sequence to restore that behavior.
I'm kindof hoping that no one notices, but I'm prepared to explicitly
add default key assignments for that.

The other aspect of this commit is that I now understand a bit better
what a dead key is and how they should be handled.  I've tested the
behavior of wezterm with these changes and the behavior is consistent
with a regular CMD window when I have the DEU keymap active.
Specifically, using the on-screen keyboard, if I click `^` then click
`e` wezterm will emit `ê`.  If I click `^` then `^` then wezterm emits
`^^`.

refs: #275
refs: #296
2020-10-14 20:02:23 -07:00
Wez Furlong
5f0c859caa windows: fix an issue processing ctrl+shift for non-alpha keys
This appears to be an unexpected consequence of 6708ea4b36
but thankfully that change allows de-coupling shift processing
from the ctrl processing in this block of code.

refs: #275
2020-10-14 18:12:03 -07:00
Wez Furlong
9e46ac83be Windows: force Mesa/Software mode when started in an RDP session
refs: #265
2020-10-14 09:21:30 -07:00
Wez Furlong
05b02e178b window: fix Hide action on Windows
This was hiding the window completely with no way to show it again(!).
Change it instead to minimize, which was the intent.

refs: #296
2020-10-14 08:42:55 -07:00
Wez Furlong
8fcad1c1ee egl: improve trace logging of successful choice
refs: #272
2020-10-13 19:45:43 -07:00
Wez Furlong
baebc81432 egl: try all configs one by one in case first choice fails
It's not clear why the first choice isn't always the right choice
for some users.

This commit changes the logic to try all potential configs,
one after the other, until we find one that sticks.

I don't know if this will work in practice: I suspect that
trying to configure one of them may prevent later configs from
being used.

But maybe it will, and it may reveal more information about
what the real cause of the problem is.

refs: #272
2020-10-13 19:22:37 -07:00
Wez Furlong
0a39328e9d macos: adjust trackpad scroll sensitivity
This is imperfect in that it may feel slightly off for very large
or very small font sizes, but it feels more similar to the scroll
speed in eg: iTerm2 with these changes.

refs: #206
2020-10-12 19:24:23 -07:00
Wez Furlong
ce44ec2e70 macos: improve positioning for new windows
We used to always create them in the center of the screen,
but now subsequently created windows are offset slightly.
2020-10-12 17:54:44 -07:00
Wez Furlong
c8d59dffb6 macos: fix an issue where new windows created cocoa tabs
To reproduce the problem, maximize wezterm, then press CMD-N.

This commit tells the window not to use cocoa native tabs and
instead really create a new window when we ask it to create
a new window.

closes: #254
2020-10-12 17:20:12 -07:00
Wez Furlong
da2bba866d window: macos: trigger resize event when screen resolution changes
The easiest repro for this is dragging a window between monitors.

refs: #161
2020-10-12 11:29:17 -07:00
Wez Furlong
5257e34e2c window: update to latest glium version 2020-10-11 17:07:47 -07:00
Wez Furlong
dedfc4513b wayland: clear modifiers when keyboard focus changes
refs: #222
2020-10-11 10:02:37 -07:00
Wez Furlong
807ed3ba1e wayland: fixup timing issue on startup
025732d00f introduced deferred
window creation; the creation would get scheduled into the
spawn queue and then get run again a few milliseconds later
on the main thread.

For reasons that I don't understand, returning to the scheduler
loop to flush or otherwise process messages causes a wayland
protocol error.

Adjusting the notify routine to dispatch immediately if we're
already on the mux thread seems to resolve this.

While looking at this, I cleaned up a destruction order issue
with the opengl state that was then causing a segfault on shutdown.

I also removed a bit of dead paint related code that doesn't
appear to be needed any more.

refs: #293
2020-10-10 16:09:04 -07:00
Wez Furlong
5fb1414b69 fix clipboard on x11
This was broken by the changes in
aad493ab2a.  The issue was that the
channel send didn't wakeup the receiver.  I'm not sure why, and I tried
a couple of different async channel implementation.

Doing the simplistic solution here works reliably.
2020-10-09 11:07:18 -07:00
Wez Furlong
f497391958 gah, cargo fmt 2020-10-05 11:57:27 -07:00
Wez Furlong
bf266a326d maybe fixup build for windows 2020-10-05 11:57:08 -07:00
Wez Furlong
5eb4d32004 upgrade misc deps, notably, async-task 2020-10-05 00:06:01 -07:00
Wez Furlong
f3bccc7d08 window: X/Wayland: Software frontend is now llvmpipe
refs: https://github.com/wez/wezterm/issues/265#issuecomment-701882933
2020-10-01 20:03:45 -07:00
Wez Furlong
e6a858664f windows: Software frontend is now mesa llvmpipe
This is a bit of a switch-up, see this comment for more background:
refs: https://github.com/wez/wezterm/issues/265#issuecomment-701882933

This commit:

* Adds a pre-compiled mesa3d opengl32.dll replacement
* The mesa dll is deployed to `<appdir>/mesa/opengl32.dll` which by
  default is ignored.
* When the frontend is set to `Software` then the `mesa` directory
  is added to the dll search path, causing the llvmpipe renderer
  to be enabled.
* The old software renderer implementation is available using the
  `OldSoftware` frontend name

I'm not a huge fan of the subdirectory for the opengl32.dll, but
I couldn't get it to work under a different dll name; the code
thought that everything was initialized, but the window just rendered
a white rectangle.
2020-10-01 18:31:57 -07:00
Wez Furlong
6069eabc9b window: speculatively try enabling mesa llvmpipe as egl fallback
If we've failed to initialize EGL, try setting `LIBGL_ALWAYS_SOFTWARE=true`
in the environment and make another pass at initialization in the hope
that it brings up something usable.

This commit only impacts linux systems at the time of writing.

I've made the line that logs the GL implementation information
have `error` level again, because it is more convenient for me
even if it isn't technically an error.

refs: https://github.com/wez/wezterm/issues/272
(but isn't the true fix; this is just trying to make the consequences
of that problem less.  I would like to get that fixed correctly)

refs: https://github.com/wez/wezterm/issues/265#issuecomment-701882933
(which discusses what I think the end state should be)
2020-09-30 22:41:02 -07:00
Wez Furlong
6708ea4b36 window: normalize SHIFT modifier state
When a keypress is ASCII uppercase and SHIFT is held, remove SHIFT
from the set of active modifiers.

refs: https://github.com/wez/wezterm/issues/157#issuecomment-699516096
2020-09-26 09:17:51 -07:00
Wez Furlong
70fc76a040 window: fix segv when using multiple egl windows with linux/X11
This could be reproduced via `wezterm connect localhost`.
This bug was surfaced after the last release added a Drop impl
to cleanup the display.

This commit tracks the display in the connection.

closes: https://github.com/wez/wezterm/issues/252
2020-08-16 10:43:14 -07:00
Wez Furlong
11b298d3ed window: add some more application keypad mappings
@petermblair: I didn't test this beyond it compiling because I don't
have any keyboards that have a keypad :-p
2020-08-12 22:53:53 -07:00
Wez Furlong
ea7d28e2f3 Add error reason to X11 connection error
refs: https://github.com/wez/wezterm/issues/249
2020-08-12 22:03:57 -07:00
Wez Furlong
96cdadca48 Terrible workaround for an opengl crash
This isn't a fix by any stretch of the imagination, but it stops
a crash.  Should be good enough until I get a chance to fix this
properly.

refs: https://github.com/wez/wezterm/issues/252
2020-08-12 21:49:01 -07:00
Wez Furlong
4605244af7 egl: prefer some amount of alpha when selecting a config
This fixes a sort of hilarious accidental window transparency for
me when running under XWayland.
2020-08-02 22:45:18 -07:00
Wez Furlong
dddf67e07a egl: add explicit drop impl for GlState
This tidies up the valgrind output some more, but seems to highlight
some leaks in the egl implementation around init/shutdown.

I still don't see a smoking gun for a memory leak that grows over time.

refs: https://github.com/wez/wezterm/issues/238
2020-07-13 09:36:37 -07:00
Wez Furlong
888cded0e3 x11: remove Rc cycle between XConnection, Window, bitmaps
refs: https://github.com/wez/wezterm/issues/238

It's not a smoking gun, but helps clean up the valgrind output
2020-07-13 09:00:00 -07:00
Wez Furlong
4cd4ee2eb5 egl: revise how we report egl init errors 2020-07-13 08:02:19 -07:00
Wez Furlong
30f0e5b2c1 egl: look for exactly 8bpc configurations
When running on a 30bpp display with 2 bit alpha, eglChooseConfig
will match and list the 10bpc configuration first, which don't match
the desired pixel format.

Filter the config list so that it only includes 8bpc configurations.

refs: https://github.com/wez/wezterm/issues/240
2020-07-11 13:29:05 -07:00
Wez Furlong
68a91835ee window: egl: speculatively relax min alpha size
In refs: https://github.com/wez/wezterm/issues/240 there are a number
of configurations that report 0 for the alpha size and where we are
unable to otherwise find a working config.

This is a speculative commit to releax the alpha channel size to
basically anything available and see if that helps.
2020-07-09 17:47:38 -07:00
Wez Furlong
1e50493b84 window: x11: fix minor leak of a display connection
These were two separate one-time losses.

refs: https://github.com/wez/wezterm/issues/238
2020-07-08 09:16:43 -07:00
Wez Furlong
95a52fb661 window: egl: log available, matching configurations
Hopefully this can shed some light on why we're not matching any configs
in refs: https://github.com/wez/wezterm/issues/240
2020-07-07 08:59:44 -07:00
Wez Furlong
793af71592 egl: relax context creation requirements
This commit refactors the wayland EGL init code to call into the
non-wayland init code which is more in the spirit of DRY.

It also highlights that we were requesting PBUFFER and PIXMAP capable
contexts in the non-wayland case.  Since we appear to survive without
those in the wayland renderer, presumably we can survive without them
in all cases.

This may help with activating opengl for this issue:
refs: https://github.com/wez/wezterm/issues/240
2020-07-06 07:49:02 -07:00
Wez Furlong
627a1c6c1b x11: improve support for non-24bpp displays
While looking into what it might take to support 10bpc (30bpp) displays
(https://github.com/wez/wezterm/issues/240) I was experimenting with
Xephyr at a reduced 16bpp depth and noticed that the server still
offered a 32bpp TrueColor depth option.

This commit adjusts the window/bitmap code to allow it to select depths
24bpp or 32bpp, preferring the largest depth.  we restrict ourselves to
24 and 32 bit selections for this, as those appear to be bit for bit
compatible for the r/g/b channels.  I suspect that 10bpc will require
some scaling somewhere.

This change allows running wezterm against the reduced depth Xephyr, but
since Xephyr doesn't support GL it runs with the software renderer; I
don't know quite how opengl is going to play with this.  I can confirm
that running wezterm on my native 24bpp display when it picks a 32bpp
visual does run with opengl enabled, so maybe this is good enough?
2020-07-05 11:10:18 -07:00
Wez Furlong
ab1e83c7eb window: fallback to basic opengl context if extensions fail
8f1f1a65ea added support for probing
for opengl extensions, and I thought that I had the fallback covered
but it turned out that we were only falling back if one of the major
extensions wasn't present.

This commit adds a fallback for the case where things look ok at
first glance, but where they fail at runtime for whatever reason.

refs: https://github.com/wez/wezterm/issues/235
2020-06-29 18:05:43 -07:00
Wez Furlong
8f1f1a65ea window: handle opengl context loss on windows.
With this commit, we now survive a reinstall or upgrade of the nvidia
drivers on my Windows sytem without crashing.

This commit allows notifying the application of the context loss
so the application can either try to reinit opengl or open a new
window as a replacement and init opengl there.

I've not had success at reinitializing opengl after a driver upgrade;
it seems to be persistently stuck in a state where it fails to allocate
a vertex buffer.

SO, the state we have now is that we try to reinit opengl on a new
window, and if that fails, leave it set to the software renderer.

This isn't a perfect UX, but it is better than terminating!

refs: https://github.com/wez/wezterm/issues/156
2020-06-16 21:17:48 -07:00
Wez Furlong
ff32dc727f window: allow opengl reinit on context loss on macos
Again, I haven't seen a case where this triggers, but this compiles
and works in the normal case.
2020-06-15 12:33:52 -07:00