mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
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:
parent
c29d752cb8
commit
35b7065879
7 changed files with 68 additions and 16 deletions
|
@ -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
|
||||
|
|
28
src/Bar.cpp
28
src/Bar.cpp
|
@ -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,7 +493,9 @@ namespace Bar
|
|||
auto margin = Widget::Create<Box>();
|
||||
margin->SetHorizontalTransform({12, true, Alignment::Left});
|
||||
parent.AddChild(std::move(margin));
|
||||
|
||||
auto eventBox = Widget::Create<EventBox>();
|
||||
eventBox->SetScrollFn(DynCtx::ScrollWorkspaces);
|
||||
{
|
||||
auto box = Widget::Create<Box>();
|
||||
box->SetSpacing({8, true});
|
||||
box->SetHorizontalTransform({-1, true, Alignment::Left});
|
||||
|
@ -492,7 +514,9 @@ namespace Bar
|
|||
}
|
||||
}
|
||||
box->AddTimer<Box>(DynCtx::UpdateWorkspaces, DynCtx::updateTimeFast);
|
||||
parent.AddChild(std::move(box));
|
||||
eventBox->AddChild(std::move(box));
|
||||
}
|
||||
parent.AddChild(std::move(eventBox));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue