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
|
# 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
|
||||||
|
|
56
src/Bar.cpp
56
src/Bar.cpp
|
@ -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,26 +493,30 @@ 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>();
|
||||||
auto box = Widget::Create<Box>();
|
eventBox->SetScrollFn(DynCtx::ScrollWorkspaces);
|
||||||
box->SetSpacing({8, true});
|
|
||||||
box->SetHorizontalTransform({-1, true, Alignment::Left});
|
|
||||||
{
|
{
|
||||||
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>();
|
for (size_t i = 0; i < DynCtx::workspaces.size(); i++)
|
||||||
workspace->SetHorizontalTransform({8, false, Alignment::Fill});
|
{
|
||||||
workspace->OnClick(
|
auto workspace = Widget::Create<Button>();
|
||||||
[i](Button&)
|
workspace->SetHorizontalTransform({8, false, Alignment::Fill});
|
||||||
{
|
workspace->OnClick(
|
||||||
System::GotoWorkspace((uint32_t)i + 1);
|
[i](Button&)
|
||||||
});
|
{
|
||||||
DynCtx::workspaces[i] = workspace.get();
|
System::GotoWorkspace((uint32_t)i + 1);
|
||||||
box->AddChild(std::move(workspace));
|
});
|
||||||
|
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(eventBox));
|
||||||
parent.AddChild(std::move(box));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue