Skip to content

Commit

Permalink
directvt#86 WIP: Allow moving and resizing tile's grips using arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Dec 17, 2024
1 parent 7d8a277 commit 2d29121
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 16 deletions.
8 changes: 8 additions & 0 deletions doc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,14 @@ Notes
<key="Alt+Shift+E" action=TileEqualizeSplitRatio/> <!-- Equalize split ratio. -->
<key="Alt+Shift+F2" action=TileSetManagerTitle /> <!-- Set tiling window manager title using clipboard data. -->
<key="Alt+Shift+W" action=TileClosePane /> <!-- Close active application. -->
<grips key*>
<key="LeftArrow" ><action=TileMoveGrip data="-1, 0"/></key> <!-- Move the split grip to the left. -->
<key="RightArrow" ><action=TileMoveGrip data=" 1, 0"/></key> <!-- Move the split grip to the right. -->
<key="UpArrow" ><action=TileMoveGrip data=" 0,-1"/></key> <!-- Move the split grip up. -->
<key="DownArrow" ><action=TileMoveGrip data=" 0, 1"/></key> <!-- Move the split grip down. -->
<key="'-'" ><action=TileResizeGrip data="-1" /></key> <!-- Decrease the split grip width. -->
<key="Shift+'+'" ><action=TileResizeGrip data=" 1" /></key> <!-- Increase the split grip width. -->
</grips>
</tile>
<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). -->
Expand Down
6 changes: 6 additions & 0 deletions doc/user-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@
<tr><th>Alt+Shift+E</th> <td>Equalize split ratio.</td></tr>
<tr><th>Alt+Shift+F2</th> <td>Set tiling window manager title using clipboard data.</td></tr>
<tr><th>Alt+Shift+W</th> <td>Close active application.</td></tr>
<tr><th>LeftArrow</th> <td>Move the split grip to the left.</td></tr>
<tr><th>RightArrow</th> <td>Move the split grip to the right.</td></tr>
<tr><th>UpArrow</th> <td>Move the split grip up.</td></tr>
<tr><th>DownArrow</th> <td>Move the split grip down.</td></tr>
<tr><th>'-'</th> <td>Decrease the split grip width.</td></tr>
<tr><th>Shift+'+'</th> <td>Increase the split grip width.</td></tr>
</tbody>
</table>

Expand Down
59 changes: 46 additions & 13 deletions src/netxs/apps/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace netxs::events::userland
EVENT_XS( title , input::hids ), // Set window manager title using clipboard.
GROUP_XS( focus , input::hids ), // Focusize prev/next pane.
GROUP_XS( split , input::hids ), // Split panes.
GROUP_XS( grips , twod ), // Splitting grip modification.

SUBSET_XS( focus )
{
Expand All @@ -35,6 +36,11 @@ namespace netxs::events::userland
EVENT_XS( vt, input::hids ),
EVENT_XS( hz, input::hids ),
};
SUBSET_XS( grips )
{
EVENT_XS( move , twod ),
EVENT_XS( resize, si32 ),
};
};
};
};
Expand Down Expand Up @@ -62,7 +68,9 @@ namespace netxs::app::tile
X(TileSwapPanes ) \
X(TileEqualizeSplitRatio) \
X(TileSetManagerTitle ) \
X(TileClosePane )
X(TileClosePane ) \
X(TileMoveGrip ) \
X(TileResizeGrip )

struct action
{
Expand Down Expand Up @@ -276,7 +284,7 @@ namespace netxs::app::tile
}))
->branch(slot::_2, what.applet);
};
auto build_node = [](auto tag, auto slot1, auto slot2, auto grip_width)
auto build_node = [](auto tag, auto slot1, auto slot2, auto grip_width, auto grip_bindings_ptr)
{
auto highlight_color = skin::color(tone::winfocus);
auto c3 = highlight_color.bga(0x40);
Expand All @@ -285,6 +293,7 @@ namespace netxs::app::tile
: ui::fork::ctor(axis::Y, grip_width == -1 ? 1 : grip_width, slot1, slot2);
node->isroot(faux, base::node) // Set object kind to 1 to be different from others. See node_veer::select.
->template plugin<pro::focus>()
->template plugin<pro::keybd>()
->limits(dot_00)
->invoke([&](auto& boss)
{
Expand All @@ -300,6 +309,29 @@ namespace netxs::app::tile
gear.dismiss();
}
};
boss.LISTEN(tier::preview, app::tile::events::ui::grips::move, delta)
{
if (delta)
{
auto [orientation, griparea, ratio] = boss.get_config();
auto step = orientation == axis::X ? delta.x : delta.y;
if (step == 0) boss.bell::expire(tier::preview, true);
else boss.move_slider(step);
}
};
boss.LISTEN(tier::preview, app::tile::events::ui::grips::resize, step)
{
if (step)
{
auto [orientation, griparea, ratio] = boss.get_config();
auto grip_width = orientation == axis::X ? griparea.size.x : griparea.size.y;
boss.set_grip_width(grip_width + step);
}
};
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.bind(*grip_bindings_ptr);
});
auto grip = node->attach(slot::_I,
ui::mock::ctor()
Expand Down Expand Up @@ -407,7 +439,7 @@ namespace netxs::app::tile
menu_block->alignment({ snap::head, snap::head })
);
};
auto node_veer = [](auto&& node_veer, auto min_state) -> netxs::sptr<ui::veer>
auto node_veer = [](auto&& node_veer, auto min_state, auto grip_bindings_ptr) -> netxs::sptr<ui::veer>
{
return ui::veer::ctor()
->plugin<pro::focus>()
Expand Down Expand Up @@ -566,7 +598,7 @@ namespace netxs::app::tile
}
}
};
boss.LISTEN(tier::release, app::tile::events::ui::split::any, gear)
boss.LISTEN(tier::release, app::tile::events::ui::split::any, gear, -, (grip_bindings_ptr))
{
if (auto deed = boss.bell::protos(tier::release))
{
Expand All @@ -576,9 +608,9 @@ namespace netxs::app::tile
if (depth > inheritance_limit) return;

auto heading = deed == app::tile::events::ui::split::vt.id;
auto newnode = build_node(heading ? 'v':'h', 1, 1, heading ? 1 : 2);
auto empty_1 = node_veer(node_veer, ui::fork::min_ratio);
auto empty_2 = node_veer(node_veer, ui::fork::max_ratio);
auto newnode = build_node(heading ? 'v':'h', 1, 1, heading ? 1 : 2, grip_bindings_ptr);
auto empty_1 = node_veer(node_veer, ui::fork::min_ratio, grip_bindings_ptr);
auto empty_2 = node_veer(node_veer, ui::fork::max_ratio, grip_bindings_ptr);
auto gear_id_list = pro::focus::cut(boss.back());
auto curitem = boss.pop_back();
if (boss.empty())
Expand Down Expand Up @@ -664,9 +696,9 @@ namespace netxs::app::tile
})
->branch(empty_slot());
};
auto parse_data = [](auto&& parse_data, view& utf8, auto min_ratio) -> netxs::sptr<ui::veer>
auto parse_data = [](auto&& parse_data, view& utf8, auto min_ratio, auto grip_bindings_ptr) -> netxs::sptr<ui::veer>
{
auto slot = node_veer(node_veer, min_ratio);
auto slot = node_veer(node_veer, min_ratio, grip_bindings_ptr);
utf::trim_front(utf8, ", ");
if (utf8.empty()) return slot;
auto tag = utf8.front();
Expand Down Expand Up @@ -701,9 +733,9 @@ namespace netxs::app::tile
}
if (utf8.empty() || utf8.front() != '(') return slot;
utf8.remove_prefix(1);
auto node = build_node(tag, s1, s2, w);
auto slot1 = node->attach(slot::_1, parse_data(parse_data, utf8, ui::fork::min_ratio));
auto slot2 = node->attach(slot::_2, parse_data(parse_data, utf8, ui::fork::max_ratio));
auto node = build_node(tag, s1, s2, w, grip_bindings_ptr);
auto slot1 = node->attach(slot::_1, parse_data(parse_data, utf8, ui::fork::min_ratio, grip_bindings_ptr));
auto slot2 = node->attach(slot::_2, parse_data(parse_data, utf8, ui::fork::max_ratio, grip_bindings_ptr));
slot->attach(node);
utf::trim_front(utf8, ") ");
}
Expand Down Expand Up @@ -1152,6 +1184,7 @@ namespace netxs::app::tile
{ tile::action::TileClosePane , [](auto& boss, auto& /*item*/){ on_left_click(boss, app::tile::events::ui::close ); }},
};
config.cd("/config/tile", "/config/defapp");
auto grip_bindings_ptr = ptr::shared(pro::keybd::load(config, "tile/grips"));
auto [menu_block, cover, menu_data] = menu::load(config, proc_map);
object->attach(slot::_1, menu_block)
->invoke([](auto& boss)
Expand Down Expand Up @@ -1182,7 +1215,7 @@ namespace netxs::app::tile
if (err) log("%%Failed to change current directory to '%cwd%', error code: %error%", prompt::tile, appcfg.cwd, err.value());
else log("%%Change current directory to '%cwd%'", prompt::tile, appcfg.cwd);
}
object->attach(slot::_2, parse_data(parse_data, param, ui::fork::min_ratio))
object->attach(slot::_2, parse_data(parse_data, param, ui::fork::min_ratio, grip_bindings_ptr))
->invoke([&](auto& boss)
{
boss.LISTEN(tier::release, e2::form::proceed::attach, fullscreen_item)
Expand Down
21 changes: 18 additions & 3 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ namespace netxs::ui
{
for (auto& proc_name : proc_names)
{
auto args_ptr = ptr::shared(std::move(proc_name.args));
auto args_ptr = ptr::shared(proc_name.args);
set(proc_name.action, args_ptr);
}
}
Expand Down Expand Up @@ -2920,10 +2920,14 @@ namespace netxs::ui
{
return rotation == axis::X ? p : twod{ p.y, p.x };
}
void _set_grip_width(si32 grip_width)
{
griparea.size = xpose({ std::max(0, grip_width), 0 });
}
void _config(axis orientation, si32 grip_width, si32 s1 = 1, si32 s2 = 1)
{
rotation = orientation;
griparea.size = xpose({ std::max(0, grip_width), 0 });
_set_grip_width(grip_width);
_config_ratio(s1, s2);
}
void _config_ratio(si32 s1, si32 s2)
Expand Down Expand Up @@ -3046,6 +3050,12 @@ namespace netxs::ui
fraction = new_ratio;
}
// fork: .
auto set_grip_width(si32 new_grip_width)
{
_set_grip_width(new_grip_width);
base::reflow();
}
// fork: .
void config(si32 s1, si32 s2 = 1)
{
_config_ratio(s1, s2);
Expand All @@ -3058,6 +3068,11 @@ namespace netxs::ui
return This();
}
// fork: .
auto get_config()
{
return std::tuple{ rotation, griparea, fraction };
}
// fork: .
void rotate()
{
auto width = xpose(griparea.size).x;
Expand All @@ -3078,7 +3093,7 @@ namespace netxs::ui
{
if (splitter)
{
auto delta = griparea.size * xpose({ step, 0 });
auto delta = std::max(dot_11, griparea.size) * xpose({ step, 0 });
splitter->bell::signal(tier::preview, e2::form::upon::changed, delta);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/netxs/desktopio/xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace netxs::xml
template<class T>
auto take(qiew utf8) -> std::optional<T>
{
utf::trim_front(utf8);
if (utf8.starts_with("0x"))
{
utf8.remove_prefix(2);
Expand All @@ -21,6 +22,7 @@ namespace netxs::xml
template<>
auto take<fp32>(qiew utf8) -> std::optional<fp32>
{
utf::trim_front(utf8);
return utf8 ? utf::to_int<fp32>(utf8)
: std::nullopt;
}
Expand All @@ -32,6 +34,7 @@ namespace netxs::xml
template<>
auto take<bool>(qiew utf8) -> std::optional<bool>
{
utf::trim_front(utf8);
auto value = utf::to_lower(utf8.str());
if (value.starts_with("undef")) return std::nullopt; // Use default.
if (value.empty() || value == "1"
Expand Down
8 changes: 8 additions & 0 deletions src/vtm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ R"==(
<key="Alt+Shift+E" action=TileEqualizeSplitRatio/> <!-- Equalize split ratio. -->
<key="Alt+Shift+F2" action=TileSetManagerTitle /> <!-- Set tiling window manager title using clipboard data. -->
<key="Alt+Shift+W" action=TileClosePane /> <!-- Close active application. -->
<grips key*>
<key="LeftArrow" ><action=TileMoveGrip data="-1, 0"/></key> <!-- Move the split grip to the left. -->
<key="RightArrow" ><action=TileMoveGrip data=" 1, 0"/></key> <!-- Move the split grip to the right. -->
<key="UpArrow" ><action=TileMoveGrip data=" 0,-1"/></key> <!-- Move the split grip up. -->
<key="DownArrow" ><action=TileMoveGrip data=" 0, 1"/></key> <!-- Move the split grip down. -->
<key="'-'" ><action=TileResizeGrip data="-1" /></key> <!-- Decrease the split grip width. -->
<key="Shift+'+'" ><action=TileResizeGrip data=" 1" /></key> <!-- Increase the split grip width. -->
</grips>
</tile>
<terminal key*> <!-- Application specific layer key bindings. -->
)=="
Expand Down

0 comments on commit 2d29121

Please sign in to comment.