Implement Workspace scroll

Scrolling the workspace widgets now scroll through the workspaces. The
exact behaviour is governed by
'WorkspaceScrollOnMonitor'(either 'm[+/-]1' or 'e[+/-]1'). The direction
can be inverted with 'WorkspaceScrollInvert'.

For the ping: https://github.com/scorpion-26/gBar/issues/5
This commit is contained in:
scorpion-26 2023-02-12 14:57:32 +01:00
parent c29d752cb8
commit 35b7065879
7 changed files with 68 additions and 16 deletions

View file

@ -28,6 +28,12 @@ BatteryFolder: /sys/class/power_supply/BAT1
# The default symbol for the workspaces # The default symbol for the workspaces
DefaultWorkspaceSymbol:  DefaultWorkspaceSymbol: 
# Scroll through the workspaces of the current monitor instead of all workspaces
WorkspaceScrollOnMonitor: true
# When true: Scroll up -> Next workspace instead of previous workspace. Analogous with scroll down
WorkspaceScrollInvert: false
# Forces the time to be centered. # Forces the time to be centered.
# This can cause issues, if there is not enough space on screen (e.g. when opening the text) # This can cause issues, if there is not enough space on screen (e.g. when opening the text)
CenterTime: true CenterTime: true

View file

@ -196,6 +196,26 @@ namespace Bar
} }
return TimerResult::Ok; return TimerResult::Ok;
} }
void ScrollWorkspaces(EventBox&, ScrollDirection direction)
{
switch (direction)
{
case ScrollDirection::Up:
if (Config::Get().workspaceScrollInvert)
System::GotoNextWorkspace('+');
else
System::GotoNextWorkspace('-');
break;
case ScrollDirection::Down:
if (Config::Get().workspaceScrollInvert)
System::GotoNextWorkspace('-');
else
System::GotoNextWorkspace('+');
break;
default: break;
}
}
#endif #endif
} }
@ -473,7 +493,9 @@ namespace Bar
auto margin = Widget::Create<Box>(); auto margin = Widget::Create<Box>();
margin->SetHorizontalTransform({12, true, Alignment::Left}); margin->SetHorizontalTransform({12, true, Alignment::Left});
parent.AddChild(std::move(margin)); parent.AddChild(std::move(margin));
auto eventBox = Widget::Create<EventBox>();
eventBox->SetScrollFn(DynCtx::ScrollWorkspaces);
{
auto box = Widget::Create<Box>(); auto box = Widget::Create<Box>();
box->SetSpacing({8, true}); box->SetSpacing({8, true});
box->SetHorizontalTransform({-1, true, Alignment::Left}); box->SetHorizontalTransform({-1, true, Alignment::Left});
@ -492,7 +514,9 @@ namespace Bar
} }
} }
box->AddTimer<Box>(DynCtx::UpdateWorkspaces, DynCtx::updateTimeFast); box->AddTimer<Box>(DynCtx::UpdateWorkspaces, DynCtx::updateTimeFast);
parent.AddChild(std::move(box)); eventBox->AddChild(std::move(box));
}
parent.AddChild(std::move(eventBox));
} }
#endif #endif

View file

@ -134,6 +134,8 @@ void Config::Load()
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty); AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty); AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty);
AddConfigVar("NetworkWidget", config.networkWidget, lineView, foundProperty); AddConfigVar("NetworkWidget", config.networkWidget, lineView, foundProperty);
AddConfigVar("WorkspaceScrollOnMonitor", config.workspaceScrollOnMonitor, lineView, foundProperty);
AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty);
AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty); AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty);
AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty); AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty);

View file

@ -17,6 +17,8 @@ public:
bool centerTime = true; bool centerTime = true;
bool audioRevealer = false; bool audioRevealer = false;
bool networkWidget = true; bool networkWidget = true;
bool workspaceScrollOnMonitor = true; // Scroll through workspaces on monitor instead of all
bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1
// Controls for color progression of the network widget // Controls for color progression of the network widget
uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under" uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under"

View file

@ -115,5 +115,17 @@ namespace Hyprland
system(("hyprctl dispatch workspace " + std::to_string(workspace)).c_str()); system(("hyprctl dispatch workspace " + std::to_string(workspace)).c_str());
} }
// direction: + or -
inline void GotoNext(char direction)
{
char scrollOp = 'e';
if (Config::Get().workspaceScrollOnMonitor)
{
scrollOp = 'm';
}
std::string cmd = std::string("hyprctl dispatch workspace ") + scrollOp + direction + "1";
system(cmd.c_str());
}
} }
#endif #endif

View file

@ -446,6 +446,10 @@ namespace System
{ {
return Hyprland::Goto(workspace); return Hyprland::Goto(workspace);
} }
void GotoNextWorkspace(char direction)
{
return Hyprland::GotoNext(direction);
}
std::string GetWorkspaceSymbol(int index) std::string GetWorkspaceSymbol(int index)
{ {
if (index < 0 || index > 9) if (index < 0 || index > 9)

View file

@ -90,6 +90,8 @@ namespace System
}; };
WorkspaceStatus GetWorkspaceStatus(uint32_t monitor, uint32_t workspace); WorkspaceStatus GetWorkspaceStatus(uint32_t monitor, uint32_t workspace);
void GotoWorkspace(uint32_t workspace); void GotoWorkspace(uint32_t workspace);
// direction: + or -
void GotoNextWorkspace(char direction);
std::string GetWorkspaceSymbol(int index); std::string GetWorkspaceSymbol(int index);
#endif #endif