From 29837d0c410ac81500c3c87edc01fbc24914ca57 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 8 Jun 2021 21:31:09 -0400 Subject: [PATCH 1/9] Replaced fill loop with SDL_FillRect. --- src/renderer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/renderer.c b/src/renderer.c index b08c25d9..9be08588 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -309,7 +309,8 @@ void ren_draw_rect(RenRect rect, RenColor color) { int dr = surface->w - (x2 - x1); if (color.a == 0xff) { - rect_draw_loop(color); + SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; + SDL_FillRect(surface, &rect, 255 << 24 | color.r << 16 | color.g << 8 | color.r); } else { rect_draw_loop(blend_pixel(*d, color)); } From aa9f16c74ca4aaab43b03a0af8aa91ad11a381a7 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 9 Jun 2021 18:05:39 -0400 Subject: [PATCH 2/9] Added in #if guard for ARM achitectures. --- src/renderer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/renderer.c b/src/renderer.c index 9be08588..8cecbcf4 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -309,8 +309,12 @@ void ren_draw_rect(RenRect rect, RenColor color) { int dr = surface->w - (x2 - x1); if (color.a == 0xff) { - SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; - SDL_FillRect(surface, &rect, 255 << 24 | color.r << 16 | color.g << 8 | color.r); + #if defined(__arm__) || defined(__aarch64__) + rect_draw_loop(color); + #else + SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; + SDL_FillRect(surface, &rect, SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a)); + #endif } else { rect_draw_loop(blend_pixel(*d, color)); } From 214e6898df88d1855ae595ea7e76c1e7603bea74 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 9 Jun 2021 19:34:02 -0400 Subject: [PATCH 3/9] Reverted if guard. --- src/renderer.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/renderer.c b/src/renderer.c index 8cecbcf4..cd269687 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -309,12 +309,8 @@ void ren_draw_rect(RenRect rect, RenColor color) { int dr = surface->w - (x2 - x1); if (color.a == 0xff) { - #if defined(__arm__) || defined(__aarch64__) - rect_draw_loop(color); - #else - SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; - SDL_FillRect(surface, &rect, SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a)); - #endif + SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; + SDL_FillRect(surface, &rect, SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a)); } else { rect_draw_loop(blend_pixel(*d, color)); } From 752ecd5ece0a8797b37a44e12b0cbd69bf7635a0 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 9 Jun 2021 23:37:03 +0200 Subject: [PATCH 4/9] Group mouse move events from C API function Groups together consecutive mouse move events like done in core.step() lua function but on the C side. It does not introduce any meaningful speedup but it theory is more efficient and simplifies the Lua code. The simplification of the Lua code alone is enough to justify this change? --- data/core/init.lua | 14 +++----------- src/api/system.c | 8 ++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index c16307c8..3f85c6e0 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -949,26 +949,18 @@ end function core.step() -- handle events local did_keymap = false - local mouse_moved = false - local mouse = { x = 0, y = 0, dx = 0, dy = 0 } - for type, a,b,c,d in system.poll_event do - if type == "mousemoved" then - mouse_moved = true - mouse.x, mouse.y = a, b - mouse.dx, mouse.dy = mouse.dx + c, mouse.dy + d - elseif type == "textinput" and did_keymap then + if type == "textinput" and did_keymap then did_keymap = false + elseif type == "mousemoved" then + core.try(core.on_event, type, a, b, c, d) else local _, res = core.try(core.on_event, type, a, b, c, d) did_keymap = res or did_keymap end core.redraw = true end - if mouse_moved then - core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy) - end local width, height = renderer.get_size() diff --git a/src/api/system.c b/src/api/system.c index bbe0801b..d00a9e47 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -201,6 +201,14 @@ top: return 4; case SDL_MOUSEMOTION: + SDL_PumpEvents(); + SDL_Event event_plus; + while (SDL_PeepEvents(&event_plus, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) { + e.motion.x = event_plus.motion.x; + e.motion.y = event_plus.motion.y; + e.motion.xrel += event_plus.motion.xrel; + e.motion.yrel += event_plus.motion.yrel; + } lua_pushstring(L, "mousemoved"); lua_pushnumber(L, e.motion.x); lua_pushnumber(L, e.motion.y); From 0f2ac136d0b8e0a852d53cee05399046fd22fa56 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 11 Jun 2021 14:57:41 +0200 Subject: [PATCH 5/9] Fix whitespace errors --- src/api/system.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index d00a9e47..4b98509f 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -538,11 +538,11 @@ static int f_fuzzy_match(lua_State *L) { bool files = false; if (lua_gettop(L) > 2 && lua_isboolean(L,3)) files = lua_toboolean(L, 3); - + int score = 0; int run = 0; - - // Match things *backwards*. This allows for better matching on filenames than the above + + // Match things *backwards*. This allows for better matching on filenames than the above // function. For example, in the lite project, opening "renderer" has lib/font_render/build.sh // as the first result, rather than src/renderer.c. Clearly that's wrong. if (files) { From 7ea096247ce0c96a4c04c5fe2ce87e256d1a8c63 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 11 Jun 2021 23:38:25 +0200 Subject: [PATCH 6/9] documents should not be put into global doc root --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 9b1ab84d..3ac0e7a1 100644 --- a/meson.build +++ b/meson.build @@ -22,7 +22,7 @@ if get_option('portable') lite_docdir = 'doc' lite_datadir = 'data' else - lite_docdir = 'share/doc' + lite_docdir = 'share/doc/lite-xl' lite_datadir = 'share/lite-xl' endif From f729d7d0081933fd00080ed31eb210d9ecdf44f7 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 5 Jun 2021 20:46:09 -0400 Subject: [PATCH 7/9] Allows you to drag nodes around splits. --- data/core/rootview.lua | 85 +++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index b01303c5..31268d36 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -129,36 +129,42 @@ function Node:split(dir, view, locked, resizable) return self.b end +function Node:remove_view(root, view, new_active_view) + if #self.views > 1 then + local idx = self:get_view_idx(view) + if idx < self.tab_offset then + self.tab_offset = self.tab_offset - 1 + end + table.remove(self.views, idx) + if new_active_view then + self:set_active_view(self.views[idx] or self.views[#self.views]) + end + else + local parent = self:get_parent_node(root) + local is_a = (parent.a == self) + local other = parent[is_a and "b" or "a"] + if other:get_locked_size() then + self.views = {} + self:add_view(EmptyView()) + else + parent:consume(other) + local p = parent + while p.type ~= "leaf" do + p = p[is_a and "a" or "b"] + end + p:set_active_view(p.active_view) + if self.is_primary_node then + p.is_primary_node = true + end + end + end + core.last_active_view = nil +end function Node:close_view(root, view) local new_active_view = view == self.active_view local do_close = function() - if #self.views > 1 then - local idx = self:get_view_idx(view) - table.remove(self.views, idx) - if new_active_view then - self:set_active_view(self.views[idx] or self.views[#self.views]) - end - else - local parent = self:get_parent_node(root) - local is_a = (parent.a == self) - local other = parent[is_a and "b" or "a"] - if other:get_locked_size() then - self.views = {} - self:add_view(EmptyView()) - else - parent:consume(other) - local p = parent - while p.type ~= "leaf" do - p = p[is_a and "a" or "b"] - end - p:set_active_view(p.active_view) - if self.is_primary_node then - p.is_primary_node = true - end - end - end - core.last_active_view = nil + self:remove_view(root, view, new_active_view) end view:try_close(do_close) end @@ -169,13 +175,13 @@ function Node:close_active_view(root) end -function Node:add_view(view) +function Node:add_view(view, idx) assert(self.type == "leaf", "Tried to add view to non-leaf node") assert(not self.locked, "Tried to add view to locked node") if self.views[1] and self.views[1]:is(EmptyView) then table.remove(self.views) end - table.insert(self.views, view) + table.insert(self.views, idx or (#self.views + 1), view) self:set_active_view(view) end @@ -749,7 +755,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks) if button == "middle" or node.hovered_close == idx then node:close_view(self.root_node, node.views[idx]) else - self.dragged_node = idx + self.dragged_node = { node, idx } node:set_active_view(node.views[idx]) end else @@ -816,15 +822,24 @@ function RootView:on_mouse_moved(x, y, dx, dy) end elseif tab_index then core.request_cursor("arrow") - if self.dragged_node and self.dragged_node ~= tab_index then - local tab = node.views[self.dragged_node] - table.remove(node.views, self.dragged_node) - table.insert(node.views, tab_index, tab) - self.dragged_node = tab_index - end else core.request_cursor(node.active_view.cursor) end + if self.dragged_node and (self.dragged_node[1] ~= node or (tab_index and self.dragged_node[2] ~= tab_index)) + and node.type == "leaf" and #node.views > 0 and node.views[1]:is(DocView) then + local tab = self.dragged_node[1].views[self.dragged_node[2]] + if self.dragged_node[1] ~= node then + self.dragged_node[1]:remove_view(self.root_node, tab) + node:add_view(tab, tab_index) + tab_index = tab_index or #node.views + self.root_node:update_layout() + core.redraw = true + else + table.remove(self.dragged_node[1].views, self.dragged_node[2]) + table.insert(node.views, tab_index, tab) + end + self.dragged_node = { node, tab_index } + end end From a18eeafbc815b2bf3b080eb3776a26de36d2911f Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 5 Jun 2021 21:55:12 -0400 Subject: [PATCH 8/9] Added in some more checks. --- data/core/rootview.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 31268d36..ba644455 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -822,10 +822,10 @@ function RootView:on_mouse_moved(x, y, dx, dy) end elseif tab_index then core.request_cursor("arrow") - else + elseif node then core.request_cursor(node.active_view.cursor) end - if self.dragged_node and (self.dragged_node[1] ~= node or (tab_index and self.dragged_node[2] ~= tab_index)) + if node and self.dragged_node and (self.dragged_node[1] ~= node or (tab_index and self.dragged_node[2] ~= tab_index)) and node.type == "leaf" and #node.views > 0 and node.views[1]:is(DocView) then local tab = self.dragged_node[1].views[self.dragged_node[2]] if self.dragged_node[1] ~= node then From 66b76f15c290b60a868817905d310443913601cf Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 12 Jun 2021 14:24:31 -0400 Subject: [PATCH 9/9] Added a check for duplicate tabs, also ensured that the appropriate view is set as active. --- data/core/rootview.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index ba644455..1fd5135d 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -129,14 +129,14 @@ function Node:split(dir, view, locked, resizable) return self.b end -function Node:remove_view(root, view, new_active_view) +function Node:remove_view(root, view) if #self.views > 1 then local idx = self:get_view_idx(view) if idx < self.tab_offset then self.tab_offset = self.tab_offset - 1 end table.remove(self.views, idx) - if new_active_view then + if self.active_view == view then self:set_active_view(self.views[idx] or self.views[#self.views]) end else @@ -162,9 +162,8 @@ function Node:remove_view(root, view, new_active_view) end function Node:close_view(root, view) - local new_active_view = view == self.active_view local do_close = function() - self:remove_view(root, view, new_active_view) + self:remove_view(root, view) end view:try_close(do_close) end @@ -829,16 +828,19 @@ function RootView:on_mouse_moved(x, y, dx, dy) and node.type == "leaf" and #node.views > 0 and node.views[1]:is(DocView) then local tab = self.dragged_node[1].views[self.dragged_node[2]] if self.dragged_node[1] ~= node then - self.dragged_node[1]:remove_view(self.root_node, tab) - node:add_view(tab, tab_index) - tab_index = tab_index or #node.views - self.root_node:update_layout() - core.redraw = true + for i, v in ipairs(node.views) do if v.doc == tab.doc then tab = nil break end end + if tab then + self.dragged_node[1]:remove_view(self.root_node, tab) + node:add_view(tab, tab_index) + self.root_node:update_layout() + self.dragged_node = { node, tab_index or #node.views } + core.redraw = true + end else table.remove(self.dragged_node[1].views, self.dragged_node[2]) table.insert(node.views, tab_index, tab) + self.dragged_node = { node, tab_index } end - self.dragged_node = { node, tab_index } end end