Skip to content

Commit

Permalink
directvt#86 WIP: Unify FocusNextWindow (breaking changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Dec 21, 2024
1 parent 10b71e7 commit 332ad1d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 71 deletions.
25 changes: 12 additions & 13 deletions doc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ 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.
`FocusPrevWindow` | | Desktop | Switch focus to the next desktop window.
`FocusNextWindow` | | Desktop | Switch focus to the previous desktop window.
`FocusNextWindow` | `on` \| `off` | Desktop | Switch focus to the next desktop window. The data parameter specifies the direction of focus switching: prev ("off"), next ("on").
`Disconnect` | | Desktop | Disconnect from the desktop.
`RunApplication` | _`Taskbar item id`_ | Desktop | Run application. Run the default application if no arguments are specified.
`RunScript` | _`Script body`_ | Desktop | Run script.
Expand Down Expand Up @@ -905,17 +904,17 @@ Notes
<key="Space-Backspace | Backspace-Space" action=ToggleDebugOverlay/> <!-- Toggle debug overlay. -->
</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" preview action=TryToQuit/> <!-- Shut down the desktop server if no applications are running. -->
<key="Alt+Shift+N" action=RunApplication/> <!-- Run default application. -->
<key="" action=AlwaysOnTopWindow/><!-- Toggle AlwaysOnTop window flag. -->
<key="" action=CloseWindow/> <!-- Close window. -->
<key="" action=MinimizeWindow/> <!-- Minimize window. -->
<key="Esc+F11" action=MaximizeWindow/> <!-- Maximize window. -->
<key="Esc+F12" action=FullscreenWindow/> <!-- Maximize window to full screen. -->
<key="Esc+F1"> <action=RunScript data="vtm.run(title='Info-page' hidden=true label=Info type=info)"/></key> <!-- Run Info-page. -->
<key="Ctrl+PageUp"> <action=FocusNextWindow data=0/></key> <!-- Switch focus to the previous desktop window. -->
<key="Ctrl+PageDown"><action=FocusNextWindow data=1/></key> <!-- Switch focus to the next desktop window. -->
<key="Shift+F7" action=Disconnect/> <!-- Disconnect from the desktop. -->
<key="F10" preview action=TryToQuit/> <!-- Shut down the desktop server if no applications are running. -->
<key="Alt+Shift+N" action=RunApplication/> <!-- Run default application. -->
<key="" action=AlwaysOnTopWindow/> <!-- Toggle AlwaysOnTop window flag. -->
<key="" action=CloseWindow/> <!-- Close window. -->
<key="" action=MinimizeWindow/> <!-- Minimize window. -->
<key="Esc+F11" action=MaximizeWindow/> <!-- Maximize window. -->
<key="Esc+F12" action=FullscreenWindow/> <!-- Maximize window to full screen. -->
<key="Esc+F1"> <action=RunScript data="vtm.run(title='Info-page' hidden=true label=Info type=info)"/></key> <!-- Run Info-page. -->

<key=""><action=WarpWindow data="0,0,0,0"/></key> <!-- Warp desktop window. The data parameter specifies four deltas for the left, right, top and bottom window sides. -->
<key="Esc+'=' | Esc+'+'"> <action=WarpWindow data=" 1, 1, 1, 1"/></key> <!-- Increase window size. -->
Expand Down
1 change: 1 addition & 0 deletions src/netxs/desktopio/baseui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ namespace netxs::events::userland
EVENT_XS( minimize , input::hids ),
EVENT_XS( maximize , input::hids ),
EVENT_XS( fullscreen , input::hids ),
EVENT_XS( nextwindow , input::hids ),
};
};
SUBSET_XS( cursor )
Expand Down
102 changes: 55 additions & 47 deletions src/vtm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ namespace netxs::app::vtm
if (new_area.coor != boss.base::coor()) unbind();
else what.applet->base::resize(new_area.size + pads);
};
boss.LISTEN(tier::preview, e2::form::proceed::action::nextwindow, gear, memo)
{
unbind();
boss.bell::expire(tier::preview);
};
window_ptr->LISTEN(tier::preview, e2::form::size::enlarge::any, gear, memo)
{
auto deed = what.applet->bell::protos(tier::preview);
Expand Down Expand Up @@ -749,11 +754,10 @@ namespace netxs::app::vtm
{
//todo local=>nexthop
local = faux;
keybd.proc("FocusPrevWindow", [&](hids& gear){ focus_next_window(gear, feed::rev); });
keybd.proc("FocusNextWindow", [&](hids& gear){ focus_next_window(gear, feed::fwd); });
keybd.proc("Disconnect", [&](hids& gear){ disconnect(gear); });
keybd.proc("TryToQuit", [&](hids& gear){ try_quit(gear); });
keybd.proc("RunApplication", [&](hids& gear){ create_app(gear); gear.set_handled(); });
keybd.proc("FocusNextWindow", [&](hids& gear){ base::riseup(tier::preview, e2::form::proceed::action::nextwindow , gear); });
keybd.proc("RunScript", [&](hids& gear){ base::riseup(tier::preview, e2::form::proceed::action::runscript , gear); });
keybd.proc("AlwaysOnTopWindow", [&](hids& gear){ base::riseup(tier::preview, e2::form::proceed::action::alwaysontop, gear); });
keybd.proc("WarpWindow", [&](hids& gear){ base::riseup(tier::preview, e2::form::proceed::action::warp , gear); });
Expand Down Expand Up @@ -926,51 +930,6 @@ namespace netxs::app::vtm
this->bell::expire(tier::preview);
gear.set_handled();
}
void focus_next_window(hids& gear, feed forward)
{
auto down = forward == feed::fwd;
if (gear.shared_event) // Give another process a chance to handle this event.
{
auto gear_id = gear.id;
down ? this->base::riseup(tier::request, e2::form::layout::focus::next, gear_id)
: this->base::riseup(tier::request, e2::form::layout::focus::prev, gear_id);
if (!gear_id) return;
}

if (align.what.applet)
{
align.unbind();
}
auto window_ptr = this->base::riseup(tier::request, e2::form::layout::go::item); // Take current window.
if (window_ptr) window_ptr->bell::signal(tier::release, e2::form::layout::unselect, gear);

auto current = window_ptr;
auto maximized = faux;
auto owner_id = id_t{};
do
{
window_ptr.reset();
owner_id = id_t{};
if (down) this->base::riseup(tier::request, e2::form::layout::go::prev, window_ptr); // Take prev window.
else this->base::riseup(tier::request, e2::form::layout::go::next, window_ptr); // Take next window.
if (window_ptr) window_ptr->bell::signal(tier::request, e2::form::state::maximized, owner_id);
maximized = owner_id == gear.owner.id;
if (!owner_id || maximized) break;
}
while (window_ptr != current); // Skip all foreign maximized windows.

if (window_ptr && (!owner_id || maximized))
{
auto& window = *window_ptr;
window.bell::signal(tier::release, e2::form::layout::selected, gear);
if (!maximized) jump_to(window);
bell::enqueue(window_ptr, [&, gear_id = gear.id](auto& /*boss*/) // Keep the focus tree intact while processing key events.
{
pro::focus::set(window.This(), gear_id, solo::on);
});
}
gear.set_handled();
}
void move_viewport(twod newpos, rect viewport)
{
auto oldpos = viewport.center();
Expand Down Expand Up @@ -1796,6 +1755,51 @@ namespace netxs::app::vtm
bell::signal(tier::general, e2::shutdown, utf::concat(prompt::repl, "Server shutdown"));
return "ok"s;
}

void next_window(hids& gear)
{
auto go_forward = gear.get_args_or(true);
if (gear.shared_event) // Give another process a chance to handle this event.
{
auto gear_id = gear.id;
go_forward ? bell::signal(tier::request, e2::form::layout::focus::next, gear_id)
: bell::signal(tier::request, e2::form::layout::focus::prev, gear_id);
if (!gear_id) return;
}

auto window_ptr = bell::signal(tier::request, e2::form::layout::go::item); // Take current window.
if (window_ptr) window_ptr->bell::signal(tier::release, e2::form::layout::unselect, gear);

auto current = window_ptr;
auto maximized = faux;
auto owner_id = id_t{};
do
{
window_ptr.reset();
owner_id = id_t{};
if (go_forward) bell::signal(tier::request, e2::form::layout::go::prev, window_ptr); // Take prev window.
else bell::signal(tier::request, e2::form::layout::go::next, window_ptr); // Take next window.
if (window_ptr) window_ptr->bell::signal(tier::request, e2::form::state::maximized, owner_id);
maximized = owner_id == gear.owner.id;
if (!owner_id || maximized) break;
}
while (window_ptr != current); // Skip all foreign maximized windows.

if (window_ptr && (!owner_id || maximized))
{
auto& window = *window_ptr;
window.bell::signal(tier::release, e2::form::layout::selected, gear);
if (!maximized)
{
gear.owner.bell::signal(tier::release, e2::form::layout::jumpto, window);
}
bell::enqueue(window_ptr, [&, gear_id = gear.id](auto& /*boss*/) // Keep the focus tree intact while processing key events.
{
pro::focus::set(window.This(), gear_id, solo::on);
});
}
gear.set_handled();
}
void run_script(hids& gear)
{
if (gear.args_ptr)
Expand Down Expand Up @@ -2288,6 +2292,10 @@ namespace netxs::app::vtm
}
};

LISTEN(tier::preview, e2::form::proceed::action::nextwindow, gear)
{
next_window(gear);
};
LISTEN(tier::preview, e2::form::proceed::action::runscript, gear)
{
run_script(gear);
Expand Down
22 changes: 11 additions & 11 deletions src/vtm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,17 @@ R"==(
<key="Space-Backspace | Backspace-Space" action=ToggleDebugOverlay/> <!-- Toggle debug overlay. -->
</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" preview action=TryToQuit/> <!-- Shut down the desktop server if no applications are running. -->
<key="Alt+Shift+N" action=RunApplication/> <!-- Run default application. -->
<key="" action=AlwaysOnTopWindow/><!-- Toggle AlwaysOnTop window flag. -->
<key="" action=CloseWindow/> <!-- Close window. -->
<key="" action=MinimizeWindow/> <!-- Minimize window. -->
<key="Esc+F11" action=MaximizeWindow/> <!-- Maximize window. -->
<key="Esc+F12" action=FullscreenWindow/> <!-- Maximize window to full screen. -->
<key="Esc+F1"> <action=RunScript data="vtm.run(title='Info-page' hidden=true label=Info type=info)"/></key> <!-- Run Info-page. -->
<key="Ctrl+PageUp"> <action=FocusNextWindow data=0/></key> <!-- Switch focus to the previous desktop window. -->
<key="Ctrl+PageDown"><action=FocusNextWindow data=1/></key> <!-- Switch focus to the next desktop window. -->
<key="Shift+F7" action=Disconnect/> <!-- Disconnect from the desktop. -->
<key="F10" preview action=TryToQuit/> <!-- Shut down the desktop server if no applications are running. -->
<key="Alt+Shift+N" action=RunApplication/> <!-- Run default application. -->
<key="" action=AlwaysOnTopWindow/> <!-- Toggle AlwaysOnTop window flag. -->
<key="" action=CloseWindow/> <!-- Close window. -->
<key="" action=MinimizeWindow/> <!-- Minimize window. -->
<key="Esc+F11" action=MaximizeWindow/> <!-- Maximize window. -->
<key="Esc+F12" action=FullscreenWindow/> <!-- Maximize window to full screen. -->
<key="Esc+F1"> <action=RunScript data="vtm.run(title='Info-page' hidden=true label=Info type=info)"/></key> <!-- Run Info-page. -->

<key=""><action=WarpWindow data="0,0,0,0"/></key> <!-- Warp desktop window. The data parameter specifies four deltas for the left, right, top and bottom window sides. -->
<key="Esc+'=' | Esc+'+'"> <action=WarpWindow data=" 1, 1, 1, 1"/></key> <!-- Increase window size. -->
Expand Down

0 comments on commit 332ad1d

Please sign in to comment.