Skip to content

Commit

Permalink
directvt#393 WIP: Lua scripting (vtm.gate.*)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Jan 8, 2025
1 parent 08846ff commit c2e2999
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 79 deletions.
19 changes: 19 additions & 0 deletions src/netxs/desktopio/baseui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ namespace netxs
twod win{}; // eccc: Console window size.
id_t gear_id{}; // eccc: Gear id.
};
struct syscmd
{
static constexpr auto _counter = __COUNTER__ + 1;
static constexpr auto minimize = __COUNTER__ - _counter;
static constexpr auto maximize = __COUNTER__ - _counter;
static constexpr auto restore = __COUNTER__ - _counter;
static constexpr auto move = __COUNTER__ - _counter;
static constexpr auto monitorpower = __COUNTER__ - _counter;
static constexpr auto update = __COUNTER__ - _counter;
static constexpr auto close = __COUNTER__ - _counter;
static constexpr auto tunecellheight = __COUNTER__ - _counter;
static constexpr auto rollfontlist = __COUNTER__ - _counter;
static constexpr auto resetcellheight = __COUNTER__ - _counter;
static constexpr auto resetwheelaccum = __COUNTER__ - _counter;
static constexpr auto togglefsmode = __COUNTER__ - _counter;
static constexpr auto toggleaamode = __COUNTER__ - _counter;
};
}
namespace netxs::input
{
Expand Down Expand Up @@ -50,6 +67,7 @@ namespace netxs::ui
using s11n = directvt::binary::s11n;
using escx = ansi::escx;
using book = std::vector<sptr>;
using guicmd = directvt::binary::gui_command_t;
}

namespace netxs::events::userland
Expand Down Expand Up @@ -167,6 +185,7 @@ namespace netxs::events::userland
EVENT_XS( custom , si32 ), // Custom command, arg: cmd_id.
EVENT_XS( printscreen, input::hids ), // Copy screen area to clipboard.
EVENT_XS( run , eccc ), // Run script.
EVENT_XS( gui , ui::guicmd ), // Request a gui command.
GROUP_XS( request , input::hids ), // general: Request input field list.

SUBSET_XS( request )
Expand Down
135 changes: 117 additions & 18 deletions src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,30 +826,117 @@ namespace netxs::ui

static auto proc_map = pro::luafx::fxmap<gate>
{
{ "Disconnect", [](auto& boss, auto& luafx)
{
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{ "Disconnect", [](auto& boss, auto& luafx)
{
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gear_ptr->set_handled();
}
boss.bell::signal(tier::preview, e2::conio::quit);
gear_ptr->set_handled();
}
luafx.set_return(ok);
}},
{ "DebugOverlay", [](auto& boss, auto& luafx)
{
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
luafx.set_return();
}},
{ "DebugOverlay", [](auto& boss, auto& luafx)
{
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gear_ptr->set_handled();
}
auto& debug = boss.plugins<pro::debug>();
boss.props.debug_overlay ? debug.stop() : debug.start();
boss.props.debug_overlay = !boss.props.debug_overlay;
gear_ptr->set_handled();
}
luafx.set_return(ok);
}},
luafx.set_return();
}},
{ "IncreasecCellHeight", [](auto& boss, auto& luafx)
{
auto gui_cmd = e2::command::gui.param();
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gui_cmd.gear_id = gear_ptr->id;
gear_ptr->set_handled();
}
gui_cmd.cmd_id = syscmd::tunecellheight;
gui_cmd.args = luafx.get_args_or(1, fp32{ 1.f });
boss.bell::signal(tier::preview, e2::command::gui, gui_cmd);
luafx.set_return();
}},
{ "RollFonts", [](auto& boss, auto& luafx)
{
auto gui_cmd = e2::command::gui.param();
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gui_cmd.gear_id = gear_ptr->id;
gear_ptr->set_handled();
}
gui_cmd.cmd_id = syscmd::rollfontlist;
gui_cmd.args = luafx.get_args_or(1, fp32{ 1.f });
boss.bell::signal(tier::preview, e2::command::gui, gui_cmd);
luafx.set_return();
}},
{ "WheelAccumReset", [](auto& boss, auto& luafx)
{
auto gui_cmd = e2::command::gui.param();
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gui_cmd.gear_id = gear_ptr->id;
}
gui_cmd.cmd_id = syscmd::resetwheelaccum;
boss.bell::signal(tier::preview, e2::command::gui, gui_cmd);
luafx.set_return();
}},
{ "CellHeightReset", [](auto& boss, auto& luafx)
{
auto gui_cmd = e2::command::gui.param();
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gui_cmd.gear_id = gear_ptr->id;
gear_ptr->set_handled();
}
gui_cmd.cmd_id = syscmd::resetcellheight;
boss.bell::signal(tier::preview, e2::command::gui, gui_cmd);
luafx.set_return();
}},
{ "Fullscreen", [](auto& boss, auto& luafx)
{
auto gui_cmd = e2::command::gui.param();
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gui_cmd.gear_id = gear_ptr->id;
gear_ptr->set_handled();
}
//todo args
gui_cmd.cmd_id = syscmd::togglefsmode;
boss.bell::signal(tier::preview, e2::command::gui, gui_cmd);
luafx.set_return();
}},
{ "AntialiasingMode", [](auto& boss, auto& luafx)
{
auto gui_cmd = e2::command::gui.param();
auto gear_ptr = luafx.get_object<hids>("gear");
auto ok = !!gear_ptr;
if (ok)
{
gui_cmd.gear_id = gear_ptr->id;
gear_ptr->set_handled();
}
//todo args
gui_cmd.cmd_id = syscmd::toggleaamode;
boss.bell::signal(tier::preview, e2::command::gui, gui_cmd);
luafx.set_return();
}},
};
luafx.activate(proc_map);

Expand Down Expand Up @@ -879,6 +966,18 @@ namespace netxs::ui
{
xmap.face::area(new_area);
};
LISTEN(tier::preview, e2::command::gui, gui_cmd, tokens)
{
if (gui_cmd.gear_id)
{
auto [ext_gear_id, gear_ptr] = get_ext_gear_id(gui_cmd.gear_id);
if (gear_ptr)
{
gui_cmd.gear_id = ext_gear_id;
}
}
conio.gui_command.send(canal, gui_cmd);
};
LISTEN(tier::release, e2::command::run, script)
{
if (auto world_ptr = parent())
Expand Down
4 changes: 3 additions & 1 deletion src/netxs/desktopio/directvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ namespace netxs::directvt
STRUCT_macro(restored, (id_t, gear_id))
STRUCT_macro(req_input_fields, (id_t, gear_id) (si32, acpStart) (si32, acpEnd))
STRUCT_macro(ack_input_fields, (id_t, gear_id) (regs, field_list))
STRUCT_macro(gui_command, (id_t, gear_id) (si32, cmd_id) (fp32, args))

#undef STRUCT_macro
#undef STRUCT_macro_lite
Expand Down Expand Up @@ -1444,7 +1445,8 @@ namespace netxs::directvt
X(cwd ) /* CWD Notification. */\
X(restored ) /* Notify normal window state. */\
X(req_input_fields ) /* Request input field list. */\
X(ack_input_fields ) /* Reply input field list. */
X(ack_input_fields ) /* Reply input field list. */\
X(gui_command ) /* GUI command request. */
//X(quit ) /* Close and disconnect dtvt app. */
//X(focus ) /* Request to set focus. */

Expand Down
72 changes: 36 additions & 36 deletions src/netxs/desktopio/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1462,17 +1462,6 @@ namespace netxs::gui
static constexpr auto clipboard = __COUNTER__ - _counter;
static constexpr auto rightshift = __COUNTER__ - _counter;
};
struct syscmd
{
static constexpr auto _counter = __COUNTER__ + 1;
static constexpr auto minimize = __COUNTER__ - _counter;
static constexpr auto maximize = __COUNTER__ - _counter;
static constexpr auto restore = __COUNTER__ - _counter;
static constexpr auto move = __COUNTER__ - _counter;
static constexpr auto monitorpower = __COUNTER__ - _counter;
static constexpr auto update = __COUNTER__ - _counter;
static constexpr auto close = __COUNTER__ - _counter;
};
struct ipc
{
#define ipc_t \
Expand Down Expand Up @@ -1890,6 +1879,10 @@ namespace netxs::gui
// owner.base::riseup(tier::preview, e2::form::prop::cwd, path);
//});
}
void handle(s11n::xs::gui_command lock)
{
owner.sys_command(lock.thing.cmd_id, lock.thing.args);
}

evnt(winbase& owner, ui::pipe& intio)
: s11n{ *this },
Expand Down Expand Up @@ -2957,45 +2950,40 @@ namespace netxs::gui
chords.reset(gear);
stream_keybd(gear);
}

void ResetWheelAccumulator()
{
whlacc = {};
}
void IncreaseCellHeight(fp32 dir)
{
if (!isbusy.exchange(true))
bell::enqueue(This(), [&, dir](auto& /*boss*/)
{
change_cell_size(faux, dir);
sync_cellsz();
update_gui();
});
change_cell_size(faux, dir);
sync_cellsz();
update_gui();
}
void ResetCellHeight()
{
bell::enqueue(This(), [&](auto& /*boss*/)
{
auto dy = origsz - cellsz.y;
change_cell_size(faux, (fp32)dy, master.area.size / 2);
sync_cellsz();
update_gui();
});
auto dy = origsz - cellsz.y;
change_cell_size(faux, (fp32)dy, master.area.size / 2);
sync_cellsz();
update_gui();
}
void ToggleFullscreenMode()
{
bell::enqueue(This(), [&](auto& /*boss*/)
if (fsmode != state::minimized)
{
if (fsmode != state::minimized) set_state(fsmode == state::maximized ? state::normal : state::maximized);
});
set_state(fsmode == state::maximized ? state::normal : state::maximized);
}
}
void ToggleAntialiasingMode()
{
bell::enqueue(This(), [&](auto& /*boss*/)
{
set_aa_mode(!gcache.aamode);
});
set_aa_mode(!gcache.aamode);
}
void RollFontList(feed dir)
void RollFontList(fp32 dir)
{
if (fcache.families.empty()) return;
auto& families = fcache.families;
if (dir == feed::fwd)
if (dir > 0)
{
families.push_back(std::move(families.front()));
families.pop_front();
Expand All @@ -3007,6 +2995,7 @@ namespace netxs::gui
}
set_font_list(families);
}

arch run_command(arch command, arch lParam)
{
if constexpr (debug_foci) log("command: ", ipc::str(command));
Expand Down Expand Up @@ -3167,10 +3156,14 @@ namespace netxs::gui
update_gui();
});
}
void sys_command(si32 menucmd)
void sys_command(si32 menucmd, fp32 dir = {})
{
if (menucmd == syscmd::update && !reload) return;
bell::enqueue(This(), [&, menucmd](auto& /*boss*/)
if (menucmd == syscmd::tunecellheight)
{
if (isbusy.exchange(true) || dir == 0.f) return;
}
bell::enqueue(This(), [&, menucmd, dir](auto& /*boss*/)
{
//log("sys_command: menucmd=", utf::to_hex_0x(menucmd));
switch (menucmd)
Expand All @@ -3183,6 +3176,13 @@ namespace netxs::gui
//case syscmd::monitorpower: break;
case syscmd::close: window_shutdown(); break;
case syscmd::update: update_gui(); break;
//
case syscmd::resetwheelaccum: ResetWheelAccumulator(); break;
case syscmd::tunecellheight: IncreaseCellHeight(dir); break;
case syscmd::resetcellheight: ResetCellHeight(); break;
case syscmd::togglefsmode: ToggleFullscreenMode(); break;
case syscmd::toggleaamode: ToggleAntialiasingMode(); break;
case syscmd::rollfontlist: RollFontList(dir); break;
}
});
}
Expand Down
14 changes: 12 additions & 2 deletions src/netxs/desktopio/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7961,7 +7961,7 @@ namespace netxs::ui
gear.set_handled();
});
}},
{ "ClearClipboard", [](auto& boss, auto& luafx)
{ "ClearClipboard", [](auto& /*boss*/, auto& luafx)
{
luafx.run_with_gear([&](auto& gear)
{
Expand Down Expand Up @@ -8015,7 +8015,7 @@ namespace netxs::ui
}},
{ "OneShotSelection", [](auto& boss, auto& luafx)
{
luafx.run_with_gear([&](auto& gear)
luafx.run_with_gear([&](auto& /*gear*/)
{
auto format = luafx.get_args_or(1, ""s);
if (format.empty())
Expand Down Expand Up @@ -8576,6 +8576,16 @@ namespace netxs::ui
owner.base::riseup(tier::preview, e2::form::prop::cwd, path);
});
}
void handle(s11n::xs::gui_command lock)
{
owner.bell::enqueue(owner_wptr, [&, gui_cmd = lock.thing](auto& /*boss*/)
{
if (auto gear_ptr = owner.bell::getref<hids>(gui_cmd.gear_id))
{
gear_ptr->owner.bell::signal(tier::preview, e2::command::gui, gui_cmd);
}
});
}

evnt(dtvt& owner)
: s11n{ *this, owner.id },
Expand Down
Loading

0 comments on commit c2e2999

Please sign in to comment.