From 1cf0f2009caeac07f5d7345107d810b214e8896e Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 21 Jun 2021 11:18:52 +0200 Subject: [PATCH 1/9] Add a C API copy method for font_desc objects Add a renderer.font's method "copy" to clone the font object by specifying an optional new size. In the size is not given the size of the original object is used. Should fulfill the request from issue #288. --- data/core/style.lua | 4 ++-- src/api/renderer_font.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/data/core/style.lua b/data/core/style.lua index 60df7c73..7cf16eb1 100644 --- a/data/core/style.lua +++ b/data/core/style.lua @@ -22,9 +22,9 @@ style.tab_width = common.round(170 * SCALE) -- On High DPI monitor or non RGB monitor you may consider using antialiasing grayscale instead. -- The antialiasing grayscale with full hinting is interesting for crisp font rendering. style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE) -style.big_font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 40 * SCALE) +style.big_font = style.font:copy(40 * SCALE) style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE, {antialiasing="grayscale", hinting="full"}) -style.icon_big_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 20 * SCALE, {antialiasing="grayscale", hinting="full"}) +style.icon_big_font = style.icon_font:copy(20 * SCALE) style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE) style.background = { common.color "#2e2e32" } diff --git a/src/api/renderer_font.c b/src/api/renderer_font.c index f510da70..7c6587ea 100644 --- a/src/api/renderer_font.c +++ b/src/api/renderer_font.c @@ -55,6 +55,21 @@ static int f_load(lua_State *L) { } +static int f_copy(lua_State *L) { + FontDesc *self = luaL_checkudata(L, 1, API_TYPE_FONT); + float size; + if (lua_gettop(L) >= 2) { + size = luaL_checknumber(L, 2); + } else { + size = self->size; + } + FontDesc *new_font_desc = lua_newuserdata(L, font_desc_alloc_size(self->filename)); + font_desc_init(new_font_desc, self->filename, size, self->options); + luaL_setmetatable(L, API_TYPE_FONT); + return 1; +} + + static int f_set_tab_size(lua_State *L) { FontDesc *self = luaL_checkudata(L, 1, API_TYPE_FONT); int n = luaL_checknumber(L, 2); @@ -123,6 +138,7 @@ static int f_set_size(lua_State *L) { static const luaL_Reg lib[] = { { "__gc", f_gc }, { "load", f_load }, + { "copy", f_copy }, { "set_tab_size", f_set_tab_size }, { "get_width", f_get_width }, { "get_width_subpixel", f_get_width_subpixel }, From 8c71b35888915a902b515ac9de6260678bc4e9c9 Mon Sep 17 00:00:00 2001 From: redtide Date: Thu, 24 Jun 2021 14:00:04 +0200 Subject: [PATCH 2/9] Set default documents line endings behavior --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitattributes b/.gitattributes index bd2cfac4..c847cf1a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,7 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +# See https://help.github.com/en/articles/dealing-with-line-endings +* text=auto + winlib/* linguist-vendored src/lib/* linguist-vendored icon.inl linguist-vendored From 3f58e554ba8730bf4a6e862e3096a4d13d212288 Mon Sep 17 00:00:00 2001 From: redtide Date: Sun, 20 Jun 2021 17:37:08 +0200 Subject: [PATCH 3/9] Reorganization of data resources --- .gitattributes | 2 +- build-packages.sh | 10 +++++----- meson.build | 2 +- {dev-utils => resources/icons}/icon.icns | Bin icon.ico => resources/icons/icon.ico | Bin icon.inl => resources/icons/icon.inl | 0 res.rc => resources/icons/icon.rc | 0 {dev-utils => resources/icons}/lite.svg | 0 {dev-utils => resources/linux}/lite-xl.desktop | 0 {dev-utils => resources/macos}/Info.plist | 0 .../macos}/macos-retina-display.md | 0 src/main.c | 2 +- 12 files changed, 8 insertions(+), 8 deletions(-) rename {dev-utils => resources/icons}/icon.icns (100%) rename icon.ico => resources/icons/icon.ico (100%) rename icon.inl => resources/icons/icon.inl (100%) rename res.rc => resources/icons/icon.rc (100%) rename {dev-utils => resources/icons}/lite.svg (100%) rename {dev-utils => resources/linux}/lite-xl.desktop (100%) rename {dev-utils => resources/macos}/Info.plist (100%) rename {dev-utils => resources/macos}/macos-retina-display.md (100%) diff --git a/.gitattributes b/.gitattributes index bd2cfac4..31ff9dfc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ winlib/* linguist-vendored src/lib/* linguist-vendored -icon.inl linguist-vendored +resources/icons/icon.inl linguist-vendored diff --git a/build-packages.sh b/build-packages.sh index 76b0ebf5..593aaba8 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -84,7 +84,7 @@ lite_build_package_windows () { rm -fr ".package-build" echo "created package $package_name" } - + lite_build_package_macos () { local build="$1" local arch="$2" @@ -100,8 +100,8 @@ lite_build_package_macos () { for module_name in plugins colors; do cp -r "$build/third/data/$module_name" "$datadir" done - cp dev-utils/icon.icns "$appdir/Contents/Resources/icon.icns" - cp dev-utils/Info.plist "$appdir/Contents/Info.plist" + cp resources/icons/icon.icns "$appdir/Contents/Resources/icon.icns" + cp resources/macos/Info.plist "$appdir/Contents/Info.plist" cp "$build/src/lite" "$bindir/lite-xl" strip "$bindir/lite-xl" pushd ".package-build" @@ -142,8 +142,8 @@ lite_build_package_linux () { strip "$bindir/lite" if [ -z "$portable" ]; then mkdir -p "$pdir/share/applications" "$pdir/share/icons/hicolor/scalable/apps" - cp "dev-utils/lite-xl.desktop" "$pdir/share/applications" - cp "dev-utils/lite.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" + cp "resources/linux/lite-xl.desktop" "$pdir/share/applications" + cp "resources/icons/lite.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" fi pushd ".package-build" local package_name="lite-xl-$os-$arch$portable.tar.gz" diff --git a/meson.build b/meson.build index c1108ee7..38eda308 100644 --- a/meson.build +++ b/meson.build @@ -55,7 +55,7 @@ endif lite_rc = [] if host_machine.system() == 'windows' windows = import('windows') - lite_rc += windows.compile_resources('res.rc') + lite_rc += windows.compile_resources('resources/icons/icon.rc') endif # On macos we need to use the SDL renderer to support retina displays diff --git a/dev-utils/icon.icns b/resources/icons/icon.icns similarity index 100% rename from dev-utils/icon.icns rename to resources/icons/icon.icns diff --git a/icon.ico b/resources/icons/icon.ico similarity index 100% rename from icon.ico rename to resources/icons/icon.ico diff --git a/icon.inl b/resources/icons/icon.inl similarity index 100% rename from icon.inl rename to resources/icons/icon.inl diff --git a/res.rc b/resources/icons/icon.rc similarity index 100% rename from res.rc rename to resources/icons/icon.rc diff --git a/dev-utils/lite.svg b/resources/icons/lite.svg similarity index 100% rename from dev-utils/lite.svg rename to resources/icons/lite.svg diff --git a/dev-utils/lite-xl.desktop b/resources/linux/lite-xl.desktop similarity index 100% rename from dev-utils/lite-xl.desktop rename to resources/linux/lite-xl.desktop diff --git a/dev-utils/Info.plist b/resources/macos/Info.plist similarity index 100% rename from dev-utils/Info.plist rename to resources/macos/Info.plist diff --git a/dev-utils/macos-retina-display.md b/resources/macos/macos-retina-display.md similarity index 100% rename from dev-utils/macos-retina-display.md rename to resources/macos/macos-retina-display.md diff --git a/src/main.c b/src/main.c index 46befe51..f84cc3b8 100644 --- a/src/main.c +++ b/src/main.c @@ -79,7 +79,7 @@ static void get_exe_filename(char *buf, int sz) { static void init_window_icon(void) { #ifndef _WIN32 - #include "../icon.inl" + #include "../resources/icons/icon.inl" (void) icon_rgba_len; /* unused */ SDL_Surface *surf = SDL_CreateRGBSurfaceFrom( icon_rgba, 64, 64, From 36ff3b1c765706125ad71e560bdf5791eda85162 Mon Sep 17 00:00:00 2001 From: redtide Date: Wed, 23 Jun 2021 15:29:25 +0200 Subject: [PATCH 4/9] Renamed dev-utils directory to scripts --- {dev-utils => scripts}/fontello-config.json | 0 {dev-utils => scripts}/repackage.sh | 0 {dev-utils => scripts}/run-local | 0 {dev-utils => scripts}/run-plugin | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {dev-utils => scripts}/fontello-config.json (100%) rename {dev-utils => scripts}/repackage.sh (100%) rename {dev-utils => scripts}/run-local (100%) rename {dev-utils => scripts}/run-plugin (100%) diff --git a/dev-utils/fontello-config.json b/scripts/fontello-config.json similarity index 100% rename from dev-utils/fontello-config.json rename to scripts/fontello-config.json diff --git a/dev-utils/repackage.sh b/scripts/repackage.sh similarity index 100% rename from dev-utils/repackage.sh rename to scripts/repackage.sh diff --git a/dev-utils/run-local b/scripts/run-local similarity index 100% rename from dev-utils/run-local rename to scripts/run-local diff --git a/dev-utils/run-plugin b/scripts/run-plugin similarity index 100% rename from dev-utils/run-plugin rename to scripts/run-plugin From cc568e65fc865a75ea639f94e6e1d5e2cc907980 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 24 Jun 2021 18:00:50 -0400 Subject: [PATCH 5/9] Changed over ctrl+w keybinding over to cmd+w, as per #311. --- data/core/keymap-macos.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua index 3db4d4f7..327a1cc5 100644 --- a/data/core/keymap-macos.lua +++ b/data/core/keymap-macos.lua @@ -17,7 +17,7 @@ local function keymap_macos(keymap) ["cmd+ctrl+i"] = "root:switch-to-up", ["cmd+ctrl+k"] = "root:switch-to-down", - ["ctrl+w"] = "root:close", + ["cmd+w"] = "root:close", ["ctrl+tab"] = "root:switch-to-next-tab", ["ctrl+shift+tab"] = "root:switch-to-previous-tab", ["cmd+pageup"] = "root:move-tab-left", From df63775dca20b61b4ca454d4b819bd525abd2fc8 Mon Sep 17 00:00:00 2001 From: redtide Date: Thu, 24 Jun 2021 14:49:18 +0200 Subject: [PATCH 6/9] Use lite-xl as project and exacutable names --- .gitignore | 2 +- build-packages.sh | 14 +++++++------- build.sh | 4 ++-- meson.build | 2 +- resources/icons/{lite.svg => lite-xl.svg} | 0 resources/linux/lite-xl.desktop | 3 +-- src/meson.build | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) rename resources/icons/{lite.svg => lite-xl.svg} (100%) diff --git a/.gitignore b/.gitignore index 6a26aa12..92d20437 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ build* subprojects/lua subprojects/libagg subprojects/reproc -lite +lite-xl error.txt diff --git a/build-packages.sh b/build-packages.sh index 593aaba8..3701ac53 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -44,7 +44,7 @@ lite_build_pgo () { meson setup --buildtype=release -Db_pgo=generate "$build" || exit 1 ninja -C "$build" || exit 1 copy_directory_from_repo data "$build/src" - "$build/src/lite" + "$build/src/lite-xl" meson configure -Db_pgo=use "$build" ninja -C "$build" || exit 1 } @@ -74,8 +74,8 @@ lite_build_package_windows () { for module_name in plugins colors; do cp -r "$build/third/data/$module_name" "$datadir" done - cp "$build/src/lite.exe" "$bindir" - strip --strip-all "$bindir/lite.exe" + cp "$build/src/lite-xl.exe" "$bindir" + strip --strip-all "$bindir/lite-xl.exe" pushd ".package-build" local package_name="lite-xl-$os-$arch$portable.zip" zip "$package_name" -r "lite-xl" @@ -102,7 +102,7 @@ lite_build_package_macos () { done cp resources/icons/icon.icns "$appdir/Contents/Resources/icon.icns" cp resources/macos/Info.plist "$appdir/Contents/Info.plist" - cp "$build/src/lite" "$bindir/lite-xl" + cp "$build/src/lite-xl" "$bindir/lite-xl" strip "$bindir/lite-xl" pushd ".package-build" local package_name="lite-xl-$os-$arch.zip" @@ -138,12 +138,12 @@ lite_build_package_linux () { for module_name in plugins colors; do cp -r "$build/third/data/$module_name" "$datadir" done - cp "$build/src/lite" "$bindir" - strip "$bindir/lite" + cp "$build/src/lite-xl" "$bindir" + strip "$bindir/lite-xl" if [ -z "$portable" ]; then mkdir -p "$pdir/share/applications" "$pdir/share/icons/hicolor/scalable/apps" cp "resources/linux/lite-xl.desktop" "$pdir/share/applications" - cp "resources/icons/lite.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" + cp "resources/icons/lite-xl.svg" "$pdir/share/icons/hicolor/scalable/apps/lite-xl.svg" fi pushd ".package-build" local package_name="lite-xl-$os-$arch$portable.tar.gz" diff --git a/build.sh b/build.sh index eb1d420a..b49dc1bf 100755 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ if [[ $* == *windows* ]]; then echo "cross compiling for windows is not yet supported" exit 1 else - outfile="lite" + outfile="lite-xl" compiler="gcc" cxxcompiler="g++" fi @@ -20,7 +20,7 @@ fi lib/font_renderer/build.sh || exit 1 libs=libfontrenderer.a -echo "compiling lite..." +echo "compiling lite-xl..." for f in `find src -name "*.c"`; do $compiler -c $cflags $f -o "${f//\//_}.o" if [[ $? -ne 0 ]]; then diff --git a/meson.build b/meson.build index 38eda308..1f1ff0d2 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('lite', 'c', 'cpp', default_options : ['c_std=gnu11', 'cpp_std=c++03']) +project('lite-xl', 'c', 'cpp', default_options : ['c_std=gnu11', 'cpp_std=c++03']) if host_machine.system() == 'darwin' add_languages('objc') diff --git a/resources/icons/lite.svg b/resources/icons/lite-xl.svg similarity index 100% rename from resources/icons/lite.svg rename to resources/icons/lite-xl.svg diff --git a/resources/linux/lite-xl.desktop b/resources/linux/lite-xl.desktop index dbcb779a..f2fa9610 100644 --- a/resources/linux/lite-xl.desktop +++ b/resources/linux/lite-xl.desktop @@ -2,10 +2,9 @@ Type=Application Name=Lite XL Comment=A lightweight text editor written in Lua -Exec=lite %F +Exec=lite-xl %F Icon=lite-xl Terminal=false StartupNotify=false Categories=Utility;TextEditor;Development; MimeType=text/plain; - diff --git a/src/meson.build b/src/meson.build index 9516c94d..03cc826f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -17,7 +17,7 @@ if host_machine.system() == 'darwin' lite_sources += 'bundle_open.m' endif -executable('lite', +executable('lite-xl', lite_sources + lite_rc, include_directories: [lite_include, font_renderer_include], dependencies: lite_deps, From c2c59e9c99e4ec36b48238060529d0361181d690 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Mon, 28 Jun 2021 10:44:40 -0400 Subject: [PATCH 7/9] Fixed XDG issue. --- data/core/start.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/core/start.lua b/data/core/start.lua index 3ef806cc..6090df4e 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -12,7 +12,8 @@ else local prefix = EXEDIR:match("^(.+)[/\\]bin$") DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data') end -USERDIR = os.getenv("XDG_CONFIG_HOME") or (HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')) +USERDIR = (os.getenv("XDG_CONFIG_HOME") and os.getenv("XDG_CONFIG_HOME") .. "/lite-xl") + or (HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')) package.path = DATADIR .. '/?.lua;' .. package.path package.path = DATADIR .. '/?/init.lua;' .. package.path From 4188269cef2f98f360089344f6dcfe079addedb1 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Thu, 24 Jun 2021 13:54:22 -0400 Subject: [PATCH 8/9] Added system.rmdir(path) It is reported that the built-in lua function os.remove(path) does not removes empty directories on windows. To fix this a system.rmdir function is introduced that calls a native win32 function. Also common.rm(path, recursively) was added which wraps system.rmdir() to easily delete an entire folder with all its contents. --- data/core/common.lua | 47 +++++++++++++++++++++++++++++++++++++++++++ src/api/system.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/data/core/common.lua b/data/core/common.lua index 548b5faa..3df3e8f1 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -322,4 +322,51 @@ function common.mkdirp(path) return true end +function common.rm(path, recursively) + local stat = system.get_file_info(path) + if not stat or (stat.type ~= "file" and stat.type ~= "dir") then + return false, "invalid path given", path + end + + if stat.type == "file" then + local removed, error = os.remove(path) + if not removed then + return false, error, path + end + else + local contents = system.list_dir(path) + if #contents > 0 and not recursively then + return false, "directory is not empty", path + end + + for _, item in pairs(contents) do + local item_path = path .. PATHSEP .. item + local item_stat = system.get_file_info(item_path) + + if not item_stat then + return false, "invalid file encountered", item_path + end + + if item_stat.type == "dir" then + local deleted, error, ipath = common.rm(item_path, recursively) + if not deleted then + return false, error, ipath + end + elseif item_stat.type == "file" then + local removed, error = os.remove(item_path) + if not removed then + return false, error, item_path + end + end + end + + local removed, error = system.rmdir(path) + if not removed then + return false, error, path + end + end + + return true +end + return common diff --git a/src/api/system.c b/src/api/system.c index 4b98509f..2f1bf763 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -10,6 +10,7 @@ #ifdef _WIN32 #include #include + #include #endif extern SDL_Window *window; @@ -384,6 +385,52 @@ static int f_show_fatal_error(lua_State *L) { } +// removes an empty directory +static int f_rmdir(lua_State *L) { + const char *path = luaL_checkstring(L, 1); + +#ifdef _WIN32 + int deleted = RemoveDirectoryA(path); + if(deleted > 0) { + lua_pushboolean(L, 1); + } else { + DWORD error_code = GetLastError(); + LPVOID message; + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + error_code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &message, + 0, + NULL + ); + + lua_pushboolean(L, 0); + lua_pushlstring(L, (LPCTSTR)message, lstrlen((LPCTSTR)message)); + LocalFree(message); + + return 2; + } +#else + int deleted = remove(path); + if(deleted < 0) { + lua_pushboolean(L, 0); + lua_pushstring(L, strerror(errno)); + + return 2; + } else { + lua_pushboolean(L, 1); + } +#endif + + return 1; +} + + static int f_chdir(lua_State *L) { const char *path = luaL_checkstring(L, 1); int err = chdir(path); @@ -604,6 +651,7 @@ static const luaL_Reg lib[] = { { "set_window_size", f_set_window_size }, { "window_has_focus", f_window_has_focus }, { "show_fatal_error", f_show_fatal_error }, + { "rmdir", f_rmdir }, { "chdir", f_chdir }, { "mkdir", f_mkdir }, { "list_dir", f_list_dir }, From e5b2a7cbe85e1f11edb3ca7c54385b71b0df1310 Mon Sep 17 00:00:00 2001 From: lqdev Date: Thu, 1 Jul 2021 14:50:28 +0200 Subject: [PATCH 9/9] reset blink timer when a new cursor is created --- data/core/commands/doc.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 2a3d608f..815d9511 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -26,7 +26,7 @@ end local function doc_multiline_selections(sort) local iter, state, idx, line1, col1, line2, col2 = doc():get_selections(sort) - return function() + return function() idx, line1, col1, line2, col2 = iter(state, idx) if idx and line2 > line1 and col2 == 1 then line2 = line2 - 1 @@ -74,6 +74,7 @@ local function split_cursor(direction) end end for i,v in ipairs(new_cursors) do doc():add_selection(v[1], v[2]) end + core.blink_reset() end local commands = { @@ -156,8 +157,8 @@ local commands = { local line, col = doc():get_selection() doc():set_selection(line, col) end, - - + + ["doc:indent"] = function() for idx, line1, col1, line2, col2 in doc_multiline_selections(true) do local l1, c1, l2, c2 = doc():indent_text(false, line1, col1, line2, col2) @@ -296,7 +297,7 @@ local commands = { ["doc:lower-case"] = function() doc():replace(string.lower) end, - + ["doc:go-to-line"] = function() local dv = dv() @@ -370,7 +371,7 @@ local commands = { end end, common.path_suggest) end, - + ["file:delete"] = function() local filename = doc().abs_filename @@ -390,7 +391,7 @@ local commands = { split_cursor(-1) doc():merge_cursors() end, - + ["doc:create-cursor-next-line"] = function() split_cursor(1) doc():merge_cursors()