Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxqt-config-brightness: Set minimum backlight #858

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 53 additions & 22 deletions lxqt-config-brightness/brightnesssettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <QMessageBox>
#include <QPushButton>

BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent)
BrightnessSettings::BrightnessSettings(LXQt::Settings *settings, QWidget *parent):QDialog(parent)
{
ui = new Ui::BrightnessSettings();
ui->setupUi(this);
Expand All @@ -31,8 +31,17 @@ BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent)
mMonitorsInitial = mBrightness->getMonitorsInfo();
mBacklight = new LXQt::Backlight(this);

ui->headIconLabel->setPixmap(QIcon::fromTheme(QStringLiteral("display-brightness-symbolic")).pixmap(32, 32));
// Get minimum backlight
mSettings = settings;
mSettings->beginGroup(QStringLiteral("Backlight"));
mMinBacklightValue = mSettings->value(QStringLiteral("min"), -1).toInt();
if(mMinBacklightValue < 0) {
// Set the minimum to 5% of the maximum to prevent a black screen
mMinBacklightValue = qMax(qRound((qreal)(mBacklight->getMaxBacklight())*0.05), 1);
}
mInitialMinBacklightValue = mMinBacklightValue;

ui->minBacklightSlider->setEnabled(mBacklight->isBacklightAvailable() || mBacklight->isBacklightOff());
ui->backlightSlider->setEnabled(mBacklight->isBacklightAvailable() || mBacklight->isBacklightOff());
ui->backlightGroupBox->setEnabled(mBacklight->isBacklightAvailable() || mBacklight->isBacklightOff());
if(mBacklight->isBacklightAvailable()) {
Expand All @@ -45,6 +54,34 @@ BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent)
[this](bool){ ui->backlightSlider->setValue(ui->backlightSlider->value()-1); });
connect(ui->backlightUpButton, &QToolButton::clicked,
[this](bool){ ui->backlightSlider->setValue(ui->backlightSlider->value()+1); });

ui->minBacklightSlider->setMinimum(0);
ui->minBacklightSlider->setMaximum(mBacklight->getMaxBacklight());
ui->minBacklightSlider->setValue(mMinBacklightValue);

connect(ui->minBacklightSlider, &QSlider::valueChanged, this,
[this](int){
mMinBacklightValue = ui->minBacklightSlider->value();
setBacklightSliderValue(mLastBacklightValue);
});

connect(ui->minBacklightDownButton, &QToolButton::clicked,
[this](bool){
ui->minBacklightSlider->setValue(ui->minBacklightSlider->value()-1);
mMinBacklightValue = ui->minBacklightSlider->value();
setBacklightSliderValue(mLastBacklightValue);
});
connect(ui->minBacklightUpButton, &QToolButton::clicked,
[this](bool){
ui->minBacklightSlider->setValue(ui->minBacklightSlider->value()+1);
mMinBacklightValue = ui->minBacklightSlider->value();
setBacklightSliderValue(mLastBacklightValue);
});

connect(ui->checkMinBacklightButton, &QPushButton::pressed,
[this](){ mBacklight->setBacklight(ui->minBacklightSlider->value()); });
connect(ui->checkMinBacklightButton, &QPushButton::released,
[this](){ mBacklight->setBacklight(mLastBacklightValue); });
}

for(const MonitorInfo &monitor: qAsConst(mMonitors))
Expand All @@ -64,6 +101,13 @@ BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent)
[this](QAbstractButton *button) {
if(ui->buttonBox->button(QDialogButtonBox::Reset) == button) {
revertValues();
} else if(ui->buttonBox->button(QDialogButtonBox::Close) == button) {
close();
} else if(ui->buttonBox->button(QDialogButtonBox::Save) == button) {
mSettings->setValue(QStringLiteral("min"), mMinBacklightValue);
QMessageBox msgBox;
msgBox.setText(tr("Backlight minimum value has been saved."));
msgBox.exec();
}
} );
}
Expand All @@ -80,14 +124,8 @@ BrightnessSettings::~BrightnessSettings()
void BrightnessSettings::setBacklight()
{
int value = ui->backlightSlider->value();
// Set the minimum to 5% of the maximum to prevent a black screen
int minBacklight = qMax(qRound((qreal)(mBacklight->getMaxBacklight())*0.05), 1);
int maxBacklight = mBacklight->getMaxBacklight();
int interval = maxBacklight - minBacklight;
if(interval > 100)
value = (value * maxBacklight) / 100;
mBacklight->setBacklight(value);

if (ui->confirmCB->isChecked())
mConfirmRequestTimer.start();
}
Expand Down Expand Up @@ -160,6 +198,7 @@ void BrightnessSettings::revertValues()
disconnect(ui->backlightSlider, &QSlider::valueChanged, this, &BrightnessSettings::setBacklight);
mBacklight->setBacklight(mInitialBacklightValue);
setBacklightSliderValue(mInitialBacklightValue);
ui->minBacklightSlider->setValue(mInitialMinBacklightValue);
connect(ui->backlightSlider, &QSlider::valueChanged, this, &BrightnessSettings::setBacklight);
}

Expand All @@ -171,18 +210,10 @@ void BrightnessSettings::revertValues()

void BrightnessSettings::setBacklightSliderValue(int value)
{
// Set the minimum to 5% of the maximum to prevent a black screen
int minBacklight = qMax(qRound((qreal)(mBacklight->getMaxBacklight())*0.05), 1);
int minBacklight = mMinBacklightValue;
int maxBacklight = mBacklight->getMaxBacklight();
int interval = maxBacklight - minBacklight;
if(interval <= 100) {
ui->backlightSlider->setMaximum(maxBacklight);
ui->backlightSlider->setMinimum(minBacklight);
ui->backlightSlider->setValue(value);
} else {
ui->backlightSlider->setMaximum(100);
// Set the minimum to 5% of the maximum to prevent a black screen
ui->backlightSlider->setMinimum(5);
ui->backlightSlider->setValue( (value * 100) / maxBacklight);
}

ui->backlightSlider->setMaximum(maxBacklight);
ui->backlightSlider->setMinimum(minBacklight);
ui->backlightSlider->setValue(value);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline is missing here.

7 changes: 5 additions & 2 deletions lxqt-config-brightness/brightnesssettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
#include "ui_brightnesssettings.h"

#include <LXQt/lxqtbacklight.h>
#include <LXQt/Settings>

class BrightnessSettings: public QDialog
{
Q_OBJECT

public:
BrightnessSettings(QWidget *parent =nullptr);
BrightnessSettings(LXQt::Settings *settings, QWidget *parent =nullptr);
~BrightnessSettings();

void revertValues();
Expand All @@ -55,7 +56,9 @@ public slots:
LXQt::Backlight *mBacklight;
int mLastBacklightValue;
int mInitialBacklightValue;

int mInitialMinBacklightValue;
int mMinBacklightValue;
LXQt::Settings *mSettings;
};


Expand Down
Loading