From d7cc1f9f9d75c4e388845fc74bcbebbf254a0c07 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 6 Apr 2021 17:50:46 +0200 Subject: [PATCH 01/12] Add plugin verification by version tag --- data/core/init.lua | 36 +++++++++++++++++++++++++++++++- data/plugins/autocomplete.lua | 1 + data/plugins/autoreload.lua | 1 + data/plugins/detectindent.lua | 1 + data/plugins/language_c.lua | 1 + data/plugins/language_css.lua | 1 + data/plugins/language_js.lua | 1 + data/plugins/language_lua.lua | 1 + data/plugins/language_md.lua | 1 + data/plugins/language_python.lua | 1 + data/plugins/language_xml.lua | 1 + data/plugins/macro.lua | 1 + data/plugins/projectsearch.lua | 1 + data/plugins/quote.lua | 1 + data/plugins/reflow.lua | 1 + data/plugins/tabularize.lua | 1 + data/plugins/toolbarview.lua | 1 + data/plugins/treeview.lua | 1 + data/plugins/trimwhitespace.lua | 1 + data/plugins/workspace.lua | 1 + 20 files changed, 54 insertions(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index d1118a45..59944c9a 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -552,6 +552,35 @@ function core.restart() end +local function version_components(version) + local a, b, c = version:match('(%d+)%.(%d+)%.(%d+)') + if a then + return tonumber(a), tonumber(b), tonumber(c) + end + a, b = version:match('(%d+)%.(%d+)') + if a then + return tonumber(a), tonumber(b) + end +end + + +local function check_plugin_version(filename) + local f = io.open(filename, "r") + if not f then return false end + local version_match = false + for line in f:lines() do + local version = line:match('%-%-%s*lite%-xl%s*(%d+%.%d+)%s*$') + if not version then break end + local ver_major, ver_minor = version_components(version) + local ref_major, ref_minor = version_components(VERSION) + version_match = (ver_major == ref_major and ver_minor == ref_minor) + break + end + f:close() + return version_match +end + + function core.load_plugins() local no_errors = true for _, root_dir in ipairs {USERDIR, DATADIR} do @@ -559,7 +588,12 @@ function core.load_plugins() local files = system.list_dir(plugin_dir) for _, filename in ipairs(files or {}) do local basename = filename:match("(.-)%.lua$") or filename - if config[basename] ~= false then + local version_match = check_plugin_version(plugin_dir .. '/' .. filename) + if not version_match then + core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir) + no_errors = false + end + if version_match and config[basename] ~= false then local modname = "plugins." .. basename local ok = core.try(require, modname) if ok then core.log_quiet("Loaded plugin %q from %s", basename, plugin_dir) end diff --git a/data/plugins/autocomplete.lua b/data/plugins/autocomplete.lua index ee318a1c..c0a3d36a 100644 --- a/data/plugins/autocomplete.lua +++ b/data/plugins/autocomplete.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local common = require "core.common" local config = require "core.config" diff --git a/data/plugins/autoreload.lua b/data/plugins/autoreload.lua index a077b6d6..cbef8a21 100644 --- a/data/plugins/autoreload.lua +++ b/data/plugins/autoreload.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local config = require "core.config" local Doc = require "core.doc" diff --git a/data/plugins/detectindent.lua b/data/plugins/detectindent.lua index 2a97e291..9ee171e9 100644 --- a/data/plugins/detectindent.lua +++ b/data/plugins/detectindent.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local command = require "core.command" local common = require "core.common" diff --git a/data/plugins/language_c.lua b/data/plugins/language_c.lua index 8e8ee985..9bb074bf 100644 --- a/data/plugins/language_c.lua +++ b/data/plugins/language_c.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local syntax = require "core.syntax" syntax.add { diff --git a/data/plugins/language_css.lua b/data/plugins/language_css.lua index 021c5d33..2f934551 100644 --- a/data/plugins/language_css.lua +++ b/data/plugins/language_css.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local syntax = require "core.syntax" syntax.add { diff --git a/data/plugins/language_js.lua b/data/plugins/language_js.lua index af650655..9f877ef0 100644 --- a/data/plugins/language_js.lua +++ b/data/plugins/language_js.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local syntax = require "core.syntax" syntax.add { diff --git a/data/plugins/language_lua.lua b/data/plugins/language_lua.lua index 915d2732..64b7847f 100644 --- a/data/plugins/language_lua.lua +++ b/data/plugins/language_lua.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local syntax = require "core.syntax" syntax.add { diff --git a/data/plugins/language_md.lua b/data/plugins/language_md.lua index 9f0f14e6..0998c11e 100644 --- a/data/plugins/language_md.lua +++ b/data/plugins/language_md.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local syntax = require "core.syntax" syntax.add { diff --git a/data/plugins/language_python.lua b/data/plugins/language_python.lua index e6315c4b..b9c07e4e 100644 --- a/data/plugins/language_python.lua +++ b/data/plugins/language_python.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local syntax = require "core.syntax" syntax.add { diff --git a/data/plugins/language_xml.lua b/data/plugins/language_xml.lua index 5240bdc4..8687ab6a 100644 --- a/data/plugins/language_xml.lua +++ b/data/plugins/language_xml.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local syntax = require "core.syntax" syntax.add { diff --git a/data/plugins/macro.lua b/data/plugins/macro.lua index 3458977a..c8873102 100644 --- a/data/plugins/macro.lua +++ b/data/plugins/macro.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local command = require "core.command" local keymap = require "core.keymap" diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index 22c16ef8..c4499339 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local common = require "core.common" local keymap = require "core.keymap" diff --git a/data/plugins/quote.lua b/data/plugins/quote.lua index b17407d3..bca0797b 100644 --- a/data/plugins/quote.lua +++ b/data/plugins/quote.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local command = require "core.command" local keymap = require "core.keymap" diff --git a/data/plugins/reflow.lua b/data/plugins/reflow.lua index 95090a64..9556e37e 100644 --- a/data/plugins/reflow.lua +++ b/data/plugins/reflow.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local config = require "core.config" local command = require "core.command" diff --git a/data/plugins/tabularize.lua b/data/plugins/tabularize.lua index f4dda1f9..31821525 100644 --- a/data/plugins/tabularize.lua +++ b/data/plugins/tabularize.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local command = require "core.command" local translate = require "core.doc.translate" diff --git a/data/plugins/toolbarview.lua b/data/plugins/toolbarview.lua index 65e782ae..2edfa8bc 100644 --- a/data/plugins/toolbarview.lua +++ b/data/plugins/toolbarview.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local common = require "core.common" local command = require "core.command" diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 5e16ce55..44422b77 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local common = require "core.common" local command = require "core.command" diff --git a/data/plugins/trimwhitespace.lua b/data/plugins/trimwhitespace.lua index d4d25c8f..5a43653b 100644 --- a/data/plugins/trimwhitespace.lua +++ b/data/plugins/trimwhitespace.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local command = require "core.command" local Doc = require "core.doc" diff --git a/data/plugins/workspace.lua b/data/plugins/workspace.lua index 81d2207d..c24358c2 100644 --- a/data/plugins/workspace.lua +++ b/data/plugins/workspace.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local common = require "core.common" local DocView = require "core.docview" From 119f406d3c69366078b667f4ca4e9cda747391ab Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 7 Apr 2021 09:42:19 +0200 Subject: [PATCH 02/12] Add NagView message for refused plugins --- data/core/init.lua | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 59944c9a..d7c3177e 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -441,7 +441,7 @@ function core.init() core.project_scan_thread_id = core.add_thread(project_scan_thread) command.add_defaults() local got_user_error = not core.load_user_directory() - local got_plugin_error = not core.load_plugins() + local plugins_success, plugins_refuse_list = core.load_plugins() do local pdir, pname = project_dir_abs:match("(.*)[/\\\\](.*)") @@ -457,9 +457,28 @@ function core.init() core.error(delayed_error) end - if got_plugin_error or got_user_error or got_project_error then + if not plugins_success or got_user_error or got_project_error then command.perform("core:open-log") end + + if #plugins_refuse_list.userdir.plugins > 0 or #plugins_refuse_list.datadir.plugins > 0 then + local opt = { + { font = style.font, text = "Exit", default_no = true }, + { font = style.font, text = "Continue" , default_yes = true } + } + local msg = {} + for _, entry in pairs(plugins_refuse_list) do + if #entry.plugins > 0 then + msg[#msg + 1] = string.format("from %s: %s", common.home_encode(entry.dir), table.concat(entry.plugins, ", ")) + end + end + core.nag_view:show( + "Refused Plugins", + string.format("Refused plugins %s", table.concat(msg, " and ")), + opt, function(item) + if item.text == "Exit" then os.exit(1) end + end) + end end @@ -583,6 +602,10 @@ end function core.load_plugins() local no_errors = true + local refused_list = { + userdir = {dir = USERDIR, plugins = {}}, + datadir = {dir = DATADIR, plugins = {}}, + } for _, root_dir in ipairs {USERDIR, DATADIR} do local plugin_dir = root_dir .. "/plugins" local files = system.list_dir(plugin_dir) @@ -591,7 +614,8 @@ function core.load_plugins() local version_match = check_plugin_version(plugin_dir .. '/' .. filename) if not version_match then core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir) - no_errors = false + local ls = refused_list[root_dir == USERDIR and 'userdir' or 'datadir'].plugins + ls[#ls + 1] = filename end if version_match and config[basename] ~= false then local modname = "plugins." .. basename @@ -603,7 +627,7 @@ function core.load_plugins() end end end - return no_errors + return no_errors, refused_list end From f250adcda17ccf3d06ecd7227564295ea425c740 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 7 Apr 2021 23:46:45 +0200 Subject: [PATCH 03/12] Implement multi-lines for NagView Related to issue #147 --- data/core/init.lua | 7 +++-- data/core/nagview.lua | 59 ++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index d7c3177e..7573aa32 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -469,12 +469,15 @@ function core.init() local msg = {} for _, entry in pairs(plugins_refuse_list) do if #entry.plugins > 0 then - msg[#msg + 1] = string.format("from %s: %s", common.home_encode(entry.dir), table.concat(entry.plugins, ", ")) + msg[#msg + 1] = string.format("Plugins from directory \"%s\":\n%s", common.home_encode(entry.dir), table.concat(entry.plugins, "\n")) end end core.nag_view:show( "Refused Plugins", - string.format("Refused plugins %s", table.concat(msg, " and ")), + string.format( + "Some plugins are not loaded due to version mismatch.\n\n%s.\n\n" .. + "Please download a recent version from https://github.com/franko/lite-plugins.", + table.concat(msg, ".\n\n")), opt, function(item) if item.text == "Exit" then os.exit(1) end end) diff --git a/data/core/nagview.lua b/data/core/nagview.lua index ff5bad10..accb1a45 100644 --- a/data/core/nagview.lua +++ b/data/core/nagview.lua @@ -1,6 +1,7 @@ local core = require "core" local command = require "core.command" local common = require "core.common" +local config = require "core.config" local View = require "core.view" local style = require "core.style" @@ -23,24 +24,33 @@ function NagView:get_title() return self.title end -function NagView:get_options_line_height() - local max = 0 - for _, opt in ipairs(self.options) do - local lh = style.font:get_height(opt.text) - if lh > max then max = lh end - end - return max +-- The two methods below are duplicated from DocView +function NagView:get_line_height() + return math.floor(style.font:get_height() * config.line_height) end -function NagView:get_line_height() - return self.max_lh + 2 * BORDER_WIDTH + 2 * style.padding.y +function NagView:get_line_text_y_offset() + local lh = self:get_line_height() + local th = style.font:get_height() + return (lh - th) / 2 +end + +-- Buttons height without padding +function NagView:get_buttons_height() + local lh = style.font:get_height() + local bt_padding = lh / 2 + return lh + 2 * BORDER_WIDTH + 2 * bt_padding +end + +function NagView:get_target_height() + return self.target_height + 2 * style.padding.y end function NagView:update() NagView.super.update(self) if core.active_view == self and self.title then - self:move_towards(self.size, "y", self:get_line_height()) + self:move_towards(self.size, "y", self:get_target_height()) self:move_towards(self, "underline_progress", 1) else self:move_towards(self.size, "y", 0) @@ -68,10 +78,10 @@ function NagView:each_option() return coroutine.wrap(function() if not self.options then return end local opt, bw,bh,ox,oy - bh = self.max_lh + 2 * BORDER_WIDTH + style.padding.y + bh = self:get_buttons_height() ox,oy = self:get_content_offset() ox = ox + self.size.x - oy = oy + (self.size.y / 2) - (bh / 2) + oy = oy + self.size.y - bh - style.padding.y for i = #self.options, 1, -1 do opt = self.options[i] @@ -112,6 +122,7 @@ function NagView:on_text_input(text) end end + function NagView:draw() if self.size.y <= 0 or not self.title then return end @@ -129,7 +140,13 @@ function NagView:draw() end -- draw message - common.draw_text(style.font, style.nagbar_text, self.message, "left", ox, oy, self.size.x, self.size.y) + local lh = style.font:get_height() * config.line_height + oy = oy + style.padding.y + (self.target_height - self:get_message_height()) / 2 + for msg_line in self.message:gmatch("(.-)\n") do + local ty = oy + self:get_line_text_y_offset() + renderer.draw_text(style.font, msg_line, ox, ty, style.nagbar_text) + oy = oy + lh + end -- draw buttons for i, opt, bx,by,bw,bh in self:each_option() do @@ -159,14 +176,26 @@ local function findindex(tbl, prop) end end +function NagView:get_message_height() + local h = 0 + for str in string.gmatch(self.message, "(.-)\n") do + h = h + style.font:get_height() * config.line_height + end + return h +end + + function NagView:next() local opts = table.remove(self.queue, 1) or {} self.title = opts.title - self.message = opts.message + self.message = opts.message and opts.message .. "\n" self.options = opts.options self.on_selected = opts.on_selected if self.message and self.options then - self.max_lh = math.max(style.font:get_height(self.message), self:get_options_line_height()) + local message_height = self:get_message_height() + -- self.target_height is the nagview height needed to display the message and + -- the buttons, excluding the top and bottom padding space. + self.target_height = math.max(message_height, self:get_buttons_height()) self:change_hovered(findindex(self.options, "default_yes")) end self.force_focus = self.message ~= nil From d6f2f1f0a44918cf47a6a779081c6ae01d72fdb3 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 8 Apr 2021 15:40:44 +0200 Subject: [PATCH 04/12] Add script to test third-part plugins --- dev-utils/run-local-plugin | 91 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 dev-utils/run-local-plugin diff --git a/dev-utils/run-local-plugin b/dev-utils/run-local-plugin new file mode 100644 index 00000000..db38167b --- /dev/null +++ b/dev-utils/run-local-plugin @@ -0,0 +1,91 @@ +#!/bin/bash + +set -o errexit + +option_copy=on +pargs=() +while [[ "$#" -gt 0 ]]; do + case $1 in + -keep) + option_copy=off + ;; + -plugin-dir=*) + plugin_dir="${1#-plugin-dir=}" + ;; + -plugin=*) + # should be like -plugin=franko/lite-plugins/master/plugins/autowrap.lua + plugin+=("${1#-plugin=}") + ;; + -global) + option_global=on + ;; + -*) + echo "error: unknown option \"$1\"" + exit 1 + ;; + *) + pargs+=("$1") + ;; + esac + shift +done + +if [ "${#pargs[@]}" -lt 1 ]; then + echo "usage: $0 [options] " + exit 1 +fi + +if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then + run_windows=yes +fi + +rundir=".run" +bindir="$rundir/bin" +datadir="$rundir/share/lite-xl" + +userdir="$(realpath "$rundir")" +builddir="${pargs[0]}" + +build_lite () { + echo "running ninja" + ninja -C "$builddir" +} + +copy_lite_build () { + echo "copying lite executable and data" + rm -fr "$rundir" + mkdir -p "$bindir" "$datadir" + if [ ! -z ${run_windows+x} ]; then + cp "$builddir/src/lite.exe" "$bindir" + else + cp "$builddir/src/lite" "$bindir" + fi + for module_name in core plugins colors fonts; do + cp -r "data/$module_name" "$datadir" + done +} + +run_lite () { + if [ ! -z ${option_global+x} ]; then + echo "running \"lite ${pargs[@]:1}\"" + exec "$bindir/lite" "${pargs[@]:1}" + else + echo "running \"lite ${pargs[@]:1}\" with local HOME" + if [ ! -z ${run_windows+x} ]; then + USERPROFILE="$userdir" exec "$bindir/lite" "${pargs[@]:1}" + else + HOME="$userdir" exec "$bindir/lite" "${pargs[@]:1}" + fi + fi +} + +copy_plugin () { + echo "-- lite-xl 1.16" | cat - "$plugin_dir/$plugin.lua" > "$datadir/plugins/$plugin.lua" +} + +if [ $option_copy == on ]; then + build_lite + copy_lite_build +fi +copy_plugin +run_lite From 7531a0ddc80f557426aff98ddad8fa2e12609065 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 10 Apr 2021 19:35:57 +0200 Subject: [PATCH 05/12] Preliminary implementation of border-less mode Not yet functional but most ingredients are there --- data/core/config.lua | 1 + data/core/init.lua | 14 ++++++- data/core/titleview.lua | 30 ++++++++++++++ data/fonts/icons.ttf | Bin 8680 -> 9288 bytes dev-utils/fontello-config-small.json | 20 +++++++++- src/api/system.c | 57 +++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 data/core/titleview.lua diff --git a/data/core/config.lua b/data/core/config.lua index 5ee5d576..4c56a697 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -22,6 +22,7 @@ config.transitions = true config.animation_rate = 1.0 config.blink_period = 0.8 config.draw_whitespace = false +config.borderless = true -- Disable plugin loading setting to false the config entry -- of the same name. diff --git a/data/core/init.lua b/data/core/init.lua index 7573aa32..bd92f23c 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -6,6 +6,7 @@ local command local keymap local RootView local StatusView +local TitleView local CommandView local NagView local DocView @@ -358,6 +359,7 @@ function core.init() keymap = require "core.keymap" RootView = require "core.rootview" StatusView = require "core.statusview" + TitleView = require "core.titleview" CommandView = require "core.commandview" NagView = require "core.nagview" DocView = require "core.docview" @@ -398,6 +400,11 @@ function core.init() end end + if config.borderless then + system.set_window_bordered(false) + system.set_window_hit_test() + end + core.frame_start = 0 core.clip_rect_stack = {{ 0,0,0,0 }} core.log_items = {} @@ -430,9 +437,12 @@ function core.init() core.command_view = CommandView() core.status_view = StatusView() core.nag_view = NagView() + core.title_view = TitleView() local cur_node = core.root_view.root_node cur_node.is_primary_node = true + cur_node:split("up", core.title_view, {y = true}) + cur_node = cur_node.b cur_node:split("up", core.nag_view, {y = true}) cur_node = cur_node.b cur_node = cur_node:split("down", core.command_view, {y = true}) @@ -828,7 +838,7 @@ local function get_title_filename(view) end -local function compose_window_title(title) +function core.compose_window_title(title) return title == "" and "Lite XL" or title .. " - Lite XL" end @@ -877,7 +887,7 @@ function core.step() -- update window title local current_title = get_title_filename(core.active_view) if current_title ~= core.window_title then - system.set_window_title(compose_window_title(current_title)) + system.set_window_title(core.compose_window_title(current_title)) core.window_title = current_title end diff --git a/data/core/titleview.lua b/data/core/titleview.lua new file mode 100644 index 00000000..988b34bd --- /dev/null +++ b/data/core/titleview.lua @@ -0,0 +1,30 @@ +local core = require "core" +local style = require "core.style" +local StatusView = require "core.statusview" + + +local TitleView = StatusView:extend() + +TitleView.separator = " " + +function TitleView:new() + TitleView.super.new(self) +end + + +function TitleView:on_mouse_pressed() + core.set_active_view(core.last_active_view) +end + + +function TitleView:get_items() + local title = core.compose_window_title(core.window_title) + return { + style.text, style.icon_font, "g ", style.font, title, + }, { + style.text, style.icon_font, "_", TitleView.separator, "w", TitleView.separator, "W", + } +end + + +return TitleView diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 2b24bae7683d02cb6c3fe281cec032baf12c67b3..398e73e90734d359b00db8d867baebffa6028275 100644 GIT binary patch delta 1240 zcmZ8gU1%It6h7z9?93*+nb}D!IOxOyy7CmC$d+@(Hv^Z0Dc0&-A#~fr%4Y$ zgdOrnXbu5_pu;#EgISn^Q!o#Ukc2ekpa50Jp{!Q)YAuhZ^(i2`K z?FoM;>j~X4P0gtL_(nm$#VXID0}v2tW)H@W{;QP>iF5P|ui zARuF65=2oGpPw|tk#N5xN5+jQ%X|!7H4;^Elq)Gbh%#5*@oDVoj-wWqWIZ}ErJ2^0 z9`9xsPfOB;3zBqNQn*#5t%n@AWE%heIBcP52$o^K@qgk&c~pTHV9z$s8YWu9>~n5t zIKb9G@H27Sw zxD?@nX|Ud5OU41*-8KyzXf_PFdg2bKLWA>k^V5$$xo4d_ zd^G!eW$;MN&F6u8OSA7PWBm=s5xDFC2rto3U*XniiWSGPA6I*hoE6^{zw)*F^1hqW zlWq;Ient%lF%20CD54J~l+llE*p2}VVh1XyVhA-Z(Tk5=Qi`>fUf0@Wt;T~a|ZbH zrJH7PakCFlIX|#g$QjweQ)5leea8M&fd$_O@s;@|^U;D;siqd+I6qiuv2dbP&KS{$ zk>5c02=o1xQMIXGf6LsxVEnpa}Af4l?}VRTzQgsw*>S}v;W?{k+aR2SKKTy z{kXM61vy8jsVLXz;CutbDZn~J`)iyrz>_wh;x6m`Jcoc62^_`*&SDm6TtF6i6di~C zjz05WH(gyOl-MM3ZD;Sp?jGa{g2E@N@bIZV_|e1tg3u6R%PUD7kWZDV_RDc{XK@1i z?A?+PF%;I?>dUSfk`F|ABFoGTzB|lr1R3+)aBGU)2-RoRZ@&6`=(Un`r{^erO5M90 zKG{TAY_o#T3%?HSqSJJ)sjKpPWH`FoeJ$7OEL{%tCMRovxXAx^#YN|D+bW@kEn26R zl2&TM6gz5Mt*Tp|^X$4^_4@tZpcv9gAwep6$V)!*Qx63wNE(Gmr?717nUiC&qyp40 I#eVAl0Fu^y3IG5A diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json index ff3952ff..b5027e87 100644 --- a/dev-utils/fontello-config-small.json +++ b/dev-utils/fontello-config-small.json @@ -83,6 +83,24 @@ "css": "cancel-1", "code": 67, "src": "fontawesome" + }, + { + "uid": "04f022b8bd044d4ccfffd3887ff72088", + "css": "window-minimize", + "code": 95, + "src": "fontawesome" + }, + { + "uid": "d0e62145dbf40f30e47b3819b8b43a8f", + "css": "window-restore", + "code": 119, + "src": "fontawesome" + }, + { + "uid": "7394501fc0b17cb7bda99538f92e26d6", + "css": "window-close", + "code": 87, + "src": "fontawesome" } ] -} +} \ No newline at end of file diff --git a/src/api/system.c b/src/api/system.c index 44f57fb7..b5c732c5 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -35,6 +35,44 @@ static char* key_name(char *dst, int sym) { return dst; } +// FIXME: shouldn't be hard-coded but should depend on TitleView's height +#define TITLE_BAR_WIDTH 100 +#define RESIZE_BORDER 40 + +static SDL_HitTestResult SDLCALL +hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { + int w, h; + + SDL_GetWindowSize(window, &w, &h); + + if (pt->y < TITLE_BAR_WIDTH && pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER) { + return SDL_HITTEST_DRAGGABLE; + } + + #define REPORT_RESIZE_HIT(name) { \ + return SDL_HITTEST_RESIZE_##name; \ + } + + if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) { + REPORT_RESIZE_HIT(TOPLEFT); + } else if (pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER && pt->y < RESIZE_BORDER) { + REPORT_RESIZE_HIT(TOP); + } else if (pt->x > w - RESIZE_BORDER && pt->y < RESIZE_BORDER) { + REPORT_RESIZE_HIT(TOPRIGHT); + } else if (pt->x > w - RESIZE_BORDER && pt->y > RESIZE_BORDER && pt->y < h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(RIGHT); + } else if (pt->x > w - RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(BOTTOMRIGHT); + } else if (pt->x < w - RESIZE_BORDER && pt->x > RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(BOTTOM); + } else if (pt->x < RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(BOTTOMLEFT); + } else if (pt->x < RESIZE_BORDER && pt->y < h - RESIZE_BORDER && pt->y > RESIZE_BORDER) { + REPORT_RESIZE_HIT(LEFT); + } + + return SDL_HITTEST_NORMAL; +} static int f_poll_event(lua_State *L) { char buf[16]; @@ -201,6 +239,23 @@ static int f_set_window_mode(lua_State *L) { } +static int f_set_window_bordered(lua_State *L) { + int bordered = lua_toboolean(L, 1); + SDL_SetWindowBordered(window, bordered); + return 0; +} + + +static int f_set_window_hit_test(lua_State *L) { + if (SDL_SetWindowHitTest(window, hit_test, NULL) == -1) { + lua_pushboolean(L, 0); + } else { + lua_pushboolean(L, 1); + } + return 1; +} + + static int f_get_window_size(lua_State *L) { int x, y, w, h; SDL_GetWindowSize(window, &w, &h); @@ -441,6 +496,8 @@ static const luaL_Reg lib[] = { { "set_cursor", f_set_cursor }, { "set_window_title", f_set_window_title }, { "set_window_mode", f_set_window_mode }, + { "set_window_bordered", f_set_window_bordered }, + { "set_window_hit_test", f_set_window_hit_test }, { "get_window_size", f_get_window_size }, { "set_window_size", f_set_window_size }, { "window_has_focus", f_window_has_focus }, From 8ad87d77da9f66839fc88db8424aae692c78a2f2 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 11 Apr 2021 15:08:25 +0200 Subject: [PATCH 06/12] Add correct hit-test information and menu icon --- data/core/init.lua | 4 ++- data/core/titleview.lua | 16 ++++++++- data/fonts/icons.ttf | Bin 9288 -> 9512 bytes dev-utils/fontello-config-small.json | 8 ++++- dev-utils/{run-local-plugin => run-plugin} | 0 src/api/system.c | 37 ++++++++++++--------- 6 files changed, 47 insertions(+), 18 deletions(-) rename dev-utils/{run-local-plugin => run-plugin} (100%) diff --git a/data/core/init.lua b/data/core/init.lua index bd92f23c..d4ef5494 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -400,9 +400,11 @@ function core.init() end end + core.window_borderless = false + core.hit_test_title_height = 0 if config.borderless then system.set_window_bordered(false) - system.set_window_hit_test() + core.window_borderless = true end core.frame_start = 0 diff --git a/data/core/titleview.lua b/data/core/titleview.lua index 988b34bd..e4487a55 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -16,11 +16,25 @@ function TitleView:on_mouse_pressed() core.set_active_view(core.last_active_view) end +function TitleView:on_mouse_moved(px, py, ...) +end + + +function TitleView:update() + TitleView.super.update(self) + local title_height = self.size.y + if core.window_borderless and title_height ~= core.hit_test_title_height then + local resize_border = title_height / 2 + system.set_window_hit_test(title_height, resize_border) + core.hit_test_title_height = title_height + end +end + function TitleView:get_items() local title = core.compose_window_title(core.window_title) return { - style.text, style.icon_font, "g ", style.font, title, + style.text, style.icon_font, "M ", style.font, title, }, { style.text, style.icon_font, "_", TitleView.separator, "w", TitleView.separator, "W", } diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 398e73e90734d359b00db8d867baebffa6028275..02ad3694b9c0f0ed00fa10f40cb5f02600dc2ac0 100644 GIT binary patch delta 829 zcmZ9KO-NKx6vzMf-S=iR$M@z{rGU^;iWkaREqd+zU?bI<+YF2@&7 zKZwoj0N4P4;bhi!njSY<#EXFPDtSF$=c_HX0iig>ThdM@d%1P%HgO)%eHnYoA-|uv zhipY={AM~n_pJn|=Yi_>v6MX;{%~&&Fy|@WIYtieNB*67iMW0&o1gAZ442l(K~BWS zCz5vUm+&kQI85A-wWl4nM}JF91yPr?v#H{Xn%%_HbikrBF_m9`e>VUG#Q`^+$&`~m z`SLl{zVmSN5}S30Sf+IajDo;t@bavMthn!6hOX*}YQU=*8QsPWEq)hPAM(H*G#Rm(+YL_;{ zfzoe&QCWh4S{y=a&%ymn)heKXDQD+rs?Y0h7RgSJl=5gzM$pt zMxqUk9qpZ6k+u*gZj`)Ba%?+au>6018Ws!b-0U?%Y#aVhqkZMP^2q#gosy06$n-uv z6w>>|0u<&ek9xz!?%dT8&?AC!5M$bGNKi!49tLe*w-`l~4cx delta 617 zcmZ4Cb;4tUay>5t17iRK14CGHZeoGr3!Mu<{t5;LrbWqRB?>(9|BV50V!Kyd*eKLJQ{q~}zo#W^1BVPIhKVPN1X$Vg30k=Y-27N}$o zP~I#9D8PP*`8kmP1;|&)$StX`{ulQD83Ti$1W>>wCqFq+(oALpkRJn5kegUhz$nSL z6Uc7>@)hzDb5qaGm5>DT7XTf2wjjT_q~dD79s`32$RY0wic$;GoYv1_U{GE#@kcac z`{WSDbi+#wj6g{ShBFMzV3rP$<^uZh5(5jv0-(4I&i0#H%_sHbM~ z1SVd79nHEy`E9;3@H4*v zDrUGdy>}Xnp1eWOoKbM{3qj4vqC$G&Y0RHkqF7p3HnDQCX0YC2vj7LI;O00XZf2me VEK#M&eWIR|?};XFb`X2P2LLt1dwT!? diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json index b5027e87..fa7e6334 100644 --- a/dev-utils/fontello-config-small.json +++ b/dev-utils/fontello-config-small.json @@ -101,6 +101,12 @@ "css": "window-close", "code": 87, "src": "fontawesome" + }, + { + "uid": "559647a6f430b3aeadbecd67194451dd", + "css": "menu-1", + "code": 77, + "src": "fontawesome" } ] -} \ No newline at end of file +} diff --git a/dev-utils/run-local-plugin b/dev-utils/run-plugin similarity index 100% rename from dev-utils/run-local-plugin rename to dev-utils/run-plugin diff --git a/src/api/system.c b/src/api/system.c index b5c732c5..7d316d58 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -35,17 +35,22 @@ static char* key_name(char *dst, int sym) { return dst; } -// FIXME: shouldn't be hard-coded but should depend on TitleView's height -#define TITLE_BAR_WIDTH 100 -#define RESIZE_BORDER 40 +struct HitTestInfo { + int title_height; + int resize_border; +}; +typedef struct HitTestInfo HitTestInfo; -static SDL_HitTestResult SDLCALL -hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { +static HitTestInfo window_hit_info[1] = {{0, 0}}; + +static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { + const HitTestInfo *hit_info = (HitTestInfo *) data; + const int resize_border = hit_info->resize_border; int w, h; SDL_GetWindowSize(window, &w, &h); - if (pt->y < TITLE_BAR_WIDTH && pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER) { + if (pt->y < hit_info->title_height && pt->x > resize_border && pt->x < w - resize_border) { return SDL_HITTEST_DRAGGABLE; } @@ -53,21 +58,21 @@ hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { return SDL_HITTEST_RESIZE_##name; \ } - if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) { + if (pt->x < resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPLEFT); - } else if (pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER && pt->y < RESIZE_BORDER) { + } else if (pt->x > resize_border && pt->x < w - resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOP); - } else if (pt->x > w - RESIZE_BORDER && pt->y < RESIZE_BORDER) { + } else if (pt->x > w - resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPRIGHT); - } else if (pt->x > w - RESIZE_BORDER && pt->y > RESIZE_BORDER && pt->y < h - RESIZE_BORDER) { + } else if (pt->x > w - resize_border && pt->y > resize_border && pt->y < h - resize_border) { REPORT_RESIZE_HIT(RIGHT); - } else if (pt->x > w - RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + } else if (pt->x > w - resize_border && pt->y > h - resize_border) { REPORT_RESIZE_HIT(BOTTOMRIGHT); - } else if (pt->x < w - RESIZE_BORDER && pt->x > RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + } else if (pt->x < w - resize_border && pt->x > resize_border && pt->y > h - resize_border) { REPORT_RESIZE_HIT(BOTTOM); - } else if (pt->x < RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + } else if (pt->x < resize_border && pt->y > h - resize_border) { REPORT_RESIZE_HIT(BOTTOMLEFT); - } else if (pt->x < RESIZE_BORDER && pt->y < h - RESIZE_BORDER && pt->y > RESIZE_BORDER) { + } else if (pt->x < resize_border && pt->y < h - resize_border && pt->y > resize_border) { REPORT_RESIZE_HIT(LEFT); } @@ -247,7 +252,9 @@ static int f_set_window_bordered(lua_State *L) { static int f_set_window_hit_test(lua_State *L) { - if (SDL_SetWindowHitTest(window, hit_test, NULL) == -1) { + window_hit_info->title_height = luaL_checknumber(L, 1); + window_hit_info->resize_border = luaL_checknumber(L, 2); + if (SDL_SetWindowHitTest(window, hit_test, window_hit_info) == -1) { lua_pushboolean(L, 0); } else { lua_pushboolean(L, 1); From 67dc16ad2645ad0282860bdd7efc9d8452fdc7aa Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 11 Apr 2021 23:52:31 +0200 Subject: [PATCH 07/12] Make windows control buttons active --- data/core/titleview.lua | 105 ++++++++++++++++++++++++++++++++-------- src/api/system.c | 15 ++++-- 2 files changed, 95 insertions(+), 25 deletions(-) diff --git a/data/core/titleview.lua b/data/core/titleview.lua index e4487a55..c53c5371 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -1,44 +1,109 @@ local core = require "core" +local common = require "core.common" local style = require "core.style" -local StatusView = require "core.statusview" +local View = require "core.view" +local title_commands = { + {symbol = "_", action = function() system.set_window_mode("minimized") end}, + {symbol = "w", action = function() system.set_window_mode("maximized") end}, + {symbol = "W", action = function() core.quit() end}, +} -local TitleView = StatusView:extend() +local TitleView = View:extend() -TitleView.separator = " " +local function title_view_height() + return style.font:get_height() + style.padding.y * 2 +end function TitleView:new() TitleView.super.new(self) + -- FIXME: decide if visible is actually needed + self.visible = true end - -function TitleView:on_mouse_pressed() - core.set_active_view(core.last_active_view) -end - -function TitleView:on_mouse_moved(px, py, ...) -end - - function TitleView:update() + if self.visible then + self.size.y = title_view_height() + else + self.size.y = 0 + end TitleView.super.update(self) local title_height = self.size.y if core.window_borderless and title_height ~= core.hit_test_title_height then - local resize_border = title_height / 2 - system.set_window_hit_test(title_height, resize_border) + local icon_w = style.icon_font:get_width("_") + local icon_spacing = icon_w + local controls_width = (icon_w + icon_spacing) * #title_commands + icon_spacing + system.set_window_hit_test(title_height, controls_width, icon_spacing) core.hit_test_title_height = title_height end end -function TitleView:get_items() +function TitleView:draw_window_title() + local h = style.font:get_height() + local ox, oy = self:get_content_offset() + local color = style.text + local x, y = ox + style.padding.x, oy + style.padding.y + x = common.draw_text(style.icon_font, color, "M ", nil, x, y, 0, h) local title = core.compose_window_title(core.window_title) - return { - style.text, style.icon_font, "M ", style.font, title, - }, { - style.text, style.icon_font, "_", TitleView.separator, "w", TitleView.separator, "W", - } + common.draw_text(style.font, color, title, nil, x, y, 0, h) +end + +function TitleView:each_control_item() + local icon_h, icon_w = style.icon_font:get_height(), style.icon_font:get_width("_") + local icon_spacing = icon_w + local ox, oy = self:get_content_offset() + ox = ox + self.size.x + local i, n = 0, #title_commands + local iter = function() + i = i + 1 + if i <= n then + local dx = - (icon_w + icon_spacing) * (n - i + 1) + local dy = style.padding.y + return title_commands[i], ox + dx, oy + dy, icon_w, icon_h + end + end + return iter end +function TitleView:draw_window_controls() + for item, x, y, w, h in self:each_control_item() do + local color = item == self.hovered_item and style.text or style.dim + common.draw_text(style.icon_font, color, item.symbol, nil, x, y, 0, h) + end +end + + +function TitleView:on_mouse_pressed(button, x, y, clicks) + local caught = TitleView.super.on_mouse_pressed(self, button, x, y, clicks) + if caught then return end + core.set_active_view(core.last_active_view) + if self.hovered_item then + self.hovered_item.action() + end +end + + +function TitleView:on_mouse_moved(px, py, ...) + TitleView.super.on_mouse_moved(self, px, py, ...) + self.hovered_item = nil + local x_min, x_max, y_min, y_max = self.size.x, 0, self.size.y, 0 + for item, x, y, w, h in self:each_control_item() do + x_min, x_max = math.min(x, x_min), math.max(x + w, x_max) + y_min, y_max = y, y + h + if px > x and py > y and px <= x + w and py <= y + h then + self.hovered_item = item + return + end + end +end + + +function TitleView:draw() + self:draw_background(style.background2) + self:draw_window_title() + self:draw_window_controls() +end + return TitleView diff --git a/src/api/system.c b/src/api/system.c index 7d316d58..024b04f0 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -37,6 +37,7 @@ static char* key_name(char *dst, int sym) { struct HitTestInfo { int title_height; + int controls_width; int resize_border; }; typedef struct HitTestInfo HitTestInfo; @@ -46,11 +47,13 @@ static HitTestInfo window_hit_info[1] = {{0, 0}}; static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { const HitTestInfo *hit_info = (HitTestInfo *) data; const int resize_border = hit_info->resize_border; + const int controls_width = hit_info->controls_width; int w, h; SDL_GetWindowSize(window, &w, &h); - if (pt->y < hit_info->title_height && pt->x > resize_border && pt->x < w - resize_border) { + if (pt->y < hit_info->title_height && pt->y > hit_info->resize_border && + pt->x > resize_border && pt->x < w - controls_width) { return SDL_HITTEST_DRAGGABLE; } @@ -60,7 +63,7 @@ static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *p if (pt->x < resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPLEFT); - } else if (pt->x > resize_border && pt->x < w - resize_border && pt->y < resize_border) { + } else if (pt->x > resize_border && pt->x < w - controls_width && pt->y < resize_border) { REPORT_RESIZE_HIT(TOP); } else if (pt->x > w - resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPRIGHT); @@ -231,8 +234,8 @@ static int f_set_window_title(lua_State *L) { } -static const char *window_opts[] = { "normal", "maximized", "fullscreen", 0 }; -enum { WIN_NORMAL, WIN_MAXIMIZED, WIN_FULLSCREEN }; +static const char *window_opts[] = { "normal", "minimized", "maximized", "fullscreen", 0 }; +enum { WIN_NORMAL, WIN_MINIMIZED, WIN_MAXIMIZED, WIN_FULLSCREEN }; static int f_set_window_mode(lua_State *L) { int n = luaL_checkoption(L, 1, "normal", window_opts); @@ -240,6 +243,7 @@ static int f_set_window_mode(lua_State *L) { n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); if (n == WIN_NORMAL) { SDL_RestoreWindow(window); } if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); } + if (n == WIN_MINIMIZED) { SDL_MinimizeWindow(window); } return 0; } @@ -253,7 +257,8 @@ static int f_set_window_bordered(lua_State *L) { static int f_set_window_hit_test(lua_State *L) { window_hit_info->title_height = luaL_checknumber(L, 1); - window_hit_info->resize_border = luaL_checknumber(L, 2); + window_hit_info->controls_width = luaL_checknumber(L, 2); + window_hit_info->resize_border = luaL_checknumber(L, 3); if (SDL_SetWindowHitTest(window, hit_test, window_hit_info) == -1) { lua_pushboolean(L, 0); } else { From 96a0ae802a3a08374cc00cc0ca8c6d19c81ab50a Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 12 Apr 2021 11:08:47 +0200 Subject: [PATCH 08/12] Improve run-plugin to use positional arguments --- dev-utils/run-plugin | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) mode change 100644 => 100755 dev-utils/run-plugin diff --git a/dev-utils/run-plugin b/dev-utils/run-plugin old mode 100644 new mode 100755 index db38167b..ee950b0d --- a/dev-utils/run-plugin +++ b/dev-utils/run-plugin @@ -9,13 +9,6 @@ while [[ "$#" -gt 0 ]]; do -keep) option_copy=off ;; - -plugin-dir=*) - plugin_dir="${1#-plugin-dir=}" - ;; - -plugin=*) - # should be like -plugin=franko/lite-plugins/master/plugins/autowrap.lua - plugin+=("${1#-plugin=}") - ;; -global) option_global=on ;; @@ -30,11 +23,14 @@ while [[ "$#" -gt 0 ]]; do shift done -if [ "${#pargs[@]}" -lt 1 ]; then - echo "usage: $0 [options] " +if [ "${#pargs[@]}" -lt 3 ]; then + echo "usage: $0 [options] " exit 1 fi +plugin_dir="${pargs[0]}" +plugin="${pargs[1]}" + if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then run_windows=yes fi @@ -44,7 +40,7 @@ bindir="$rundir/bin" datadir="$rundir/share/lite-xl" userdir="$(realpath "$rundir")" -builddir="${pargs[0]}" +builddir="${pargs[2]}" build_lite () { echo "running ninja" @@ -67,14 +63,14 @@ copy_lite_build () { run_lite () { if [ ! -z ${option_global+x} ]; then - echo "running \"lite ${pargs[@]:1}\"" - exec "$bindir/lite" "${pargs[@]:1}" + echo "running \"lite ${pargs[@]:3}\"" + exec "$bindir/lite" "${pargs[@]:3}" else - echo "running \"lite ${pargs[@]:1}\" with local HOME" + echo "running \"lite ${pargs[@]:3}\" with local HOME" if [ ! -z ${run_windows+x} ]; then - USERPROFILE="$userdir" exec "$bindir/lite" "${pargs[@]:1}" + USERPROFILE="$userdir" exec "$bindir/lite" "${pargs[@]:3}" else - HOME="$userdir" exec "$bindir/lite" "${pargs[@]:1}" + HOME="$userdir" exec "$bindir/lite" "${pargs[@]:3}" fi fi } From 46791aefe59e610b9d2055fbb05785e43ee633f6 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 12 Apr 2021 11:54:52 +0200 Subject: [PATCH 09/12] Implement maximize/restore controls Remove also resize from top and right of the window --- data/core/titleview.lua | 14 ++++++++++++-- data/fonts/icons.ttf | Bin 9512 -> 9620 bytes dev-utils/fontello-config-small.json | 12 +++++++++--- src/api/system.c | 28 ++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/data/core/titleview.lua b/data/core/titleview.lua index c53c5371..702d8b63 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -3,10 +3,18 @@ local common = require "core.common" local style = require "core.style" local View = require "core.view" +local restore_command = { + symbol = "w", action = function() system.set_window_mode("normal") end +} + +local maximize_command = { + symbol = "W", action = function() system.set_window_mode("maximized") end +} + local title_commands = { {symbol = "_", action = function() system.set_window_mode("minimized") end}, - {symbol = "w", action = function() system.set_window_mode("maximized") end}, - {symbol = "W", action = function() core.quit() end}, + maximize_command, + {symbol = "X", action = function() core.quit() end}, } local TitleView = View:extend() @@ -28,6 +36,8 @@ function TitleView:update() self.size.y = 0 end TitleView.super.update(self) + local window_mode = system.get_window_mode() + title_commands[2] = window_mode == "maximized" and restore_command or maximize_command local title_height = self.size.y if core.window_borderless and title_height ~= core.hit_test_title_height then local icon_w = style.icon_font:get_width("_") diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 02ad3694b9c0f0ed00fa10f40cb5f02600dc2ac0..00b4cc3bd262b1cb9f3339d2e5379c4b45f983c2 100644 GIT binary patch delta 998 zcmYL|OGs2v7{~wTK1Lm#w=J%Iv%2DH*=|{r>;+opaAQ-<_$wW38i= z!$yF$0SJT=!L;joV*%+YKzJHD)o(89gNS|DX*{r&HPfEgRcE1J+5}v^Jdy zr+atIOwih2t}S=5OUfY@@h^bUWZ*5t992`+QuzWT+#P9UNP4pgBAE!dAXbf8oD z#ts)aq5j-(EA4_yHq$JP!o*7Drr@_1{Vp{Lx-!$3L0gDx8}9_srBdC=BoJEhtDVp24&r#v_n>;?hqrrAnm|yXUM?9|I^G+Z0xI~}J)6DKY zUpeaXFrQPnqoxPCF{$iE)6J=FL*q{v#N3%ajL*HMmq5+ReUqPAltq(Q*_XF8QzsEED-R>}t?Vi#u_Hny3whWuTewFt0-oD1P*x0Qg! z>yCv|$!vQ#G7t}Da-4ev!kKI=m9*E_*5$PF#4_C)LkKA(kwrVg)X@RN5k!Xi`Ojac z099nDGM1ZRM?Gp$w_d5dES{u$?z1`tR;*mHb{P$Wv1Ctbu!jCKu|(`lSXr`m&NkVW G^nU>%Zn)|I delta 885 zcmZ9JPe>GD7{;G(XLeoPf9~jRe^_wMO_DTJ+Pq{&7)T|E%C6wSrge5!ncW$7*D``E z5-W(XJ`WW|Ap~}af;|NhBwY&Z5Yi#M1?o8ngbwz8^$Fz+@4Ua~dB6E)=9z`FOK0Yr zW@-R703emg>rTr;OFii&!1X$Fu^jg|YevH0Afgg=Hj5hS59|IUdn*U(w>H`pG z0tr6oI!L#BI8&PVQ&(49>_~@STmlG&L=68NVOn^V&%1nlM)6dy$w`>sRc@XhBPB}Q zJ1#3gJu53n-INugJ|Rmy;gYOyC8t)rl^cQEYHX#aFgX@F{u3dQEwJ`ru_$|qAJV#* z#?Na>{!nX;yj9oT^=`}k$#cTBSwn(^E#VG+`Iw9Y@-CEZ$cCqB{#41(adH uqSMA8k%=i{9Yy*z|4(;m&LVq4yS>K9GfI9rlHi+>Q9cwMsl1GC1b+kneWslN diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json index fa7e6334..895de303 100644 --- a/dev-utils/fontello-config-small.json +++ b/dev-utils/fontello-config-small.json @@ -1,5 +1,5 @@ { - "name": "", + "name": "icons", "css_prefix_text": "icon-", "css_use_suffix": false, "hinting": true, @@ -99,7 +99,7 @@ { "uid": "7394501fc0b17cb7bda99538f92e26d6", "css": "window-close", - "code": 87, + "code": 88, "src": "fontawesome" }, { @@ -107,6 +107,12 @@ "css": "menu-1", "code": 77, "src": "fontawesome" + }, + { + "uid": "07f0832c07f3d9713fffb06c8bffa027", + "css": "window-maximize", + "code": 87, + "src": "fontawesome" } ] -} +} \ No newline at end of file diff --git a/src/api/system.c b/src/api/system.c index 024b04f0..cd6ba90f 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -44,6 +44,9 @@ typedef struct HitTestInfo HitTestInfo; static HitTestInfo window_hit_info[1] = {{0, 0}}; +#define RESIZE_FROM_TOP 0 +#define RESIZE_FROM_RIGHT 0 + static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { const HitTestInfo *hit_info = (HitTestInfo *) data; const int resize_border = hit_info->resize_border; @@ -52,7 +55,10 @@ static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *p SDL_GetWindowSize(window, &w, &h); - if (pt->y < hit_info->title_height && pt->y > hit_info->resize_border && + if (pt->y < hit_info->title_height && + #if RESIZE_FROM_TOP + pt->y > hit_info->resize_border && + #endif pt->x > resize_border && pt->x < w - controls_width) { return SDL_HITTEST_DRAGGABLE; } @@ -63,12 +69,16 @@ static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *p if (pt->x < resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPLEFT); + #if RESIZE_FROM_TOP } else if (pt->x > resize_border && pt->x < w - controls_width && pt->y < resize_border) { REPORT_RESIZE_HIT(TOP); + #endif } else if (pt->x > w - resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPRIGHT); + #if RESIZE_FROM_RIGHT } else if (pt->x > w - resize_border && pt->y > resize_border && pt->y < h - resize_border) { REPORT_RESIZE_HIT(RIGHT); + #endif } else if (pt->x > w - resize_border && pt->y > h - resize_border) { REPORT_RESIZE_HIT(BOTTOMRIGHT); } else if (pt->x < w - resize_border && pt->x > resize_border && pt->y > h - resize_border) { @@ -298,6 +308,21 @@ static int f_window_has_focus(lua_State *L) { } +static int f_get_window_mode(lua_State *L) { + unsigned flags = SDL_GetWindowFlags(window); + if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) { + lua_pushstring(L, "fullscreen"); + } else if (flags & SDL_WINDOW_MINIMIZED) { + lua_pushstring(L, "minimized"); + } else if (flags & SDL_WINDOW_MAXIMIZED) { + lua_pushstring(L, "maximized"); + } else { + lua_pushstring(L, "normal"); + } + return 1; +} + + static int f_show_fatal_error(lua_State *L) { const char *title = luaL_checkstring(L, 1); const char *msg = luaL_checkstring(L, 2); @@ -508,6 +533,7 @@ static const luaL_Reg lib[] = { { "set_cursor", f_set_cursor }, { "set_window_title", f_set_window_title }, { "set_window_mode", f_set_window_mode }, + { "get_window_mode", f_get_window_mode }, { "set_window_bordered", f_set_window_bordered }, { "set_window_hit_test", f_set_window_hit_test }, { "get_window_size", f_get_window_size }, From 4de97d51fb41d086b36b0a2ab25aa860c5ce2016 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 12 Apr 2021 13:31:32 +0200 Subject: [PATCH 10/12] Avoid always calling system.get_window_mode --- data/core/init.lua | 5 +++++ data/core/titleview.lua | 3 +-- src/api/system.c | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index d4ef5494..6aa0b848 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -411,6 +411,7 @@ function core.init() core.clip_rect_stack = {{ 0,0,0,0 }} core.log_items = {} core.docs = {} + core.window_mode = "normal" core.threads = setmetatable({}, { __mode = "k" }) local project_dir_abs = system.absolute_path(project_dir) @@ -812,6 +813,10 @@ function core.on_event(type, ...) core.root_view:on_mouse_released(...) elseif type == "mousewheel" then core.root_view:on_mouse_wheel(...) + elseif type == "resized" then + core.window_mode = system.get_window_mode() + elseif type == "minimized" or type == "maximized" or type == "restored" then + core.window_mode = type == "restored" and "normal" or type elseif type == "filedropped" then local filename, mx, my = ... local info = system.get_file_info(filename) diff --git a/data/core/titleview.lua b/data/core/titleview.lua index 702d8b63..08f06505 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -36,8 +36,7 @@ function TitleView:update() self.size.y = 0 end TitleView.super.update(self) - local window_mode = system.get_window_mode() - title_commands[2] = window_mode == "maximized" and restore_command or maximize_command + title_commands[2] = core.window_mode == "maximized" and restore_command or maximize_command local title_height = self.size.y if core.window_borderless and title_height ~= core.hit_test_title_height then local icon_w = style.icon_font:get_width("_") diff --git a/src/api/system.c b/src/api/system.c index cd6ba90f..d52453a7 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -117,6 +117,16 @@ top: rencache_invalidate(); lua_pushstring(L, "exposed"); return 1; + } else if (e.window.event == SDL_WINDOWEVENT_MINIMIZED) { + lua_pushstring(L, "minimized"); + return 1; + } else if (e.window.event == SDL_WINDOWEVENT_MAXIMIZED) { + fprintf(stderr, "maximized event!\n"); + lua_pushstring(L, "maximized"); + return 1; + } else if (e.window.event == SDL_WINDOWEVENT_RESTORED) { + lua_pushstring(L, "restored"); + return 1; } if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { lua_pushstring(L, "focuslost"); From f7375924abce8acb298d4f2c1dbf783a4ef00501 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 12 Apr 2021 19:05:30 +0200 Subject: [PATCH 11/12] Make non-borderless mode work --- data/core/commands/core.lua | 2 ++ data/core/init.lua | 16 +++++++++------- data/core/titleview.lua | 25 +++++++++++++------------ src/api/system.c | 12 ++++++------ 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index a13f760c..afba8d28 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -28,6 +28,8 @@ command.add(nil, { ["core:toggle-fullscreen"] = function() fullscreen = not fullscreen system.set_window_mode(fullscreen and "fullscreen" or "normal") + core.show_title_bar(not fullscreen) + core.title_view:configure_hit_test(not fullscreen) end, ["core:reload-module"] = function() diff --git a/data/core/init.lua b/data/core/init.lua index 6aa0b848..18617f63 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -400,13 +400,6 @@ function core.init() end end - core.window_borderless = false - core.hit_test_title_height = 0 - if config.borderless then - system.set_window_bordered(false) - core.window_borderless = true - end - core.frame_start = 0 core.clip_rect_stack = {{ 0,0,0,0 }} core.log_items = {} @@ -474,6 +467,10 @@ function core.init() command.perform("core:open-log") end + system.set_window_bordered(not config.borderless) + core.title_view:configure_hit_test(config.borderless) + core.title_view.visible = config.borderless + if #plugins_refuse_list.userdir.plugins > 0 or #plugins_refuse_list.datadir.plugins > 0 then local opt = { { font = style.font, text = "Exit", default_no = true }, @@ -696,6 +693,11 @@ function core.set_active_view(view) end +function core.show_title_bar(show) + core.title_view.visible = show +end + + function core.add_thread(f, weak_ref) local key = weak_ref or #core.threads + 1 local fn = function() return core.try(f) end diff --git a/data/core/titleview.lua b/data/core/titleview.lua index 08f06505..9090861c 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -25,28 +25,28 @@ end function TitleView:new() TitleView.super.new(self) - -- FIXME: decide if visible is actually needed self.visible = true end -function TitleView:update() - if self.visible then - self.size.y = title_view_height() - else - self.size.y = 0 - end - TitleView.super.update(self) - title_commands[2] = core.window_mode == "maximized" and restore_command or maximize_command - local title_height = self.size.y - if core.window_borderless and title_height ~= core.hit_test_title_height then +function TitleView:configure_hit_test(borderless) + if borderless then + local title_height = title_view_height() local icon_w = style.icon_font:get_width("_") local icon_spacing = icon_w local controls_width = (icon_w + icon_spacing) * #title_commands + icon_spacing system.set_window_hit_test(title_height, controls_width, icon_spacing) - core.hit_test_title_height = title_height + -- core.hit_test_title_height = title_height + else + system.set_window_hit_test() end end +function TitleView:update() + self.size.y = self.visible and title_view_height() or 0 + title_commands[2] = core.window_mode == "maximized" and restore_command or maximize_command + TitleView.super.update(self) +end + function TitleView:draw_window_title() local h = style.font:get_height() @@ -95,6 +95,7 @@ end function TitleView:on_mouse_moved(px, py, ...) + if self.size.y == 0 then return end TitleView.super.on_mouse_moved(self, px, py, ...) self.hovered_item = nil local x_min, x_max, y_min, y_max = self.size.x, 0, self.size.y, 0 diff --git a/src/api/system.c b/src/api/system.c index d52453a7..0a2c6986 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -276,15 +276,15 @@ static int f_set_window_bordered(lua_State *L) { static int f_set_window_hit_test(lua_State *L) { + if (lua_gettop(L) == 0) { + SDL_SetWindowHitTest(window, NULL, NULL); + return 0; + } window_hit_info->title_height = luaL_checknumber(L, 1); window_hit_info->controls_width = luaL_checknumber(L, 2); window_hit_info->resize_border = luaL_checknumber(L, 3); - if (SDL_SetWindowHitTest(window, hit_test, window_hit_info) == -1) { - lua_pushboolean(L, 0); - } else { - lua_pushboolean(L, 1); - } - return 1; + SDL_SetWindowHitTest(window, hit_test, window_hit_info); + return 0; } From d5e9ef6bff887e7c4c46e10b7e473ea286e2b078 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 12 Apr 2021 19:12:21 +0200 Subject: [PATCH 12/12] Remove trailing debug message --- src/api/system.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/system.c b/src/api/system.c index 0a2c6986..224c6ac3 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -121,7 +121,6 @@ top: lua_pushstring(L, "minimized"); return 1; } else if (e.window.event == SDL_WINDOWEVENT_MAXIMIZED) { - fprintf(stderr, "maximized event!\n"); lua_pushstring(L, "maximized"); return 1; } else if (e.window.event == SDL_WINDOWEVENT_RESTORED) {