+12
README.md
+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
+
13
# lite
14

15
+1
-1
build.sh
+1
-1
build.sh
+3
data/user/init.lua
+3
data/user/init.lua
+36
-37
src/api/system.c
+36
-37
src/api/system.c
···
1
-
#include <SDL2/SDL.h>
2
#include <stdbool.h>
3
#include <ctype.h>
4
#include <dirent.h>
5
#include <unistd.h>
···
37
38
static int f_poll_event(lua_State *L) {
39
char buf[16];
40
-
int mx, my, wx, wy;
41
SDL_Event e;
42
43
top:
···
46
}
47
48
switch (e.type) {
49
-
case SDL_QUIT:
50
lua_pushstring(L, "quit");
51
return 1;
52
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
-
}
64
/* on some systems, when alt-tabbing to the window SDL will queue up
65
** several KEYDOWN events for the `tab` key; we flush all keydown
66
** events on focus so these are discarded */
67
-
if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
68
-
SDL_FlushEvent(SDL_KEYDOWN);
69
-
}
70
goto top;
71
72
-
case SDL_DROPFILE:
73
SDL_GetGlobalMouseState(&mx, &my);
74
SDL_GetWindowPosition(window, &wx, &wy);
75
lua_pushstring(L, "filedropped");
76
-
lua_pushstring(L, e.drop.file);
77
lua_pushnumber(L, mx - wx);
78
lua_pushnumber(L, my - wy);
79
-
SDL_free(e.drop.file);
80
return 4;
81
82
-
case SDL_KEYDOWN:
83
lua_pushstring(L, "keypressed");
84
-
lua_pushstring(L, key_name(buf, e.key.keysym.sym));
85
return 2;
86
87
-
case SDL_KEYUP:
88
lua_pushstring(L, "keyreleased");
89
-
lua_pushstring(L, key_name(buf, e.key.keysym.sym));
90
return 2;
91
92
-
case SDL_TEXTINPUT:
93
lua_pushstring(L, "textinput");
94
lua_pushstring(L, e.text.text);
95
return 2;
96
97
-
case SDL_MOUSEBUTTONDOWN:
98
if (e.button.button == 1) { SDL_CaptureMouse(1); }
99
lua_pushstring(L, "mousepressed");
100
lua_pushstring(L, button_name(e.button.button));
···
103
lua_pushnumber(L, e.button.clicks);
104
return 5;
105
106
-
case SDL_MOUSEBUTTONUP:
107
if (e.button.button == 1) { SDL_CaptureMouse(0); }
108
lua_pushstring(L, "mousereleased");
109
lua_pushstring(L, button_name(e.button.button));
···
111
lua_pushnumber(L, e.button.y);
112
return 4;
113
114
-
case SDL_MOUSEMOTION:
115
lua_pushstring(L, "mousemoved");
116
lua_pushnumber(L, e.motion.x);
117
lua_pushnumber(L, e.motion.y);
···
119
lua_pushnumber(L, e.motion.yrel);
120
return 5;
121
122
-
case SDL_MOUSEWHEEL:
123
lua_pushstring(L, "mousewheel");
124
lua_pushnumber(L, e.wheel.y);
125
return 2;
···
139
}
140
141
142
-
static SDL_Cursor* cursor_cache[SDL_SYSTEM_CURSOR_HAND + 1];
143
144
static const char *cursor_opts[] = {
145
"arrow",
···
151
};
152
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
159
};
160
161
static int f_set_cursor(lua_State *L) {
···
183
184
static int f_set_window_mode(lua_State *L) {
185
int n = luaL_checkoption(L, 1, "normal", window_opts);
186
-
SDL_SetWindowFullscreen(window,
187
-
n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
188
if (n == WIN_NORMAL) { SDL_RestoreWindow(window); }
189
if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); }
190
return 0;
···
1
+
#include <SDL3/SDL.h>
2
#include <stdbool.h>
3
+
#include <stdlib.h>
4
#include <ctype.h>
5
#include <dirent.h>
6
#include <unistd.h>
···
38
39
static int f_poll_event(lua_State *L) {
40
char buf[16];
41
+
float mx, my;
42
+
int wx, wy;
43
SDL_Event e;
44
45
top:
···
48
}
49
50
switch (e.type) {
51
+
case SDL_EVENT_QUIT :
52
lua_pushstring(L, "quit");
53
return 1;
54
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:
67
/* on some systems, when alt-tabbing to the window SDL will queue up
68
** several KEYDOWN events for the `tab` key; we flush all keydown
69
** events on focus so these are discarded */
70
+
SDL_FlushEvent(SDL_EVENT_KEY_DOWN);
71
goto top;
72
73
+
case SDL_EVENT_DROP_FILE :
74
SDL_GetGlobalMouseState(&mx, &my);
75
SDL_GetWindowPosition(window, &wx, &wy);
76
lua_pushstring(L, "filedropped");
77
+
lua_pushstring(L, e.drop.data);
78
lua_pushnumber(L, mx - wx);
79
lua_pushnumber(L, my - wy);
80
return 4;
81
82
+
case SDL_EVENT_KEY_DOWN :
83
lua_pushstring(L, "keypressed");
84
+
lua_pushstring(L, key_name(buf, e.key.key));
85
return 2;
86
87
+
case SDL_EVENT_KEY_UP :
88
lua_pushstring(L, "keyreleased");
89
+
lua_pushstring(L, key_name(buf, e.key.key));
90
return 2;
91
92
+
case SDL_EVENT_TEXT_INPUT :
93
lua_pushstring(L, "textinput");
94
lua_pushstring(L, e.text.text);
95
return 2;
96
97
+
case SDL_EVENT_MOUSE_BUTTON_DOWN :
98
if (e.button.button == 1) { SDL_CaptureMouse(1); }
99
lua_pushstring(L, "mousepressed");
100
lua_pushstring(L, button_name(e.button.button));
···
103
lua_pushnumber(L, e.button.clicks);
104
return 5;
105
106
+
case SDL_EVENT_MOUSE_BUTTON_UP :
107
if (e.button.button == 1) { SDL_CaptureMouse(0); }
108
lua_pushstring(L, "mousereleased");
109
lua_pushstring(L, button_name(e.button.button));
···
111
lua_pushnumber(L, e.button.y);
112
return 4;
113
114
+
case SDL_EVENT_MOUSE_MOTION :
115
lua_pushstring(L, "mousemoved");
116
lua_pushnumber(L, e.motion.x);
117
lua_pushnumber(L, e.motion.y);
···
119
lua_pushnumber(L, e.motion.yrel);
120
return 5;
121
122
+
case SDL_EVENT_MOUSE_WHEEL :
123
lua_pushstring(L, "mousewheel");
124
lua_pushnumber(L, e.wheel.y);
125
return 2;
···
139
}
140
141
142
+
static SDL_Cursor* cursor_cache[SDL_SYSTEM_CURSOR_POINTER + 1];
143
144
static const char *cursor_opts[] = {
145
"arrow",
···
151
};
152
153
static const int cursor_enums[] = {
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
};
160
161
static int f_set_cursor(lua_State *L) {
···
183
184
static int f_set_window_mode(lua_State *L) {
185
int n = luaL_checkoption(L, 1, "normal", window_opts);
186
+
SDL_SetWindowFullscreen(window, n == WIN_FULLSCREEN ? SDL_GetWindowFullscreenMode(window) : 0);
187
if (n == WIN_NORMAL) { SDL_RestoreWindow(window); }
188
if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); }
189
return 0;
+20
-27
src/main.c
+20
-27
src/main.c
···
1
#include <stdio.h>
2
-
#include <SDL2/SDL.h>
3
#include "api/api.h"
4
#include "renderer.h"
5
···
16
17
18
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
26
}
27
28
···
48
#ifndef _WIN32
49
#include "../icon.inl"
50
(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);
58
SDL_SetWindowIcon(window, surf);
59
-
SDL_FreeSurface(surf);
60
#endif
61
}
62
···
70
71
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
72
SDL_EnableScreenSaver();
73
-
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
74
atexit(SDL_Quit);
75
76
-
#ifdef SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR /* Available since 2.0.8 */
77
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
78
-
#endif
79
-
#if SDL_VERSION_ATLEAST(2, 0, 5)
80
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
81
-
#endif
82
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);
89
init_window_icon();
90
ren_init(window);
91
92
93
lua_State *L = luaL_newstate();
···
1
#include <stdio.h>
2
+
#include <stdlib.h>
3
+
#include <SDL3/SDL.h>
4
#include "api/api.h"
5
#include "renderer.h"
6
···
17
18
19
static double get_scale(void) {
20
+
return (double)SDL_min(SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()), 1.0);
21
}
22
23
···
43
#ifndef _WIN32
44
#include "../icon.inl"
45
(void) icon_rgba_len; /* unused */
46
+
SDL_Surface *surf = SDL_CreateSurfaceFrom(64, 64, SDL_PIXELFORMAT_ABGR8888, icon_rgba, 64 * 4);
47
SDL_SetWindowIcon(window, surf);
48
+
SDL_DestroySurface(surf);
49
#endif
50
}
51
···
59
60
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
61
SDL_EnableScreenSaver();
62
+
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, true);
63
atexit(SDL_Quit);
64
65
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
66
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
67
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
+
}
75
init_window_icon();
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
+
}
84
85
86
lua_State *L = luaL_newstate();
+2
-1
src/renderer.h
+2
-1
src/renderer.h