Skip to content

Commit

Permalink
Merge pull request #658 from o-sdn-o/gui-bridge
Browse files Browse the repository at this point in the history
Fix annoyingly broken mouse text selection in GUI mode
  • Loading branch information
o-sdn-o authored Oct 23, 2024
2 parents 0e220d9 + bbf9a9a commit ecf205d
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 81 deletions.
4 changes: 3 additions & 1 deletion src/netxs/apps/calc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ namespace netxs::ui
};
boss.LISTEN(tier::release, e2::form::drag::start::_<Button>, gear, memo)
{
if (items.take(gear).grab(gear.coord, gear.meta(hids::anyCtrl)))
auto& g = items.take(gear);
g.calc(boss, gear.click);
if (g.grab(gear.click, gear.meta(hids::anyCtrl)))
{
gear.dismiss();
}
Expand Down
1 change: 1 addition & 0 deletions src/netxs/apps/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ namespace netxs::app::tile

// Take coor and detach from the tiling wm.
gear.coord -= applet.base::coor(); // Rebase mouse coor.
gear.click -= applet.base::coor(); // Rebase mouse click.
what.square.size = applet.base::size();
applet.global(what.square.coor);
what.square.coor = -what.square.coor;
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace netxs::app

namespace netxs::app::shared
{
static const auto version = "v0.9.99.27";
static const auto version = "v0.9.99.28";
static const auto repository = "https://github.com/directvt/vtm";
static const auto usr_config = "~/.config/vtm/settings.xml"s;
static const auto sys_config = "/etc/vtm/settings.xml"s;
Expand Down
4 changes: 2 additions & 2 deletions src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ namespace netxs::ui
LISTEN(tier::release, hids::events::mouse::scroll::any, gear, tokens)
{
auto [ext_gear_id, gear_ptr] = input.get_foreign_gear_id(gear.id);
if (gear_ptr) conio.mouse_event.send(canal, ext_gear_id, gear.ctlstate, gear.mouse::cause, gear.coord, gear.delta.get(), gear.take_button_state(), gear.whlfp, gear.whlsi, gear.hzwhl);
if (gear_ptr) conio.mouse_event.send(canal, ext_gear_id, gear.ctlstate, gear.mouse::cause, gear.coord, gear.delta.get(), gear.take_button_state(), gear.whlfp, gear.whlsi, gear.hzwhl, gear.click);
gear.dismiss();
};
LISTEN(tier::release, hids::events::mouse::button::any, gear, tokens, (isvtm))
Expand Down Expand Up @@ -1454,7 +1454,7 @@ namespace netxs::ui
if (forward)
{
auto [ext_gear_id, gear_ptr] = input.get_foreign_gear_id(gear.id);
if (gear_ptr) conio.mouse_event.send(canal, ext_gear_id, gear.ctlstate, cause, gear.coord, gear.delta.get(), gear.take_button_state(), gear.whlfp, gear.whlsi, gear.hzwhl);
if (gear_ptr) conio.mouse_event.send(canal, ext_gear_id, gear.ctlstate, cause, gear.coord, gear.delta.get(), gear.take_button_state(), gear.whlfp, gear.whlsi, gear.hzwhl, gear.click);
gear.dismiss();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,7 +3202,7 @@ namespace netxs::ui
{
if (gear.captured(bell::id))
{
if (auto delta = twod{ gear.coord } - twod { drag_origin })
if (auto delta = twod{ gear.coord } - twod{ drag_origin })
{
drag_origin = gear.coord;
auto value = permit * delta;
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/directvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ namespace netxs::directvt
STRUCT_macro(frame_element, (blob, data))
STRUCT_macro(jgc_element, (ui64, token) (text, cluster))
STRUCT_macro(tooltip_element, (id_t, gear_id) (text, tip_text) (bool, update))
STRUCT_macro(mouse_event, (id_t, gear_id) (si32, ctlstat) (hint, cause) (fp2d, coord) (fp2d, delta) (si32, buttons) (fp32, whlfp) (si32, whlsi) (bool, hzwhl))
STRUCT_macro(mouse_event, (id_t, gear_id) (si32, ctlstat) (hint, cause) (fp2d, coord) (fp2d, delta) (si32, buttons) (fp32, whlfp) (si32, whlsi) (bool, hzwhl) (fp2d, click))
STRUCT_macro(keybd_event, (id_t, gear_id) (si32, ctlstat) (bool, extflag) (byte, payload) (si32, virtcod) (si32, scancod) (bool, pressed) (text, cluster) (bool, handled))
STRUCT_macro(focus_cut, (id_t, gear_id))
STRUCT_macro(focus_set, (id_t, gear_id) (si32, solo))
Expand Down
12 changes: 10 additions & 2 deletions src/netxs/desktopio/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ namespace netxs

T x, y;

template<class D> constexpr static auto cast(D x) requires(std::is_floating_point_v<T> || (std::is_integral_v<T> == std::is_integral_v<D>)) { return netxs::saturate_cast<T>(x); }
template<class D> constexpr static auto cast(D x) requires(std::is_integral_v<T> && std::is_floating_point_v<D>) { return netxs::saturate_cast<T>(std::floor(x)); }
template<class D>
constexpr static auto cast(D x) requires(std::is_floating_point_v<T> || (std::is_integral_v<T> == std::is_integral_v<D>))
{
return netxs::saturate_cast<T>(x);
}
template<class D>
constexpr static auto cast(D x) requires(std::is_integral_v<T> && std::is_floating_point_v<D>)
{
return netxs::saturate_cast<T>(std::floor(x));
}

constexpr xy2d(xy2d const&) = default;
constexpr xy2d()
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ namespace netxs::gui
auto& mouse = lock.thing;
auto basis = gear.owner.base::coor();
owner.global(basis);
gear.replay(mouse.cause, mouse.coord - basis, mouse.delta, mouse.buttons, mouse.ctlstat, mouse.whlfp, mouse.whlsi, mouse.hzwhl);
gear.replay(mouse.cause, mouse.coord - basis, mouse.click - basis, mouse.delta, mouse.buttons, mouse.ctlstat, mouse.whlfp, mouse.whlsi, mouse.hzwhl);
gear.pass<tier::release>(owner.This(), gear.owner.base::coor(), true);
}
void handle(s11n::xs::warping lock)
Expand Down
32 changes: 20 additions & 12 deletions src/netxs/desktopio/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ namespace netxs::input
struct mouse
{
using mouse_event = netxs::events::userland::hids::mouse;
using click = mouse_event::button::click;

enum mode
{
Expand All @@ -559,12 +558,12 @@ namespace netxs::input
};
enum buttons
{
left = click::left .index(),
right = click::right .index(),
middle = click::middle .index(),
xbutton1 = click::xbutton1 .index(),
xbutton2 = click::xbutton2 .index(),
leftright = click::leftright.index(),
left = mouse_event::button::click::left .index(),
right = mouse_event::button::click::right .index(),
middle = mouse_event::button::click::middle .index(),
xbutton1 = mouse_event::button::click::xbutton1 .index(),
xbutton2 = mouse_event::button::click::xbutton2 .index(),
leftright = mouse_event::button::click::leftright.index(),
numofbuttons,
};

Expand All @@ -583,6 +582,7 @@ namespace netxs::input
bool pressed; // knod: Button pressed state.
bool dragged; // knod: The button is in a dragging state.
bool blocked; // knod: The button is blocked (leftright disables left and right).
fp2d clickxy; // knob: Press coordinates.
};
struct hist_t // Timer for successive double-clicks, e.g. triple-clicks.
{
Expand All @@ -607,9 +607,11 @@ namespace netxs::input
static constexpr auto wheeling = mouse_event::scroll::act.id;
static constexpr auto movement = mouse_event::move.id;
static constexpr auto noactive = si32{ -1 };
static constexpr auto drag_threshold = 0.3f; // mouse: Mouse drag threshold (to support jittery clicks).

fp2d prime{}; // mouse: System mouse cursor coordinates.
fp2d coord{}; // mouse: Relative mouse cursor coordinates.
fp2d click{}; // mouse: Click position on drag start. Should be used in area selection (not dragging).
fp32 accum{}; // mouse: Mouse motion accumulator to delay mouse drag.
tail delta{}; // mouse: History of mouse movements for a specified period of time.
bool reach{}; // mouse: Has the event tree relay reached the mouse event target.
Expand All @@ -629,7 +631,6 @@ namespace netxs::input
sysmouse m_sys{}; // mouse: Device state.
sysmouse m_sav{}; // mouse: Previous device state.

static constexpr auto drag_threshold = 0.5f; // mouse: Threshold for mouse drag.

// mouse: Forward the extended mouse event.
virtual void fire(hint cause, si32 index = mouse::noactive) = 0;
Expand Down Expand Up @@ -752,6 +753,7 @@ namespace netxs::input
{
if (allow_drag && !genbtn.dragged)
{
click = genbtn.clickxy;
fire(dragstrt, i);
genbtn.dragged = true;
}
Expand Down Expand Up @@ -787,6 +789,7 @@ namespace netxs::input
genbtn.pressed = sysbtn;
if (genbtn.pressed)
{
genbtn.clickxy = prime;
fire(pushdown, i);
}
else
Expand Down Expand Up @@ -1404,13 +1407,14 @@ namespace netxs::input
return faux;
}

void replay(hint new_cause, fp2d new_coord, fp2d new_delta, si32 new_button_state, si32 new_ctlstate, fp32 new_whlfp, si32 new_whlsi, bool new_hzwhl)
void replay(hint new_cause, fp2d new_coord, fp2d new_click, fp2d new_delta, si32 new_button_state, si32 new_ctlstate, fp32 new_whlfp, si32 new_whlsi, bool new_hzwhl)
{
static constexpr auto mask = netxs::events::level_mask(hids::events::mouse::button::any.id);
static constexpr auto base = mask & hids::events::mouse::button::any.id;
alive = true;
ctlstate = new_ctlstate;
mouse::coord = new_coord;
mouse::click = new_click;
mouse::whlfp = new_whlfp;
mouse::whlsi = new_whlsi;
mouse::hzwhl = new_hzwhl;
Expand Down Expand Up @@ -1491,14 +1495,18 @@ namespace netxs::input
{
if (object)
{
auto temp = mouse::coord;
mouse::coord += offset;
auto temp_coord = mouse::coord;
auto temp_click = mouse::click;
if (relative)
{
object->global(coord);
click += coord - temp_coord;
}
mouse::coord += offset;
mouse::click += offset;
object->bell::template signal<Tier>(mouse::cause, *this);
mouse::coord = temp;
mouse::coord = temp_coord;
mouse::click = temp_click;
}
}
void mouse_leave(id_t last_id, id_t start_id)
Expand Down
8 changes: 4 additions & 4 deletions src/netxs/desktopio/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7250,9 +7250,9 @@ namespace netxs::ui
auto& console = *target;
auto boxed = selalt ^ !!gear.meta(hids::anyAlt);
auto go_on = gear.meta(hids::anyCtrl);
console.selection_follow(gear.coord, go_on);
if (go_on) console.selection_extend(gear.coord, boxed);
else console.selection_create(gear.coord, boxed);
console.selection_follow(gear.click, go_on);
if (go_on) console.selection_extend(gear.click, boxed);
else console.selection_create(gear.click, boxed);
base::deface();
}
void selection_moveto(twod delta)
Expand Down Expand Up @@ -8044,7 +8044,7 @@ namespace netxs::ui
if (gear.captured(owner.id)) gear.setfree(true);
auto basis = gear.owner.base::coor();
owner.global(basis);
gear.replay(m.cause, m.coord - basis, m.delta, m.buttons, m.ctlstat, m.whlfp, m.whlsi, m.hzwhl);
gear.replay(m.cause, m.coord - basis, m.click - basis, m.delta, m.buttons, m.ctlstat, m.whlfp, m.whlsi, m.hzwhl);
gear.pass<tier::release>(parent_ptr, gear.owner.base::coor(), true);
}
});
Expand Down
58 changes: 32 additions & 26 deletions src/netxs/desktopio/unidata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace netxs::unidata
static constexpr auto zwj = 13; // ZERO WIDTH JOINER
static constexpr auto ep = 14; // Extended_Pictographic
static constexpr auto combo = 15; // EP + ZWJ
static constexpr auto count = 16; // GB class count.
}

enum cntrls : ui32
Expand Down Expand Up @@ -277,34 +278,38 @@ namespace netxs::unidata
// Unicode 15.1.0 UAX #29 https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules
bool allied(unidata const& next)
{
static const auto lut = []
{
auto table = std::array<byte, gbreak::count * gbreak::count>{};
auto check = [](auto l, auto r)
{
return ( l == gbreak::cr && r == gbreak::lf ) ? true: // GB3
( l >= gbreak::cr && l <= gbreak::ctrl ) ? faux: // GB4
( r >= gbreak::cr && r <= gbreak::ctrl ) ? faux: // GB5
( l == gbreak::l && (r == gbreak::l
|| r == gbreak::v
|| r == gbreak::lv
|| r == gbreak::lvt )) ? true: // GB6
(( l == gbreak::lv || l == gbreak::v )
&& ( r == gbreak::v || r == gbreak::t )) ? true: // GB7
(( l == gbreak::lvt || l == gbreak::t )
&& r == gbreak::t ) ? true: // GB8
( l == gbreak::prep || r == gbreak::zwj
|| r == gbreak::sm
|| r == gbreak::ext ) ? true: // GB9,a,b
( l == gbreak::combo && r == gbreak::ep ) ? true: // GB11
( l == gbreak::ri && r == gbreak::ri ) ? true: // GB12,13
faux; // GB999
};
for (auto l = 0; l < gbreak::count; l++)
for (auto r = 0; r < gbreak::count; r++)
{
table[l + r * gbreak::count] = check(l, r);
}
return table;
}();
auto l = brgroup;
auto r = next.brgroup;
auto result = //todo use lut(l, r)
( l == gbreak::cr && r == gbreak::lf ) ? true: // GB3

( l >= gbreak::cr && l <= gbreak::ctrl ) ? faux: // GB4

( r >= gbreak::cr && r <= gbreak::ctrl ) ? faux: // GB5

( l == gbreak::l && (r == gbreak::l
|| r == gbreak::v
|| r == gbreak::lv
|| r == gbreak::lvt )) ? true: // GB6

(( l == gbreak::lv || l == gbreak::v )
&& ( r == gbreak::v || r == gbreak::t )) ? true: // GB7

(( l == gbreak::lvt || l == gbreak::t )
&& r == gbreak::t ) ? true: // GB8

( l == gbreak::prep || r == gbreak::zwj
|| r == gbreak::sm
|| r == gbreak::ext ) ? true: // GB9,a,b

( l == gbreak::combo && r == gbreak::ep ) ? true: // GB11

( l == gbreak::ri && r == gbreak::ri ) ? true: // GB12,13
faux; // GB999
if (l == gbreak::ep)
{
brgroup = (r == gbreak::ext) ? gbreak::ep :
Expand All @@ -314,6 +319,7 @@ namespace netxs::unidata
{
brgroup = (l == gbreak::ri && r == gbreak::ri) ? gbreak::any : r;
}
auto result = lut[l + r * gbreak::count];
return result;
}
};
Expand Down
Loading

0 comments on commit ecf205d

Please sign in to comment.