From b919e5b942393f3a45b981cf2d054b258228f720 Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Tue, 11 Jan 2022 23:32:45 +0000 Subject: [PATCH] Disabled dmon and process and added all fixes for OS4 --- data/core/keymap.lua | 4 ++- data/core/modkeys-os4.lua | 15 +++++++++ data/core/start.lua | 3 +- lib/dmon/dmon.h | 4 +++ src/api/api.c | 5 +-- src/api/renderer.c | 5 +-- src/api/system.c | 69 +++++++++++++++++++++++---------------- src/main.c | 14 ++++++-- src/platform/amigaos4.c | 61 ++++++++++++++++++++++++++++++++++ src/platform/amigaos4.h | 17 ++++++++++ src/rencache.h | 3 +- src/renwindow.c | 15 ++++++++- 12 files changed, 176 insertions(+), 39 deletions(-) create mode 100755 data/core/modkeys-os4.lua create mode 100644 src/platform/amigaos4.c create mode 100644 src/platform/amigaos4.h diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 404cff39..0999dc53 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -7,9 +7,10 @@ keymap.map = {} keymap.reverse_map = {} local macos = PLATFORM == "Mac OS X" +local os4 = PLATFORM == "AmigaOS 4" -- Thanks to mathewmariani, taken from his lite-macos github repository. -local modkeys_os = require("core.modkeys-" .. (macos and "macos" or "generic")) +local modkeys_os = require("core.modkeys-" .. (macos and "macos" or os4 and "os4" or "generic")) local modkey_map = modkeys_os.map local modkeys = modkeys_os.keys @@ -259,3 +260,4 @@ keymap.add_direct { } return keymap + diff --git a/data/core/modkeys-os4.lua b/data/core/modkeys-os4.lua new file mode 100755 index 00000000..45522e66 --- /dev/null +++ b/data/core/modkeys-os4.lua @@ -0,0 +1,15 @@ +local modkeys = {} + +modkeys.map = { + ["left amiga"] = "cmd", + ["right amiga"] = "cmd", + ["control"] = "ctrl", + ["left shift"] = "shift", + ["right shift"] = "shift", + ["left alt"] = "alt", + ["right alt"] = "altgr", +} + +modkeys.keys = { "cmd", "ctrl", "alt", "altgr", "shift" } + +return modkeys diff --git a/data/core/start.lua b/data/core/start.lua index f3bc89c6..68782502 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -1,5 +1,5 @@ -- this file is used by lite-xl to setup the Lua environment when starting -VERSION = "@PROJECT_VERSION@" +VERSION = "2.0.4" MOD_VERSION = "2" SCALE = tonumber(os.getenv("LITE_SCALE") or os.getenv("GDK_SCALE") or os.getenv("QT_SCALE_FACTOR")) or SCALE @@ -31,3 +31,4 @@ end } table.pack = table.pack or pack or function(...) return {...} end table.unpack = table.unpack or unpack + diff --git a/lib/dmon/dmon.h b/lib/dmon/dmon.h index 2bc9e0c3..1650bc00 100644 --- a/lib/dmon/dmon.h +++ b/lib/dmon/dmon.h @@ -137,6 +137,9 @@ DMON_API_DECL void dmon_unwatch(dmon_watch_id id); #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) # undef DMON_OS_MACOS # define DMON_OS_MACOS __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +#elif defined(__amigaos4__) +# undef DMON_OS_AMIGAOS4 +# define DMON_OS_AMIGAOS4 1 #else # define DMON_OS 0 # error "unsupported platform" @@ -175,6 +178,7 @@ DMON_API_DECL void dmon_unwatch(dmon_watch_id id); # include # include # include +#elif DMON_OS_AMIGAOS4 #endif #ifndef DMON_MALLOC diff --git a/src/api/api.c b/src/api/api.c index 9f74f6b5..4ef8e5d0 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -4,13 +4,13 @@ int luaopen_system(lua_State *L); int luaopen_renderer(lua_State *L); int luaopen_regex(lua_State *L); -int luaopen_process(lua_State *L); +// int luaopen_process(lua_State *L); static const luaL_Reg libs[] = { { "system", luaopen_system }, { "renderer", luaopen_renderer }, { "regex", luaopen_regex }, - { "process", luaopen_process }, + // { "process", luaopen_process }, { NULL, NULL } }; @@ -18,3 +18,4 @@ void api_load_libs(lua_State *L) { for (int i = 0; libs[i].name; i++) luaL_requiref(L, libs[i].name, libs[i].func, 1); } + diff --git a/src/api/renderer.c b/src/api/renderer.c index bd001cdf..fa8316c5 100644 --- a/src/api/renderer.c +++ b/src/api/renderer.c @@ -1,6 +1,6 @@ #include "api.h" -#include "../renderer.h" -#include "../rencache.h" +#include "renderer.h" +#include "rencache.h" static int f_font_load(lua_State *L) { const char *filename = luaL_checkstring(L, 1); @@ -249,3 +249,4 @@ int luaopen_renderer(lua_State *L) { lua_setfield(L, -2, "font"); return 1; } + diff --git a/src/api/system.c b/src/api/system.c index cbddd5f9..dc6827ad 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -6,8 +6,8 @@ #include #include #include "api.h" -#include "../dirmonitor.h" -#include "../rencache.h" +// #include "dirmonitor.h" +#include "rencache.h" #ifdef _WIN32 #include #include @@ -252,20 +252,20 @@ top: case SDL_USEREVENT: lua_pushstring(L, "dirchange"); lua_pushnumber(L, e.user.code >> 16); - switch (e.user.code & 0xffff) { - case DMON_ACTION_DELETE: - lua_pushstring(L, "delete"); - break; - case DMON_ACTION_CREATE: - lua_pushstring(L, "create"); - break; - case DMON_ACTION_MODIFY: - lua_pushstring(L, "modify"); - break; - default: - return luaL_error(L, "unknown dmon event action: %d", e.user.code & 0xffff); - } - lua_pushstring(L, e.user.data1); + // switch (e.user.code & 0xffff) { + // case DMON_ACTION_DELETE: + // lua_pushstring(L, "delete"); + // break; + // case DMON_ACTION_CREATE: + // lua_pushstring(L, "create"); + // break; + // case DMON_ACTION_MODIFY: + // lua_pushstring(L, "modify"); + // break; + // default: + // return luaL_error(L, "unknown dmon event action: %d", e.user.code & 0xffff); + // } + // lua_pushstring(L, e.user.data1); free(e.user.data1); return 4; @@ -335,7 +335,11 @@ static int f_set_window_mode(lua_State *L) { int n = luaL_checkoption(L, 1, "normal", window_opts); SDL_SetWindowFullscreen(window, n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); - if (n == WIN_NORMAL) { SDL_RestoreWindow(window); } + if (n == WIN_NORMAL) + { + ren_resize_window(); + SDL_RestoreWindow(window); + } if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); } if (n == WIN_MINIMIZED) { SDL_MinimizeWindow(window); } return 0; @@ -517,6 +521,10 @@ static int f_list_dir(lua_State *L) { #define realpath(x, y) _fullpath(y, x, MAX_PATH) #endif +#ifdef __amigaos4__ + #define realpath(x, y) _fullpath(x) +#endif + static int f_absolute_path(lua_State *L) { const char *path = luaL_checkstring(L, 1); char *res = realpath(path, NULL); @@ -789,27 +797,29 @@ static int f_load_native_plugin(lua_State *L) { static int f_watch_dir(lua_State *L) { const char *path = luaL_checkstring(L, 1); const int recursive = lua_toboolean(L, 2); - uint32_t dmon_flags = (recursive ? DMON_WATCHFLAGS_RECURSIVE : 0); - dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, dmon_flags, NULL); - if (watch_id.id == 0) { luaL_error(L, "directory monitoring watch failed"); } - lua_pushnumber(L, watch_id.id); + // uint32_t dmon_flags = (recursive ? DMON_WATCHFLAGS_RECURSIVE : 0); + uint32_t dmon_flags = 0; + // dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, dmon_flags, NULL); + // if (watch_id.id == 0) { luaL_error(L, "directory monitoring watch failed"); } + // lua_pushnumber(L, watch_id.id); + lua_pushnumber(L, 0); return 1; } #if __linux__ static int f_watch_dir_add(lua_State *L) { - dmon_watch_id watch_id; - watch_id.id = luaL_checkinteger(L, 1); - const char *subdir = luaL_checkstring(L, 2); - lua_pushboolean(L, dmon_watch_add(watch_id, subdir)); + // dmon_watch_id watch_id; + // watch_id.id = luaL_checkinteger(L, 1); + // const char *subdir = luaL_checkstring(L, 2); + // lua_pushboolean(L, dmon_watch_add(watch_id, subdir)); return 1; } static int f_watch_dir_rm(lua_State *L) { - dmon_watch_id watch_id; - watch_id.id = luaL_checkinteger(L, 1); - const char *subdir = luaL_checkstring(L, 2); - lua_pushboolean(L, dmon_watch_rm(watch_id, subdir)); + // dmon_watch_id watch_id; + // watch_id.id = luaL_checkinteger(L, 1); + // const char *subdir = luaL_checkstring(L, 2); + // lua_pushboolean(L, dmon_watch_rm(watch_id, subdir)); return 1; } #endif @@ -914,3 +924,4 @@ int luaopen_system(lua_State *L) { luaL_newlib(L, lib); return 1; } + diff --git a/src/main.c b/src/main.c index 9fcbeab6..cef68ad7 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,8 @@ #include #elif __APPLE__ #include +#elif __amigaos4__ + #include "platform/amigaos4.h" #endif #include "dirmonitor.h" @@ -45,6 +47,8 @@ static void get_exe_filename(char *buf, int sz) { char exepath[size]; _NSGetExecutablePath(exepath, &size); realpath(exepath, buf); +#elif __amigaos4__ + strcpy(buf, _fullpath("./lite")); #else strcpy(buf, "./lite"); #endif @@ -108,11 +112,13 @@ int main(int argc, char **argv) { SDL_DisplayMode dm; SDL_GetCurrentDisplayMode(0, &dm); - dirmonitor_init(); + // dirmonitor_init(); window = SDL_CreateWindow( "", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, dm.w * 0.8, dm.h * 0.8, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN); + SDL_SetWindowDisplayMode(window, &dm); + init_window_icon(); ren_init(window); @@ -154,6 +160,9 @@ init_lua: " HOME = os.getenv('" LITE_OS_HOME "')\n" " local exedir = EXEFILE:match('^(.*)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "$')\n" " local prefix = exedir:match('^(.*)" LITE_PATHSEP_PATTERN "bin$')\n" + " if not HOME then\n" + " HOME = exedir\n" + " end\n" " dofile((MACOS_RESOURCES or (prefix and prefix .. '/share/lite-xl' or exedir .. '/data')) .. '/core/start.lua')\n" " core = require(os.getenv('LITE_XL_RUNTIME') or 'core')\n" " core.init()\n" @@ -192,7 +201,8 @@ init_lua: lua_close(L); ren_free_window_resources(); - dirmonitor_deinit(); + // dirmonitor_deinit(); return EXIT_SUCCESS; } + diff --git a/src/platform/amigaos4.c b/src/platform/amigaos4.c new file mode 100644 index 00000000..fd53bd2f --- /dev/null +++ b/src/platform/amigaos4.c @@ -0,0 +1,61 @@ + +#include +#include +#include + +#include "amigaos4.h" + +static char *getFullPath(const char *path) +{ + char *appPath = malloc(sizeof(char) * MAX_DOS_NAME); + BPTR pathLock = Lock(path, SHARED_LOCK); + if (pathLock) + { + NameFromLock(pathLock, appPath, sizeof(char) * MAX_DOS_NAME); + UnLock(pathLock); + + return appPath; + } + return NULL; +} + +static char *getCurrentPath(void) +{ + char *appPath = malloc(sizeof(char) * MAX_DOS_NAME); + BPTR pathLock = GetCurrentDir(); + if (pathLock) + { + NameFromLock(pathLock, appPath, sizeof(char) * MAX_DOS_NAME); + return appPath; + } + return NULL; +} + +char *_fullpath(const char *path) +{ + static char prvPath[MAX_DOS_NAME]; + static char result[MAX_DOS_NAME]; + + if (!strcmp(path, prvPath)) + { + return result; + } + + strcpy(prvPath, path); + + if (!strcmp(path, "./lite")) + { + // TODO: Add code to get the name of the executable + strcpy(result, getFullPath("PROGDIR:lite")); + return result; + } + + if (!strcmp(path, ".")) + { + strcpy(result, getCurrentPath()); + return result; + } + + strcpy(result, getFullPath(path)); + return result; +} diff --git a/src/platform/amigaos4.h b/src/platform/amigaos4.h new file mode 100644 index 00000000..8e2bc195 --- /dev/null +++ b/src/platform/amigaos4.h @@ -0,0 +1,17 @@ +#ifndef _AMIGAOS4_H +#define _AMIGAOS4_H + +#include +#include + +#define VSTRING "Lite XL OS4 2.0.4 (04.01.2022)" +#define VERSTAG "\0$VER: " VSTRING + +static CONST_STRPTR stack USED = "$STACK:102400"; +static CONST_STRPTR version USED = VERSTAG; + +char *_fullpath(const char *); + + +#endif + diff --git a/src/rencache.h b/src/rencache.h index 75bb5051..5f817403 100644 --- a/src/rencache.h +++ b/src/rencache.h @@ -9,9 +9,10 @@ void rencache_show_debug(bool enable); void rencache_set_clip_rect(RenRect rect); void rencache_draw_rect(RenRect rect, RenColor color); float rencache_draw_text(lua_State *L, RenFont **font, - const char *text, float x, int y, RenColor color); +const char *text, float x, int y, RenColor color); void rencache_invalidate(void); void rencache_begin_frame(lua_State *L); void rencache_end_frame(lua_State *L); #endif + diff --git a/src/renwindow.c b/src/renwindow.c index f67002f8..245f8a05 100644 --- a/src/renwindow.c +++ b/src/renwindow.c @@ -9,6 +9,18 @@ static int query_surface_scale(RenWindow *ren) { SDL_GetWindowSize(ren->window, &w_points, &h_points); /* We consider that the ratio pixel/point will always be an integer and it is the same along the x and the y axis. */ + + #ifdef __amigaos4__ + // This is a workaround when the w_pixels != w_points and h_pixels != h_points + // because of redraw delays, especially when the "Resize with contents" is enabled + if (w_pixels != w_points) { + w_pixels = w_points; + } + if (h_pixels != h_points) { + h_pixels = h_points; + } + #endif + assert(w_pixels % w_points == 0 && h_pixels % h_points == 0 && w_pixels / w_points == h_pixels / h_points); return w_pixels / w_points; } @@ -20,7 +32,7 @@ static void setup_renderer(RenWindow *ren, int w, int h) { SDL_DestroyTexture(ren->texture); SDL_DestroyRenderer(ren->renderer); } - ren->renderer = SDL_CreateRenderer(ren->window, -1, 0); + ren->renderer = SDL_CreateRenderer(ren->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); ren->texture = SDL_CreateTexture(ren->renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STREAMING, w, h); ren->surface_scale = query_surface_scale(ren); } @@ -116,3 +128,4 @@ void renwin_free(RenWindow *ren) { SDL_FreeSurface(ren->surface); #endif } +