diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5d9a388c..65fb450c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ on: inputs: version: description: Release Version - default: v2.1.1 + default: v2.1.3 required: true jobs: diff --git a/changelog.md b/changelog.md index b1d6c9d8..a488016d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,452 @@ # Changes Log +## [2.1.3] - 2024-01-29 + +This release addresses severe bugs not found in previous releases. + +### Fixes + +* Fix `doc:create-cursor-{previous,next}-line` with tabs + ([#1697](https://github.com/lite-xl/lite-xl/pull/1697)) + +* Fix heap buffer overflow and memory leaks in process and renderer API + ([#1705](https://github.com/lite-xl/lite-xl/pull/1705)) + +* Improve Python number syntax highlighting + ([#1704](https://github.com/lite-xl/lite-xl/pull/1704)) + +* Fix inconsistent NagView options on `doc:save` + ([#1696](https://github.com/lite-xl/lite-xl/pull/1696)) + +* Fix crashes with autoreload when files are deleted externally and replaced with a directory. + ([#1698](https://github.com/lite-xl/lite-xl/pull/1698)) + +* Improve JavaScript number syntax highlighting + ([#1710](https://github.com/lite-xl/lite-xl/pull/1710)) + +### Other Changes + +* Process API style changes + ([#1709](https://github.com/lite-xl/lite-xl/pull/1709)) + +## [2.1.2] - 2023-12-29 + +This release addresses some issues present in the previous release, +and improves the performance and stability of Lite XL. + +### New Features + +* The context menu in TreeView is now navigable with a keyboard. + ([#1338](https://github.com/lite-xl/lite-xl/pull/1338)) + +* A universal build of Lite XL is now available for macOS. + This build runs natively on both Intel and Apple Silicon macs. + ([#1458](https://github.com/lite-xl/lite-xl/pull/1458)) + +* Most Unicode characters should be displayed properly + if your fonts support them. + ([#1524](https://github.com/lite-xl/lite-xl/pull/1524)) + +* LogView will no longer scroll automatically if the user had scrolled. + The LogView will only scroll automatically when the user scrolls up + to the last entry. + ([#1546](https://github.com/lite-xl/lite-xl/pull/1546)) + +* When using different fonts (especially fonts that render different scripts), + the letters will be aligned vertically. + ([#1560](https://github.com/lite-xl/lite-xl/pull/1560)) + +* Unsaved named files are now saved in the workspace. + ([#1597](https://github.com/lite-xl/lite-xl/pull/1597)) + +* macOS builds are now signed with a developer certificate. + This allows the user to right click the application in Finder and execute + it directly. + ([#1656](https://github.com/lite-xl/lite-xl/pull/1656)) + +### Performance Improvements + +* Allow command buffer to be expanded. + ([#1297](https://github.com/lite-xl/lite-xl/pull/1297)) + +* Use table.move to implement `common.splice`. + ([#1324](https://github.com/lite-xl/lite-xl/pull/1324)) + +* Create renderer only when it doesn't exist. + ([#1315](https://github.com/lite-xl/lite-xl/pull/1315)) + +* Avoid drawing hidden text in `DocView:draw_line_text`. + ([#1298](https://github.com/lite-xl/lite-xl/pull/1298)) + +* Don't calculate widths per-uft8-char when not needed. + ([#1409](https://github.com/lite-xl/lite-xl/pull/1409)) + +* Allow tokenizer to pause and resume in the middle of a line. + ([#1444](https://github.com/lite-xl/lite-xl/pull/1444)) + +* Optimize CI build times on MSYS2. + ([#1435](https://github.com/lite-xl/lite-xl/pull/1435)) + +* Significant memory usage improvements when using huge fonts on Windows. + ([#1555](https://github.com/lite-xl/lite-xl/pull/1555)) + +* Optimize background tasks response time. + ([#1601](https://github.com/lite-xl/lite-xl/pull/1601)) + +### Backward Incompatible Changes + +* The native plugin API is now usable on multiple source files, + without causing any duplicated symbol errors during compilation. + Plugins using the new plugin API header must define `LITE_XL_PLUGIN_ENTRYPOINT` + before importing the header, in one of their source files. + ([#1335](https://github.com/lite-xl/lite-xl/pull/1335)) + +* The native plugin API header now follows the Lua 5.4 API. + Previously, the plugin API header followed the Lua 5.2 API. + ([#1436](https://github.com/lite-xl/lite-xl/pull/1436)) + +* On Linux, `process.start()` will now throw an error if `execv()` fails. + ([#1363](https://github.com/lite-xl/lite-xl/pull/1363)) + +* Lite XL will use the default `SCALE` of 1 due to unreliable display + scale detection. This may be fixed in a later version of Lite XL. + Set the `LITE_SCALE` environment variable to override this value. + +### Fixes + +* Fix minor typos in user module + ([#1289](https://github.com/lite-xl/lite-xl/pull/1289)) + +* Do not allow users to create an empty font group + ([#1303](https://github.com/lite-xl/lite-xl/pull/1303)) + +* Fix a memory leak + ([#1305](https://github.com/lite-xl/lite-xl/pull/1305)) + +* Make dirwatch sorting compatible with what file_bisect expects + ([#1300](https://github.com/lite-xl/lite-xl/pull/1300)) + +* Handle readlink errors + ([#1292](https://github.com/lite-xl/lite-xl/pull/1292)) + +* Disable horizontal scrolling when linewrapping is enabled + ([#1309](https://github.com/lite-xl/lite-xl/pull/1309)) + +* Update widgets install location + +* Add missing luaL_typeerror symbol to plugin API + ([#1313](https://github.com/lite-xl/lite-xl/pull/1313)) + +* Defer lua error until after cleanup + ([#1310](https://github.com/lite-xl/lite-xl/pull/1310)) + +* Make empty groups in regex.gmatch return their offset + ([#1325](https://github.com/lite-xl/lite-xl/pull/1325)) + +* Add missing header declaration + +* Fix msys build now requiring ca-certificates + ([#1348](https://github.com/lite-xl/lite-xl/pull/1348)) + +* Fix path to macOS arm64 cross file in GitHub workflows + +* Fix Doc contextmenu not registering commands if scale plugin is not found + ([#1338](https://github.com/lite-xl/lite-xl/pull/1338)) + +* Fix TreeView contextmenu commands not working if the mouse hovers DocView + ([#1338](https://github.com/lite-xl/lite-xl/pull/1338)) + +* Fix incorrect contextmenu predicate + ([#1338](https://github.com/lite-xl/lite-xl/pull/1338)) + +* Properly rescale NagView on scale change + ([#1379](https://github.com/lite-xl/lite-xl/pull/1379)) + +* Scale plugin also rescales `style.expanded_scrollbar_size` + ([#1380](https://github.com/lite-xl/lite-xl/pull/1380)) + +* Improve DocView:get_visible_line_range precision + ([#1382](https://github.com/lite-xl/lite-xl/pull/1382)) + +* Fix up some post 5.1/JIT Symbols + ([#1385](https://github.com/lite-xl/lite-xl/pull/1385)) + +* Fix incorrect x_offset if opened docs have different tab sizes + ([#1383](https://github.com/lite-xl/lite-xl/pull/1383)) + +* Use correct view for scrolling to find-replace:repeat-find results + ([#1400](https://github.com/lite-xl/lite-xl/pull/1400)) + +* Improve text width calculation precision + ([#1408](https://github.com/lite-xl/lite-xl/pull/1408)) + +* Add asynchronous process reaping + ([#1412](https://github.com/lite-xl/lite-xl/pull/1412)) + +* Fix cursors positions when deleting multiple selections + ([#1393](https://github.com/lite-xl/lite-xl/pull/1393), + [#1463](https://github.com/lite-xl/lite-xl/pull/1463)) + +* Fix invalid EXEFILE and EXEDIR on Windows + ([#1396](https://github.com/lite-xl/lite-xl/pull/1396)) + +* Fix `os.getenv()` not supporting UTF-8 output + ([#1397](https://github.com/lite-xl/lite-xl/pull/1397)) + +* Fix differing stacktrace on stdout and file + ([#1404](https://github.com/lite-xl/lite-xl/pull/1404)) + +* Update api_require to expose more symbols + ([#1437](https://github.com/lite-xl/lite-xl/pull/1437)) + +* Make system.path_compare more case-aware + ([#1457](https://github.com/lite-xl/lite-xl/pull/1457)) + +* Fix for api_require wrong macro && conditions + ([#1465](https://github.com/lite-xl/lite-xl/pull/1465)) + +* Merge carets after doc:move-to-{previous,next}-char + ([#1462](https://github.com/lite-xl/lite-xl/pull/1462)) + +* Process API improvements (again) + ([#1370](https://github.com/lite-xl/lite-xl/pull/1370)) + +* Make system.path_compare more digit-aware + ([#1474](https://github.com/lite-xl/lite-xl/pull/1474)) + +* Check for HANDLE_INVALID in Process API + ([#1475](https://github.com/lite-xl/lite-xl/pull/1475)) + +* Fix linewrapping bug to do with wordwrapping + +* Fix compiler warning for printing size_t in rencache.c + +* Return error string from C searcher + +* Restore horizontal scroll position after scale change + ([#494](https://github.com/lite-xl/lite-xl/pull/494)) + +* Fix memory leak in renderer.c when freeing glyphsets + +* Move lineguide below blinking cursor + ([#1511](https://github.com/lite-xl/lite-xl/pull/1511)) + +* Close lua state when exiting on a runtime error + ([#1487](https://github.com/lite-xl/lite-xl/pull/1487)) + +* Mark linewrapping open_files table as weak + +* Don't use core.status_view if not yet initialized when logging + +* Revert "core syntax: strip the path from filename on syntax.get ([#1168](https://github.com/lite-xl/lite-xl/pull/1168))" + ([#1322](https://github.com/lite-xl/lite-xl/pull/1322)) + +* Make Doc:sanitize_position return a more appropriate col + ([#1469](https://github.com/lite-xl/lite-xl/pull/1469)) + +* Skip checking files if no filename was provided to syntax.get + +* Normalize stroke before adding keybind + ([#1334](https://github.com/lite-xl/lite-xl/pull/1334)) + +* Make DocView aware of scrollbars sizes + ([#1177](https://github.com/lite-xl/lite-xl/pull/1177)) + +* Normalize strokes in fixed order + ([#1572](https://github.com/lite-xl/lite-xl/pull/1572)) + +* Defer core:open-log until everything is loaded + ([#1585](https://github.com/lite-xl/lite-xl/pull/1585)) + +* Fix returned percent when clicking the Scrollbar track + +* Fix C++14 digit separators + ([#1593](https://github.com/lite-xl/lite-xl/pull/1593)) + +* Make linewrapping consider the expanded Scrollbar size + +* Fix dimmed text when antialiasing is turned off + ([#1641](https://github.com/lite-xl/lite-xl/pull/1641)) + +* Mark unsaved named files as dirty + ([#1598](https://github.com/lite-xl/lite-xl/pull/1598)) + +* Make `common.serialize()` locale-independent and nan/inf compatible + ([#1640](https://github.com/lite-xl/lite-xl/pull/1640)) + +* Ignore keypresses during IME composition + ([#1573](https://github.com/lite-xl/lite-xl/pull/1573)) + +* Fix deadlock if error handler jumps somewhere else + ([#1647](https://github.com/lite-xl/lite-xl/pull/1647)) + +* Avoid considering single spaces in detectindent + ([#1595](https://github.com/lite-xl/lite-xl/pull/1595)) + +* Fix deleting indentation with multiple cursors + ([#1670](https://github.com/lite-xl/lite-xl/pull/1670)) + +* Fix `set_target_size` passing the wrong value to plugins + ([#1657](https://github.com/lite-xl/lite-xl/pull/1657)) + +* Limit `system.{sleep,wait_event}` to `timeouts >= 0` + ([#1666](https://github.com/lite-xl/lite-xl/pull/1666)) + +* Fix running core.step when receiving an event while not waiting + ([#1667](https://github.com/lite-xl/lite-xl/pull/1667)) + +* Fix dirmonitor sorting issues + ([#1599](https://github.com/lite-xl/lite-xl/pull/1599)) + +* Scale mouse coordinates by window scale + ([#1630](https://github.com/lite-xl/lite-xl/pull/1630)) + +* Made coroutines make more sense, and fixed a bug + ([#1381](https://github.com/lite-xl/lite-xl/pull/1381)) + +* Fix selecting newlines with `find-replace:select-add-{next,all}` + ([#1608](https://github.com/lite-xl/lite-xl/pull/1608)) + +* Fix editing after undo not clearing the change id + ([#1574](https://github.com/lite-xl/lite-xl/pull/1574)) + +* Fix language_js regex constant detection + ([#1581](https://github.com/lite-xl/lite-xl/pull/1581)) + +* Fix patterns starting with `^` in tokenizer + ([#1645](https://github.com/lite-xl/lite-xl/pull/1645)) + +* Use x offset to define render command rect in rencache_draw_text + ([#1618](https://github.com/lite-xl/lite-xl/pull/1618)) + +* Improve font/color change detection in `language_md` + ([#1614](https://github.com/lite-xl/lite-xl/pull/1614)) + +* Allow long commands and envs on process_start + ([#1477](https://github.com/lite-xl/lite-xl/pull/1477)) + +* Fix typo in `drawwhitespace.lua` + +* Fix NagBar save failed message + ([#1678](https://github.com/lite-xl/lite-xl/pull/1678)) + +* Fix typo in `drawwhitespace.lua` + +* Add autocompletion to multicursor + ([#1394](https://github.com/lite-xl/lite-xl/pull/1394)) + +### Other Changes + +* Make api_require's nodes const + ([#1296](https://github.com/lite-xl/lite-xl/pull/1296)) + +* Don't set a value twice + ([#1306](https://github.com/lite-xl/lite-xl/pull/1306)) + +* Center title and version in emptyview + ([#1311](https://github.com/lite-xl/lite-xl/pull/1311)) + +* Use master branch for packaging plugins for addons release + +* Reorganize resources folder and add wasm target + ([#1244](https://github.com/lite-xl/lite-xl/pull/1244)) + +* Replace uses of SDL_Window with RenWindow + ([#1319](https://github.com/lite-xl/lite-xl/pull/1319)) + +* Update dummy dirmonitor method signature to match prototypes + +* Remove static libgcc from meson + ([#1290](https://github.com/lite-xl/lite-xl/pull/1290)) + +* Pass RenWindow by argument + ([#1321](https://github.com/lite-xl/lite-xl/pull/1321)) + +* Get rid of annoying forward slash on windows + ([#1345](https://github.com/lite-xl/lite-xl/pull/1345)) + +* Improve plugins config table handling + ([#1356](https://github.com/lite-xl/lite-xl/pull/1356)) + +* Add manifest on Windows + ([#1405](https://github.com/lite-xl/lite-xl/pull/1405)) + +* Split Command struct into different structs for each command type + ([#1407](https://github.com/lite-xl/lite-xl/pull/1407)) + +* Move SetProcessDPIAware to manifests + ([#1413](https://github.com/lite-xl/lite-xl/pull/1413)) + +* Use clipping functions provided by SDL + ([#1426](https://github.com/lite-xl/lite-xl/pull/1426)) + +* Aggregate SDL_Surfaces and their scale in RenSurface + ([#1429](https://github.com/lite-xl/lite-xl/pull/1429)) + +* Disable trimwhitespace and drawwhitespace via their configs + ([#1446](https://github.com/lite-xl/lite-xl/pull/1446)) + +* Bump dependency versions + ([#1434](https://github.com/lite-xl/lite-xl/pull/1434)) + +* Improvements to cross-compilation + ([#1458](https://github.com/lite-xl/lite-xl/pull/1458)) + +* Move native plugin API header into include/ + ([#1440](https://github.com/lite-xl/lite-xl/pull/1440)) + +* Build releases with Ubuntu 18.04 container + ([#1460](https://github.com/lite-xl/lite-xl/pull/1460)) + +* Update GitHub Actions dependencies + +* Make all parameters for set_window_hit_test optional in documentation + +* Attach command buffer to Renderer Window + ([#1472](https://github.com/lite-xl/lite-xl/pull/1472)) + +* Fix comment typo in object.lua + ([#1541](https://github.com/lite-xl/lite-xl/pull/1541)) + +* Allow setting custom glyphset size + ([#1542](https://github.com/lite-xl/lite-xl/pull/1542)) + +* Use FreeType header names in renderer.c + ([#1554](https://github.com/lite-xl/lite-xl/pull/1554)) + +* Add documentation for core.common + ([#1510](https://github.com/lite-xl/lite-xl/pull/1510)) + +* Document missing parameter for system.path_compare + ([#1566](https://github.com/lite-xl/lite-xl/pull/1566)) + +* Add documentation for core.command + ([#1564](https://github.com/lite-xl/lite-xl/pull/1564)) + +* Update the *Installing prebuild* section in README.md + ([#1548](https://github.com/lite-xl/lite-xl/pull/1548)) + +* Update README.md to remove previously installed files + prior to installing a new version + +* Use lite-xl Build Box to build releases + ([#1571](https://github.com/lite-xl/lite-xl/pull/1571)) + +* Use Lua wrap by default + ([#1481](https://github.com/lite-xl/lite-xl/pull/1481)) + +* Add documentation for contextmenu + ([#1567](https://github.com/lite-xl/lite-xl/pull/1567)) + +* Use dmgbuild to create DMGs + ([#1664](https://github.com/lite-xl/lite-xl/pull/1664)) + +* Un-hardcode lua subproject detection and update dependencies + ([#1676](https://github.com/lite-xl/lite-xl/pull/1676)) + +* Make license time-independent + ([#1655](https://github.com/lite-xl/lite-xl/pull/1655)) + ## [2.1.1] - 2022-12-29 ### New Features @@ -1004,6 +1451,8 @@ A new global variable `USERDIR` is exposed to point to the user's directory. - subpixel font rendering with gamma correction +[2.1.3]: https://github.com/lite-xl/lite-xl/releases/tag/v2.1.3 +[2.1.2]: https://github.com/lite-xl/lite-xl/releases/tag/v2.1.2 [2.1.1]: https://github.com/lite-xl/lite-xl/releases/tag/v2.1.1 [2.1.0]: https://github.com/lite-xl/lite-xl/releases/tag/v2.1.0 [2.0.5]: https://github.com/lite-xl/lite-xl/releases/tag/v2.0.5 diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index aca5fc65..65c92e28 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -44,8 +44,8 @@ local function save(filename) else core.error(err) core.nag_view:show("Saving failed", string.format("Couldn't save file \"%s\". Do you want to save to another location?", doc().filename), { - { text = "No", default_no = true }, - { text = "Yes", default_yes = true } + { text = "Yes", default_yes = true }, + { text = "No", default_no = true } }, function(item) if item.text == "Yes" then core.add_thread(function() @@ -93,11 +93,14 @@ local function cut_or_copy(delete) system.set_clipboard(full_text) end -local function split_cursor(direction) +local function split_cursor(dv, direction) local new_cursors = {} - for _, line1, col1 in doc():get_selections() do - if line1 + direction >= 1 and line1 + direction <= #doc().lines then - table.insert(new_cursors, { line1 + direction, col1 }) + local dv_translate = direction < 0 + and DocView.translate.previous_line + or DocView.translate.next_line + for _, line1, col1 in dv.doc:get_selections() do + if line1 + direction >= 1 and line1 + direction <= #dv.doc.lines then + table.insert(new_cursors, { dv_translate(dv.doc, line1, col1, dv) }) end end -- add selections in the order that will leave the "last" added one as doc.last_selection @@ -107,7 +110,7 @@ local function split_cursor(direction) end for i = start, stop, direction do local v = new_cursors[i] - doc():add_selection(v[1], v[2]) + dv.doc:add_selection(v[1], v[2]) end core.blink_reset() end @@ -626,12 +629,12 @@ local commands = { end, ["doc:create-cursor-previous-line"] = function(dv) - split_cursor(-1) + split_cursor(dv, -1) dv.doc:merge_cursors() end, ["doc:create-cursor-next-line"] = function(dv) - split_cursor(1) + split_cursor(dv, 1) dv.doc:merge_cursors() end diff --git a/data/core/config.lua b/data/core/config.lua index 88f8d96d..4f32f244 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -257,14 +257,7 @@ config.skip_plugins_version = false -- holds the plugins real config table local plugins_config = {} ----A table containing configuration for all the plugins. ---- ----This is a metatable that automaticaly creates a minimal ----configuration when a plugin is initially configured. ----Each plugins will then call `common.merge()` to get the finalized ----plugin config. ----Do not use raw operations on this table. ----@type table +-- virtual representation of plugins config table config.plugins = {} -- allows virtual access to the plugins config table diff --git a/data/core/init.lua b/data/core/init.lua index db1e10a3..9bc63838 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1412,10 +1412,11 @@ local run_threads = coroutine.wrap(function() else core.threads[k] = nil end - else - wait = wait or (1/30) + elseif wait then thread.wake = system.get_time() + wait minimal_time_to_wake = math.min(minimal_time_to_wake, wait) + else + minimal_time_to_wake = 0 end else minimal_time_to_wake = math.min(minimal_time_to_wake, thread.wake - system.get_time()) diff --git a/data/core/modkeys-generic.lua b/data/core/modkeys-generic.lua index 613813dc..c1642966 100644 --- a/data/core/modkeys-generic.lua +++ b/data/core/modkeys-generic.lua @@ -13,6 +13,6 @@ modkeys.map = { ["right windows"] = "super" } -modkeys.keys = { "ctrl", "shift", "alt", "altgr", "super" } +modkeys.keys = { "ctrl", "shift", "alt", "altgr" } return modkeys diff --git a/data/core/tokenizer.lua b/data/core/tokenizer.lua index a027712f..5d00dcf1 100644 --- a/data/core/tokenizer.lua +++ b/data/core/tokenizer.lua @@ -139,6 +139,8 @@ function tokenizer.tokenize(incoming_syntax, text, state, resume) return { "normal", text }, state end + state = state or string.char(0) + if resume then res = resume.res -- Remove "incomplete" tokens diff --git a/data/plugins/autoreload.lua b/data/plugins/autoreload.lua index 8286d62f..f1ba6e0d 100644 --- a/data/plugins/autoreload.lua +++ b/data/plugins/autoreload.lua @@ -69,7 +69,7 @@ function dirwatch:check(change_callback, ...) for _, doc in ipairs(core.docs) do if doc.abs_filename and (dir == common.dirname(doc.abs_filename) or dir == doc.abs_filename) then local info = system.get_file_info(doc.filename or "") - if info and times[doc] ~= info.modified then + if info and info.type == "file" and times[doc] ~= info.modified then if not doc:is_dirty() and not config.plugins.autoreload.always_show_nagview then reload_doc(doc) else diff --git a/data/plugins/language_js.lua b/data/plugins/language_js.lua index 307aeecf..2eb38741 100644 --- a/data/plugins/language_js.lua +++ b/data/plugins/language_js.lua @@ -57,18 +57,18 @@ syntax.add { comment = "//", block_comment = { "/*", "*/" }, patterns = { - { pattern = "//.*", type = "comment" }, - { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = "//.*", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, { regex = regex_pattern, syntax = inner_regex_syntax, type = {"string", "string"} }, - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = { "`", "`", '\\' }, type = "string" }, - { pattern = "0x[%da-fA-F_]+n?()%s*()/?", type = {"number", "normal", "operator"} }, - { pattern = "-?%d+[%d%.eE_n]*()%s*()/?", type = {"number", "normal", "operator"} }, - { pattern = "-?%.?%d+()%s*()/?", type = {"number", "normal", "operator"} }, - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, - { pattern = "[%a_][%w_]*%f[(]", type = "function" }, - { pattern = "[%a_][%w_]*()%s*()/?", type = {"symbol", "normal", "operator"} }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { "`", "`", '\\' }, type = "string" }, + { pattern = "-?0[xXbBoO][%da-fA-F_]+n?()%s*()/?", type = {"number", "normal", "operator"} }, + { pattern = "-?%d+[%d%.eE_n]*()%s*()/?", type = {"number", "normal", "operator"} }, + { pattern = "-?%.?%d+()%s*()/?", type = {"number", "normal", "operator"} }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { pattern = "[%a_][%w_]*()%s*()/?", type = {"symbol", "normal", "operator"} }, }, symbols = { ["async"] = "keyword", diff --git a/data/plugins/language_python.lua b/data/plugins/language_python.lua index 743e990a..220ddd54 100644 --- a/data/plugins/language_python.lua +++ b/data/plugins/language_python.lua @@ -16,8 +16,8 @@ syntax.add { { pattern = { "[ruU]?'''", "'''", '\\' }, type = "string" }, { pattern = { '[ruU]?"', '"', '\\' }, type = "string" }, { pattern = { "[ruU]?'", "'", '\\' }, type = "string" }, - { pattern = "0x[%da-fA-F]+", type = "number" }, - { pattern = "-?%d+[%d%.eE]*", type = "number" }, + { pattern = "-?0[xboXBO][%da-fA-F_]+",type = "number" }, + { pattern = "-?%d+[%d%.eE_]*", type = "number" }, { pattern = "-?%.?%d+", type = "number" }, { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, { pattern = "[%a_][%w_]*%f[(]", type = "function" }, diff --git a/meson.build b/meson.build index f0614cc8..f01e702c 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('lite-xl', ['c'], - version : '2.1.1', + version : '2.1.3', license : 'MIT', meson_version : '>= 0.56', default_options : [ @@ -101,7 +101,7 @@ if not get_option('source-only') endforeach else lua_dep = dependency('', fallback: ['lua', 'lua_dep'], required : true, - default_options: default_fallback_options + ['default_library=static', 'line_editing=disabled', 'interpreter=false'] + default_options: default_fallback_options + ['default_library=static', 'line_editing=false', 'interpreter=false'] ) endif diff --git a/resources/include/lite_xl_plugin_api.h b/resources/include/lite_xl_plugin_api.h index bae9efdd..fa31e350 100644 --- a/resources/include/lite_xl_plugin_api.h +++ b/resources/include/lite_xl_plugin_api.h @@ -31,14 +31,9 @@ * An example command would be: gcc -shared -o xxxxx.so xxxxx.c * You must not link to ANY lua library to avoid symbol collision. * - * This file contains stock configuration for a typical installation of Lua 5.4.6. + * This file contains stock configuration for a typical installation of Lua 5.4. * DO NOT MODIFY ANYTHING. MODIFYING STUFFS IN HERE WILL BREAK * COMPATIBILITY WITH LITE XL AND CAUSE UNDEBUGGABLE BUGS. - * - * For reference, here are a list of permalinks to previous version of this file that targets an older version of Lua. - * If you don't need functionalities offered by the new version, use the OLDEST FILE for backwards compatibility. - * - * - Lua 5.4.4: https://github.com/lite-xl/lite-xl/blob/397973067f14420b26e3b20a238a50016c0b75e2/resources/include/lite_xl_plugin_api.h **/ #ifndef LITE_XL_PLUGIN_API #define LITE_XL_PLUGIN_API @@ -1033,7 +1028,6 @@ extern const char lua_ident[]; SYMBOL_DECLARE(lua_State *, lua_newstate, lua_Alloc f, void *ud) SYMBOL_DECLARE(void, lua_close, lua_State *L) SYMBOL_DECLARE(lua_State *, lua_newthread, lua_State *L) -SYMBOL_DECLARE(int, lua_closethread, lua_State *L, lua_State *from) SYMBOL_DECLARE(int, lua_resetthread, lua_State *L) SYMBOL_DECLARE(lua_CFunction, lua_atpanic, lua_State *L, lua_CFunction panicf) @@ -1745,9 +1739,6 @@ SYMBOL_WRAP_DECL(void, lua_close, lua_State *L) { SYMBOL_WRAP_DECL(lua_State *, lua_newthread, lua_State *L) { return SYMBOL_WRAP_CALL(lua_newthread, L); } -SYMBOL_WRAP_DECL(int, lua_closethread, lua_State *L, lua_State *from) { - return SYMBOL_WRAP_CALL(lua_closethread, L, from); -} SYMBOL_WRAP_DECL(int, lua_resetthread, lua_State *L) { return SYMBOL_WRAP_CALL(lua_resetthread, L); } @@ -2360,7 +2351,6 @@ void lite_xl_plugin_init(void *XL) { IMPORT_SYMBOL(lua_newstate, lua_State *, lua_Alloc f, void *ud); IMPORT_SYMBOL(lua_close, void, lua_State *L); IMPORT_SYMBOL(lua_newthread, lua_State *, lua_State *L); - IMPORT_SYMBOL(lua_closethread, int, lua_State *L, lua_State *from); IMPORT_SYMBOL(lua_resetthread, int, lua_State *L); IMPORT_SYMBOL(lua_atpanic, lua_CFunction, lua_State *L, lua_CFunction panicf); IMPORT_SYMBOL(lua_version, lua_Number, lua_State *L); diff --git a/resources/linux/com.lite_xl.LiteXL.appdata.xml b/resources/linux/com.lite_xl.LiteXL.appdata.xml index 8e033d03..5285cd66 100644 --- a/resources/linux/com.lite_xl.LiteXL.appdata.xml +++ b/resources/linux/com.lite_xl.LiteXL.appdata.xml @@ -29,6 +29,6 @@ - + diff --git a/resources/windows/001-lua-unicode.diff b/resources/windows/001-lua-unicode.diff index 9252666f..6617ad26 100644 --- a/resources/windows/001-lua-unicode.diff +++ b/resources/windows/001-lua-unicode.diff @@ -1,6 +1,6 @@ -diff -ruN lua-5.4.4/meson.build lua-5.4.4-patched/meson.build ---- lua-5.4.4/meson.build Wed Feb 22 18:16:56 2023 -+++ lua-5.4.4-patched/meson.build Wed Feb 22 04:10:01 2023 +diff -ruN lua-5.4.4\meson.build lua-5.4.4-patched\meson.build +--- lua-5.4.4\meson.build Wed Feb 22 18:16:56 2023 ++++ lua-5.4.4-patched\meson.build Wed Feb 22 04:10:01 2023 @@ -85,6 +85,7 @@ 'src/lutf8lib.c', 'src/lvm.c', @@ -9,9 +9,9 @@ diff -ruN lua-5.4.4/meson.build lua-5.4.4-patched/meson.build dependencies: lua_lib_deps, version: meson.project_version(), soversion: lua_versions[0] + '.' + lua_versions[1], -diff -ruN lua-5.4.4/src/luaconf.h lua-5.4.4-patched/src/luaconf.h ---- lua-5.4.4/src/luaconf.h Thu Jan 13 19:24:43 2022 -+++ lua-5.4.4-patched/src/luaconf.h Wed Feb 22 04:10:02 2023 +diff -ruN lua-5.4.4\src\luaconf.h lua-5.4.4-patched\src\luaconf.h +--- lua-5.4.4\src\luaconf.h Thu Jan 13 19:24:43 2022 ++++ lua-5.4.4-patched\src\luaconf.h Wed Feb 22 04:10:02 2023 @@ -782,5 +782,15 @@ @@ -28,9 +28,9 @@ diff -ruN lua-5.4.4/src/luaconf.h lua-5.4.4-patched/src/luaconf.h + #endif -diff -ruN lua-5.4.4/src/Makefile lua-5.4.4-patched/src/Makefile ---- lua-5.4.4/src/Makefile Thu Jul 15 22:01:52 2021 -+++ lua-5.4.4-patched/src/Makefile Wed Feb 22 04:10:02 2023 +diff -ruN lua-5.4.4\src\Makefile lua-5.4.4-patched\src\Makefile +--- lua-5.4.4\src\Makefile Thu Jul 15 22:01:52 2021 ++++ lua-5.4.4-patched\src\Makefile Wed Feb 22 04:10:02 2023 @@ -33,7 +33,7 @@ PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris @@ -40,9 +40,9 @@ diff -ruN lua-5.4.4/src/Makefile lua-5.4.4-patched/src/Makefile LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) -diff -ruN lua-5.4.4/src/utf8_wrappers.c lua-5.4.4-patched/src/utf8_wrappers.c ---- lua-5.4.4/src/utf8_wrappers.c Thu Jan 01 08:00:00 1970 -+++ lua-5.4.4-patched/src/utf8_wrappers.c Wed Feb 22 18:13:45 2023 +diff -ruN lua-5.4.4\src\utf8_wrappers.c lua-5.4.4-patched\src\utf8_wrappers.c +--- lua-5.4.4\src\utf8_wrappers.c Thu Jan 01 08:00:00 1970 ++++ lua-5.4.4-patched\src\utf8_wrappers.c Wed Feb 22 18:13:45 2023 @@ -0,0 +1,129 @@ +/** + * Wrappers to provide Unicode (UTF-8) support on Windows. @@ -173,9 +173,9 @@ diff -ruN lua-5.4.4/src/utf8_wrappers.c lua-5.4.4-patched/src/utf8_wrappers.c + return env_value; +} +#endif -diff -ruN lua-5.4.4/src/utf8_wrappers.h lua-5.4.4-patched/src/utf8_wrappers.h ---- lua-5.4.4/src/utf8_wrappers.h Thu Jan 01 08:00:00 1970 -+++ lua-5.4.4-patched/src/utf8_wrappers.h Wed Feb 22 18:09:48 2023 +diff -ruN lua-5.4.4\src\utf8_wrappers.h lua-5.4.4-patched\src\utf8_wrappers.h +--- lua-5.4.4\src\utf8_wrappers.h Thu Jan 01 08:00:00 1970 ++++ lua-5.4.4-patched\src\utf8_wrappers.h Wed Feb 22 18:09:48 2023 @@ -0,0 +1,46 @@ +/** + * Wrappers to provide Unicode (UTF-8) support on Windows. diff --git a/src/api/process.c b/src/api/process.c index 2ab24317..7a1aa73b 100644 --- a/src/api/process.c +++ b/src/api/process.c @@ -563,14 +563,13 @@ static int process_env_add(process_env_t *env_list, size_t *env_len, const char } -static void process_env_free(process_env_t *list) { +static void process_env_free(process_env_t *list, size_t list_len) { if (!*list) return; -#ifdef _WIN32 - free(*list); -#else - for (size_t i = 0; (*list)[i]; i++) free((*list)[i]); - free(*list); +#ifndef _WIN32 + for (size_t i = 0; i < list_len; i++) + free((*list)[i]); #endif + free(*list); *list = NULL; } @@ -833,7 +832,7 @@ static int process_start(lua_State* L) { } } process_arglist_free(&arglist); - process_env_free(&env_vars); + process_env_free(&env_vars, env_vars_len); if (retval == -1) return lua_error(L); @@ -975,10 +974,7 @@ static int self_signal(lua_State* L, signal_e sig) { static int f_terminate(lua_State* L) { return self_signal(L, SIGNAL_TERM); } static int f_kill(lua_State* L) { return self_signal(L, SIGNAL_KILL); } static int f_interrupt(lua_State* L) { return self_signal(L, SIGNAL_INTERRUPT); } -<<<<<<< HEAD -======= ->>>>>>> master static int f_gc(lua_State* L) { process_kill_list_t *list = NULL; process_kill_t *p = NULL; diff --git a/src/api/renderer.c b/src/api/renderer.c index 2d8aaca4..31862643 100644 --- a/src/api/renderer.c +++ b/src/api/renderer.c @@ -90,7 +90,7 @@ static int f_font_load(lua_State *L) { return ret_code; RenFont** font = lua_newuserdata(L, sizeof(RenFont*)); - *font = ren_font_load(window_renderer, filename, size, antialiasing, hinting, style); + *font = ren_font_load(&window_renderer, filename, size, antialiasing, hinting, style); if (!*font) return luaL_error(L, "failed to load font"); luaL_setmetatable(L, API_TYPE_FONT); @@ -130,7 +130,7 @@ static int f_font_copy(lua_State *L) { } for (int i = 0; i < FONT_FALLBACK_MAX && fonts[i]; ++i) { RenFont** font = lua_newuserdata(L, sizeof(RenFont*)); - *font = ren_font_copy(window_renderer, fonts[i], size, antialiasing, hinting, style); + *font = ren_font_copy(&window_renderer, fonts[i], size, antialiasing, hinting, style); if (!*font) return luaL_error(L, "failed to copy font"); luaL_setmetatable(L, API_TYPE_FONT); @@ -198,7 +198,7 @@ static int f_font_get_width(lua_State *L) { size_t len; const char *text = luaL_checklstring(L, 2, &len); - lua_pushnumber(L, ren_font_group_get_width(window_renderer, fonts, text, len, NULL)); + lua_pushnumber(L, ren_font_group_get_width(&window_renderer, fonts, text, len, NULL)); return 1; } @@ -217,7 +217,7 @@ static int f_font_get_size(lua_State *L) { static int f_font_set_size(lua_State *L) { RenFont* fonts[FONT_FALLBACK_MAX]; font_retrieve(L, fonts, 1); float size = luaL_checknumber(L, 2); - ren_font_group_set_size(window_renderer, fonts, size); + ren_font_group_set_size(&window_renderer, fonts, size); return 0; } @@ -276,7 +276,7 @@ static int f_show_debug(lua_State *L) { static int f_get_size(lua_State *L) { int w, h; - ren_get_size(window_renderer, &w, &h); + ren_get_size(&window_renderer, &w, &h); lua_pushnumber(L, w); lua_pushnumber(L, h); return 2; @@ -284,13 +284,13 @@ static int f_get_size(lua_State *L) { static int f_begin_frame(UNUSED lua_State *L) { - rencache_begin_frame(window_renderer); + rencache_begin_frame(&window_renderer); return 0; } static int f_end_frame(UNUSED lua_State *L) { - rencache_end_frame(window_renderer); + rencache_end_frame(&window_renderer); // clear the font reference table lua_newtable(L); lua_rawseti(L, LUA_REGISTRYINDEX, RENDERER_FONT_REF); @@ -311,7 +311,7 @@ static int f_set_clip_rect(lua_State *L) { lua_Number w = luaL_checknumber(L, 3); lua_Number h = luaL_checknumber(L, 4); RenRect rect = rect_to_grid(x, y, w, h); - rencache_set_clip_rect(window_renderer, rect); + rencache_set_clip_rect(&window_renderer, rect); return 0; } @@ -323,7 +323,7 @@ static int f_draw_rect(lua_State *L) { lua_Number h = luaL_checknumber(L, 4); RenRect rect = rect_to_grid(x, y, w, h); RenColor color = checkcolor(L, 5, 255); - rencache_draw_rect(window_renderer, rect, color); + rencache_draw_rect(&window_renderer, rect, color); return 0; } @@ -348,7 +348,7 @@ static int f_draw_text(lua_State *L) { double x = luaL_checknumber(L, 3); int y = luaL_checknumber(L, 4); RenColor color = checkcolor(L, 5, 255); - x = rencache_draw_text(window_renderer, fonts, text, len, x, y, color); + x = rencache_draw_text(&window_renderer, fonts, text, len, x, y, color); lua_pushnumber(L, x); return 1; } diff --git a/src/api/system.c b/src/api/system.c index 384f2580..0cbcc437 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -78,7 +78,7 @@ static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *p const int controls_width = hit_info->controls_width; int w, h; - SDL_GetWindowSize(window_renderer->window, &w, &h); + SDL_GetWindowSize(window_renderer.window, &w, &h); if (pt->y < hit_info->title_height && #if RESIZE_FROM_TOP @@ -197,7 +197,7 @@ top: case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_RESIZED) { - ren_resize_window(window_renderer); + ren_resize_window(&window_renderer); lua_pushstring(L, "resized"); /* The size below will be in points. */ lua_pushinteger(L, e.window.data1); @@ -236,8 +236,8 @@ top: SDL_GetMouseState(&mx, &my); lua_pushstring(L, "filedropped"); lua_pushstring(L, e.drop.file); - lua_pushinteger(L, mx * window_renderer->scale_x); - lua_pushinteger(L, my * window_renderer->scale_y); + lua_pushinteger(L, mx * window_renderer.scale_x); + lua_pushinteger(L, my * window_renderer.scale_y); SDL_free(e.drop.file); return 4; @@ -294,8 +294,8 @@ top: if (e.button.button == 1) { SDL_CaptureMouse(1); } lua_pushstring(L, "mousepressed"); lua_pushstring(L, button_name(e.button.button)); - lua_pushinteger(L, e.button.x * window_renderer->scale_x); - lua_pushinteger(L, e.button.y * window_renderer->scale_y); + lua_pushinteger(L, e.button.x * window_renderer.scale_x); + lua_pushinteger(L, e.button.y * window_renderer.scale_y); lua_pushinteger(L, e.button.clicks); return 5; @@ -303,8 +303,8 @@ top: if (e.button.button == 1) { SDL_CaptureMouse(0); } lua_pushstring(L, "mousereleased"); lua_pushstring(L, button_name(e.button.button)); - lua_pushinteger(L, e.button.x * window_renderer->scale_x); - lua_pushinteger(L, e.button.y * window_renderer->scale_y); + lua_pushinteger(L, e.button.x * window_renderer.scale_x); + lua_pushinteger(L, e.button.y * window_renderer.scale_y); return 4; case SDL_MOUSEMOTION: @@ -316,10 +316,10 @@ top: e.motion.yrel += event_plus.motion.yrel; } lua_pushstring(L, "mousemoved"); - lua_pushinteger(L, e.motion.x * window_renderer->scale_x); - lua_pushinteger(L, e.motion.y * window_renderer->scale_y); - lua_pushinteger(L, e.motion.xrel * window_renderer->scale_x); - lua_pushinteger(L, e.motion.yrel * window_renderer->scale_y); + lua_pushinteger(L, e.motion.x * window_renderer.scale_x); + lua_pushinteger(L, e.motion.y * window_renderer.scale_y); + lua_pushinteger(L, e.motion.xrel * window_renderer.scale_x); + lua_pushinteger(L, e.motion.yrel * window_renderer.scale_y); return 5; case SDL_MOUSEWHEEL: @@ -335,7 +335,7 @@ top: return 3; case SDL_FINGERDOWN: - SDL_GetWindowSize(window_renderer->window, &w, &h); + SDL_GetWindowSize(window_renderer.window, &w, &h); lua_pushstring(L, "touchpressed"); lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w)); @@ -344,7 +344,7 @@ top: return 4; case SDL_FINGERUP: - SDL_GetWindowSize(window_renderer->window, &w, &h); + SDL_GetWindowSize(window_renderer.window, &w, &h); lua_pushstring(L, "touchreleased"); lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w)); @@ -360,7 +360,7 @@ top: e.tfinger.dx += event_plus.tfinger.dx; e.tfinger.dy += event_plus.tfinger.dy; } - SDL_GetWindowSize(window_renderer->window, &w, &h); + SDL_GetWindowSize(window_renderer.window, &w, &h); lua_pushstring(L, "touchmoved"); lua_pushinteger(L, (lua_Integer)(e.tfinger.x * w)); @@ -440,7 +440,7 @@ static int f_set_cursor(lua_State *L) { static int f_set_window_title(lua_State *L) { const char *title = luaL_checkstring(L, 1); - SDL_SetWindowTitle(window_renderer->window, title); + SDL_SetWindowTitle(window_renderer.window, title); return 0; } @@ -450,39 +450,39 @@ enum { WIN_NORMAL, WIN_MINIMIZED, WIN_MAXIMIZED, WIN_FULLSCREEN }; static int f_set_window_mode(lua_State *L) { int n = luaL_checkoption(L, 1, "normal", window_opts); - SDL_SetWindowFullscreen(window_renderer->window, + SDL_SetWindowFullscreen(window_renderer.window, n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); - if (n == WIN_NORMAL) { SDL_RestoreWindow(window_renderer->window); } - if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window_renderer->window); } - if (n == WIN_MINIMIZED) { SDL_MinimizeWindow(window_renderer->window); } + if (n == WIN_NORMAL) { SDL_RestoreWindow(window_renderer.window); } + if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window_renderer.window); } + if (n == WIN_MINIMIZED) { SDL_MinimizeWindow(window_renderer.window); } return 0; } static int f_set_window_bordered(lua_State *L) { int bordered = lua_toboolean(L, 1); - SDL_SetWindowBordered(window_renderer->window, bordered); + SDL_SetWindowBordered(window_renderer.window, bordered); return 0; } static int f_set_window_hit_test(lua_State *L) { if (lua_gettop(L) == 0) { - SDL_SetWindowHitTest(window_renderer->window, NULL, NULL); + SDL_SetWindowHitTest(window_renderer.window, NULL, NULL); return 0; } window_hit_info->title_height = luaL_checknumber(L, 1); window_hit_info->controls_width = luaL_checknumber(L, 2); window_hit_info->resize_border = luaL_checknumber(L, 3); - SDL_SetWindowHitTest(window_renderer->window, hit_test, window_hit_info); + SDL_SetWindowHitTest(window_renderer.window, hit_test, window_hit_info); return 0; } static int f_get_window_size(lua_State *L) { int x, y, w, h; - SDL_GetWindowSize(window_renderer->window, &w, &h); - SDL_GetWindowPosition(window_renderer->window, &x, &y); + SDL_GetWindowSize(window_renderer.window, &w, &h); + SDL_GetWindowPosition(window_renderer.window, &x, &y); lua_pushinteger(L, w); lua_pushinteger(L, h); lua_pushinteger(L, x); @@ -496,22 +496,22 @@ static int f_set_window_size(lua_State *L) { double h = luaL_checknumber(L, 2); double x = luaL_checknumber(L, 3); double y = luaL_checknumber(L, 4); - SDL_SetWindowSize(window_renderer->window, w, h); - SDL_SetWindowPosition(window_renderer->window, x, y); - ren_resize_window(window_renderer); + SDL_SetWindowSize(window_renderer.window, w, h); + SDL_SetWindowPosition(window_renderer.window, x, y); + ren_resize_window(&window_renderer); return 0; } static int f_window_has_focus(lua_State *L) { - unsigned flags = SDL_GetWindowFlags(window_renderer->window); + unsigned flags = SDL_GetWindowFlags(window_renderer.window); lua_pushboolean(L, flags & SDL_WINDOW_INPUT_FOCUS); return 1; } static int f_get_window_mode(lua_State *L) { - unsigned flags = SDL_GetWindowFlags(window_renderer->window); + unsigned flags = SDL_GetWindowFlags(window_renderer.window); if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) { lua_pushstring(L, "fullscreen"); } else if (flags & SDL_WINDOW_MINIMIZED) { @@ -549,8 +549,8 @@ static int f_raise_window(lua_State *L) { to allow the window to be focused. Also on wayland the raise window event may not always be obeyed. */ - SDL_SetWindowInputFocus(window_renderer->window); - SDL_RaiseWindow(window_renderer->window); + SDL_SetWindowInputFocus(window_renderer.window); + SDL_RaiseWindow(window_renderer.window); return 0; } @@ -931,7 +931,7 @@ static int f_fuzzy_match(lua_State *L) { static int f_set_window_opacity(lua_State *L) { double n = luaL_checknumber(L, 1); - int r = SDL_SetWindowOpacity(window_renderer->window, n); + int r = SDL_SetWindowOpacity(window_renderer.window, n); lua_pushboolean(L, r > -1); return 1; } diff --git a/src/main.c b/src/main.c index 3c9c17c6..685277ad 100644 --- a/src/main.c +++ b/src/main.c @@ -303,7 +303,7 @@ init_lua: // This allows the window to be destroyed before lite-xl is done with // reaping child processes - ren_free(window_renderer); + ren_free_window_resources(&window_renderer); lua_close(L); #if defined(__amigaos4__) diff --git a/src/renderer.c b/src/renderer.c index 5a96eb29..c998f3c9 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -22,7 +22,7 @@ #define MAX_LOADABLE_GLYPHSETS (MAX_UNICODE / GLYPHSET_SIZE) #define SUBPIXEL_BITMAPS_CACHED 3 -RenWindow* window_renderer = NULL; +RenWindow window_renderer = {0}; static FT_Library library; // draw_rect_surface is used as a 1x1 surface to simplify ren_draw_rect with blending @@ -501,19 +501,26 @@ void ren_draw_rect(RenSurface *rs, RenRect rect, RenColor color) { } /*************** Window Management ****************/ -RenWindow* ren_init(SDL_Window *win) { +void ren_free_window_resources(RenWindow *window_renderer) { + renwin_free(window_renderer); + SDL_FreeSurface(draw_rect_surface); + free(window_renderer->command_buf); + window_renderer->command_buf = NULL; + window_renderer->command_buf_size = 0; +} + +// TODO remove global and return RenWindow* +void ren_init(SDL_Window *win) { assert(win); int error = FT_Init_FreeType( &library ); if ( error ) { fprintf(stderr, "internal font error when starting the application\n"); return NULL; } - RenWindow* window_renderer = malloc(sizeof(RenWindow)); - - window_renderer->window = win; - renwin_init_surface(window_renderer); - renwin_init_command_buf(window_renderer); - renwin_clip_to_surface(window_renderer); + window_renderer.window = win; + renwin_init_surface(&window_renderer); + renwin_init_command_buf(&window_renderer); + renwin_clip_to_surface(&window_renderer); draw_rect_surface = SDL_CreateRGBSurface(0, 1, 1, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); @@ -536,6 +543,12 @@ void ren_resize_window(RenWindow *window_renderer) { } +void ren_resize_window(RenWindow *window_renderer) { + renwin_resize_surface(window_renderer); + renwin_update_scale(window_renderer); +} + + void ren_update_rects(RenWindow *window_renderer, RenRect *rects, int count) { static bool initial_frame = true; if (initial_frame) { diff --git a/src/renderer.h b/src/renderer.h index 78811341..1c865c8f 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -23,7 +23,7 @@ typedef struct { SDL_Surface *surface; int scale; } RenSurface; struct RenWindow; typedef struct RenWindow RenWindow; -extern RenWindow* window_renderer; +extern RenWindow window_renderer; RenFont* ren_font_load(RenWindow *window_renderer, const char *filename, float size, ERenFontAntialiasing antialiasing, ERenFontHinting hinting, unsigned char style); RenFont* ren_font_copy(RenWindow *window_renderer, RenFont* font, float size, ERenFontAntialiasing antialiasing, ERenFontHinting hinting, int style); @@ -39,12 +39,12 @@ double ren_draw_text(RenSurface *rs, RenFont **font, const char *text, size_t le void ren_draw_rect(RenSurface *rs, RenRect rect, RenColor color); -RenWindow* ren_init(SDL_Window *win); -void ren_free(RenWindow* window_renderer); +void ren_init(SDL_Window *win); void ren_resize_window(RenWindow *window_renderer); void ren_update_rects(RenWindow *window_renderer, RenRect *rects, int count); void ren_set_clip_rect(RenWindow *window_renderer, RenRect rect); void ren_get_size(RenWindow *window_renderer, int *x, int *y); /* Reports the size in points. */ +void ren_free_window_resources(RenWindow *window_renderer); #endif