Commit Graph

510 Commits

Author SHA1 Message Date
Jan200101 c15910856a convert unix style paths literals into meson path segments 2024-11-15 17:41:57 +08:00
Jan200101 1345e9f345 Format renderer font scale code to be actually readable 2024-10-31 16:00:35 +08:00
Takase d925da47fa
Allow writing to hidden files on Windows (#1653)
* feat(system): add system.ftruncate

* fix: EPERM writing to hidden files on Windows

* chore(doc): fix capitalization

* refactor(system): make ftruncate length optional

* refactor(doc): don't specify length
2024-10-22 18:14:30 +02:00
Adam Harrison e8a4ed2a21 Additional small fixes for windows as part of the process API move to lua. 2024-10-22 11:48:51 -04:00
Adam Harrison 56b7d8abef Fixed minor typo from merge of #1854 for windows builds. 2024-10-22 11:33:41 -04:00
takase1121 a5d466d6cf arena_allocator: return lxl_arena instead of initializing an existing struct 2024-10-22 17:17:40 +02:00
takase1121 a25ab3c535 process: migrate arg validation and checking to Lua 2024-10-22 17:17:40 +02:00
takase1121 1f0533482b utfconv: add functions that use arena_allocator 2024-10-22 17:17:40 +02:00
takase1121 9293a317cd allocator: add arena_allocator
This allocator uses Lua userdatas for dynamic allocation
that is automatically freed when the current scope exits.
2024-10-22 17:17:40 +02:00
Jan de805aaf64
Implement logic for tracking target window (#1891)
this will be needed when SDL3 happens due to many more functions requesting a window handle

Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
2024-10-22 17:09:20 +02:00
Guldoman de118ab82a
Add primary selection support (#1729)
* Add support for primary selections

* Handle primary selection in `DocView`s
2024-09-13 13:31:15 -04:00
Adam f5c63d8c8f
Removed draw asserts for window renderer, because certain commands between frames may want to use draw commands to get the sizes of things. (#1878) 2024-09-12 21:20:38 -04:00
Takase 27d95f63cb
renderer: rewrite glyph cache (#1845)
* renderer: rewrite glyph cache

This commit splits the current GlyphSet-based system into 2 caches,
CharMap and GlyphMap, which maps codepoints -> glyph IDs and glyph IDs -> glyphs respectively.
Each GlyphMap contains a number of GlyphAtlas mapped by their width,
and each GlyphAtlas has a list of surfaces with the same width.
Surfaces within the GlyphAtlas acts like a bump allocator, but is flexible
enough to allow older GlyphAtlas surfaces to be recycled.

GlyphMetric now contains atlas_idx and surface_idx, which points to the correct surface.
Since GlyphAtlas supports rudimentary packing & allocation, we no longer render whole
GlyphSets and this speeds up rendering in most cases.

Tab width is no longer set with the hacky "modify the GlyphMetric" hack.

* renderer: set natlas to 0 after freeing

* renderer: fix printf warning

* renderer: fix memory leak

* renderer: better whitespace rendering

* renderer: fix ubsan warning when casting ints

* renderer: fix tab handling

There's a bug with inconsistent tab widths caused by fontgroups.

* renderer: fix glyphs being loaded over and over

* renderer: add glyphmap size

* renderer: store per-surface offset_y and use it to find best-fitting surface

* renderer: fix MSVC compiler error

* renderer: remove return value from ren_font_glyph

* renderer: refactor xadvance calculation

* renderer: fix double free SDL_RWops if FT_Set_Pixel_Size fail

* renderer: always try .notdef before U+25A1

* renderer: disable ren_font_dump yet again

Accidentally commited this change.

* renderer: remove unused imports

* renderer: fix double free with FT_Open_Face

* renderer: return SDL_Surface in font_find_glyph_surface

* renderer: bring back metric flags for future extension

* renderer: refactor xadvance calculation into macro

* renderer: fix comment

* renderer: store GlyphMetric directly in the surface

* renderer: remove duplicated comment

* renderer: rename font_find_glyph_surface to font_allocate_glyph_surface

* renderer: refactor glyphmetric retrieval into an inline function

* renderer: do not render glyphs with bitmap set to null

This is a weird edge case, but at least it shouldn't crash

* renderer: refactor face metric code into its own function

* renderer: actually check if glyph fits in surface

* renderer: rudimentary support for non-scalable faces

At least it won't render nothing on the screen

* renderer: check for font_surface instead of metric directly

This is safe and shorter

* renderer: fix indentation

* renderer: rename GLYPH_PER_ATLAS to GLYPHS_PER_ATLAS

* renderer: rename all GLYPH_PER_ATLAS correctly

* renderer: make utf8_to_codepoint slightly more durable

* renderer: fix compiler unsigned cast warning
2024-07-13 02:39:49 +02:00
takase1121 77d443c53d api/system: check if a window is created when firing DND events 2024-07-04 22:25:36 +08:00
takase1121 3d0344393c src/renwindow: correctly free texture and renderer 2024-07-04 21:57:33 +08:00
Guldoman 9dd4b81b39 refactor(mac): adapt `LITE_USE_SDL_RENDERER` scaling to new windowing system 2024-06-25 13:42:17 +08:00
Adam Harrison 1a293cd42e Fix window memory allocation bug. 2024-06-24 22:15:34 +08:00
Guldoman face6af0da
fix(dirmonitor): avoid calling the change callback multiple times in the same notification (#1824) 2024-06-22 16:36:27 -04:00
Jan 1a045e5e86
move window creation and management to Lua (#1751)
* remove scaling logic from font code
for the time being its been hardcoded to 1 for the non SDL Renderer basewin setup, so nothing is lost for non MacOS users.
will be revisited in the future when scaling is improved with SDL3 and moved into scripts.

* remove unused window_renderer argument from font functions

* move window logic to lua, pass window via argument

* rename window creation functions `*_create`, `*_destroy`, add real init

* Set active window when processing frame

* get size directly from RenWindow, get active window size from renderer

* correct reverted draw calls

* fix window not reappearing on restart

* add simple logic to persist the core window

* fix style

* add renwindow documentation

* make windows hidden by default again

* reorder ren_update_rects execution, add comment to note future work
2024-06-22 15:01:39 -04:00
Guldoman 290c7bc27f
Update font scale on monitor scale change for `RENDERER` backend (macOS) (#1650)
* Update font scale on monitor scale change for `RENDERER` backend (macOS)

* fix(renderer): check every font of a fontgroup for scale changes in `update_font_scale`

It is needed because fonts can be reused between groups and outside of them.
So if the first font of a group has already been scaled, we still need to check if the others still needs to be scaled.
2024-06-21 01:56:51 +02:00
Takase e74cee1419
api/system: fix newlines returned by get_clipboard (#1788) 2024-05-23 22:19:15 +02:00
Guldoman 7d876f81ad
build: fix dirmonitor backend selection (#1790)
When a backend was specified using meson, the relative source files weren't being added.
2024-05-17 17:19:39 +02:00
Andrei Vinca 0795a5dad4
Fix BufferSize in g_read for Windows (#1722) 2024-04-15 08:52:49 +08:00
Jan 5d264e14ef
Add SerenityOS platform support (#1745)
* Add SerenityOS platform support

* remove cpp_std default option
2024-03-18 13:55:01 -04:00
Takase 8090c1aa29
process: fix unitialized variables (#1719)
* process: fix potential unitialized variables

* process: fix brace initializer error on Windows
2024-02-05 09:23:24 -05:00
Chloé Vulquin 1a5fd97c20
Add system.setenv (#1706)
* add system.setenv

* document system.setenv

* system.setenv: use wide versions of functions on windows

* do not include processenv.h

* system.setenv: report failure, including of utfconv

* system.setenv: free utfconv output
2024-01-23 00:22:44 +01:00
Takase 0383e17475
process: style changes (#1709) 2024-01-21 10:18:32 +08:00
Chloé Vulquin e9a8dff884
Memory fixes (#1705)
* fix: free-before-init in renwin_init_surface when using sdl renderer

`ren->rensurface.surface` presupposes zero-initialized rensurface.
Rensurface was not actually zero-initialized.
It is now.

* fix: heap buffer overflow in process_env_free

`process_env_free` presupposed that it was null-terminated.
Pass length to free instead.

* use calloc instead of memset for zero-init

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

---------

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>
2024-01-20 08:02:46 +08:00
Jan badcaef13b
turn window_renderer into managed pointer (#1683)
* turn window_renderer into managed pointer
this will make it easier to move it into userdata in the future

* remove unused function, remove comment
2023-12-06 12:51:45 +01:00
Takase 142f0a17ba
feat(process): allow commands and envs on proces_start (#1477)
* feat(process): allow commands and envs on proces_start

* refactor(process): copy process arguments once whenever possible

Refactors the code to use an arglist type which is just lpCmdline on Windows
and a list in Linux.
The function automatically escapes the command when it is needed, avoiding
a second copy.

This also allows UTF-8 commands btw.

* fix(process): fix invalid dereference

* refactor(process): mark xstrdup as potentially unused

* feat(process): add parent process environment when launching process

* fix(process): fix operator precedence with array operators

* fix(process): fix segfault when freeing random memory

* fix(process): fix wrong check for setenv()

* fix(process): fix accidentally initializing an array by assignment

* fix(process): clear return value if success
2023-11-30 10:33:24 -05:00
Guldoman 3575898e62
Use x offset to define render command rect in `rencache_draw_text` (#1618)
* Return x offset for the first character in `ren_font_group_get_width`

* Use x offset to define render command rect in `rencache_draw_text`
2023-11-29 15:44:48 -05:00
Guldoman 8fd76d5d5c
Scale mouse coordinates by window scale (#1630)
* Update window scale on resize

* Scale mouse coordinates by window scale

* Avoid scaling mouse coordinates while using `LITE_USE_SDL_RENDERER`
2023-11-29 10:21:58 -05:00
Guldoman baa0c16e4d
Fix `dirmonitor` sorting issues (#1599)
* Use `PATHSEP` in path-related functions

* Don't stop on digits when getting the common part in `system.path_compare`

* Avoid sorting multiple times in `dirwatch.get_directory_files`

This also fixes the timeout detection in `recurse_pred`.
2023-11-29 09:55:38 -05:00
Guldoman a0ef2906a1
Limit `system.{sleep,wait_event}` to timeouts >= 0 (#1666)
Otherwise we might wait forever by mistake.
2023-11-29 09:07:33 +08:00
Takase 1620a92d54
fix(dirmonitor): deadlock if error handler jumps somewhere else (#1647)
* fix: deadlock if error handler jumps somewhere else

* docs(dirmonitor): fix wrong data type in error callback

* docs(dirmonitor): clarify coroutines and deadlocks

* docs(dirmonitor): wording

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

---------

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>
2023-10-21 19:17:49 +02:00
Guldoman 8a1a34c1ff
Set SDL hint to prefer software render driver (#1646) 2023-10-21 08:16:32 +02:00
Takase 5a5674d130
fix: dim rendering when antialiasing is turned off (#1641) 2023-10-14 16:16:36 -04:00
Guldoman 57dffbaf2a
Remove DPI detection for default `SCALE`
This often leads to `SCALE` values that are way off, and makes Lite XL 
unusable, so we now just default it to 1.
2023-09-30 16:48:38 +02:00
Takase a867beffdd
feat(src/renderer): unify fontgroup baseline (#1560)
* feat(src/renderer): unify fontgroup baseline

* fix(src/renderer): use the first font's baseline for the text run
2023-08-03 20:03:33 +02:00
Takase 76f23a2dc9
feat(src/renderer): stream fonts with SDL_RWops on all platforms (#1555)
* feat(src/renderer): stream fonts with SDL_RWops on all platforms

This fixes #1529 where the font itself carries the font file, which gets copied around.
This commit streams the file, so the file is not entirely in memory.

* style(src/renderer): use standard C types

* refactor(src/renderer): implement FT_Stream.close

* fix(src/renderer): fix SDL_RWops double free
2023-07-10 21:45:36 -04:00
Takase 99d72eaebd
style(src/renderer): use FreeType header names (#1554) 2023-07-09 02:42:40 +02:00
Guldoman f52f017424
Allow setting custom glyphset size (#1542)
* Properly set glyphset size

* Rename `MAX_GLYPHSET` to `GLYPHSET_SIZE`

* Use more appropriate types for font metrics
2023-07-03 23:50:28 -04:00
Jan dfaa7be4cc
Attach command buffer to Renderer Window (#1472) 2023-06-16 16:19:52 +02:00
Guldoman 8e71d3f050
Increase number of loadable glyphsets (#1524)
This should be enough to load every unicode codepoint.
2023-06-13 16:45:43 -04:00
Jefferson González 77f412e7e8
Close lua state when exiting on a runtime error (#1487)
* Close lua state when exiting on a runtime error

* This change allows calling the garbage collector before exiting the
  application for a cleaner shutdown.
* Components like the shared memory object on #1486 will have a better
  chance at destroying no longer needed resources.

* Overriden os.exit to always close the state

* Allow setting close param on os.exit override

* Simplified the os.exit override a bit more

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

---------

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>
2023-05-19 13:28:39 -04:00
takase1121 37b6803094
fix(renderer): fix memory leak when freeing glyphsets 2023-05-16 21:18:04 +08:00
takase1121 83399280f5
fix(rencache): fix compiler warning for printing size_t 2023-04-23 16:44:07 +08:00
Takase 246d4fc93f
fix(process): check for HANDLE_INVALID (#1475) 2023-04-18 21:02:10 -04:00
Jan 76ec16f299
Make `system.path_compare` more digit-aware (#1474)
This allows a human friendly sorting filenames with numbers in them
So
- asd1
- asd10
- asd2
becomes
- asd1
- asd2
- asd10
2023-04-18 14:55:25 -04:00
Takase a3a1c5d069
Process API improvements (again) (#1370)
* feat(process): add push_error
* refactor(process): use push_error for better errors
* style(process): consistent error messages
* refactor(process): reimplement process.strerror() with push_error
* refactor(process): implement close_fd only once
* refactor(process): rename process_handle to process_handle_t
* fix(process): prevent errors from a NULL error message
* refactor(process): refactor push_error into 2 functions
* fix(process): fix wrong error message
* fix(process): check if push_error_string actually pushed something
* refactor(process): make error messages descriptive
* fix(process): check for empty table instead of aborting
* refactor(process): make error messages descriptive on Windows
* refactor(process): rename process_stream_handle to process_stream_t
* refactor(process): fix wrong usage of process_handle_t
* fix(process): fix wrong type name
* refactor(process): incoporate kill_list_thread into process_kill_list_t
* refactor(process): make kill_list per-state data
2023-04-17 14:56:04 -04:00