Customized fork of github.com/rxi/lite

Fork

Changed files
+74 -66
data
user
src
+12
README.md
··· 1 + # lite (emmeline's fork) 2 + 3 + A fork of the [lite](https://github.com/rxi/lite) editor by rxi. 4 + 5 + ## Changes 6 + 7 + - [ ] Reformat to my code style :p 8 + - [/] Update to SDL 3 9 + - [ ] Use LuaJIT 10 + 11 + --- 12 + 1 13 # lite 2 14 ![screenshot](https://user-images.githubusercontent.com/3920290/81471642-6c165880-91ea-11ea-8cd1-fae7ae8f0bc4.png) 3 15
+1 -1
build.sh
··· 1 1 #!/bin/bash 2 2 3 3 cflags="-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc" 4 - lflags="-lSDL2 -lm" 4 + lflags="-lSDL3 -lm" 5 5 6 6 if [[ $* == *windows* ]]; then 7 7 platform="windows"
+3
data/user/init.lua
··· 5 5 local config = require "core.config" 6 6 local style = require "core.style" 7 7 8 + config.tab_type = "hard" 9 + config.indent_size = 8 10 + 8 11 -- light theme: 9 12 -- require "user.colors.summer" 10 13
+36 -37
src/api/system.c
··· 1 - #include <SDL2/SDL.h> 1 + #include <SDL3/SDL.h> 2 2 #include <stdbool.h> 3 + #include <stdlib.h> 3 4 #include <ctype.h> 4 5 #include <dirent.h> 5 6 #include <unistd.h> ··· 37 38 38 39 static int f_poll_event(lua_State *L) { 39 40 char buf[16]; 40 - int mx, my, wx, wy; 41 + float mx, my; 42 + int wx, wy; 41 43 SDL_Event e; 42 44 43 45 top: ··· 46 48 } 47 49 48 50 switch (e.type) { 49 - case SDL_QUIT: 51 + case SDL_EVENT_QUIT : 50 52 lua_pushstring(L, "quit"); 51 53 return 1; 52 54 53 - case SDL_WINDOWEVENT: 54 - if (e.window.event == SDL_WINDOWEVENT_RESIZED) { 55 - lua_pushstring(L, "resized"); 56 - lua_pushnumber(L, e.window.data1); 57 - lua_pushnumber(L, e.window.data2); 58 - return 3; 59 - } else if (e.window.event == SDL_WINDOWEVENT_EXPOSED) { 60 - rencache_invalidate(); 61 - lua_pushstring(L, "exposed"); 62 - return 1; 63 - } 55 + case SDL_EVENT_WINDOW_RESIZED: 56 + lua_pushstring(L, "resized"); 57 + lua_pushnumber(L, e.window.data1); 58 + lua_pushnumber(L, e.window.data2); 59 + return 3; 60 + 61 + case SDL_EVENT_WINDOW_EXPOSED: 62 + rencache_invalidate(); 63 + lua_pushstring(L, "exposed"); 64 + return 1; 65 + 66 + case SDL_EVENT_WINDOW_FOCUS_GAINED: 64 67 /* on some systems, when alt-tabbing to the window SDL will queue up 65 68 ** several KEYDOWN events for the `tab` key; we flush all keydown 66 69 ** events on focus so these are discarded */ 67 - if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { 68 - SDL_FlushEvent(SDL_KEYDOWN); 69 - } 70 + SDL_FlushEvent(SDL_EVENT_KEY_DOWN); 70 71 goto top; 71 72 72 - case SDL_DROPFILE: 73 + case SDL_EVENT_DROP_FILE : 73 74 SDL_GetGlobalMouseState(&mx, &my); 74 75 SDL_GetWindowPosition(window, &wx, &wy); 75 76 lua_pushstring(L, "filedropped"); 76 - lua_pushstring(L, e.drop.file); 77 + lua_pushstring(L, e.drop.data); 77 78 lua_pushnumber(L, mx - wx); 78 79 lua_pushnumber(L, my - wy); 79 - SDL_free(e.drop.file); 80 80 return 4; 81 81 82 - case SDL_KEYDOWN: 82 + case SDL_EVENT_KEY_DOWN : 83 83 lua_pushstring(L, "keypressed"); 84 - lua_pushstring(L, key_name(buf, e.key.keysym.sym)); 84 + lua_pushstring(L, key_name(buf, e.key.key)); 85 85 return 2; 86 86 87 - case SDL_KEYUP: 87 + case SDL_EVENT_KEY_UP : 88 88 lua_pushstring(L, "keyreleased"); 89 - lua_pushstring(L, key_name(buf, e.key.keysym.sym)); 89 + lua_pushstring(L, key_name(buf, e.key.key)); 90 90 return 2; 91 91 92 - case SDL_TEXTINPUT: 92 + case SDL_EVENT_TEXT_INPUT : 93 93 lua_pushstring(L, "textinput"); 94 94 lua_pushstring(L, e.text.text); 95 95 return 2; 96 96 97 - case SDL_MOUSEBUTTONDOWN: 97 + case SDL_EVENT_MOUSE_BUTTON_DOWN : 98 98 if (e.button.button == 1) { SDL_CaptureMouse(1); } 99 99 lua_pushstring(L, "mousepressed"); 100 100 lua_pushstring(L, button_name(e.button.button)); ··· 103 103 lua_pushnumber(L, e.button.clicks); 104 104 return 5; 105 105 106 - case SDL_MOUSEBUTTONUP: 106 + case SDL_EVENT_MOUSE_BUTTON_UP : 107 107 if (e.button.button == 1) { SDL_CaptureMouse(0); } 108 108 lua_pushstring(L, "mousereleased"); 109 109 lua_pushstring(L, button_name(e.button.button)); ··· 111 111 lua_pushnumber(L, e.button.y); 112 112 return 4; 113 113 114 - case SDL_MOUSEMOTION: 114 + case SDL_EVENT_MOUSE_MOTION : 115 115 lua_pushstring(L, "mousemoved"); 116 116 lua_pushnumber(L, e.motion.x); 117 117 lua_pushnumber(L, e.motion.y); ··· 119 119 lua_pushnumber(L, e.motion.yrel); 120 120 return 5; 121 121 122 - case SDL_MOUSEWHEEL: 122 + case SDL_EVENT_MOUSE_WHEEL : 123 123 lua_pushstring(L, "mousewheel"); 124 124 lua_pushnumber(L, e.wheel.y); 125 125 return 2; ··· 139 139 } 140 140 141 141 142 - static SDL_Cursor* cursor_cache[SDL_SYSTEM_CURSOR_HAND + 1]; 142 + static SDL_Cursor* cursor_cache[SDL_SYSTEM_CURSOR_POINTER + 1]; 143 143 144 144 static const char *cursor_opts[] = { 145 145 "arrow", ··· 151 151 }; 152 152 153 153 static const int cursor_enums[] = { 154 - SDL_SYSTEM_CURSOR_ARROW, 155 - SDL_SYSTEM_CURSOR_IBEAM, 156 - SDL_SYSTEM_CURSOR_SIZEWE, 157 - SDL_SYSTEM_CURSOR_SIZENS, 158 - SDL_SYSTEM_CURSOR_HAND 154 + SDL_SYSTEM_CURSOR_DEFAULT, 155 + SDL_SYSTEM_CURSOR_TEXT, 156 + SDL_SYSTEM_CURSOR_EW_RESIZE, 157 + SDL_SYSTEM_CURSOR_NS_RESIZE, 158 + SDL_SYSTEM_CURSOR_POINTER 159 159 }; 160 160 161 161 static int f_set_cursor(lua_State *L) { ··· 183 183 184 184 static int f_set_window_mode(lua_State *L) { 185 185 int n = luaL_checkoption(L, 1, "normal", window_opts); 186 - SDL_SetWindowFullscreen(window, 187 - n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); 186 + SDL_SetWindowFullscreen(window, n == WIN_FULLSCREEN ? SDL_GetWindowFullscreenMode(window) : 0); 188 187 if (n == WIN_NORMAL) { SDL_RestoreWindow(window); } 189 188 if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); } 190 189 return 0;
+20 -27
src/main.c
··· 1 1 #include <stdio.h> 2 - #include <SDL2/SDL.h> 2 + #include <stdlib.h> 3 + #include <SDL3/SDL.h> 3 4 #include "api/api.h" 4 5 #include "renderer.h" 5 6 ··· 16 17 17 18 18 19 static double get_scale(void) { 19 - float dpi; 20 - SDL_GetDisplayDPI(0, NULL, &dpi, NULL); 21 - #if _WIN32 22 - return dpi / 96.0; 23 - #else 24 - return 1.0; 25 - #endif 20 + return (double)SDL_min(SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()), 1.0); 26 21 } 27 22 28 23 ··· 48 43 #ifndef _WIN32 49 44 #include "../icon.inl" 50 45 (void) icon_rgba_len; /* unused */ 51 - SDL_Surface *surf = SDL_CreateRGBSurfaceFrom( 52 - icon_rgba, 64, 64, 53 - 32, 64 * 4, 54 - 0x000000ff, 55 - 0x0000ff00, 56 - 0x00ff0000, 57 - 0xff000000); 46 + SDL_Surface *surf = SDL_CreateSurfaceFrom(64, 64, SDL_PIXELFORMAT_ABGR8888, icon_rgba, 64 * 4); 58 47 SDL_SetWindowIcon(window, surf); 59 - SDL_FreeSurface(surf); 48 + SDL_DestroySurface(surf); 60 49 #endif 61 50 } 62 51 ··· 70 59 71 60 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); 72 61 SDL_EnableScreenSaver(); 73 - SDL_EventState(SDL_DROPFILE, SDL_ENABLE); 62 + SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, true); 74 63 atexit(SDL_Quit); 75 64 76 - #ifdef SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR /* Available since 2.0.8 */ 77 65 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0"); 78 - #endif 79 - #if SDL_VERSION_ATLEAST(2, 0, 5) 80 66 SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); 81 - #endif 82 67 83 - SDL_DisplayMode dm; 84 - SDL_GetCurrentDisplayMode(0, &dm); 85 - 86 - window = SDL_CreateWindow( 87 - "", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, dm.w * 0.8, dm.h * 0.8, 88 - SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN); 68 + const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay()); 69 + window = SDL_CreateWindow("", (int)(dm->w * 0.8), (int)(dm->h * 0.8), SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_HIDDEN); 70 + if (!window) 71 + { 72 + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to create window: %s\n", SDL_GetError()); 73 + return EXIT_FAILURE; 74 + } 89 75 init_window_icon(); 90 76 ren_init(window); 77 + 78 + if (!SDL_StartTextInput(window)) 79 + { 80 + #ifndef _WIN32 81 + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: failed SDL_StartTextInput() - text entry may not work"); 82 + #endif 83 + } 91 84 92 85 93 86 lua_State *L = luaL_newstate();
+2 -1
src/renderer.h
··· 1 1 #ifndef RENDERER_H 2 2 #define RENDERER_H 3 3 4 - #include <SDL2/SDL.h> 4 + #include <SDL3/SDL.h> 5 + #include <stdlib.h> 5 6 #include <stdint.h> 6 7 7 8 typedef struct RenImage RenImage;