Lift reverse-scrolling option into AModule

The option is generally useful when scrolling is used, when configuring
input devices to use "natural scroll direction".
Both backlight and pulseaudio were using different implementations, this
unifies and documents them.

Signed-off-by: Robert Günzler <r@gnzler.io>
This commit is contained in:
Robert Günzler 2023-06-12 13:55:28 +09:00
parent 62f4125927
commit 0f8c156f24
No known key found for this signature in database
GPG Key ID: 2143BD2AAB94BCC4
3 changed files with 5 additions and 17 deletions

View File

@ -97,11 +97,14 @@ bool AModule::handleToggle(GdkEventButton* const& e) {
}
AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
// only affects up/down
bool reverse = config_["reverse-scrolling"].asBool();
switch (e->direction) {
case GDK_SCROLL_UP:
return SCROLL_DIR::UP;
return reverse ? SCROLL_DIR::DOWN : SCROLL_DIR::UP;
case GDK_SCROLL_DOWN:
return SCROLL_DIR::DOWN;
return reverse ? SCROLL_DIR::UP : SCROLL_DIR::DOWN;
case GDK_SCROLL_LEFT:
return SCROLL_DIR::LEFT;
case GDK_SCROLL_RIGHT:

View File

@ -305,14 +305,6 @@ bool waybar::modules::Backlight::handleScroll(GdkEventScroll *e) {
return true;
}
if (config_["reverse-scrolling"].asBool()) {
if (dir == SCROLL_DIR::UP) {
dir = SCROLL_DIR::DOWN;
} else if (dir == SCROLL_DIR::DOWN) {
dir = SCROLL_DIR::UP;
}
}
// Get scroll step
double step = 1;

View File

@ -81,13 +81,6 @@ bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
if (dir == SCROLL_DIR::NONE) {
return true;
}
if (config_["reverse-scrolling"].asInt() == 1) {
if (dir == SCROLL_DIR::UP) {
dir = SCROLL_DIR::DOWN;
} else if (dir == SCROLL_DIR::DOWN) {
dir = SCROLL_DIR::UP;
}
}
double volume_tick = static_cast<double>(PA_VOLUME_NORM) / 100;
pa_volume_t change = volume_tick;
pa_cvolume pa_volume = pa_volume_;