tdf#103033 Enable tab scrolling in notebook bar

Also requires 100ms between switches to reduce sensitivity.
Before that, it was unusable with touchpads.

Change-Id: I42e60d9fb88766b133c56fa677ad907a5182e862
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201108
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Jonas Greifenhain
2026-03-09 09:13:54 +01:00
committed by Samuel Mehrbrodt
parent d37154decd
commit 14bd0b6499
2 changed files with 30 additions and 0 deletions
@@ -9,6 +9,7 @@
#pragma once
#include <chrono>
#include <vcl/tabctrl.hxx>
#include <com/sun/star/frame/XFrame.hpp>
@@ -25,11 +26,14 @@ public:
~NotebookbarTabControl() override;
virtual void KeyInput( const KeyEvent& rKEvt ) override;
virtual void Command( const CommandEvent& rCEvt ) override;
virtual bool EventNotify( NotifyEvent& rNEvt ) override;
virtual void StateChanged(StateChangedType nStateChange) override;
virtual Size calculateRequisition() const override;
private:
// time-based debounce: track when the last tab switch via scroll happened
std::chrono::steady_clock::time_point m_lastTabSwitch{};
static void FillShortcutsToolBox(css::uno::Reference<css::uno::XComponentContext> const & xContext,
const css::uno::Reference<css::frame::XFrame>& xFrame,
const OUString& aModuleName,
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <chrono>
#include <vcl/builderfactory.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/layout.hxx>
#include <vcl/notebookbar/notebookbar.hxx>
#include <vcl/tabpage.hxx>
@@ -222,6 +224,30 @@ void NotebookbarTabControl::KeyInput( const KeyEvent& rKEvt )
return NotebookbarTabControlBase::KeyInput( rKEvt );
}
void NotebookbarTabControl::Command( const CommandEvent& rCEvt )
{
if ( rCEvt.GetCommand() == CommandEventId::Wheel )
{
const CommandWheelData* pData = rCEvt.GetWheelData();
if ( pData && !pData->GetModifier()
&& pData->GetMode() == CommandWheelMode::SCROLL
&& pData->GetDelta() != 0 )
{
// Debounce: require at least 100 ms between tab switches so that
// casual scrolling does not rapidly cycle through tabs.
auto now = std::chrono::steady_clock::now();
static constexpr auto debounceMs = std::chrono::milliseconds(100);
if ( now - m_lastTabSwitch >= debounceMs )
{
m_lastTabSwitch = now;
ImplActivateTabPage( pData->GetDelta() < 0 );
}
return;
}
}
NotebookbarTabControlBase::Command( rCEvt );
}
bool NotebookbarTabControl::EventNotify( NotifyEvent& rNEvt )
{
if ( rNEvt.GetType() == NotifyEventType::KEYINPUT )