Skip to content

Commit

Permalink
Merge pull request #686 from o-sdn-o/gui-bridge
Browse files Browse the repository at this point in the history
Allow hotkey scheme to be an arbitrary string
  • Loading branch information
o-sdn-o authored Nov 22, 2024
2 parents d6cb9c5 + 5e291e1 commit 37a1522
Show file tree
Hide file tree
Showing 19 changed files with 666 additions and 640 deletions.
267 changes: 123 additions & 144 deletions doc/apps.md

Large diffs are not rendered by default.

228 changes: 119 additions & 109 deletions doc/settings.md

Large diffs are not rendered by default.

23 changes: 16 additions & 7 deletions src/netxs/apps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,26 @@ namespace netxs::app::shared
subs_ptr->clear();
if (auto focusable_parent = boss.base::riseup(tier::request, e2::config::plugins::focus::owner))
{
focusable_parent->LISTEN(tier::release, e2::form::state::keybd::hotkey, state, (*subs_ptr))
focusable_parent->LISTEN(tier::release, e2::form::state::keybd::scheme, hscheme, (*subs_ptr))
{
boss.set(state ? ansi::bgc(greendk).fgc(whitelt).add(" on █")
: ansi::bgc(reddk).fgx(0) .add("█off "));
//todo unify
boss.set(hscheme.size() ? ansi::bgc(greendk).fgc(whitelt).add(" on █")
: ansi::bgc(reddk).fgx(0) .add("█off "));
boss.base::reflow();
};
}
};
boss.LISTEN(tier::release, hids::events::mouse::button::click::left, gear)
{
gear.set_hotkey_scheme(gear.meta(hids::HotkeyScheme) ? 0 : hids::HotkeyScheme);
//todo unify
if (gear.hscheme != ""sv)
{
gear.set_hotkey_scheme("");
}
else
{
gear.set_hotkey_scheme("1");
}
gear.dismiss_dblclick();
};
});
Expand Down Expand Up @@ -744,12 +753,12 @@ namespace netxs::app::shared
auto& items_inst = *items;
auto& keybd = boss.template plugins<pro::keybd>();
app::shared::base_kb_navigation(keybd, scroll, boss);
keybd.proc("UpdateChordPreview", [&, update_ptr](hids& gear)
keybd.proc("UpdateChordPreview", [&, update_ptr](hids& gear, txts&)
{
if (gear.keystat != input::key::repeated) (*update_ptr)(items_inst, gear, true);
});
keybd.template bind<tier::release>( "Any", "UpdateChordPreview", 0);
keybd.template bind<tier::release>( "Any", "UpdateChordPreview", 1);
keybd.template bind<tier::release>( "Any", "", "UpdateChordPreview");
keybd.template bind<tier::release>( "Any", "1", "UpdateChordPreview");
});
inside->attach(slot::_2, ui::post::ctor())
->limits({ -1, 1 })
Expand Down
182 changes: 68 additions & 114 deletions src/netxs/apps/term.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ namespace netxs::app::terminal
gear.set_tooltip(look.tooltip, true);
_update(boss, item);
}
auto _update_to(ui::item& boss, menu::item& item, si32 i)
auto _update_to(ui::item& boss, menu::item& item, ui64 i)
{
item.select(i);
_update(boss, item);
}
auto _update_to(ui::item& boss, menu::item& item, text utf8)
{
_update_to(boss, item, qiew::hash{}(utf8));
}
template<bool AutoUpdate = faux, class P>
auto _submit(ui::item& boss, menu::item& item, P proc)
{
Expand Down Expand Up @@ -203,57 +207,51 @@ namespace netxs::app::terminal
{ menu::type::Repeat, menu::item::Repeat }};

#define proc_list \
X(Noop ) /* */ \
X(ToggleHotkeyScheme ) /* */ \
X(TerminalQuit ) /* */ \
X(TerminalCwdSync ) /* */ \
X(TerminalToggleFullscreen ) /* */ \
X(TerminalToggleMaximize ) /* */ \
X(TerminalRestart ) /* */ \
X(TerminalSendKey ) /* */ \
X(TerminalWrapMode ) /* */ \
X(TerminalAlignMode ) /* */ \
X(TerminalOutput ) /* */ \
X(TerminalFindNext ) /* */ \
X(TerminalFindPrev ) /* */ \
X(TerminalUndo ) /* Undo/Redo for cooked read on win32 */ \
X(TerminalRedo ) /* */ \
X(TerminalClipboardPaste ) /* */ \
X(TerminalClipboardWipe ) /* */ \
X(TerminalSelectionCopy ) /* */ \
X(TerminalSelectionMode ) /* */ \
X(TerminalSelectionRect ) /* Linear/Rectangular */ \
X(TerminalSelectionCancel ) /* */ \
X(TerminalSelectionOneShot ) /* One-shot toggle to copy text while mouse tracking is active */ \
X(TerminalViewportPageUp ) /* */ \
X(TerminalViewportPageDown ) /* */ \
X(TerminalViewportLineUp ) /* */ \
X(TerminalViewportLineDown ) /* */ \
X(TerminalViewportPageLeft ) /* */ \
X(TerminalViewportPageRight ) /* */ \
X(TerminalViewportCharLeft ) /* */ \
X(TerminalViewportCharRight ) /* */ \
X(TerminalViewportTop ) /* */ \
X(TerminalViewportEnd ) /* */ \
X(TerminalViewportCopy ) /* */ \
X(TerminalStdioLog ) /* */ \
X(TerminalLogStart ) /* */ \
X(TerminalLogPause ) /* */ \
X(TerminalLogStop ) /* */ \
X(TerminalLogAbort ) /* */ \
X(TerminalLogRestart ) /* */ \
X(TerminalVideoRecStart ) /* */ \
X(TerminalVideoRecStop ) /* */ \
X(TerminalVideoRecPause ) /* */ \
X(TerminalVideoRecAbort ) /* */ \
X(TerminalVideoRecRestart ) /* */ \
X(TerminalVideoPlay ) /* */ \
X(TerminalVideoPause ) /* */ \
X(TerminalVideoStop ) /* */ \
X(TerminalVideoForward ) /* */ \
X(TerminalVideoBackward ) /* */ \
X(TerminalVideoHome ) /* */ \
X(TerminalVideoEnd ) /* */
X(Noop ) /* */ \
X(SwitchHotkeyScheme ) /* */ \
X(TerminalQuit ) /* */ \
X(TerminalCwdSync ) /* */ \
X(TerminalToggleFullscreen ) /* */ \
X(TerminalToggleMaximize ) /* */ \
X(TerminalRestart ) /* */ \
X(TerminalSendKey ) /* */ \
X(TerminalWrapMode ) /* */ \
X(TerminalAlignMode ) /* */ \
X(TerminalOutput ) /* */ \
X(TerminalFindNext ) /* */ \
X(TerminalFindPrev ) /* */ \
X(TerminalUndo ) /* Undo/Redo for cooked read on win32 */ \
X(TerminalRedo ) /* */ \
X(TerminalClipboardPaste ) /* */ \
X(TerminalClipboardWipe ) /* */ \
X(TerminalSelectionCopy ) /* */ \
X(TerminalSelectionMode ) /* */ \
X(TerminalSelectionRect ) /* Linear/Rectangular */ \
X(TerminalSelectionCancel ) /* */ \
X(TerminalSelectionOneShot ) /* One-shot toggle to copy text while mouse tracking is active */ \
X(TerminalScrollViewportByPage) /* */ \
X(TerminalScrollViewportByCell) /* */ \
X(TerminalScrollViewportToTop ) /* */ \
X(TerminalScrollViewportToEnd ) /* */ \
X(TerminalViewportCopy ) /* */ \
X(TerminalStdioLog ) /* */ \
X(TerminalLogStart ) /* */ \
X(TerminalLogPause ) /* */ \
X(TerminalLogStop ) /* */ \
X(TerminalLogAbort ) /* */ \
X(TerminalLogRestart ) /* */ \
X(TerminalVideoRecStart ) /* */ \
X(TerminalVideoRecStop ) /* */ \
X(TerminalVideoRecPause ) /* */ \
X(TerminalVideoRecAbort ) /* */ \
X(TerminalVideoRecRestart ) /* */ \
X(TerminalVideoPlay ) /* */ \
X(TerminalVideoPause ) /* */ \
X(TerminalVideoStop ) /* */ \
X(TerminalVideoForward ) /* */ \
X(TerminalVideoBackward ) /* */ \
X(TerminalVideoHome ) /* */ \
X(TerminalVideoEnd ) /* */

enum func
{
Expand All @@ -275,21 +273,21 @@ namespace netxs::app::terminal
using release = terminal::events::release;

static void Noop(ui::item& /*boss*/, menu::item& /*item*/) { }
static void ToggleHotkeyScheme(ui::item& boss, menu::item& item)
static void SwitchHotkeyScheme(ui::item& boss, menu::item& item)
{
item.reindex([](auto& utf8){ auto v = xml::take<bool>(utf8); return v ? v.value() + 1 : 0; });
_submit<true>(boss, item, [](auto& /*boss*/, auto& /*item*/, auto& gear)
item.reindex<text>([](auto& utf8){ return xml::take_or<text>(utf8, ""s); });
_submit<true>(boss, item, [](auto& /*boss*/, auto& item, auto& gear)
{
gear.set_handled();
gear.set_hotkey_scheme(gear.meta(hids::HotkeyScheme) ? 0 : hids::HotkeyScheme);
gear.set_hotkey_scheme(item.views[item.taken].data);
});
boss.LISTEN(tier::anycast, e2::form::upon::started, root, -, (hook_ptr = ptr::shared<hook>()))
{
if (auto focusable_parent = boss.base::riseup(tier::request, e2::config::plugins::focus::owner))
{
focusable_parent->LISTEN(tier::release, e2::form::state::keybd::hotkey, state, (*hook_ptr))
focusable_parent->LISTEN(tier::release, e2::form::state::keybd::scheme, hscheme, (*hook_ptr))
{
_update_to(boss, item, state + 1);
_update_to(boss, item, hscheme);
};
}
};
Expand Down Expand Up @@ -346,14 +344,14 @@ namespace netxs::app::terminal
{
_submit<true>(boss, item, [](auto& boss, auto& item, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, terminal::events::data::in, view{ item.views[item.taken].param });
boss.bell::signal(tier::anycast, terminal::events::data::in, view{ item.views[item.taken].data });
});
}
static void TerminalSendKey(ui::item& boss, menu::item& item)
{
_submit<true>(boss, item, [](auto& boss, auto& item, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, terminal::events::data::out, view{ item.views[item.taken].param });
boss.bell::signal(tier::anycast, terminal::events::data::out, view{ item.views[item.taken].data });
});
}
static void TerminalQuit(ui::item& boss, menu::item& item)
Expand Down Expand Up @@ -469,80 +467,36 @@ namespace netxs::app::terminal
boss.bell::signal(tier::anycast, terminal::events::data::prnscrn, gear);
});
}
static void TerminalViewportPageUp(ui::item& boss, menu::item& item)
static void TerminalScrollViewportByPage(ui::item& boss, menu::item& item)
{
_submit<true>(boss, item, [](auto& boss, auto& /*item*/, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bypage::y, { .vector = dot_01 });
});
}
static void TerminalViewportPageDown(ui::item& boss, menu::item& item)
{
_submit<true>(boss, item, [](auto& boss, auto& /*item*/, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bypage::y, { .vector = -dot_01 });
});
}
static void TerminalViewportLineUp(ui::item& boss, menu::item& item)
{
item.reindex([](auto& utf8){ auto v = xml::take<si32>(utf8); return v ? v.value() : 1; });
_submit<true>(boss, item, [](auto& boss, auto& item, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bystep::y, { .vector = { 0, std::abs(item.views[item.taken].value) }});
auto delta = xml::take_or<twod>(item.views[item.taken].data, dot_00);
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bypage::v, { .vector = delta });
});
}
static void TerminalViewportLineDown(ui::item& boss, menu::item& item)
static void TerminalScrollViewportByCell(ui::item& boss, menu::item& item)
{
item.reindex([](auto& utf8){ auto v = xml::take<si32>(utf8); return v ? v.value() : 1; });
_submit<true>(boss, item, [](auto& boss, auto& item, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bystep::y, { .vector = { 0, -std::abs(item.views[item.taken].value) }});
auto delta = xml::take_or<twod>(item.views[item.taken].data, dot_00);
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bystep::v, { .vector = delta });
});
}
static void TerminalViewportTop(ui::item& boss, menu::item& item)
static void TerminalScrollViewportToTop(ui::item& boss, menu::item& item)
{
_submit<true>(boss, item, [](auto& boss, auto& /*item*/, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::to_top::y);
});
}
static void TerminalViewportEnd(ui::item& boss, menu::item& item)
static void TerminalScrollViewportToEnd(ui::item& boss, menu::item& item)
{
_submit<true>(boss, item, [](auto& boss, auto& /*item*/, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::to_end::y);
});
}
static void TerminalViewportPageLeft(ui::item& boss, menu::item& item)
{
_submit<true>(boss, item, [](auto& boss, auto& /*item*/, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bypage::x, { .vector = dot_10 });
});
}
static void TerminalViewportPageRight(ui::item& boss, menu::item& item)
{
_submit<true>(boss, item, [](auto& boss, auto& /*item*/, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bypage::x, { .vector = -dot_10 });
});
}
static void TerminalViewportCharLeft(ui::item& boss, menu::item& item)
{
item.reindex([](auto& utf8){ auto v = xml::take<si32>(utf8); return v ? v.value() : 1; });
_submit<true>(boss, item, [](auto& boss, auto& item, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bystep::x, { .vector = { std::abs(item.views[item.taken].value), 0 }});
});
}
static void TerminalViewportCharRight(ui::item& boss, menu::item& item)
{
item.reindex([](auto& utf8){ auto v = xml::take<si32>(utf8); return v ? v.value() : 1; });
_submit<true>(boss, item, [](auto& boss, auto& item, auto& /*gear*/)
{
boss.bell::signal(tier::anycast, e2::form::upon::scroll::bystep::x, { .vector = { -std::abs(item.views[item.taken].value), 0 }});
});
}
static void TerminalStdioLog(ui::item& boss, menu::item& item)
{
item.reindex([](auto& utf8){ return xml::take<bool>(utf8).value(); });
Expand Down Expand Up @@ -654,15 +608,15 @@ namespace netxs::app::terminal
auto route = data.take(menu::attr::route, func::Noop, route_options);
item.brand = data.take(menu::attr::brand, menu::item::Command, brand_options);
defs.tooltip = data.take(menu::attr::tooltip, ""s);
defs.param = data.take(menu::attr::param, ""s);
defs.data = data.take(menu::attr::data, ""s);
item.alive = route != func::Noop && item.brand != menu::item::Splitter;
for (auto label : data.list(menu::attr::label))
{
item.views.push_back(
{
.label = label->take_value(),
.tooltip = label->take(menu::attr::tooltip, defs.tooltip),
.param = label->take(menu::attr::param, defs.param),
.data = label->take(menu::attr::data, defs.data),
});
}
if (item.views.empty()) continue; // Menu item without label.
Expand Down
Loading

0 comments on commit 37a1522

Please sign in to comment.