Skip to content

Commit

Permalink
Added support for a tiltable scroll wheel to scroll the context of wi…
Browse files Browse the repository at this point in the history
…dgets left and right in an xterm
  • Loading branch information
gansm committed Jun 4, 2023
1 parent 63af59f commit 3dbdeee
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 55 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2023-06-04 Markus Gans <guru.mail@muenster.de>
* Added support for a tiltable scroll wheel. This allows you to scroll
the context of widgets left and right in an xterm

2023-05-31 Markus Gans <guru.mail@muenster.de>
* Fix setFormatedNumber() in FString for separator > 127
(e.g. non-breaking space)
Expand Down
49 changes: 29 additions & 20 deletions final/fapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,9 @@ void FApplication::determineClickedWidget (const FMouseData& md)
&& ! md.isRightButtonPressed()
&& ! md.isMiddleButtonPressed()
&& ! md.isWheelUp()
&& ! md.isWheelDown() )
&& ! md.isWheelDown()
&& ! md.isWheelLeft()
&& ! md.isWheelRight() )
return;

const auto& mouse_position = md.getPos();
Expand Down Expand Up @@ -1215,27 +1217,34 @@ void FApplication::sendWheelEvent ( const FMouseData& md
, const FPoint& widgetMousePos
, const FPoint& mouse_position ) const
{
if ( md.isWheelUp() )
{
FWheelEvent wheel_ev ( Event::MouseWheel
, widgetMousePos
, mouse_position
, MouseWheel::Up );
auto scroll_over_widget = clicked_widget;
setClickedWidget(nullptr);
sendEvent(scroll_over_widget, &wheel_ev);
}
if ( ! md.isWheelUp() && ! md.isWheelDown()
&& ! md.isWheelLeft() && ! md.isWheelRight() )
return;

if ( md.isWheelDown() )
auto mouse_wheel = [&md] ()
{
FWheelEvent wheel_ev ( Event::MouseWheel
, widgetMousePos
, mouse_position
, MouseWheel::Down );
auto scroll_over_widget = clicked_widget;
setClickedWidget(nullptr);
sendEvent (scroll_over_widget, &wheel_ev);
}
if ( md.isWheelUp() )
return MouseWheel::Up;

if ( md.isWheelDown() )
return MouseWheel::Down;

if ( md.isWheelLeft() )
return MouseWheel::Left;

if ( md.isWheelRight() )
return MouseWheel::Right;

return MouseWheel::None;
}();

FWheelEvent wheel_ev ( Event::MouseWheel
, widgetMousePos
, mouse_position
, mouse_wheel );
auto scroll_over_widget = clicked_widget;
setClickedWidget(nullptr);
sendEvent (scroll_over_widget, &wheel_ev);
}

//----------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions final/fc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,11 @@ constexpr auto operator &= (MouseButton& b1, const MouseButton& b2) noexcept ->
// Mouse wheel state values
enum class MouseWheel
{
None = 0x00,
Up = 0x01,
Down = 0x02
None = 0x00,
Up = 0x01,
Down = 0x02,
Left = 0x03,
Right = 0x04,
};

// Terminal type
Expand Down
2 changes: 1 addition & 1 deletion final/ftimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/* Standalone class Base class
* ════════════════ ══════════
*
*
* ▕▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
* ▕ FTimer ▏ ▕ FObjectTimer ▏
* ▕▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
Expand Down
77 changes: 71 additions & 6 deletions final/input/fmouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ auto FMouseData::isWheelDown() const noexcept -> bool
return getButtonState().wheel_down;
}

//----------------------------------------------------------------------
auto FMouseData::isWheelLeft() const noexcept -> bool
{
return getButtonState().wheel_left;
}

//----------------------------------------------------------------------
auto FMouseData::isWheelRight() const noexcept -> bool
{
return getButtonState().wheel_right;
}

//----------------------------------------------------------------------
auto FMouseData::isMoved() const noexcept -> bool
{
Expand All @@ -185,6 +197,8 @@ void FMouseData::clearButtonState() noexcept
b_state.meta_button = false;
b_state.wheel_up = false;
b_state.wheel_down = false;
b_state.wheel_left = false;
b_state.wheel_right = false;
b_state.mouse_moved = false;
}

Expand Down Expand Up @@ -417,6 +431,11 @@ void FMouseGPM::processEvent (const TimeValue&)
else if ( gpm_ev.wdy < 0 )
getButtonState().wheel_down = true;

if ( gpm_ev.wdx > 0 )
getButtonState().wheel_right = true;
else if ( gpm_ev.wdx < 0 )
getButtonState().wheel_left = true;

switch ( gpm_ev.type & 0x0f )
{
case GPM_DOWN:
Expand Down Expand Up @@ -644,8 +663,8 @@ void FMouseX11::processEvent (const TimeValue& time)
setButtonState (btn & button_mask, time);

if ( mouse_position == getNewPos()
&& ! isWheelUp()
&& ! isWheelDown()
&& ! isWheelUp() && ! isWheelDown()
&& ! isWheelLeft() && ! isWheelRight()
&& x11_button_state == uChar(btn) )
{
clearEvent();
Expand Down Expand Up @@ -725,6 +744,16 @@ void FMouseX11::setButtonState (const int btn, const TimeValue& time) noexcept
getButtonState().wheel_down = true;
break;

case button_left:
resetMousePressedTime();
getButtonState().wheel_left = true;
break;

case button_right:
resetMousePressedTime();
getButtonState().wheel_right = true;
break;

default:
break;
}
Expand Down Expand Up @@ -875,8 +904,8 @@ void FMouseSGR::processEvent (const TimeValue& time)
setReleasedButtonState (btn & button_mask);

if ( mouse_position == getNewPos()
&& ! isWheelUp()
&& ! isWheelDown()
&& ! isWheelUp() && ! isWheelDown()
&& ! isWheelLeft() && ! isWheelRight()
&& sgr_button_state == uChar(((*p & 0x20) << 2) + btn) )
{
clearEvent();
Expand Down Expand Up @@ -952,6 +981,16 @@ void FMouseSGR::setPressedButtonState ( const int btn
getButtonState().wheel_down = true;
break;

case button_left:
resetMousePressedTime();
getButtonState().wheel_left = true;
break;

case button_right:
resetMousePressedTime();
getButtonState().wheel_right = true;
break;

default:
break;
}
Expand Down Expand Up @@ -1120,8 +1159,8 @@ void FMouseUrxvt::processEvent (const TimeValue& time)
setButtonState (btn & button_mask, time);

if ( mouse_position == getNewPos()
&& ! isWheelUp()
&& ! isWheelDown()
&& ! isWheelUp() && ! isWheelDown()
&& ! isWheelLeft() && ! isWheelRight()
&& urxvt_button_state == uChar(btn) )
{
clearEvent();
Expand Down Expand Up @@ -1213,6 +1252,16 @@ void FMouseUrxvt::setButtonState (const int btn, const TimeValue& time) noexcept
getButtonState().wheel_down = true;
break;

case button_left:
resetMousePressedTime();
getButtonState().wheel_left = true;
break;

case button_right:
resetMousePressedTime();
getButtonState().wheel_right = true;
break;

default:
break;
}
Expand Down Expand Up @@ -1462,6 +1511,22 @@ auto FMouseControl::isWheelDown() -> bool
return found ? (*iter)->isWheelDown() : false;
}

//----------------------------------------------------------------------
auto FMouseControl::isWheelLeft() -> bool
{
auto iter = findMouseWithEvent();
const bool found = (iter != mouse_protocol.end());
return found ? (*iter)->isWheelLeft() : false;
}

//----------------------------------------------------------------------
auto FMouseControl::isWheelRight() -> bool
{
auto iter = findMouseWithEvent();
const bool found = (iter != mouse_protocol.end());
return found ? (*iter)->isWheelRight() : false;
}

//----------------------------------------------------------------------
auto FMouseControl::isMoved() -> bool
{
Expand Down
32 changes: 20 additions & 12 deletions final/input/fmouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class FMouseData
auto isMetaKeyPressed() const noexcept -> bool;
auto isWheelUp() const noexcept -> bool;
auto isWheelDown() const noexcept -> bool;
auto isWheelLeft() const noexcept -> bool;
auto isWheelRight() const noexcept -> bool;
auto isMoved() const noexcept -> bool;

// Methods
Expand All @@ -152,6 +154,8 @@ class FMouseData
bool meta_button{};
bool wheel_up{};
bool wheel_down{};
bool wheel_left{};
bool wheel_right{};
bool mouse_moved{};
};

Expand Down Expand Up @@ -352,10 +356,10 @@ class FMouseX11 final : public FMouse
button2_pressed_move = 0x41,
button3_pressed_move = 0x42,
button_mask = 0x63,
button_up = 0x60,
button_down = 0x61,
button_up_move = 0x60,
button_down_move = 0x61
button_up = 0x60, // Mouse wheel scrolls up
button_down = 0x61, // Mouse wheel scrolls down
button_left = 0x62, // Mouse wheel left tilt
button_right = 0x63 // Mouse wheel right tilt
};

// Constant
Expand Down Expand Up @@ -408,9 +412,11 @@ class FMouseSGR final : public FMouse
button1_move = 0x20,
button2_move = 0x21,
button3_move = 0x22,
button_mask = 0x63,
button_up = 0x40,
button_down = 0x41,
button_mask = 0xe3,
button_up = 0x40, // Mouse wheel scrolls up
button_down = 0x41, // Mouse wheel scrolls down
button_left = 0x42, // Mouse wheel left tilt
button_right = 0x43, // Mouse wheel right tilt
pressed = 'M',
released = 'm'
};
Expand Down Expand Up @@ -466,11 +472,11 @@ class FMouseUrxvt final : public FMouse
button1_pressed_move = 0x40,
button2_pressed_move = 0x41,
button3_pressed_move = 0x42,
button_mask = 0x63,
button_up = 0x60,
button_down = 0x61,
button_up_move = 0x60,
button_down_move = 0x61
button_mask = 0xe3,
button_up = 0x60, // Mouse wheel scrolls up
button_down = 0x61, // Mouse wheel scrolls down
button_left = 0x62, // Mouse wheel left tilt
button_right = 0x63 // Mouse wheel right tilt
};

// Constant
Expand Down Expand Up @@ -561,6 +567,8 @@ class FMouseControl
auto isMetaKeyPressed() -> bool;
auto isWheelUp() -> bool;
auto isWheelDown() -> bool;
auto isWheelLeft() -> bool;
auto isWheelRight() -> bool;
auto isMoved() -> bool;
auto hasUnprocessedInput() const -> bool;
auto hasDataInQueue() const -> bool;
Expand Down
32 changes: 32 additions & 0 deletions final/widget/flistbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ void FListBox::onWheel (FWheelEvent* ev)
wheelUp (wheel_distance);
else if ( wheel == MouseWheel::Down )
wheelDown (wheel_distance);
else if ( wheel == MouseWheel::Left )
wheelLeft (wheel_distance);
else if ( wheel == MouseWheel::Right )
wheelRight (wheel_distance);

if ( current_before != current )
{
Expand Down Expand Up @@ -1180,6 +1184,30 @@ void FListBox::wheelDown (int pagesize)
current = element_count;
}

//----------------------------------------------------------------------
void FListBox::wheelLeft (int pagesize)
{
if ( getCount() == 0 || xoffset == 0 )
return;

const int xoffset_before = xoffset;
scrollLeft (pagesize);
const bool draw_hbar(xoffset_before != xoffset);
updateDrawing (false, draw_hbar);
}

//----------------------------------------------------------------------
void FListBox::wheelRight (int pagesize)
{
if ( getCount() == 0 )
return;

const int xoffset_before = xoffset;
scrollRight (pagesize);
const bool draw_hbar(xoffset_before != xoffset);
updateDrawing (false, draw_hbar);
}

//----------------------------------------------------------------------
auto FListBox::dragScrollUp() -> bool
{
Expand Down Expand Up @@ -1703,10 +1731,12 @@ void FListBox::cb_vbarChange (const FWidget*)
break;

case FScrollbar::ScrollType::WheelUp:
case FScrollbar::ScrollType::WheelLeft:
wheelUp (wheel_distance);
break;

case FScrollbar::ScrollType::WheelDown:
case FScrollbar::ScrollType::WheelRight:
wheelDown (wheel_distance);
break;

Expand Down Expand Up @@ -1764,10 +1794,12 @@ void FListBox::cb_hbarChange (const FWidget*)
break;

case FScrollbar::ScrollType::WheelUp:
case FScrollbar::ScrollType::WheelLeft:
scrollLeft (wheel_distance);
break;

case FScrollbar::ScrollType::WheelDown:
case FScrollbar::ScrollType::WheelRight:
scrollRight (wheel_distance);
break;

Expand Down
Loading

0 comments on commit 3dbdeee

Please sign in to comment.