aboutsummaryrefslogtreecommitdiff
path: root/render.c (unfollow)
Commit message (Collapse)AuthorLines
2020-02-12render: spellingDaniel Eklöf-1/+1
2020-02-10render: resize: calculated cursor row *should* never be beyond the screen bottomDaniel Eklöf-1/+2
2020-02-10render: reflow: clear new line if already allocatedDaniel Eklöf-1/+2
2020-02-10render: resize: fix cursor positioning at grid wrap aroundDaniel Eklöf-2/+6
When current view is at a grid wrap around (last emitted row index is < grid offset), the cursor row ended up being negative which we then mapped to the top line. This is wrong. When we're at a wrap around, re-adjust cursor by adding the grid's row count.
2020-02-10render: reflow: initial line is always unallocatedDaniel Eklöf-5/+5
2020-02-10vt: tag cells that were form-feed:ed, to allow correct text reflowDaniel Eklöf-1/+4
To handle text reflow correctly when a line has a printable character in the last column, but was still line breaked, we need to track the fact that the slave inserted a line break here. Otherwise, when the window width is increased, we'll end up pulling up the next line, when we really should have inserted a line break.
2020-02-10render: reflow: no need to clear cellsDaniel Eklöf-2/+1
We set initialize=true when allocating a new row. This initializes the cell to 0, with clean=1.
2020-02-10render: initial support for text reflowDaniel Eklöf-36/+141
The algorithm is as follows: Start at the beginning of the scrollback. That is, at the oldest emitted lines. This is done by taking the current offset, and adding the number of (old) screen rows, and then iterating until we find the first allocated line. Next, we iterate the entire old grid. At the beginning, we allocate a line for the new grid, and setup a global pointer for that line, and the current cell index. For each line in the old grid, iterate its cells. Copy the the cells over to the new line. Whenever the new line reaches its maximum number of columns, we line break it by increasing the current row index and allocating a new row (if necessary - we may be overwriting old scrollback if the new grid is smaller than the old grid). Whenever we reach the end of a line of the old grid, we insert a line break in the new grid's line too **if** the last cell in the old line was empty. If it was **not** empty, we **don't** line break the new line. Furthermore, empty cells in general need special consideration. A line ending with a string of empty cells doesn't have to be copied the new line. And more importantly, should **not** increase the new line's cell index (which may cause line breaks, which is incorrect). However, if a string of empty cells is followed by non empty cells, we need to copy all the preceding empty cells to the line too. When the entire scrollback history has been reflowed, we need to figure out the new grid's offset. This is done by trying to put the **last** emitted line at the bottom of the screen. I.e. the new offset is typically "last_line_idx - term->rows". However, we need to handle empty lines. So, after subtracting the number of screen rows, we _increase_ the offset until we see a non-empty line. This ensures we handle grid's that doesn't fill an entire screen. Finally, we need to re-position the cursor. This is done by trying to place the cursor **at** (_not_ after) the last emitted line. We keep the current cursor column as is (but possibly truncated, if the grid's width decreased).
2020-02-08render: resize: reset scroll damageDaniel Eklöf-1/+2
We've resized, and reset the render's 'last-buf' pointer; any scroll damage we have is **not** valid anymore.
2020-02-08render: add render_resize_force()Daniel Eklöf-5/+18
This forces a full resize operation, even though actual window size (or scale) hasn't changed.
2020-01-21presentation: store input timestamp in a per-commit contextDaniel Eklöf-32/+39
This should reduce the risk of mixing up an input timestamp with the corresponding rendered frame.
2020-01-20render: fallback to background color if cursor text color is not setDaniel Eklöf-3/+3
2020-01-19fcft: update to 1.0.0Daniel Eklöf-2/+3
Allow/disallow subpixel antialiasing in font_glyph_for_wc(), not using font_enable_subpixel_antialias().
2020-01-12render: resize: TIOCSWINSZ: don't include padding in ws_{x,y}pixelDaniel Eklöf-2/+2
2020-01-12term: shorten application_synchronized_updates -> app_sync_updatesDaniel Eklöf-2/+2
2020-01-12term/render: move {enable,disable}_application_synchronized_updates()Daniel Eklöf-31/+1
From render -> terminal
2020-01-12render: add a timeout for application synchronized updatesDaniel Eklöf-5/+17
This ensures we can recover from a crashing (or bad behaving) application that sends a BSU but then never sends an ESU.
2020-01-12render: rename render_{enable,disable}_refresh()Daniel Eklöf-3/+3
2020-01-12term: rename refresh_prohibited -> application_synchronized_updatesDaniel Eklöf-5/+5
2020-01-12render: add render_{enable,disable}_refresh()Daniel Eklöf-0/+24
Calling render_disable_refresh() causes update requests to that terminal to be ignored. Calling render_enable_refresh() re-enables updates.
2020-01-12render: don't bother trying to lookup glyph for empty cellsDaniel Eklöf-1/+2
Depending on the font, it may not have an entry for code point '0', which will cause us to try to load fallback fonts.
2020-01-06selection: update: don't dirty cells that don't change stateDaniel Eklöf-1/+1
Previously when updating a selection, we would unmark *all* cells in the old selection, and then mark all cells in the new selection. This caused *all* cells to be dirtied and thus re-rendered. Avoid this, by adding a temporary state to the cells' selected state. Before unmarking the old selection, pre-mark the new selection using a temporary state. When unmarking the old selection, ignore cells in this temporary state. When marking the new selection, ignore cells in this temporary state (except clearing the temporary state).
2020-01-05search: rename render.search_offset -> render.search_glyph_offsetDaniel Eklöf-6/+6
2020-01-05render: ensure cursor is always visible in the search boxDaniel Eklöf-6/+26
Maintain a view 'offset' (which glyph from the search string to start rendering at). This defines the start of the viewable area. The end is the offset + the search box size (which is limited to the window size). Adjust this offset whenever the cursor moves outside the viewable area. For now, this is always done in the same way: set the offset to the cursor position. This means that when we're entering text at the end of the search criteria (i.e. the normal case; we're simply typing), and the search box reaches the window size, the cursor will jump to the start of the search box, which will be empty. This could be confusing, but let's go with for now.
2020-01-04render: xcursor: remove render_xcursor_refresh()Daniel Eklöf-18/+17
2020-01-04renderer: destroy: actually free the renderer instance (doh!)Daniel Eklöf-0/+2
2020-01-04wayland: use a low priority FDM hook to flush the wayland socketDaniel Eklöf-2/+0
This way, we don't have to manually insert flushes in code paths that may execute outside of a wl_display_dispatch_pending(). (Those that execute inside a wl_display_dispatch_pending() are subject to the flush performed at the end of the normal wayland FDM handler).
2020-01-04fdm: add hook prioritiesDaniel Eklöf-2/+5
There are now three hook priorities: low, normal, high. High priority hooks are executed *first*. Normal next, and last the low priority hooks. The renderer's terminal refresh hook now runs as a normal priority hook.
2020-01-04render: throttle xcursor updatesDaniel Eklöf-20/+125
With a bad behaving client (e.g. 'less' with mouse support enabled), we can end up with a *lot* of xcursor updates (so much, that we flooded the wayland socket before we implemented a blocking wayl_flush()). Since there's little point in updating the cursor more than once per frame interval, use frame callbacks to throttle the updates. This works more or lesslike normal terminal refreshes: render_xcursor_set() stores the last terminal (window) that had (and updated) the cursor. The renderer's FDM hook checks if we have such a pending terminal set, and if so, tries to refresh the cursor. This is done by first checking if we're already waiting for a callback from a previous cursor update, and if so we do nothing; the callback will update the cursor for the next frame. If we're *not* already waiting for a callback, we update the cursor immediately.
2020-01-04wayland: wl_display_flush() never blocksDaniel Eklöf-1/+1
Since it doesn't block, we need to detect EAGAIN failures and ensure we actually flush everything. If we don't, we sooner or later end up in a wayland client library call that aborts due to the socket buffer being full. Ideally, we'd simply enable POLLOUT in the FDM. However, we cannot write *anything* to the wayland socket until we've actually managed to send everything. This means enabling POLLOUT in the FDM wont work since we may (*will*) end up trying to write more data to it before we've flushed it. So, add a wrapper function, wayl_flush(), that acts as a blocking variant of wl_display_flush(), by detecting EAGAIN failiures and calling poll() itself, on the wayland socket only, until all data has been sent.
2020-01-04render: remove debug loggingDaniel Eklöf-5/+2
2020-01-04render: attrs_to_font() is not used outside of render.cDaniel Eklöf-1/+1
2020-01-04render: trigger terminal refreshes in an FDM hookDaniel Eklöf-6/+56
In some cases, we end up calling render_refresh() multiple times in the same FDM iteration. This means will render the first update immediately, and then set the 'pending' flag, causing the updated content to be rendered in the next frame. This can cause flicker, or flashes, since we're presenting one or more intermediate frames until the final content is shown. Not to mention that it is inefficient to render multiple frames like this. Fix by: * render_refresh() only sets a flag in the terminal * install an FDM hook; this hook loops all terminals and executes what render_refresh() _used_ to do (that is, render immediately if we're not waiting for a frame callback, otherwise set 'pending' flag). for all terminals that have the 'refresh_needed' flag set.
2020-01-04selection: store cell 'selected' state in the cells' attributesDaniel Eklöf-53/+8
Instead of having the renderer calculate, for each cell, whether that cell is currently selected or not, make selection_update() mark/unmark the selected cells. The renderer now only has to look at the cells' 'selected' attribute. This makes the renderer both smaller and faster.
2020-01-03render: coord_is_selected: handle block selectionsDaniel Eklöf-8/+22
2020-01-03render: refresh: ensure window has been configuredDaniel Eklöf-0/+2
2020-01-03render: remove 'refresh' from render_resize()Daniel Eklöf-3/+2
2020-01-03render: render_resize(): don't do anything if width or height is 0Daniel Eklöf-0/+3
2020-01-03render: resize() now only calls refresh() if asked toDaniel Eklöf-2/+3
2020-01-03render: use a unique buffer cookie for the 'search' surfaceDaniel Eklöf-1/+1
This fixes an issue where rendering the 'search' box caused the last normal buffer from being purged. This meant the terminal had a pointer to a now freed buffer, which we de-referenced and occasionally memcpy:ied from.
2020-01-02render: draw_cursor: use terminal's visual focus to determine cursor shapeDaniel Eklöf-5/+3
2020-01-02wayland: rename focused/moused to kbd_focus/mouse_focusDaniel Eklöf-1/+1
2020-01-01render: presentation: cleanupDaniel Eklöf-6/+20
2020-01-01render: call wl_display_flush() right after wl_surface_commit()Daniel Eklöf-2/+1
This groups the two calls, for readability.
2020-01-01render: presentation: clean up frame interval count calculationDaniel Eklöf-1/+1
2019-12-31render: presentation: space between value and "µs"Daniel Eklöf-3/+3
2019-12-31render: presentation: also use seconds when calculating frame interval countDaniel Eklöf-2/+2
2019-12-31render: presentation: log both input -> commit and commit -> presented timesDaniel Eklöf-29/+40
2019-12-31render: reset input/commit timestamps on presentation discarded eventDaniel Eklöf-0/+3
2019-12-31wayland: optionally use the presentation time protocol to measure input lagDaniel Eklöf-0/+123
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-19render: fix bug when erasing old cursor; send correct compositor damageDaniel Eklöf-3/+3
2019-12-19render: render_cell: break out cursor renderingDaniel Eklöf-57/+68
2019-12-19render: attrs_to_font: const:ifyDaniel Eklöf-1/+1
2019-12-19term/render: check for is_shutting_down in grid_render()Daniel Eklöf-0/+3
2019-12-17render: get rid of 'all-clean' detectionDaniel Eklöf-21/+10
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-17render: move blink timer handling to term.cDaniel Eklöf-49/+2
2019-12-16render: render block cursor as a hollow rectangle when unfocusedDaniel Eklöf-14/+36
2019-12-15term: implement cursor blinkingDaniel Eklöf-2/+16
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-03fcft: update to 0.3.0Daniel Eklöf-10/+4
fcft now calculates the underline and strikeout integer positions, making our rendering code much simpler.
2019-12-03render: limit size of search surface to parent windowDaniel Eklöf-4/+2
This shouldn't be necessary, but Sway acts up when the subsurface exceeds the parent surface (window, in this case) size, and extends the window size (if floating), leaving it with no content
2019-12-03render: don't allow negative coordinates of the search surfaceDaniel Eklöf-1/+2
While the protocol allows this, it appears Sway offsets (moves) the parent surface when this happens, resulting in a window half without content.
2019-12-01fcft: include <fcft/fcft.h>, and use fcft/stride.h instead of local copyDaniel Eklöf-1/+1
2019-12-01fcft: use fcft instead of local copy of font.c/font.hDaniel Eklöf-1/+2
2019-11-30render: fix underline/strikeout positioningDaniel Eklöf-6/+8
There were two errors: * We subtracted half the line width instead of adding it to the baseline * We rounded the line positioning and thickness before the positioning calculation. In particular, rounding the thickness before using it to adjust the position was wrong. Now we round just before the pixman call.
2019-11-30render: font_baseline(): simply use the primary font's ascentDaniel Eklöf-16/+4
This is what we used as baseline for regular glyphs anyway. Thus, we can update that code to call font_baseline() now. This makes it easier to change how we define the baseline in the future.
2019-11-28render: fix rendering of cursor when cell is reversedDaniel Eklöf-13/+19
When the user had configured the cursor color, we failed to invert (reverse) the foreground and background color when the cursor was on a cell with the 'reverse' attribute set.
2019-11-26font: move metrics from terminal struct to font structDaniel Eklöf-11/+11
2019-11-17term: add struct cursorDaniel Eklöf-10/+10
2019-11-16render: configure default tab stops when resizing the terminalDaniel Eklöf-0/+5
2019-11-02Revert "render: last_buf may point to a free:d buffer"Daniel Eklöf-18/+8
This reverts commit 4d3251a93b4ba309d573aca6ff397df44c4ff760.
2019-11-01render: last_buf may point to a free:d bufferDaniel Eklöf-8/+18
So, store last buf's width/height separately
2019-11-01shm: associate a 'cookie' with each bufferDaniel Eklöf-3/+7
When re-using a buffer from cache, only re-use ones with a matching cookie. This prevents contention between multiple terminal windows.
2019-11-01shm: get_buffer(): remove 'copies' argument; it's not usedDaniel Eklöf-2/+2
2019-11-01render: limit length of title in call to xdg_toplevel_set_title()Daniel Eklöf-1/+13
Trying to pass a too long title (not sure what "too long" is though...) will trigger a call to abort() inside the wayland-client library.
2019-11-01render: call wl_display_flush() after renderingDaniel Eklöf-0/+2
This allows us to remove that call from the main event loop.
2019-10-29scrollback: regression: fix rendering of scrollback diffs less than a screenDaniel Eklöf-11/+18
When doing "small" scrolls (typically done via mouse wheel or similar), we render the scrolling by emitting a "scroll damage". A recent commit changed how scroll damage is rendered; only when the view is at the bottom ("following" the screen output) do we render the damage. To fix this, add a new type of scroll damage, SCROLL_DAMAGE_IN_VIEW and SCROLL_DAMAGE_REVERSE_IN_VIEW. These signal to the renderer that it should always render the damage.
2019-10-28render worker context: allocate, and let worker threads freeDaniel Eklöf-0/+1
Since we now initialize the worker threads from term_init(), which returns before the threads terminate, we can no longer use stack-allocated worker contexts. We _could_ put them in the terminal struct. But a simpler solution is to allocate them in term_init(), and let the threads free them when they don't need them anymore.
2019-10-28render: regression: don't apply scroll damage when view is in scrollbackDaniel Eklöf-12/+15
When user has scrolled back in the output history, new output should not trigger scrolling. This was true for normal cell rendering, which renders the cells *in view*, not caring where the "front" of the output is. However, we still applied scroll damage. I.e. we memmoved part of the screen. The fix is simple; only apply scroll damage when the view is at the front of the output.
2019-10-27wayland: move reload_cursor_theme() and update_cursor_surface() to waylandDaniel Eklöf-55/+0
2019-10-27wayland: implement wayl_init()Daniel Eklöf-28/+28
Wayland instantiation is now done by the wayland backend, not in main.
2019-10-27term: wayland struct is now not a part of the terminal structDaniel Eklöf-22/+22
We do however need access to it, so provide a pointer. The difference is that now we can have a *single* wayland instance, but multiple terminal instances.
2019-10-27wayland: implement wayl_win_destroy()Daniel Eklöf-6/+6
2019-10-27term: move per-window wayland objects from wayland struct to terminal structDaniel Eklöf-23/+25
Short term, we want to break out the wayland backend from the terminal struct. Long term, we might want to support multiple windows. One step towards both the above is separating global wayland objects from per-window objects.
2019-10-16font: font_from_name() returns an allocated font structDaniel Eklöf-2/+2
2019-09-27render: handle compositors that does buffer swappingDaniel Eklöf-45/+61
Not all compositors support buffer re-use. I.e. they will call the frame callback *before* the previous buffer has been released. Effectively causing us to swap between two buffers. Previously, this made us enter an infinite re-render loop, since we considered the window 'dirty' (and in need of re-draw) when the buffer is different from last redraw. Now, we detect the buffer swapping case; size must match, and we must not have any other condition that require a full repaint. In this case, we can memcpy() the old buffer to the new one, without dirtying the entire grid. We then update only the dirty cells (and scroll damage). Note that there was a bug here, where we erased the old cursor *before* checking for a new buffer. This worked when the buffer had *not* changed. Now that we need to handle the case where it *has* changed, we must do the memcpy() *before* we erase the cursor, or the re-painted cell is lost. This makes foot work on Plasma, without burning CPU. The memcpy() does incur a performance penalty, but we're still (much) faster than e.g. konsole. In fact, we're still mostly on par with Alacritty.
2019-09-27render: attach buffer *before* generating damageDaniel Eklöf-2/+1
Fixes 'invisible window' on Plasma
2019-09-26main: initialize scale to '1'Daniel Eklöf-13/+1
This ensures we always have a valid (but possibly incorrect) scaling value. This allows us to simplify code that uses the scale - it doesn't have to verify the scale if valid. Furthermore, since render_resize() is the function that actually updates term->scale, make sure to call it *before* updating the cursor (otherwise, the cursor will use the old scaling value).
2019-09-20render: remove assertion that isn't always trueDaniel Eklöf-1/+0
It's not true for e.g. Cascadia code.
2019-08-30render: search box: use colors from the color tableDaniel Eklöf-2/+3
Use the 'yellow' color from the 'regular' range of colors (SGR 33) for background when we have a match, or 'red' from the 'regular' range of colors (SGR 31) when we don't have a match. Foreground uses the 'black' color from the regular range of colors (SGR 30).
2019-08-30render: draw (cursor) bar using the same thickness as underlinesDaniel Eklöf-5/+7
2019-08-30render: search box: fix glyph spacingDaniel Eklöf-1/+1
We're using the same font as in the terminal, so use the same glyph spacing.
2019-08-29render: render_search_box: draw cursor as a barDaniel Eklöf-0/+6
2019-08-29render: draw_strikeout: use font_baseline() for baseline calculationDaniel Eklöf-1/+1
2019-08-29render: draw_underline: use font_baseline() for baseline calculationDaniel Eklöf-1/+1
2019-08-29render: draw_bar: don't assume height == ascent+descentDaniel Eklöf-2/+4
Instead, draw a bar that is ascent+descent tall, positioned around the baseline such that it starts at the ascent and ends at the descent.
2019-08-29render: add font_baseline() - calculates the y-coordinate for the baselineDaniel Eklöf-0/+19
The old baseline calculation was copy-pasted to a couple of places, and also assumed that the font's height was equal to ascent+descent. While this is typically true, it isn't necessarily so. Now, we assume that height >= ascent+descent, and then position the baseline in "center" (but adjusted for the descent).
2019-08-29render: remove INFO log (that really was a debug log)Daniel Eklöf-2/+0
2019-08-29search: move render() function to the 'render' moduleDaniel Eklöf-0/+54
2019-08-29render: reduce amount of dim while searching scrollback historyDaniel Eklöf-4/+10
2019-08-28render: double-dim fg+bg when searching the scrollback bufferDaniel Eklöf-0/+2
By toning down the screen content more, the selection (i.e. the search match) pops out much more.