Commit graph

162 commits

Author SHA1 Message Date
Daniel Eklöf
0ea0323d0f
wayland: don't use wl_display_dispatch()
wl_display_dispatch() calls poll(), which is unnecessary since we
already know the FD is readable.

Use the more lower level wl_display_read_events() +
wl_display_dispatch_pending().

These require wl_display_prepare_read() to have been called.

The idea is to call wl_display_prepare_read() **before** calling
poll().

Thus, we do this more or less last in wayl_init(), and at the **end**
of the FDM handler.

However, having taking this lock also means we no longer can call
wl_display_roundtrip() directly (it will hang).

So, add a wrapper, wayl_roundtrip(), that cancels the read intent,
does the roundtrip, and then re-acquires the read intent.
2020-01-03 21:02:12 +01:00
Daniel Eklöf
ef3c7d7e0a
term: init: don't resize if compositor has already resized us 2020-01-03 19:31:09 +01:00
Daniel Eklöf
782da0f8e9
term: no need to call render_refresh() when starting/stopping blink timer 2020-01-03 19:27:57 +01:00
Daniel Eklöf
d07fd7de39
render: remove 'refresh' from render_resize() 2020-01-03 13:56:10 +01:00
Daniel Eklöf
9a0238bb52
wayland: window now keeps pointer to owning terminal, not wayland 2020-01-03 13:37:03 +01:00
Daniel Eklöf
bd13c2c86a
term: render_resize() now takes a 'refresh' argument 2020-01-03 12:45:30 +01:00
Daniel Eklöf
80dfd5b645
term: visual_focus_{in,out}: do nothing if already focused/defocused 2020-01-03 11:19:56 +01:00
Daniel Eklöf
913c684844
term: term_init() calls wl_display_roundtrip()
Instead of having `wayl_win_init()` call
`wl_display_roundtrip()` (which it itself doesn't need), call it from
`term_init()`.

This allows us to add ourselves (the new terminal instance) to the
terminal list in the wayland backend, before triggering the wayland
events caused by `wayl_win_init()`.

This is turn allows the wayland backend to find/lookup the new
terminal when those events occur..
2020-01-03 11:16:06 +01:00
Daniel Eklöf
4451f4ad62
term: spell 'initialize' correctly 2020-01-03 11:15:35 +01:00
Daniel Eklöf
6f281cebfb
term: add term_visual_focus_{in,out}
These functions should be called when the terminal gets or loses
visual focus.

Note that this isn't necessarily the same as having keyboard focus.
2020-01-02 19:35:32 +01:00
Daniel Eklöf
e9325b958f
term: rename term_focus_{in,out} -> term_kbd_focus_{in,out} 2020-01-02 19:29:42 +01:00
Daniel Eklöf
4ecb0ecf4d
wayland: rename focused/moused to kbd_focus/mouse_focus 2020-01-02 15:58:52 +01:00
Daniel Eklöf
b8960f930d
term: bump lower delay limit to 500µs
Emacs with a split screen often goes above 200µs. 500µs is still much
better than 2000µs...
2019-12-31 20:39:16 +01:00
Daniel Eklöf
c5bdf7c27e
term: ptmx timing: use a define instead of #if 0 2019-12-31 20:37:43 +01:00
Daniel Eklöf
3912638141
term: lower the lower delay timeout from 2ms to 200µs 2019-12-31 20:29:47 +01:00
Daniel Eklöf
60b27a9686
term: commented out code to measure time between slave output
This allows us to measure the time between to refresh delays. That is,
when we decide to delay a refresh, we store the current time.

If we hit that code path _again_, without having refreshed, we
calculate the time that has passed.

This gives us an estimate for how we should set our lower delay
timeout.

This is of course application dependent, but is still much better than
simply guessing a value...
2019-12-31 20:26:30 +01:00
Daniel Eklöf
5a07419096
wayland: optionally use the presentation time protocol to measure input lag
This adds a flag, -p,--presentation-timings, that enables input lag
measuring using the presentation time Wayland protocol.

When enabled, we store a timestamp when we *send* a key to the
slave. Then, when we commit a frame for rendering to the compositor,
we request presentation feedback. We also store a timestamp for when
the frame was committed.

The 'presented' callback then looks at the input and commit
timestamps, and compares it with the presented timestamp.

The delay is logged at INFO when the delay was less than one frame
interval, at WARN when it was one frame interval, and at ERR when it
was two or more frame intervals.

We also update statistic counters that we log when foot is shut down.
2019-12-31 15:39:40 +01:00
Daniel Eklöf
39146fac5c
term: term_init: add 'cwd' argument
This is used when spawning the slave, to set its current working
directory just before we exec() the client.

In a regular foot instance, we set the cwd from getcwd().

In a foot server instance, each connecting client sends its cwd to the
server, and we use that.
2019-12-21 19:57:28 +01:00
Daniel Eklöf
016bde1bd4
term: wip: track current working directory
This sets the initial current working directory, as it is when the
terminal is instantiated.

We chdir() to it just before spawning a new terminal.
2019-12-21 15:35:54 +01:00
Daniel Eklöf
a484a65fef
term: term_spawn_new: always spawn foot/footclient from PATH 2019-12-21 15:29:42 +01:00
Daniel Eklöf
57de9feaa5
term: term_spawn_new(): new function, spawns a new foot/footclient process
Bind ctrl+shift+return to it
2019-12-21 15:27:17 +01:00
Daniel Eklöf
2a95f2949b
term: experimental: tweak delay timeouts
Increase the low timeout, to try to give clients/slaves more time to
emit data.

Decrease the upper timeout. On average, we should have ~½ frame left
until the next frame. So a maximum delay of a whole frame *will* delay
the update one extra frame in many cases.

Hopefully, the low timeout is still low enough that we don't miss the
next frame, on average.
2019-12-21 00:12:00 +01:00
Daniel Eklöf
f8009b549a
term: cursor blink reset doesn't force-refresh the cursor 2019-12-19 07:27:41 +01:00
Daniel Eklöf
0efcb66f3a
term/render: check for is_shutting_down in grid_render() 2019-12-19 07:27:14 +01:00
Daniel Eklöf
a366bc9ace
term: remove TODO 2019-12-19 07:24:46 +01:00
Daniel Eklöf
81840b4e8e
cursor blink: move reset to pty input 2019-12-19 07:23:58 +01:00
Daniel Eklöf
c22ae98729
render: get rid of 'all-clean' detection
Instead of trying to figure out if we had to render
something (i.e. something in the grid was dirty), and using that to
determine whether to post a callback or not, we now let
render_refresh() set a flag indication we need to render another
frame.

This simplifies render_grid(), which now _always_ renders, and pushes
it to the compositor.

The callback handler checks the pending flag and simply doesn't call
render_grid() when there's no more pending state to render.

This ends up reducing the number of wakeups when e.g. having a
blinking cursor.
2019-12-17 19:14:56 +01:00
Daniel Eklöf
418ff5bcd9
render: move blink timer handling to term.c 2019-12-17 19:14:55 +01:00
Daniel Eklöf
f4e5baa123
term: disable cursor blink on unfocus, and re-enable on focus 2019-12-16 21:33:22 +01:00
Daniel Eklöf
dac31dd9c0
term: disable cursor blink before shutting down terminal, and remove from FDM 2019-12-16 21:32:57 +01:00
Daniel Eklöf
d490cc84c0
term: cursor blink: cursor refresh now dirties the cursor cell
Normally we don't dirty the cell on cursor movement. But, since a
blinking cursor isn't a cursor that has moved, our normal cursor
rendering wont work.

Dirty the cursor cell to force a redraw of it.
2019-12-16 21:31:40 +01:00
Daniel Eklöf
7d29435d86
term: implement cursor blinking
Blinking can be enabled either by setting the cursor style with

 CSI Ps SP q

and selecting a blinking style.

Or, with 'CSI ? 12 h'

Note that both affect the same internal state. I.e. you can disable
blinking with CSI ? 12l after having selected a blinking cursor
style. This is consistent with XTerm behavior.
2019-12-15 15:07:56 +01:00
Daniel Eklöf
8dc9560431
term: determine cell width from the width of the space character 2019-12-05 19:34:47 +01:00
Daniel Eklöf
ad56afe2f4
term: test: set font DPI to the highest DPI we find
In most cases (i.e. when there's only a single output/monitor), this
will be *the* DPI value.

In other cases, well...

The _right_ thing to do is track the outputs our window is actually
mapped on, and re-instantiate fonts depending on the current output's
DPI. But that's for the future...
2019-12-04 22:02:02 +01:00
Daniel Eklöf
e9fbb371df
fcft: font_from_name() no longer accepts a tllist 2019-12-01 19:22:25 +01:00
Daniel Eklöf
fbeb1e9610
term: mouse reporting functions no longer take modifier state
The mouse reporting functions are called from input when we receive
Wayland mouse events.

We used to pass the current keyboard modifier (shift, alt, ctrl, etc)
to the terminal functions.

This however is wrong, since we may receive Wayland mouse events
without having keyboard focus. When we don't have keyboard focus, the
modifier state doesn't apply to us.

Remove the modifier arguments from the terminal mouse reporting
functions. These functions now read this state directly instead, but
only when the terminal instance in question has keyboard focus.
2019-11-30 17:11:00 +01:00
Daniel Eklöf
2208f4304b
term: add term_mouse_grabbed()
When this returns true, it means we have keyboard focus and are
grabbing the mouse (for e.g. selections), regardless of whether the
client has enabled mouse tracking or not.
2019-11-30 17:06:15 +01:00
Daniel Eklöf
62ed0ef4f2
term: "raw" mouse mode requires shift only to be pressed 2019-11-30 16:48:32 +01:00
Daniel Eklöf
8f8ef5df0e
term: define xcursor strings as global variables 2019-11-30 12:43:06 +01:00
Daniel Eklöf
c8d94931e6
term: xcursor: use selection_enabled()
Instead of duplicating the code from selection_enabled() that deals
with forced selection, just call selection_enabled().

This was previously not possible since selection_enabled() didn't
require keyboard_focus. Now it does.
2019-11-30 12:01:40 +01:00
Daniel Eklöf
a81c65caa2
term: reset: set 'origin' to ORIGIN_ABSOLUTE 2019-11-30 00:32:06 +01:00
Daniel Eklöf
8b7158703d
term: reset: don't access rows directly
We've just re-set the grid offsets, meaning rows 0..term->rows may not
all have been initialized.

Call grid_row_and_alloc() to ensure they are.
2019-11-29 23:36:04 +01:00
Daniel Eklöf
bf9a9e7b90
term: xcursor: use 'hand2' instead of 'left_ptr' when mouse tracking
Mouse tracking always reports clicks, so using a cursor that suggests
you can click makes sense I think.
2019-11-29 22:30:56 +01:00
Daniel Eklöf
f41788c185
term: xcursor cleanup
Show 'text' cursor when:

* we have no mouse tracking enabled
* forced selection has been enabled (shift being held down)
* We're *not* scrollback searching

In all other cases, show the 'left_ptr' cursor.
2019-11-29 22:15:03 +01:00
Daniel Eklöf
0dd37f0a36
terminal: use the 'text' xcursor pointer whenever selection is possible 2019-11-28 19:35:47 +01:00
Daniel Eklöf
903581b7eb
async: first synchronous write may succeed partially
When trying to write (to e.g. the slave, or to a clipboard receiver),
we first try to send the data synchronously, and only if that fails do
we switch to asynchronous mode.

However, the first synchronous may (in fact, is likely to) succeed
partially.
2019-11-28 19:20:25 +01:00
Daniel Eklöf
ae91c53fb2
font: pass dpi=96 to fontconfig
TODO: use actual output PPI. Question is *which* output...
2019-11-26 19:02:35 +01:00
Daniel Eklöf
bc86cd61c7
font: move metrics from terminal struct to font struct 2019-11-26 19:02:35 +01:00
Daniel Eklöf
ee45c48deb
term: shutdown: handle *not* being unmapped
When we're shutting down a terminal, we destroy our Wayland window,
and assume that will unmap us.

There are cases when this isn't true (most likely when e.g. a screen
locker is active, and the unmap is being deferred).

Handle by explicitly setting focused to NULL.
2019-11-21 18:18:35 +01:00
Daniel Eklöf
3c8a87168a
fonts: use 'weight' and 'slant', not 'style' when loading fonts 2019-11-19 17:35:02 +01:00