Skip to content

Commit

Permalink
Merge pull request #691 from o-sdn-o/gui-bridge
Browse files Browse the repository at this point in the history
Reimplement hotkey handling (drop schemes)
  • Loading branch information
o-sdn-o authored Nov 29, 2024
2 parents a51e6ca + 6b588c8 commit fb6d28d
Show file tree
Hide file tree
Showing 19 changed files with 345 additions and 436 deletions.
20 changes: 9 additions & 11 deletions doc/apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Value | Arguments (`data=`) | Description
-----------------------------|-------------------------------|------------
Noop | | Ignore all events for the specified key combination. No further processing.
DropAutoRepeat | | Ignore `Key Repeat` events for the specified key combination. This binding should be specified before the main action for the key combination.
SwitchHotkeyScheme | _`Scheme name`_ | Switch the hotkey scheme to the specified one.
ExclusiveKeyboardMode | | Toggle exclusive keyboard mode.
TerminalCwdSync | | Current working directory sync toggle. The command to send for synchronization is configurable via the `<config><terminal cwdsync=" cd $P\n"/></config>` setting's option. Where `$P` is a variable containing current path received via OSC 9;9 notification. <br>To enable OSC9;9 shell notifications:<br>- Windows Command Prompt:<br> `setx PROMPT $e]9;9;$P$e\$P$G`<br>- PowerShell:<br> `function prompt{ $e=[char]27; "$e]9;9;$(Convert-Path $pwd)$e\PS $pwd$('>' * ($nestedPromptLevel + 1)) " }`<br>- Bash:<br> `export PS1='\[\033]9;9;\w\033\\\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '`
TerminalWrapMode | `on` \| `off` | Set terminal scrollback lines wrapping mode. Applied to the active selection if it is.
TerminalAlignMode | `left` \| `right` \| `center` | Set terminal scrollback lines aligning mode. Applied to the active selection if it is.
Expand Down Expand Up @@ -156,7 +156,8 @@ List of hotkeys defined in the default configuration.

Hotkey | Description
-----------------------------|------------
`Ctrl-Alt | Alt-Ctrl` | Toggle hotkey scheme between `Keys0` and `Keys1`.
`Ctrl-Alt \| Alt-Ctrl` | Win32: Toggle exclusive keyboard mode.
`Alt=Shift+B` | Unix: Toggle exclusive keyboard mode.
`Alt+RightArrow` | Highlight next match of selected text fragment. Clipboard content is used if no active selection.
`Alt+LeftArrow` | Highlight previous match of selected text fragment. Clipboard content is used if no active selection.
`Shift+Ctrl+PageUp` | Scroll one page up.
Expand Down Expand Up @@ -196,12 +197,12 @@ Hotkey | Description
" Left+RightClick to clear clipboard "
</tooltip>
</item>
<item type="Option" action=SwitchHotkeyScheme label=" Keys0 " data="">
<label="\e[48:2:0:128:128;38:2:0:255:0m Keys1 \e[m" data="1"/>
<item type="Option" action=ExclusiveKeyboardMode label=" Desktop " data="off">
<label="\e[48:2:0:128:128;38:2:0:255:0m Exclusive \e[m" data="on"/>
<tooltip>
" Toggle hotkey scheme \n"
" Alternative hotkey scheme allows keystrokes \n"
" to be passed through without processing "
" Toggle exclusive keyboard mode \n"
" Exclusive keyboard mode allows keystrokes \n"
" to be passed through without processing "
</tooltip>
</item>
<item label="Wrap" type="Option" action=TerminalWrapMode data="off">
Expand Down Expand Up @@ -308,16 +309,13 @@ Hotkey | Description
<hotkeys> <!-- The required key combination sequence can be generated on the Info page, accessible by clicking on the label in the lower right corner of the vtm desktop. -->
<tui key*> <!-- TUI matrix layer key bindings. -->
<key="Space-Backspace | Backspace-Space" action=ToggleDebugOverlay/> <!-- Toggle debug overlay. -->
<key="Ctrl-Alt | Alt-Ctrl" scheme=""><action=SwitchHotkeyScheme data="1"/></key> <!-- Switch the hotkey scheme to "1" by pressing and releasing Ctrl-Alt or Alt-Ctrl (reversed release order). -->
<key="Ctrl-Alt | Alt-Ctrl" scheme="1"><action=SwitchHotkeyScheme data=""/></key> <!-- Switch the hotkey scheme to default by pressing and releasing Ctrl-Alt or Alt-Ctrl (reversed release order). -->
</tui>
<terminal key*>
<key="Ctrl-Alt | Alt-Ctrl" preview action=ExclusiveKeyboardMode/> <!-- Toggle exclusive keyboard mode by pressing and releasing Ctrl-Alt or Alt-Ctrl (reversed release order). -->
<key="Alt+RightArrow" action=TerminalFindNext/> <!-- Highlight next match of selected text fragment. Clipboard content is used if no active selection. -->
<key="Alt+LeftArrow" action=TerminalFindPrev/> <!-- Highlight previous match of selected text fragment. Clipboard content is used if no active selection. -->
<key="Shift+Ctrl+PageUp" ><action=TerminalScrollViewportByPage data=" 0, 1"/></key> <!-- Scroll viewport one page up. -->
<key="Shift+Ctrl+PageDown" ><action=TerminalScrollViewportByPage data=" 0,-1"/></key> <!-- Scroll viewport one page down. -->
<key="Ctrl+PageUp" scheme="1"><action=TerminalScrollViewportByPage data=" 0, 1"/></key> <!-- Scroll viewport one page up. -->
<key="Ctrl+PageDown" scheme="1"><action=TerminalScrollViewportByPage data=" 0,-1"/></key> <!-- Scroll viewport one page down. -->
<key="Shift+Alt+LeftArrow" ><action=TerminalScrollViewportByPage data=" 1, 0"/></key> <!-- Scroll viewport one page to the left. -->
<key="Shift+Alt+RightArrow" ><action=TerminalScrollViewportByPage data="-1, 0"/></key> <!-- Scroll viewport one page to the right. -->
<key="Shift+Ctrl+UpArrow" ><action=TerminalScrollViewportByCell data=" 0, 1"/></key> <!-- Scroll viewport one line up. -->
Expand Down
22 changes: 10 additions & 12 deletions doc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ Application `app_name` | `<config/hotkeys/app_name/>` | Application layer key bi
The syntax for defining key combination bindings is:

```xml
<key="Key+Chord | ... | Another+Key+Chord" scheme="scheme_name"> <!-- scheme="" can be omitted. -->
<key="Key+Chord | ... | Another+Key+Chord" [ preview ]>
<action="NameOfAction1" data="argument"/>
...
<action="NameOfActionN" data="argument"/>
Expand All @@ -340,8 +340,8 @@ The syntax for defining key combination bindings is:
Tag | Value
---------|--------
`key` | The text string containing the key combinations.
`scheme` | Hotkey scheme name for which mapping is being done (empty string by default).
`action` | The action name.
`preview`| A Boolean value specifying that hotkey actions should be processed while traversing the focus tree until the target object is reached (ignoring keyboard exclusive mode). Default is `off`.
`data` | The arguments passed to the action.

The following joiners are allowed for combining keys:
Expand Down Expand Up @@ -372,7 +372,6 @@ Configuration record | Interpretation
`<key="Key+Chord" action=NameOfAction/>` | Append existing bindings using an indirect reference (the `NameOfAction` variable without quotes).
`<key="Key+Chord | Another+Chord" action=NameOfAction/>` | Append existing bindings for `Key+Chord | Another+Chord`.
`<key="Key+Chord" action="NameOfAction"/>` | Append existing bindings with the directly specified command "NameOfAction".
`<key="Key+Chord" action="NameOfAction" scheme="1"/>` | Append existing bindings for scheme="1".
`<key="Key+Chord" action=""/>` | Remove all existing bindings for the specified key combination "Key+Chord".
`<key="Key+Chord"><action="NameOfAction" data="param"/></key>` | Append existing bindings with the directly specified command "NameOfAction" with arguments "param".
`<key="" action="NameOfAction"/>` | Do nothing.
Expand All @@ -391,12 +390,12 @@ Action | Arguments (`data=`)
`RollFontsBackward` | | Native GUI window | Roll font list backward.
`RollFontsForward` | | Native GUI window | Roll font list forward.
`ToggleDebugOverlay` | | TUI matrix | Toggle debug overlay.
`SwitchHotkeyScheme` | _`Scheme name`_ | TUI matrix,<br>Window menu | Switch the hotkey scheme to the specified one.
`FocusPrevWindow` | | Desktop | Switch focus to the next desktop window.
`FocusNextWindow` | | Desktop | Switch focus to the previous desktop window.
`Disconnect` | | Desktop | Disconnect from the desktop.
`RunApplication` | _`Taskbar item id`_ | Desktop | Run application. Run the default application if no arguments are specified.
`TryToQuit` | | Desktop | Shut down the desktop server if no applications are running.
`ExclusiveKeyboardMode` | `on` \| `off` | Application | Toggle exclusive keyboard mode.
`TerminalFindNext` | | Application | Highlight next match of selected text fragment. Clipboard content is used if no active selection.
`TerminalFindPrev` | | Application | Highlight previous match of selected text fragment. Clipboard content is used if no active selection.
`TerminalScrollViewportByPage` | _`IntX, IntY`_ | Application | Scroll viewport by _`IntX, IntY`_ pages.
Expand Down Expand Up @@ -774,12 +773,12 @@ Notes
" Left+RightClick to clear clipboard "
</tooltip>
</item>
<item type="Option" action=SwitchHotkeyScheme label=" Keys0 " data="">
<label="\e[48:2:0:128:128;38:2:0:255:0m Keys1 \e[m" data="1"/>
<item type="Option" action=ExclusiveKeyboardMode label=" Desktop " data="off">
<label="\e[48:2:0:128:128;38:2:0:255:0m Exclusive \e[m" data="on"/>
<tooltip>
" Toggle hotkey scheme \n"
" Alternative hotkey scheme allows keystrokes \n"
" to be passed through without processing "
" Toggle exclusive keyboard mode \n"
" Exclusive keyboard mode allows keystrokes \n"
" to be passed through without processing "
</tooltip>
</item>
<item label="Wrap" type="Option" action=TerminalWrapMode data="off">
Expand Down Expand Up @@ -860,17 +859,16 @@ Notes
</gui>
<tui key*> <!-- TUI matrix layer key bindings. -->
<key="Space-Backspace | Backspace-Space" action=ToggleDebugOverlay/> <!-- Toggle debug overlay. -->
<key="Ctrl-Alt | Alt-Ctrl" scheme=""><action=SwitchHotkeyScheme data="1"/></key> <!-- Switch the hotkey scheme to "1" by pressing and releasing Ctrl-Alt or Alt-Ctrl (reversed release order). -->
<key="Ctrl-Alt | Alt-Ctrl" scheme="1"><action=SwitchHotkeyScheme data=""/></key> <!-- Switch the hotkey scheme to default by pressing and releasing Ctrl-Alt or Alt-Ctrl (reversed release order). -->
</tui>
<desktop key*> <!-- Desktop layer key bindings. -->
<key="Ctrl+PageUp" action=FocusPrevWindow/> <!-- Switch focus to the next desktop window. -->
<key="Ctrl+PageDown" action=FocusNextWindow/> <!-- Switch focus to the previous desktop window. -->
<key="Shift+F7" action=Disconnect/> <!-- Disconnect from the desktop. -->
<key="F10" action=TryToQuit/> <!-- Shut down the desktop server if no applications are running. -->
<key="F10" preview action=TryToQuit/> <!-- Shut down the desktop server if no applications are running. -->
<key="Alt+Shift+N" action=RunApplication/> <!-- Run default application. -->
</desktop>
<terminal key*> <!-- Application specific layer key bindings. -->
<key="Ctrl-Alt | Alt-Ctrl" preview action=ExclusiveKeyboardMode/> <!-- Toggle exclusive keyboard mode by pressing and releasing Ctrl-Alt or Alt-Ctrl (reversed release order). -->
<key="Alt+RightArrow" action=TerminalFindNext/> <!-- Highlight next match of selected text fragment. Clipboard content is used if no active selection. -->
<key="Alt+LeftArrow" action=TerminalFindPrev/> <!-- Highlight previous match of selected text fragment. Clipboard content is used if no active selection. -->
<key="Shift+Ctrl+PageUp" ><action=TerminalScrollViewportByPage data=" 0, 1"/></key> <!-- Scroll viewport one page up. -->
Expand Down
49 changes: 25 additions & 24 deletions src/netxs/apps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,38 +602,25 @@ namespace netxs::app::shared
//->template plugin<pro::focus>()
->template plugin<pro::grade>();
auto state_block = title_grid_state->attach(ui::fork::ctor());
auto state_label = state_block->attach(slot::_1, ui::item::ctor("Alternate hotkey scheme:")->setpad({ 2, 1, 0, 0 }));
auto state_label = state_block->attach(slot::_1, ui::item::ctor("Exclusive keyboard mode:")->setpad({ 2, 1, 0, 0 }));
auto rawkbd_ptr = ptr::shared(faux);
auto& rawkbd = *rawkbd_ptr;
auto state_state = state_block->attach(slot::_2, ui::item::ctor(ansi::bgc(reddk).fgx(0).add("█off ")))
->setpad({ 1, 1, 0, 0 })
->active()
->shader(cell::shaders::xlight, e2::form::state::hover)
->invoke([&](auto& boss)
{
boss.LISTEN(tier::anycast, e2::form::upon::started, root, -, (subs_ptr = ptr::shared<subs>()))
boss.LISTEN(tier::release, ui::term::events::rawkbd, state, -, (rawkbd_ptr))
{
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::scheme, hscheme, (*subs_ptr))
{
//todo unify
boss.set(hscheme.size() ? ansi::bgc(greendk).fgc(whitelt).add(" on █")
: ansi::bgc(reddk).fgx(0) .add("█off "));
boss.base::reflow();
};
}
rawkbd = !rawkbd;
boss.set(rawkbd ? 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)
{
//todo unify
if (gear.hscheme != ""sv)
{
gear.set_hotkey_scheme("");
}
else
{
gear.set_hotkey_scheme("1");
}
boss.bell::signal(tier::release, ui::term::events::rawkbd);
gear.dismiss_dblclick();
};
});
Expand Down Expand Up @@ -748,14 +735,28 @@ namespace netxs::app::shared
window->invoke([&](auto& boss)
{
auto& items_inst = *items;
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&)
{
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&)
{
state_inst.bell::signal(tier::release, ui::term::events::rawkbd);
if (gear.keystat != input::key::repeated) (*update_ptr)(items_inst, gear, true);
gear.set_handled();
});
keybd.template bind<tier::release>( "Any", "", "UpdateChordPreview");
keybd.template bind<tier::release>( "Any", "1", "UpdateChordPreview");
keybd.bind("Any", "UpdateChordPreview");
keybd.bind(
#if defined(WIN32)
"Ctrl-Alt | Alt-Ctrl"
#else
"Alt+Shift+B"
#endif
, "ExclusiveKeyboardMode", true);
});
inside->attach(slot::_2, ui::post::ctor())
->limits({ -1, 1 })
Expand Down
Loading

0 comments on commit fb6d28d

Please sign in to comment.