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

786 Commits

Author SHA1 Message Date
Magnus Groß
ba309931a3 Cache xdg-desktop-portal appearance
This slightly improves the startup time of wezterm.

Right now we query the portal appearance value again over dbus every
time that we access it, for example every time that the user calls
wezterm.gui.get_appearance() from the Lua interface.

Queries over dbus are slow, they usually take a few milliseconds to
complete, for example on my system a portal query over dbus takes around
2 milliseconds to complete.

Wezterm also automatically calls the portal during its own internal
x11/wayland connection initialization, thus right now wezterm queries
the appearance portal setting n+1 times on startup, where n is the
number of times that the user calls get_appearance() from the config.

To fix this problem, we simply cache the portal appearance.

Thus this patch decreases the startup time by 2ms for users that
configure wezterm to follow the global system theme and potentially by
more for users that call get_appearance() in inflational amounts.

With the naive implementation wezterm would be subject to the following
race condition:

1. wezterm calls get_appearance() and caches the value
2. System-wide dark mode changes
3. wezterm subscribes to portal notifications

In that scenario wezterm would miss the dark mode switch entirely and
would cache the wrong value until the dark mode switches again after
wezterm subscribed.

To fix this race condition we call read_setting() again **after** we
have subscribed just to be on the safe side.

Note that while this still introduces a second "redundant" dbus query
for the same value, this time it does not actually block start up since
it happens in another thread.

refs: #2258
2022-08-20 06:06:59 -07:00
Wez Furlong
4fead3171e macos: report max_fps in ScreenInfo
Other platforms can be added later
2022-08-19 21:02:51 -07:00
Wez Furlong
8ca3faa6ee macos: implement max_fps
Use the same technique that we use on x11 systems to schedule/throttle
painting frames.

refs: https://github.com/wez/wezterm/discussions/2419
2022-08-19 20:39:39 -07:00
Davide Cavalca
0048209bcf Add missing license files 2022-08-17 07:19:12 -07:00
Wez Furlong
e2bf468393 wayland: disable use of wlr-output-management protocol
refs: #2297
refs: #2293
refs: #2360
2022-08-07 08:13:38 -07:00
Magnus Groß
60b5be2b34 x11/wayland: always try the portal for appearance
Right now the initial x11 appearance retrieval uses the specific
connection interface, which completely circumvents the already existing
more complete implementation in x_and_wayland.rs.
The latter implementation is strictly better, because it first attempts
getting the appearance from the XDG desktop portal and then falls back
to the X11 interface.

Before this patch there was a very weird issue for folks using the OS
system dark mode with the following config snippet:

```
color_scheme = scheme_for_appearance(wezterm.gui.get_appearance())
```

The color_scheme on startup would be correct, but there would be a very
weird problem where sometimes wezterm ignores the first time that the
portal notifies about an appearance update.

The source of the bug was an inconsistent retrieval of the appearance
setting:
- The Lua API used the XDG desktop portal
- The internal appearance used the X11 specific connection at startup

For example due to this, the internal appearance variable could have
stored "Dark" from the X11 connection, but the actual appearance from
the XDG desktop portal was "Light".
If then the XDG desktop portal changes to "Dark", the
appearance_changed() method would dismiss the update because
self.appearance was already "Dark".

It is only after that, that the internal inconsistency would have been
solved and following appearance changes would succeed and update the
colorscheme correctly.

To fix this problem, we now use the portal directly in both the x11 and
wayland connections,  which is consistent with the Lua
wezterm.gui.get_appearance() API.

refs: #2258
2022-07-15 15:23:47 -07:00
Wez Furlong
a1c8b4a9b3 x11/wayland: subscribe to xdg desktop portal for settings changes
We use this to detect changes in dark mode

refs: https://github.com/wez/wezterm/issues/2258
2022-07-13 18:56:21 -07:00
Wez Furlong
8ef70d1e31 windows: avoid recursing and borrowing inner twice
Querying the window can call into windowproc so we need to avoid
it when we hold `inner`.  Adjust the flow so that we can get
the info about the window state purely from an HWND.

refs: #2257
2022-07-13 11:37:04 -07:00
Wez Furlong
8dcfbc6718 x11/wayland: use xdg desktop portal settings interface to get dark mode
There are some other settings in there that could also help with
things like the cursor theme on Wayland.

Note that we don't currently subscribe to the settings changed
signal: that can be done in a follow up.

refs: https://github.com/wez/wezterm/issues/2258
refs: https://github.com/wez/wezterm/issues/1742
2022-07-13 08:55:43 -07:00
Wez Furlong
d7fa541745 windows: fixup starting maximized
Since applying the maximized state is async, we hadn't fully applied
it before we got to the startup logic that resizes the window to fit
the initial terminal size.

This adds a final check to see if we are resizable before we try
to apply that size, and skips it.

refs: #284
2022-07-10 07:19:08 -07:00
Wez Furlong
f11b240a1c wayland: double-buffer ime events
refs: #1772
2022-07-10 06:52:21 -07:00
Wez Furlong
607287935f wayland: ime: clear compose state after commit
refs: #1772
2022-07-09 23:12:43 -07:00
Wez Furlong
2196279689 wayland: workaround mutter IME issue
refs: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4776
refs: https://github.com/wez/wezterm/issues/1772
2022-07-09 22:29:25 -07:00
Wez Furlong
7f6ae3c82d wayland: fixup IME preedit
The done event shouldn't clear the state.

refs: #1772
2022-07-09 12:35:01 -07:00
Wez Furlong
9c758dd203 wayland: fix ime position when scaling > 1
refs: #1772
2022-07-09 12:20:22 -07:00
Wez Furlong
e2b748a0d4 wayland: initial support for zwp_text_input_v3 / IME
refs: #1772
2022-07-09 09:44:08 -07:00
Wez Furlong
c906179bb9 wayland: use zwlr_output_manager if available
This seems to have better names and also returns fractional
scaling information.
2022-07-08 13:40:28 -07:00
Wez Furlong
fdb5fc2d66 wayland: implement wezterm.gui.screens()
Hook it up for resolving geometry, but note that wayland doesn't
allow positioning and we don't expose a way to set width/height
based on screen right now.
2022-07-08 09:54:42 -07:00
Wez Furlong
2c093b976d windows: implement window:maximize(), window:restore() 2022-07-07 06:25:43 -07:00
Wez Furlong
9779b29c39 wayland: implement window:maximize() window:restore() 2022-07-07 06:19:08 -07:00
Wez Furlong
871f7a8115 x11: implement maximize and restore 2022-07-06 23:53:19 -07:00
Wez Furlong
8caf0615c5 add plumbing for maximize/restore on x11/wayland
Doesn't do anything yet, but I always forget to add this until
after I've implemented one or the other and then wonder why
nothing happens.

refs: #284
2022-07-06 23:14:37 -07:00
Wez Furlong
8853df02ca lua: add window:maximize() and window:restore() methods
Implemented on macOS only for the moment.

refs: https://github.com/wez/wezterm/issues/284
2022-07-06 23:11:02 -07:00
Wez Furlong
87b963981e win32: fixup initial window pos after screens changes
Ensure that we correctly use CW_USEDEFAULT for the case where
`--position` was not used.
2022-07-06 13:43:46 -07:00
Wez Furlong
2b3e5119a4 lua: screens: fixup x11 build 2022-07-06 13:30:40 -07:00
Wez Furlong
99f6fbda15 lua: implement wezterm.window.screens() for macos 2022-07-06 13:27:03 -07:00
Wez Furlong
0e36358acc fix up x11 build for screens changes on win32 2022-07-06 13:00:57 -07:00
Wez Furlong
43c7664438 screens: improve naming on Windows, move resolve_geom to Connection
On Windows, GDI returns unintuitive names like "\\.\DISPLAY6" that
may not start numbered at either 0 or 1.

This commit grubs through the various APIs so that we can produce more
meaningful names like "DISPLAY6: Gigabyte M32u on NVIDIA 2080 TI"
instead.

This commit also makes the lua wezterm.window.screens() function
consistent with the internal resolve_geom functions that each different
implementation had, so that we can eliminate those functions in
favor of this new one on the ConnectionOps trait.

Still need to do macOS and verify that this commit doesn't break X11.
2022-07-06 12:54:18 -07:00
Wez Furlong
cdeabd6a21 lua: implement wezterm.window.screens() on Windows 2022-07-06 08:58:07 -07:00
Wez Furlong
9301d1900d rustfmt 2022-07-06 08:39:14 -07:00
Wez Furlong
a6cf13e1e2 lua: add wezterm.window.screens()
Currently implemented on X11 only, this function returns information
about the geometry of the screen(s).

This is taken from the same source of information we use for the
`--position` CLI argument to `wezterm start`.

```
> wezterm.window.screens()
{
    "by_name": {
        "DisplayPort-1": {
            "height": 2160,
            "name": "DisplayPort-1",
            "width": 3840,
            "x": 0,
            "y": 0,
        },
    },
    "main": {
        "height": 2160,
        "name": "DisplayPort-1",
        "width": 3840,
        "x": 0,
        "y": 0,
    },
    "origin_x": 0,
    "origin_y": 0,
    "virtual_height": 2160,
    "virtual_width": 3840,
}
```
2022-07-06 08:35:05 -07:00
Funami580
df1b832fce wayland: add global active_surface_id to fix pasting 2022-07-05 17:35:43 -07:00
Wez Furlong
67b96b9b5c speculative fix for https://github.com/wez/wezterm/issues/2204
An alternative to a special case for just one of mappings that
we handle specially below
2022-07-04 21:12:25 -07:00
Wez Furlong
3dbd866b06 deps: tiny-skia -> 0.7
closes: #2219
2022-07-04 06:30:34 -07:00
Wez Furlong
e6efec8298 x11: remove accidentally added debug statements 2022-06-29 07:23:26 -07:00
Wez Furlong
b5518d5cd9 x11: avoid protocol error around DestroyWindow request
This is a bit of an unsatisfactory commit... the bulk of it is
augmenting our calls into XCB to ensure that we check the status of each
request; the idea was that doing so would highlight the source of the
bad drawable error that is being surfaced in #2198, but after doing
that, it still doesn't highlight the offending call.

My conclusion is that either something in MESA/EGL or the IME is
generating calls that we cannot see into and that one of those is
referencing the window id that we just destroyed.

The resolution then is a bit gross: instead of destroying the window
when we need to close it, we first unmap it to remove it from the
screen, then after 2 seconds we destroy it.

refs: https://github.com/wez/wezterm/issues/2198
2022-06-28 08:30:52 -07:00
Wez Furlong
b5f015c9bb macos: really really fix ctrl-shift-tab
refs: #1902
2022-06-24 10:57:36 -07:00
Wez Furlong
14282f99bc x11: flush prior to mapping window
Speculative change to see if that helps with this dwm related issue:
https://github.com/wez/wezterm/issues/2155

refs: https://github.com/wez/wezterm/issues/2155
2022-06-22 07:55:21 -07:00
Wez Furlong
1b2efe8c70 x11: fix copy and paste between wezterm windows race
This commit adds more trace logging around selection
related events.

That tracing uncovered a situation, when multiple wezterm windows within
the same process were involved, where one window didn't receive a
selection-clear event notification.

Since Window::get_clipboard trusted our local understand of the
clipboard contents, it would return those until the selection was
changed in that window.

This commit changes that code to always ask the X server for the
selection. It makes pasting slightly slower, but should always produce
consistent results.

refs: https://github.com/wez/wezterm/issues/2110
2022-06-21 07:32:53 -07:00
Funami580
b29089ebdc support drag and drop files for wayland 2022-06-20 13:25:32 -07:00
Wez Furlong
3d9898eb54 windows: properly fix shifted dead keys
Don't break AltGr based dead keys with the shift fix from
8e16756474

refs: https://github.com/wez/wezterm/issues/2102
refs: https://github.com/wez/wezterm/issues/473
2022-06-18 11:01:23 -07:00
Wez Furlong
e0616e5eb3 fix AltGr-7 reporting for win32 input mode
We need to carry the RIGHT_ALT modifier flag through to the win32
input mode encoder so that it is correctly handled by both win32
and wsl apps.

Take care to avoid RIGHT_ALT being encoded as ALT for the
non-win32-input-mode case.

refs: https://github.com/wez/wezterm/issues/2127
refs: https://github.com/wez/wezterm/issues/2098
2022-06-18 10:48:07 -07:00
Wez Furlong
8e16756474 windows: fix shifted dead keys
deadkeys that are triggered through shift (eg: backtick on a German
layout) weren't working because we were trying to lookup in our maps
using `SHIFT | LEFT_SHIFT` when the map data was keyed only by `SHIFT`.

This commit removes the positional modifier flags from the modifier
keys and restores the correct behavior.

refs: https://github.com/wez/wezterm/issues/2102
2022-06-18 10:26:48 -07:00
Wez Furlong
32fe7106a9 remove x11_focus_change_repaint_delay_ms code
We found the real root of the problem in so we shouldn't need this any
longer

refs: https://github.com/wez/wezterm/issues/1992
refs: https://github.com/wez/wezterm/issues/1628
refs: https://github.com/wez/wezterm/issues/2063
2022-06-18 07:39:56 -07:00
Wez Furlong
1485cf344c x11: make another run at weird resize related issue w/ nvidia
This does two things:

* Sets the event queue owner explicitly to xcb
* Adopts a dri2 resize related workaround from the rust-xcb opengl
  example

I think the latter is probably a NOP, but the former sounds like
something important.

refs: #1992
2022-06-17 21:23:18 -07:00
Wez Furlong
adf9679461 macos: use shift-tab hack with ctrl-shift-tab as well
refs: #1902
2022-06-15 22:23:15 -07:00
Wez Furlong
297377ae9a rename focus_change_repaint_delay -> x11_focus_change_repaint_delay_ms
and add changelog!

refs: #2111
2022-06-15 20:50:33 -07:00
Patrick Jones
4f015e66bc x11: query focus after repaint delay
The focus events used to trigger a query of geometry are inaccurate, so the window's focus state should also be queried.

refs: #2063
refs: #1992
2022-06-15 20:42:26 -07:00
Patrick Jones
3f01c04911 x11: allow configuration of repaint delay
Adds a configuration option, `focus_change_repaint_delay` to allow customisation of the delay added in 9b6329b454.

The default delay remains 100ms, and can be disabled by setting it to `0`, if the workaround is not required on the user's system.

refs: #2063
refs: #1992
2022-06-15 20:42:26 -07:00
Wez Furlong
26c43f784d macos: allow for keyboard translation data to be null
refs: https://github.com/wez/wezterm/issues/2119
2022-06-15 20:25:16 -07:00