Skip to content

Commit

Permalink
directvt#86 WIP: Unify gear args passing
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Dec 18, 2024
1 parent d2bd879 commit f833935
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/netxs/apps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,12 @@ namespace netxs::app::shared
auto& state_inst = *state_state;
auto& keybd = boss.template plugins<pro::keybd>();
app::shared::base_kb_navigation(keybd, scroll, boss);
keybd.proc("UpdateChordPreview", [&, update_ptr](hids& gear, txts&)
keybd.proc("UpdateChordPreview", [&, update_ptr](hids& gear)
{
if (gear.keystat != input::key::repeated) (*update_ptr)(items_inst, gear, true);
if (rawkbd) gear.set_handled();
});
keybd.proc("ExclusiveKeyboardMode", [&, update_ptr](hids& gear, txts&)
keybd.proc("ExclusiveKeyboardMode", [&, update_ptr](hids& gear)
{
state_inst.bell::signal(tier::release, ui::term::events::rawkbd);
if (gear.keystat != input::key::repeated) (*update_ptr)(items_inst, gear, true);
Expand Down
38 changes: 19 additions & 19 deletions src/netxs/apps/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ namespace netxs::app::tile
gear.dismiss();
};
auto& keybd = boss.template plugins<pro::keybd>();
keybd.proc(action::TileMoveGrip , [&](hids& gear, txts& args){ gear.set_handled(); boss.base::riseup(tier::preview, app::tile::events::ui::grips::move, { args.size() ? xml::take_or<twod>(args.front(), dot_00) : dot_00 }); });
keybd.proc(action::TileResizeGrip , [&](hids& gear, txts& args){ gear.set_handled(); boss.base::riseup(tier::preview, app::tile::events::ui::grips::resize, { args.size() ? xml::take_or<si32>(args.front(), 0) : 0 }); });
keybd.proc(action::TileFocusPrevGrip, [&](hids& gear, txts& /*args*/){ boss.base::riseup(tier::preview, app::tile::events::ui::focus::prevgrip, gear); });
keybd.proc(action::TileFocusNextGrip, [&](hids& gear, txts& /*args*/){ boss.base::riseup(tier::preview, app::tile::events::ui::focus::nextgrip, gear); });
keybd.proc(action::TileMoveGrip , [&](hids& gear){ gear.set_handled(); boss.base::riseup(tier::preview, app::tile::events::ui::grips::move, gear.get_args_or<twod>()); });
keybd.proc(action::TileResizeGrip , [&](hids& gear){ gear.set_handled(); boss.base::riseup(tier::preview, app::tile::events::ui::grips::resize, gear.get_args_or<si32>()); });
keybd.proc(action::TileFocusPrevGrip, [&](hids& gear){ boss.base::riseup(tier::preview, app::tile::events::ui::focus::prevgrip, gear); });
keybd.proc(action::TileFocusNextGrip, [&](hids& gear){ boss.base::riseup(tier::preview, app::tile::events::ui::focus::nextgrip, gear); });
keybd.bind(*grip_bindings_ptr);
});
return node;
Expand Down Expand Up @@ -902,21 +902,21 @@ namespace netxs::app::tile
boss.base::riseup(tier::release, e2::form::proceed::quit::one, true);
};
auto& keybd = boss.template plugins<pro::keybd>();
keybd.proc(action::TileFocusPrev , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::prev, gear); });
keybd.proc(action::TileFocusNext , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::next, gear); });
keybd.proc(action::TileFocusPrevPane , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::prevpane, gear); });
keybd.proc(action::TileFocusNextPane , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::nextpane, gear); });
keybd.proc(action::TileFocusPrevGrip , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::prevgrip, gear); });
keybd.proc(action::TileFocusNextGrip , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::nextgrip, gear); });
keybd.proc(action::TileRunApplicatoin , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::create, gear); });
keybd.proc(action::TileSelectAllPanes , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::select, gear); });
keybd.proc(action::TileSplitHorizontally , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::split::hz, gear); });
keybd.proc(action::TileSplitVertically , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::split::vt, gear); });
keybd.proc(action::TileSplitOrientation , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::rotate, gear); });
keybd.proc(action::TileSwapPanes , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::swap, gear); });
keybd.proc(action::TileEqualizeSplitRatio, [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::equalize, gear); });
keybd.proc(action::TileSetManagerTitle , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::title , gear); });
keybd.proc(action::TileClosePane , [&](hids& gear, txts& /*args*/){ boss.bell::signal(tier::preview, app::tile::events::ui::close, gear); });
keybd.proc(action::TileFocusPrev , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::prev, gear); });
keybd.proc(action::TileFocusNext , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::next, gear); });
keybd.proc(action::TileFocusPrevPane , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::prevpane, gear); });
keybd.proc(action::TileFocusNextPane , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::nextpane, gear); });
keybd.proc(action::TileFocusPrevGrip , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::prevgrip, gear); });
keybd.proc(action::TileFocusNextGrip , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::focus::nextgrip, gear); });
keybd.proc(action::TileRunApplicatoin , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::create, gear); });
keybd.proc(action::TileSelectAllPanes , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::select, gear); });
keybd.proc(action::TileSplitHorizontally , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::split::hz, gear); });
keybd.proc(action::TileSplitVertically , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::split::vt, gear); });
keybd.proc(action::TileSplitOrientation , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::rotate, gear); });
keybd.proc(action::TileSwapPanes , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::swap, gear); });
keybd.proc(action::TileEqualizeSplitRatio, [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::equalize, gear); });
keybd.proc(action::TileSetManagerTitle , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::title , gear); });
keybd.proc(action::TileClosePane , [&](hids& gear){ boss.bell::signal(tier::preview, app::tile::events::ui::close, gear); });
auto bindings = pro::keybd::load(config, "tile");
keybd.bind(bindings);

Expand Down
26 changes: 13 additions & 13 deletions src/netxs/desktopio/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,38 +114,38 @@ namespace netxs::app::shared
{
auto& scroll_inst = *scroll;
auto esc_pressed = ptr::shared(faux);
keybd.proc("WindowClose", [&, esc_pressed](hids& gear, txts&)
keybd.proc("WindowClose", [&, esc_pressed](hids& gear)
{
if (*esc_pressed)
{
boss.bell::signal(tier::anycast, e2::form::proceed::quit::one, true);
gear.set_handled();
}
});
keybd.proc("WindowClosePreview", [&, esc_pressed](hids& /*gear*/, txts&)
keybd.proc("WindowClosePreview", [&, esc_pressed](hids& /*gear*/)
{
if (std::exchange(*esc_pressed, true) != *esc_pressed)
{
boss.bell::signal(tier::anycast, e2::form::state::keybd::command::close, *esc_pressed);
}
});
keybd.proc("CancelWindowClose", [&, esc_pressed](hids& /*gear*/, txts&)
keybd.proc("CancelWindowClose", [&, esc_pressed](hids& /*gear*/)
{
if (std::exchange(*esc_pressed, faux) != *esc_pressed)
{
boss.bell::signal(tier::anycast, e2::form::state::keybd::command::close, *esc_pressed);
}
});
keybd.proc("ScrollPageUp" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bypage::y, { .vector = { 0, 1 }}); });
keybd.proc("ScrollPageDown" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bypage::y, { .vector = { 0,-1 }}); });
keybd.proc("ScrollLineUp" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::y, { .vector = { 0, 3 }}); });
keybd.proc("ScrollLineDown" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::y, { .vector = { 0,-3 }}); });
keybd.proc("ScrollCharLeft" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::x, { .vector = { 3, 0 }}); });
keybd.proc("ScrollCharRight" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::x, { .vector = {-3, 0 }}); });
keybd.proc("ScrollTop" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::to_top::y); });
keybd.proc("ScrollEnd" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::to_end::y); });
keybd.proc("ToggleMaximize" , [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.bell::enqueue(boss.This(), [&, gear_id = gear.id](auto& /*boss*/){ if (auto gear_ptr = boss.bell::getref<hids>(gear_id)) scroll_inst.base::riseup(tier::preview, e2::form::size::enlarge::maximize, *gear_ptr); }); }); // Refocus-related operations require execution outside of keyboard eves.
keybd.proc("ToggleFullscreen", [&](hids& gear, txts&){ gear.set_handled(); scroll_inst.bell::enqueue(boss.This(), [&, gear_id = gear.id](auto& /*boss*/){ if (auto gear_ptr = boss.bell::getref<hids>(gear_id)) scroll_inst.base::riseup(tier::preview, e2::form::size::enlarge::fullscreen, *gear_ptr); }); });
keybd.proc("ScrollPageUp" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bypage::y, { .vector = { 0, 1 }}); });
keybd.proc("ScrollPageDown" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bypage::y, { .vector = { 0,-1 }}); });
keybd.proc("ScrollLineUp" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::y, { .vector = { 0, 3 }}); });
keybd.proc("ScrollLineDown" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::y, { .vector = { 0,-3 }}); });
keybd.proc("ScrollCharLeft" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::x, { .vector = { 3, 0 }}); });
keybd.proc("ScrollCharRight" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::bystep::x, { .vector = {-3, 0 }}); });
keybd.proc("ScrollTop" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::to_top::y); });
keybd.proc("ScrollEnd" , [&](hids& gear){ gear.set_handled(); scroll_inst.base::riseup(tier::preview, e2::form::upon::scroll::to_end::y); });
keybd.proc("ToggleMaximize" , [&](hids& gear){ gear.set_handled(); scroll_inst.bell::enqueue(boss.This(), [&, gear_id = gear.id](auto& /*boss*/){ if (auto gear_ptr = boss.bell::getref<hids>(gear_id)) scroll_inst.base::riseup(tier::preview, e2::form::size::enlarge::maximize, *gear_ptr); }); }); // Refocus-related operations require execution outside of keyboard eves.
keybd.proc("ToggleFullscreen", [&](hids& gear){ gear.set_handled(); scroll_inst.bell::enqueue(boss.This(), [&, gear_id = gear.id](auto& /*boss*/){ if (auto gear_ptr = boss.bell::getref<hids>(gear_id)) scroll_inst.base::riseup(tier::preview, e2::form::size::enlarge::fullscreen, *gear_ptr); }); });

keybd.bind( "Esc", "DropAutoRepeat" , true);
keybd.bind( "Esc", "WindowClosePreview", true);
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ namespace netxs::ui
yield{ faux },
fullscreen{ faux }
{
keybd.proc("ToggleDebugOverlay", [&](hids& gear, txts&){ gear.set_handled(); debug ? debug.stop() : debug.start(); });
keybd.proc("ToggleDebugOverlay", [&](hids& gear){ gear.set_handled(); debug ? debug.stop() : debug.start(); });
auto bindings = pro::keybd::load(config, "tui");
keybd.bind(bindings);

Expand Down
13 changes: 9 additions & 4 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ namespace netxs::ui
class keybd
: public skill
{
using func = std::function<void(hids&, txts&)>;
using func = std::function<void(hids&)>;
using wptr = netxs::wptr<func>;
using sptr = netxs::sptr<func>;
using skill::boss,
Expand Down Expand Up @@ -2098,7 +2098,12 @@ namespace netxs::ui
auto proc_ptr = proc_wptr.lock();
if (proc_ptr)
{
if (!interrupt_key_proc) (*proc_ptr)(gear, *args_ptr);
if (!interrupt_key_proc)
{
auto temp = std::exchange(gear.args_ptr, args_ptr);
(*proc_ptr)(gear);
gear.args_ptr = temp;
}
}
return !proc_ptr;
});
Expand Down Expand Up @@ -2164,8 +2169,8 @@ namespace netxs::ui
if (!gear.touched && !gear.handled) _dispatch(gear, true, input::key::kmap::any_key);
}
};
proc("Noop", [&](hids& gear, txts&){ gear.set_handled(); interrupt_key_proc = true; });
proc("DropAutoRepeat", [&](hids& gear, txts&){ if (gear.keystat == input::key::repeated) { gear.set_handled(); interrupt_key_proc = true; }});
proc("Noop", [&](hids& gear){ gear.set_handled(); interrupt_key_proc = true; });
proc("DropAutoRepeat", [&](hids& gear){ if (gear.keystat == input::key::repeated) { gear.set_handled(); interrupt_key_proc = true; }});
}

auto filter(hids& gear)
Expand Down
16 changes: 8 additions & 8 deletions src/netxs/desktopio/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1994,14 +1994,14 @@ namespace netxs::gui
wdelta{ 24.f },
stream{ *this, *os::dtvt::client }
{
wkeybd.proc("IncreaseCellHeight" , [&](hids& gear, txts&){ gear.set_handled(); IncreaseCellHeight(1.f); });
wkeybd.proc("DecreaseCellHeight" , [&](hids& gear, txts&){ gear.set_handled(); IncreaseCellHeight(-1.f);});
wkeybd.proc("ResetCellHeight" , [&](hids& gear, txts&){ gear.set_handled(); ResetCellHeight(); });
wkeybd.proc("ToggleFullscreenMode" , [&](hids& gear, txts&){ gear.set_handled(); ToggleFullscreenMode(); });
wkeybd.proc("ToggleAntialiasingMode", [&](hids& gear, txts&){ gear.set_handled(); ToggleAntialiasingMode(); });
wkeybd.proc("RollFontsBackward" , [&](hids& gear, txts&){ gear.set_handled(); RollFontList(feed::rev); });
wkeybd.proc("RollFontsForward" , [&](hids& gear, txts&){ gear.set_handled(); RollFontList(feed::fwd); });
wkeybd.proc("_ResetWheelAccumulator", [&](hids& /*gear*/, txts&){ whlacc = {}; });
wkeybd.proc("IncreaseCellHeight" , [&](hids& gear){ gear.set_handled(); IncreaseCellHeight(1.f); });
wkeybd.proc("DecreaseCellHeight" , [&](hids& gear){ gear.set_handled(); IncreaseCellHeight(-1.f);});
wkeybd.proc("ResetCellHeight" , [&](hids& gear){ gear.set_handled(); ResetCellHeight(); });
wkeybd.proc("ToggleFullscreenMode" , [&](hids& gear){ gear.set_handled(); ToggleFullscreenMode(); });
wkeybd.proc("ToggleAntialiasingMode", [&](hids& gear){ gear.set_handled(); ToggleAntialiasingMode(); });
wkeybd.proc("RollFontsBackward" , [&](hids& gear){ gear.set_handled(); RollFontList(feed::rev); });
wkeybd.proc("RollFontsForward" , [&](hids& gear){ gear.set_handled(); RollFontList(feed::fwd); });
wkeybd.proc("_ResetWheelAccumulator", [&](hids& /*gear*/){ whlacc = {}; });
wkeybd.bind("-Ctrl", "_ResetWheelAccumulator", true);
wkeybd.bind("-Ctrl", "_ResetWheelAccumulator", true);
wkeybd.bind(hotkeys);
Expand Down
18 changes: 18 additions & 0 deletions src/netxs/desktopio/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,24 @@ namespace netxs::input
rect slot; // slot for pro::maker and e2::createby.
bool slot_forced = faux; // .

//todo unify
netxs::sptr<txts> args_ptr; // args passed by pro::keybd.
template<class T>
auto get_args_or(T fallback = {})
{
if (args_ptr && args_ptr->size())
{
return xml::take_or<T>(args_ptr->front(), fallback);
}
else
{
return fallback;
}
}
template<> auto get_args_or<text>(text fallback) { return args_ptr && args_ptr->size() ? args_ptr->front() : fallback; }
template<> auto get_args_or<qiew>(qiew fallback) { return args_ptr && args_ptr->size() ? qiew{ args_ptr->front() } : fallback; }
template<> auto get_args_or<view>(view fallback) { return args_ptr && args_ptr->size() ? view{ args_ptr->front() } : fallback; }

//todo unify
bool mouse_disabled = faux; // Hide mouse cursor.
bool keybd_disabled = faux; // Inactive gear.
Expand Down
Loading

0 comments on commit f833935

Please sign in to comment.