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
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.
# This can cause issues, if there is not enough space on screen (e.g. when opening the text)
CenterTime: true

View file

@ -196,6 +196,26 @@ namespace Bar
}
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
}
@ -473,26 +493,30 @@ namespace Bar
auto margin = Widget::Create<Box>();
margin->SetHorizontalTransform({12, true, Alignment::Left});
parent.AddChild(std::move(margin));
auto box = Widget::Create<Box>();
box->SetSpacing({8, true});
box->SetHorizontalTransform({-1, true, Alignment::Left});
auto eventBox = Widget::Create<EventBox>();
eventBox->SetScrollFn(DynCtx::ScrollWorkspaces);
{
for (size_t i = 0; i < DynCtx::workspaces.size(); i++)
auto box = Widget::Create<Box>();
box->SetSpacing({8, true});
box->SetHorizontalTransform({-1, true, Alignment::Left});
{
auto workspace = Widget::Create<Button>();
workspace->SetHorizontalTransform({8, false, Alignment::Fill});
workspace->OnClick(
[i](Button&)
{
System::GotoWorkspace((uint32_t)i + 1);
});
DynCtx::workspaces[i] = workspace.get();
box->AddChild(std::move(workspace));
for (size_t i = 0; i < DynCtx::workspaces.size(); i++)
{
auto workspace = Widget::Create<Button>();
workspace->SetHorizontalTransform({8, false, Alignment::Fill});
workspace->OnClick(
[i](Button&)
{
System::GotoWorkspace((uint32_t)i + 1);
});
DynCtx::workspaces[i] = workspace.get();
box->AddChild(std::move(workspace));
}
}
box->AddTimer<Box>(DynCtx::UpdateWorkspaces, DynCtx::updateTimeFast);
eventBox->AddChild(std::move(box));
}
box->AddTimer<Box>(DynCtx::UpdateWorkspaces, DynCtx::updateTimeFast);
parent.AddChild(std::move(box));
parent.AddChild(std::move(eventBox));
}
#endif

View file

@ -134,6 +134,8 @@ void Config::Load()
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
AddConfigVar("AudioRevealer", config.audioRevealer, 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("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty);

View file

@ -17,6 +17,8 @@ public:
bool centerTime = true;
bool audioRevealer = false;
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
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());
}
// 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

View file

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

View file

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