Current font caching algorithm contains a use after free error. A font
removed from `frc` might be still listed in `wx.specbuf`. It will lead
to a crash inside `XftDrawGlyphFontSpec()`.
Steps to reproduce:
$ st -f 'Misc Tamsyn:scalable=false'
$ curl https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt
Of course, result depends on fonts installed on a system and fontconfig.
In my case, I'm getting consistent segfaults with different fonts.
I replaced a fixed array with a simple unbounded buffer with a constant
growth rate. Cache starts with a capacity of 0, gets increments by 16,
and never shrinks. On my machine after `cat UTF-8-demo.txt` buffer
reaches a capacity of 192. During casual use capacity stays at 0.
Features:
- Allow input methods swap with hotkey (E.g. left ctrl + left shift).
- Over-the-spot pre-editing style, pre-edit data placed over insertion point.
- Restart IME without segmentation fault.
TODO:
- Automatically pickup IME if st started before IME
When possible, declare functions/variables static and move struct
definitions out of headers. In order to allow utf8decode to become
internal, use codepoint for DECSCUSR extension directly.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Prefer passing arguments to declaring external global variables. The
only remaining usage of extern is for config.h variables which are
needed in st.c instead of x.c (where it is now included).
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
The xinit function only needs to the rows/cols, so pass those in rather
than accessing term directly. With a bit of arithmetic, we are able to
avoid the need for term.row and term.col in x2col, y2row, and
xdrawglyphfontspecs as well, completing the removal.
Term is now fully internal to st.c.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Gradually reducing x.c dependency on Term object. Old and new cursor
glyph/position are passed to xdrawcursor. (There may be an opportunity
to refactor further if we can unify "clear old cursor" and "draw new
cursor" functionality.)
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Introduces three functions to encapsulate X-specific behavior:
* xdrawline: draws a portion of a single line (used by drawregion)
* xbegindraw: called to prepare for drawing (will be useful for e.g.
Wayland) and returns true if drawing should happen
* xfinishdraw: called to finish drawing (used by draw)
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Moves the mode bits used by x.c from Term to TermWindow, absorbing
UI/input-related mode bits (visible/focused/numlock) along the way.
This is gradually reducing external references to Term. Since
TermWindow is already internal to x.c, we add xsetmode() to allow st to
modify window bits in accordance with escape sequences.
IS_SET() is redefined accordingly (term.mode in st.c, win.mode in x.c).
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
This also allows us to remove the crlf field from the Key struct, since
the only difference it made was converting "\r" to "\r\n" (which is now
done automatically in ttywrite). In addition, MODE_CRLF is no longer
referenced from x.c.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
The only thing differentiating ttywrite and ttysend was the potential
for echo; make this a parameter and remove ttysend.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
The "done" parameter indicates a change which finalizes the selection
(e.g. a mouse button release as opposed to motion).
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
The front-end determines information about mouse clicks and motion, and
the terminal handles the actual selection start/extend/dirty logic by
row and column.
While we're in the neighborhood, we'll also rename getbuttoninfo() to
mousesel() which is, at least, less wrong.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
This removes ttynew's dependency on cresize being called first, and then
allows us to absorb the ttyresize call into cresize (which always
precedes it).
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
None of the X-related includes are needed any longer. In addition, move
the X modifier defines into x.c, as they are not used outside.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
This is an X type and should be internal to x.c.
The selcopy() function was a single line and only used in one place, so
it was inlined to reduce LOC.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
There was only a single reference to the `win` variable in st.c, so
exporting that to x.c allows us to rid ourselves of another extern.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
config.h includes references to KeySyms and other X stuff. Until we
come up with a cleaner way to separate configuration, it is simpler
(leads to more code removal) to have this here.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
This commit is purely about reducing externs and LOC. If the main and
run functions ever move elsewhere (which will probably make sense
eventually), these should come along with them.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Modifiers and keysyms are specific to X, and the functions match and
kmap are only used in x.c. Needed to global-ize the key arrays and
lengths from config.h (for now).
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
This makes x(un)loadfonts internal to x.c. Needed to reorder includes
and move a typedef to keep the compiler happy.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
This makes xsetenv internal to x.c, and allows iso14755's external
command to use $WINDOWID instead of having to snprintf it again. (The
same benefit will apply to the externalpipe patch.) The xwinid function
is no longer needed.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>