aboutsummaryrefslogtreecommitdiff
path: root/render.c (unfollow)
Commit message (Collapse)AuthorLines
2020-12-20render: fix rounding error when calculating background color with alphaDaniel Eklöf-7/+3
We use pre-multiplied alpha color channels, but were having bad rounding errors due to the alpha divider being truncated to an integer. The algorithm for pre-multiplying a color channel is: alpha_divider = 0xffff / alpha pre_mult_color = color / alpha_divider In order to fix the rounding errors, we could turn ‘alpha_divider’ into a double. That however would introduce a performance penalty since now we’d need to do floating point math for each cell. The algorithm can be trivially converted to: pre_mult_color = color * alpha / 0xffff Since both color and alpa values are < 65536, the multiplication is “safe”; it will not overflow an uint32_t. Closes #249
2020-12-08render: ime: ensure cursor is visibleDaniel Eklöf-13/+41
2020-12-07render: search: render IME pre-edit text correctly, hopefullyDaniel Eklöf-61/+116
2020-12-07render: ime: adjust cursor cell index when adjusting glyph offsetDaniel Eklöf-1/+4
2020-12-07render: ime: wip: pre-editDaniel Eklöf-22/+75
2020-12-07render: search: don’t access term->search.buf[] directlyDaniel Eklöf-8/+11
2020-12-07render: codespell: cound -> countDaniel Eklöf-1/+1
2020-12-07render: search: glyph_offset is in *cells*, cursor position in *characters*Daniel Eklöf-18/+64
When calculating the offset into the search string, from where to start rendering, take into account that the cursor position is in *characters*, and the glyph-offset is in *cells*.
2020-12-07render: search: wcsnlen() -> wcswidth()Daniel Eklöf-1/+1
2020-12-07render: search: handle multi-column charactersDaniel Eklöf-2/+3
2020-12-07render: search: render colorized glyphs (emojis) correctlyDaniel Eklöf-5/+13
2020-12-07render: ime: don’t render pre-edit string in grid while searchingDaniel Eklöf-0/+3
While doing a scrollback search, the pre-edit string should be rendered in the search box, not in the grid. Note that we don’t yet support IME in scrollback search mode. This patch simply prevents the pre-edit text being rendered in the grid, in the “background”, while searching.
2020-12-07render: ime: draw a ‘bar’ cursor when the pre-edit cursor’s begin == endDaniel Eklöf-6/+14
2020-12-07render: ime: don’t render cursor if cursor begin == endDaniel Eklöf-3/+4
2020-12-07render: ime: calculate on-screen cursor position ourselvesDaniel Eklöf-3/+12
The position calculated by render_grid() may be -1,-1 if the cursor is currently hidden. This fixes a crash when trying to input IME while the cursor is hidden.
2020-12-07render: ignore IME preedit state when deciding which cursor style to renderDaniel Eklöf-1/+1
2020-12-07ime: make IME compile-time optionalDaniel Eklöf-0/+3
2020-12-07ime: render pre-edit textDaniel Eklöf-19/+127
This is done by allocating cells for the pre-edit text when receiving the text-input::done() call, and populating them by converting the utf-8 formatted pre-edit text to wchars. We also convert the pre-edit cursor position to cell positions (it can cover multiple cells). When rendering, we simply render the pre-edit cells on-top off the regular grid. While doing so, we also mark the underlying, “real”, cells as dirty, to ensure they are re-rendered when the pre-edit text is modified or removed.
2020-12-01render: don’t call term_arm_blink_timer() from multiple threadsDaniel Eklöf-2/+5
We call term_arm_blink_timer() from render_cell(), which runs in multiple threads. This caused multiple blink timer FDs to be created and registered with the FDM, later causing read failures after one of those FDs had been closed again. This rarely happened under normal circumstances, but was easy to trigger when the whole screen was full of blinking text. As a small optimization, we don’t bother taking the lock if the timer FD already is valid. This is safe, because: 1) If the timer FD isn’t valid, we take the lock and then call term_arm_blink_timer(), which again checks if the FD is already valid. 2) The blink timer FD cannot be closed while we’re rendering cells. It is only disabled in the FDM callback, which cannot execute while we’re rendering.
2020-12-01render: allow-overflow: require a space in the next cellDaniel Eklöf-1/+5
When checking if we should allow a single-width character double-width glyph to overflow into the next cell, require the next cell to either be empty, or contain a space. Closes #203
2020-11-30config: replace union in config struct with simple width/height membersCraig Barnes-4/+4
2020-11-25resize: don’t reflow text on alt screenDaniel Eklöf-9/+8
Alt screen applications normally reflow/readjust themselves on a window resize. When we do it too, the result is graphical glitches/flashes since our re-flowed text is rendered in one frame, and the application re-flowed text soon thereafter. We can’t avoid rendering some kind of re-flowed frame, since we don’t know when, or even if, the application will update itself. To avoid glitches, we need to render, as closely as possible, what the application itself will render shortly. This is actually pretty simple; we just need to copy the visible content over from the old grid to the new grid. We don’t bother with text re-flow, but simply truncate long lines. To simplify things, we simply cancel any active selection (since often times, it will be corrupted anyway when the application redraws itself). Since we’re not reflowing text, there’s no need to translate e.g. the cursor position - we just keep the current position (but bounded to the new dimensions). Fun thing: ‘less’ gets corrupted if we don’t leave the cursor at the (new) bottom row. To handle this, we check if the cursor (before resize) is at the bottom row, and if so, we move it to the new bottom row. Closes #221
2020-11-23render: don’t call term_arm_blink_timer() from multiple threadsDaniel Eklöf-2/+5
We call term_arm_blink_timer() from render_cell(), which runs in multiple threads. This caused multiple blink timer FDs to be created and registered with the FDM, later causing read failures after one of those FDs had been closed again. This rarely happened under normal circumstances, but was easy to trigger when the whole screen was full of blinking text. As a small optimization, we don’t bother taking the lock if the timer FD already is valid. This is safe, because: 1) If the timer FD isn’t valid, we take the lock and then call term_arm_blink_timer(), which again checks if the FD is already valid. 2) The blink timer FD cannot be closed while we’re rendering cells. It is only disabled in the FDM callback, which cannot execute while we’re rendering.
2020-11-22render: no need to call attrs_to_font(), we already have a font referenceDaniel Eklöf-8/+4
2020-11-19render: allow-overflow: require a space in the next cellDaniel Eklöf-1/+5
When checking if we should allow a single-width character double-width glyph to overflow into the next cell, require the next cell to either be empty, or contain a space. Closes #203
2020-11-15render: dim/brighten: multiply/divide instead of add/subtractDaniel Eklöf-2/+2
2020-11-15render: dim and brighten colors by adjusting luminanceDaniel Eklöf-27/+30
To do this, we need to convert our RGB to HSL, adjust luminance, and then convert back to RGB.
2020-11-15render: remove debug outputDaniel Eklöf-1/+0
2020-11-14render: brighten color of bold text if default.bold-text-in-bright=yesDaniel Eklöf-0/+10
Closes #199
2020-11-13render: improve sixel rendering performanceDaniel Eklöf-43/+132
Up until now, we’ve always re-rendered the entire image (the part of it that is visible at least), *every* time we render a frame. This is not really needed. In many cases, the cells covered by the image hasn’t been touched. Rewrite the sixel rendering code to only render the part of the sixel image that covers dirty cells. This is done on a per-row basis. I.e. Each *row* of the image that covers at least one dirty cell is re-rendered. For this to work, we now also dirty all cells covered by the image when we emit the image. Finally, for this to work, the sixels need to be rendered *before* we do the normal grid render pass (since that will clear all dirty bits).
2020-11-06tiocswinsz: fix compilation error on e.g. ppc64Daniel Eklöf-1/+1
On some platforms, TIOCSWINSZ has a very large value, > 0x80000000. On some platforms, the `request` argument to `ioctl(3)` is an `int`. For platforms where both of the above is true, gcc will warn (and error out if compiled with `-Werror`) on: ioctl(fd, TIOCSWINSZ, ...) To silence this warning, we need to cast `TIOCSWINSZ` to an integer. However, doing this on platforms where `request` is an `unsigned long` will result in `TIOCSWINSZ` being sign-extended (and thus we end up with an invalid value). It seems that casting to `unsigned int` works in both cases; it silences the long -> int conversion warning, while also preserving the correct value in all cases.
2020-11-06wayland: properly restore window size when being un-tiledDaniel Eklöf-6/+11
Bind to xdg-shell version 2 if available, as this enables us to track our window’s ‘tiled’ state in the ‘configure’ events. This in turn allows us to stash the ‘old’ window size when being tiled, to be used again when restoring the window size when un-tiled.
2020-10-29tiocswinsz: fix compilation error on e.g. ppc64Daniel Eklöf-1/+1
On some platforms, TIOCSWINSZ has a very large value, > 0x80000000. On some platforms, the `request` argument to `ioctl(3)` is an `int`. For platforms where both of the above is true, gcc will warn (and error out if compiled with `-Werror`) on: ioctl(fd, TIOCSWINSZ, ...) To silence this warning, we need to cast `TIOCSWINSZ` to an integer. However, doing this on platforms where `request` is an `unsigned long` will result in `TIOCSWINSZ` being sign-extended (and thus we end up with an invalid value). It seems that casting to `unsigned int` works in both cases; it silences the long -> int conversion warning, while also preserving the correct value in all cases.
2020-10-22render: blink switches between foreground and dimmed foregroundDaniel Eklöf-3/+3
2020-10-20wayland: properly restore window size when being un-tiledDaniel Eklöf-6/+11
Bind to xdg-shell version 2 if available, as this enables us to track our window’s ‘tiled’ state in the ‘configure’ events. This in turn allows us to stash the ‘old’ window size when being tiled, to be used again when restoring the window size when un-tiled.
2020-10-11render: resize: call sixel_reflow() after reflowing gridsDaniel Eklöf-0/+3
2020-10-11render: apply opacity correctly when in reverse video modeDaniel Eklöf-2/+8
2020-10-11render: remove render_refresh_margins()Daniel Eklöf-6/+0
2020-10-11render: term->render.margins is used to explicitly tell us to re-render marginsDaniel Eklöf-15/+7
2020-10-10selection: use appropriate check for PRIMARY pasteSergey Nazaryev-600/+167
Assume it could be a copy-paste typo. We should check PRIMARY, not CLIPBOARD. Without this fix, we can't use PRIMARY until we copy anything to CLIPBOARD.
2020-10-09render: resize: call sixel_reflow() after reflowing gridsDaniel Eklöf-0/+3
2020-10-08bell: optionally render margins in red when receiving BELDaniel Eklöf-0/+32
Add anew config option, ‘bell=none|set-urgency’. When set to ‘set-urgency’, the margins will be painted in red (if the window did not have keyboard focus). This is intended as a cheap replacement for the ‘urgency’ hint, that doesn’t (yet) exist on Wayland. Closes #157
2020-10-08render: apply opacity correctly when in reverse video modeDaniel Eklöf-2/+8
2020-09-29render: remove render_refresh_margins()Daniel Eklöf-6/+0
2020-09-29render: term->render.margins is used to explicitly tell us to re-render marginsDaniel Eklöf-15/+7
2020-09-17render: fix rounding errors when setting initial window size and scale != 1Daniel Eklöf-4/+16
An odd cell width/height sometimes resulted in an odd grid size. Combined with a scaling factor of e.g. 2, that led to a rounding error when converting pixel sizes to logical window sizes. As a result, the _next_ configure event would cause us to loose a pixel, which led to us dropping a row from the grid.
2020-09-14render: best-effort attempt to set initial window size in chars when scale != 1Daniel Eklöf-6/+7
The initial window size is set *before* we’re initially mapped. This means we don’t (yet) know on which output we’ll be mapped. _That_ means we don’t know which scaling factor to use. This implements a best effort attempt, where we use the “guessed” scaling factor. This will always be correct in single-monitor configurations, but may be wrong in multi-monitor setups with different scaling factors.
2020-09-10render: csd: hide buttons when title bar gets too small to fit themDaniel Eklöf-8/+16
2020-09-08Add -W,--window-size-chars, and foot.ini:initial-window-size-charsDaniel Eklöf-6/+17
* Add -W,--window-size-chars command line option * Add initial-window-size-chars foot.ini option * Add -w,--window-size-pixels command line option * Add initial-window-size-pixels foot.ini option * Deprecate -g,--geometry command line option in favor of -w,--window-size-pixels * Deprecate geometry option in foot.ini in favor of initial-window-size-pixels
2020-09-07render: change minimum window size from 4x20 -> 1x2 (rows/cols)Daniel Eklöf-2/+2
2020-09-06grid: reflow: calculate width of composed characters correctlyDaniel Eklöf-2/+4
Before this patch, reflow called `wcwidth()` on our magic values for composed characters.
2020-09-06config: add tweak.damage-whole-windowDaniel Eklöf-0/+5
When enabled, foot will ‘damage’ the entire window, instead of just the modified/updated rows. This will force the compositor to redraw/blend the whole window. This can be used to workaround an issue with fractional scaling in Gnome, where random thin lines may appear.
2020-09-03render: optionally enable heuristics that deal with private usage area charsDaniel Eklöf-0/+25
Try to detect double-width *glyphs* for single-width *characters*, and allow them to overflow into the next cell. This is only done for single-width chars with a glyph width that is at least 1.5 cells wide, but at most 3 cells. The feature is gated by the new ‘tweak.allow-overflowing-double-width-glyphs’, and is disabled by default. Closes #116
2020-09-01render: ’redraw_margins’ is now a parameter to grid_render()Daniel Eklöf-11/+7
render_refresh_margins() now passes ’true’ here, instead of re-setting term->render.last_buf to NULL.
2020-09-01render: implement render_refresh_margins()Daniel Eklöf-2/+22
For now, it will reset term->render.last_buf to NULL, and then calls grid_render() to do a full screen refresh.
2020-08-26render: scrollback indicator: only leave room for search box when necessaryDaniel Eklöf-1/+5
2020-08-26render: scrollback indicator: subtract visible rows from populated rowsDaniel Eklöf-1/+1
This prevents the indicator from starting too high up when the number of used scrollback rows is low.
2020-08-25render: scrollback position: only count _used_ scrollback linesDaniel Eklöf-3/+11
When calculating where in the scrollback history we are, we previously did this against the total number of scrollback lines. I.e. the `scrollback.lines` setting in `footrc`. Now, we count only the used/allocated scrollback lines. Note that the initial indicator position might still seem to start a bit high up, if the number of used scrollback lines is low. This is because we use the *top* of the screen for the current position. Thus, we'll never be at the bottom (except for the special case when we're *really* at the bottom).
2020-08-23don't use empty struct initializersDaniel Eklöf-3/+3
2020-08-15Fix some spelling mistakesCraig Barnes-1/+1
2020-08-14render: render the render timer *before* committing the main surfaceDaniel Eklöf-17/+17
2020-08-14render: render-timer: position sub-surface similar to the scrollback indicatorDaniel Eklöf-0/+5
2020-08-13render: oops... swprintf() needs to number of *chars*, not *bytes*Daniel Eklöf-1/+1
2020-08-13render: fix printf-errors in 32-bit buildsDaniel Eklöf-2/+3
2020-08-13config: add tweak.render-timer optionDaniel Eklöf-53/+96
This can be set to 'none' (the default), 'osd', 'log' or 'both'. When 'osd' is enabled, we'll render the frame rendering time to a sub-surface after each frame. When 'log' is enabled, the frame rendering time is logged on stderr.
2020-08-12config: make selection foreground/background colors configurableDaniel Eklöf-8/+12
The default is still to inverse the regular foreground/background colors. If the user sets *both* of the new options, selection-foreground and selection-background, those colors will *always* be used for selected cells, instead of inverting the regular foreground/background colors.
2020-08-11render: fix compilation errors in 32-bit buildsDaniel Eklöf-6/+9
timeval.tv_usec is an 'unsigned long long' on 32-bit
2020-08-08Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes-3/+9
2020-07-31config: add 'hide-when-typing'Daniel Eklöf-0/+9
When enabled, the mouse cursor is hidden when the user types in the terminal. It is un-hidden when the user moves the mouse, or when the window loses keyboard focus.
2020-07-29render: make compiler happy; make sure 'cell_count' has been initializedDaniel Eklöf-1/+1
Compiler, in release builds, complains about 'cell_count' "may be used uninitialized". This isn't true, as it is initialized in every possible switch case below. But, make the compiler happy and zero-initialize it before the switch statement.
2020-07-28config: add free-form text variant to 'scrollback-indicator-format'Daniel Eklöf-3/+9
And make the empty string the new default.
2020-07-27config: rename scrollback-indicator-style to scrollback-indicator-positionDaniel Eklöf-5/+5
2020-07-27render: scrollback indicator: apply weston sub-surface quirkDaniel Eklöf-0/+2
2020-07-27render: scrollback indicator: render relative indicator "smoothly"Daniel Eklöf-7/+7
That is, don't require it to be placed on a grid row.
2020-07-26render: scrollback indicator: add top marginDaniel Eklöf-4/+4
2020-07-26config: scrollback-indicator-format: percent -> percentageDaniel Eklöf-1/+1
2020-07-26render: scrollback indicator: use black on bright blueDaniel Eklöf-2/+2
2020-07-26render: scrollback indicator: implement 'relative' and 'line' variantsDaniel Eklöf-9/+41
We now implement all combinations of 'scrollback-indicator-style' and 'scrollback-indicator-format'.
2020-07-26render: scrollback indicator: wip: implement 'fixed:percent' indicatorDaniel Eklöf-10/+100
When scrollback indicator has been enabled, and the viewport isn't at the bottom, we now render a *static* indicator with the position in percent. We use the color scheme's blue color as background, and it's white color as foreground. This is subject to change... Should maybe be configurable as well. The Wayland surface + sub-surface are instantiated on-demand, and automatically destroyed when no longer used.
2020-07-26render: search: fix subpixel argument to fcft_glyph_rasterize()Daniel Eklöf-1/+1
2020-07-25config: rename scrollback-indicator to scrollback-indicator-styleDaniel Eklöf-1/+1
And turn it from a boolean to an enum. It can be set to: * `none` - disables the indicator * `static` - always rendered near the top of the window * `moving` - position reflects the scrollback position
2020-07-24config: rename show-scrollback-position to scrollback-indicatorDaniel Eklöf-1/+1
2020-07-24config: add 'show-scrollback-position' option to footrcDaniel Eklöf-2/+0
2020-07-24render: add code that calculates current position in scrollbackDaniel Eklöf-0/+46
2020-07-22render: bump maximum window title length from 100 to 2048 (bytes)Daniel Eklöf-2/+1
Apparently, the max is ~8K, but lets stay on the safe side.
2020-07-15term: don't re-render last cursor cell if cursor was hiddenDaniel Eklöf-1/+2
2020-07-14term: print: write special value CELL_MULT_COL_SPACER to extra cellsDaniel Eklöf-1/+1
When printing a multi-column character, write CELL_MULT_COL_SPACER instead of '0' to both padding cells (when character doesn't fit at the end of the line), and to the cells following the actual character.
2020-07-14term: rename COMB_CHARS_LO,HI -> CELL_COMB_CHARS_LO,HIDaniel Eklöf-3/+3
2020-07-13render: render_margin: don't damage margins when rendering scroll damageDaniel Eklöf-12/+10
When applying scroll damage, we may have to re-render the margins. This is because when we SHM-scroll, we actually move the entire surface, and thus we end up overwriting the top margin area with old window content, and scroll in uninitialized memory in the bottom margin. But, we don't have to tell the compositor about this - the last frame always contains correct margins; i.e. there's no change between the last frame and current frame being rendered. TODO: we _could_ micro-optimize and only damage the margins after a surface resize. We do it slightly more often now, when dealing with state changes in screen flash or scrollback searching. But I don't think it's worth the effort.
2020-07-13render: doh! flush the last surface damage *outside* of the rendering loopDaniel Eklöf-8/+8
2020-07-13render: render_margin: add 'damage_{top,bottom,left,right}' argumentsDaniel Eklöf-20/+24
2020-07-13render: render_margin(): remove top/bottom argumentsDaniel Eklöf-24/+20
All calls to render_margin() set top=true and bottom=true anyway.
2020-07-13render: merge wl surface damage for consecutive dirty rowsDaniel Eklöf-38/+55
2020-07-13render: keep lock while pushing dirty rows to worker queueDaniel Eklöf-9/+3
Instead of locking the queue for each dirty row we append, and signaling a condition variable, just keep the lock while going through the visible rows. Release the lock once done. Since we take the lock *before* posting the 'start' semaphore, all workers will be waiting for the lock to be released. Then, one at a time they'll get the lock and pick a row to render. The queue will never get empty - when all rows have been rendered, each worker will pick a 'frame done' "job" from the queue, and break the rendering loop.
2020-07-12render: don't render cursor when it has been explicitly hiddenDaniel Eklöf-2/+2
2020-07-12render: remove most of the special handling of cursor renderingDaniel Eklöf-80/+50
Previously, we had to explicitly render the old cursor cell *before* applying scrolling damage. We then rendered all the dirty rows, *without* rendering the cursor - even if the cursor cell was among the dirty rows. Finally, when everything else was done, we explicitly rendered the cursor cell. This meant a lot of code, and unnecessary render_cell() calls, along with unnecessary wl_surface_damage_buffer() calls. This was a necessary in the early design of foot, but not anymore. We can simply mark both the old cursor cell, and the current one, as dirty and let the normal rendering framework render it. All we need to do is pass the cursor column to render_row(), so that it can pass has_cursor=true in the appropriate call to render_cell(). We pass -1 here for all rows, except the cursor's row, where we pass the actual cursor column. With this, there's no need to calculate whether the cursor is visible or not; just mark it's cell as dirty, and if that row is visible, the normal rendering will take care of it. This also simplifies the state needed to be saved between two frames; we only need a row pointer, and the cursor column index. Part of https://codeberg.org/dnkl/foot/issues/35
2020-07-11render: use kbd-focus instead of visual focus for hollow block cursorDaniel Eklöf-5/+5
When determining whether we should render a hollow block cursor, i.e. to signal that we're unfocused, base the decision on the terminals current keyboard focus, not visual focus.
2020-07-10wayland: read XCURSOR_{THEME,SIZE} in reload_xcursor themeDaniel Eklöf-2/+1
2020-07-09multi-seat: improve handling of multiple (mouse) pointersDaniel Eklöf-17/+17
* xcursor always set for all pointers * xcursor sometimes not updated when it should be * mouse grabbed state wasn't per seat, but global (i.e. "does at least one seat enable mouse grabbing") * selection enabled state wasn't per seat
2020-07-08multi-seat: enable xcursor theme support againDaniel Eklöf-50/+40