Verified Commit 4f66f4eb authored by Alf Gaida's avatar Alf Gaida

Adding upstream version 0.14.0.

Signed-off-by: Alf Gaida's avatarAlf Gaida <agaida@siduction.org>
parent baacae86
liblxqt-0.14.0 / 2019-01-25
===========================
* Implementation fixed:
- Added missing text color of our HTML delegate
- Use the new signal and slot syntax
- Don't use automatic string conversions
- lxqtbacklight: centralize fopen() and perform path handling with length checks
- lxqtbacklight: apply maximum string length to fscanf to prevent overflow
- lxqtbacklight: removed useless commented out code
- lxqtbacklight: constified char *driver, where appropriate
- lxqtbacklight: centralized error output on empty backlight dir
- lxqtbacklight: fix and improve command line parameter handling
- lxqtbacklight: only pass basename into open_driver_file()
- lxqt-backlight: Simplify string construction
- lxqthtmldelegate: Position, alignment and size fixes for HTML delegate
- lxqtpageselectwidget: Fix config dialog cell height
- lxqtpageselectwidget: Fixed config dialog select widget cells
* Improved cmake scripting
- Set cmake_minimum_required to 3.1.0
- Removed locale compile definitons
* Moved translations from lxqt-l10n back to liblxqt
- Removed obsolete translation fuctionality
- Added translation promo in README.md
* Translation updates
liblxqt-0.13.0 / 2018-05-21
===========================
......
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# CMP0000: Call the cmake_minimum_required() command at the beginning of the top-level
# CMakeLists.txt file even before calling the project() command.
# The cmake_minimum_required(VERSION) command implicitly invokes the cmake_policy(VERSION)
# command to specify that the current project code is written for the given range of CMake
# versions.
project(liblxqt)
set(LXQTBT_MINIMUM_VERSION "0.6.0")
set(KF5_MINIMUM_VERSION "5.36.0")
set(QT_MINIMUM_VERSION "5.7.1")
set(QTXDG_MINIMUM_VERSION "3.1.0")
set(LXQTBT_MINIMUM_VERSION "0.5.0")
set(QTXDG_MINIMUM_VERSION "3.3.0")
# Major LXQt Version, belong to all components
set(LXQT_MAJOR_VERSION 0)
# Minor LXQt Version, belong to all components
set(LXQT_MINOR_VERSION 13)
set(LXQT_MINOR_VERSION 14)
#
# Patch Version, belong *only* to the component
# LXQt is 0.13 - liblxqt is at patch version 0
......@@ -22,18 +28,28 @@ set(LXQT_MINOR_VERSION 13)
set(LXQT_PATCH_VERSION 0)
set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets DBus X11Extras LinguistTools)
find_package(Qt5Xdg ${QTXDG_MINIMUM_VERSION} REQUIRED)
find_package(KF5WindowSystem ${KF5_MINIMUM_VERSION} REQUIRED)
find_package(PolkitQt5-1 REQUIRED)
find_package(X11 REQUIRED)
message(STATUS "Building ${PROJECT_NAME} with Qt ${Qt5Core_VERSION}")
include(CMakePackageConfigHelpers)
include(GNUInstallDirs) # Standard directories for installation
add_subdirectory(lxqtbacklight/linux_backend/driver)
#-----------------------------------------------------------------------------
# Release is the default build type
#-----------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(LXQT_PKG_CONFIG_DESCRIPTION "Shared library for LXQt applications")
set(PUB_HDRS
......@@ -147,22 +163,6 @@ configure_file ( polkit/org.lxqt.backlight.pkexec.policy.in "${CMAKE_CURRENT_BIN
file(GLOB LXQT_CONFIG_FILES resources/*.conf)
option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
find_package(X11 REQUIRED)
find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Widgets DBus X11Extras LinguistTools)
find_package(Qt5Xdg ${QTXDG_MINIMUM_VERSION} REQUIRED)
find_package(KF5WindowSystem REQUIRED)
find_package(PolkitQt5-1 REQUIRED)
message(STATUS "Building ${PROJECT_NAME} with Qt ${Qt5Core_VERSION}")
QT5_ADD_DBUS_INTERFACE(DBUS_INTERFACE_SRCS
dbus/org.freedesktop.Notifications.xml
notifications_interface
......@@ -204,14 +204,6 @@ lxqt_translate_ts(QM_FILES
${FORMS}
INSTALL_DIR
"${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME}"
PULL_TRANSLATIONS
${PULL_TRANSLATIONS}
CLEAN_TRANSLATIONS
${CLEAN_TRANSLATIONS}
TRANSLATIONS_REPO
${TRANSLATIONS_REPO}
TRANSLATIONS_REFSPEC
${TRANSLATIONS_REFSPEC}
)
message(STATUS "")
......@@ -314,7 +306,11 @@ target_compile_definitions(${LXQT_LIBRARY_NAME}
"LXQT_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\""
"LXQT_VERSION=\"${LXQT_VERSION}\""
"COMPILE_LIBLXQT"
"QT_NO_FOREACH"
"QT_USE_QSTRINGBUILDER"
"QT_NO_CAST_FROM_ASCII"
"QT_NO_CAST_TO_ASCII"
"QT_NO_URL_CAST_FROM_STRING"
"QT_NO_CAST_FROM_BYTEARRAY"
"$<$<CONFIG:Release>:QT_NO_DEBUG_OUTPUT>"
"$<$<CONFIG:Release>:QT_NO_WARNING_OUTPUT>"
)
......
......@@ -29,3 +29,10 @@ as usual.
The library is provided by all major Linux distributions like Arch Linux, Debian,
Fedora and openSUSE. Just use your package manager to search for string `liblxqt`.
### Translation (Weblate)
<a href="https://weblate.lxqt.org/projects/lxqt/liblxqt/">
<img src="https://weblate.lxqt.org/widgets/lxqt/-/liblxqt/multi-auto.svg" alt="Translation status" />
</a>
......@@ -126,7 +126,7 @@ void ConfigDialog::addPage(QWidget* page, const QString& name, const QStringList
page->layout()->setMargin(0);
}
QStringList icons = QStringList(iconNames) << "application-x-executable";
QStringList icons = QStringList(iconNames) << QL1S("application-x-executable");
new QListWidgetItem(XdgIcon::fromTheme(icons), name, d->ui->moduleList);
d->mIcons.append(icons);
d->ui->stackedWidget->addWidget(page);
......
......@@ -58,7 +58,7 @@ public:
/*!
* Add a page to the configure dialog
*/
void addPage(QWidget* page, const QString& name, const QString& iconName="application-x-executable");
void addPage(QWidget* page, const QString& name, const QString& iconName = QLatin1String("application-x-executable"));
/*!
* Add a page to the configure dialog, attempting several alternative icons to find one in the theme
......
......@@ -61,14 +61,35 @@ PageSelectWidgetItemDelegate::PageSelectWidgetItemDelegate(PageSelectWidget *par
************************************************/
QSize PageSelectWidgetItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size = QStyledItemDelegate::sizeHint(option, index);
QVariant value = index.data(Qt::SizeHintRole);
if (value.isValid())
return qvariant_cast<QSize>(value);
//all items should have unified width
QStyle * style = option.widget ? option.widget->style() : QApplication::style();
//Note: this margin logic follows code in QCommonStylePrivate::viewItemLayout()
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
const QWidget *widget = option.widget;
QStyle *style = widget ? widget->style() : QApplication::style();
QSize size = style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget);
//NOTE: this margin logic follows code in QCommonStylePrivate::viewItemLayout()
const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, &option, option.widget) + 1;
// Find the extra vertical gap by subtracting the height of the text when wrapped within
// the default size from the height of the text when wrapped within our max. width.
const QRect R1 = mView->fontMetrics().boundingRect(QRect(0, 0, size.width() - 2 * margin, 0),
Qt::AlignLeft | Qt::TextWordWrap, opt.text);
const QRect R2 = mView->fontMetrics().boundingRect(QRect(0, 0, mView->getWrappedTextWidth(), 0),
Qt::AlignLeft | Qt::TextWordWrap, opt.text);
// compensate for the vertical gap
size.rheight() -= qAbs(R1.height() - R2.height());
//considering the icon size too
size.setWidth(qMax(mView->maxTextWidth(), option.decorationSize.width()));
// adding the margin is good but not necessary because it is already added
size.rwidth() += 2 * margin;
size.rheight() += margin; // only at the bottom
return size;
}
......@@ -81,6 +102,8 @@ PageSelectWidget::PageSelectWidget(QWidget *parent) :
QListWidget(parent)
, mMaxTextWidth(0)
{
mWrappedTextWidth = fontMetrics().averageCharWidth() * 13; // max. 13 characters
setSelectionRectVisible(false);
setViewMode(IconMode);
setSpacing(2);
......@@ -140,7 +163,8 @@ void PageSelectWidget::updateMaxTextWidth()
{
for(int i = count() - 1; 0 <= i; --i)
{
const QRect r = fontMetrics().boundingRect(QRect{}, Qt::AlignLeft | Qt::TextWordWrap, item(i)->text());
const QRect r = fontMetrics().boundingRect(QRect(0, 0, mWrappedTextWidth, 0),
Qt::AlignLeft | Qt::TextWordWrap, item(i)->text());
mMaxTextWidth = qMax(mMaxTextWidth, r.width());
}
}
......
......@@ -44,6 +44,10 @@ public:
int maxTextWidth() const;
bool event(QEvent * event) override;
int getWrappedTextWidth() const {
return mWrappedTextWidth;
}
protected:
QSize viewportSizeHint() const override;
QSize minimumSizeHint() const override;
......@@ -53,6 +57,7 @@ protected slots:
private:
int mMaxTextWidth;
int mWrappedTextWidth;
};
} // namespace LXQt
......
......@@ -60,8 +60,8 @@ void dbgMessageOutput(QtMsgType type, const QMessageLogContext &ctx, const QStri
Q_UNUSED(ctx)
QByteArray msgBuf = msgStr.toUtf8();
const char* msg = msgBuf.constData();
QDir dir(XdgDirs::configHome().toUtf8() + QLatin1String("/lxqt"));
dir.mkpath(".");
QDir dir(XdgDirs::configHome() + QLatin1String("/lxqt"));
dir.mkpath(QL1S("."));
const char* typestr;
const char* color;
......@@ -83,13 +83,13 @@ void dbgMessageOutput(QtMsgType type, const QMessageLogContext &ctx, const QStri
color = COLOR_CRITICAL;
}
QByteArray dt = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toUtf8();
QByteArray dt = QDateTime::currentDateTime().toString(QL1S("yyyy-MM-dd hh:mm:ss.zzz")).toUtf8();
if (isatty(STDERR_FILENO))
fprintf(stderr, "%s %s(%p) %s: %s%s\n", color, QAPP_NAME, static_cast<void *>(qApp), typestr, msg, COLOR_RESET);
else
fprintf(stderr, "%s(%p) %s: %s\n", QAPP_NAME, static_cast<void *>(qApp), typestr, msg);
FILE *f = fopen(dir.absoluteFilePath("debug.log").toUtf8().constData(), "a+");
FILE *f = fopen(dir.absoluteFilePath(QL1S("debug.log")).toUtf8().constData(), "a+");
fprintf(f, "%s %s(%p) %s: %s\n", dt.constData(), QAPP_NAME, static_cast<void *>(qApp), typestr, msg);
fclose(f);
......@@ -107,8 +107,8 @@ Application::Application(int &argc, char** argv)
qInstallMessageHandler(dbgMessageOutput);
#endif
setWindowIcon(QIcon(QString(LXQT_GRAPHICS_DIR) + "/lxqt_logo.png"));
connect(Settings::globalSettings(), SIGNAL(lxqtThemeChanged()), this, SLOT(updateTheme()));
setWindowIcon(QIcon(QFile::decodeName(LXQT_GRAPHICS_DIR) + QL1S("/lxqt_logo.png")));
connect(Settings::globalSettings(), &GlobalSettings::lxqtThemeChanged, this, &Application::updateTheme);
updateTheme();
}
......@@ -143,7 +143,7 @@ namespace
{
const int ret = write(instance->mSignalSock[0], &signo, sizeof (int));
if (sizeof (int) != ret)
qCritical() << QStringLiteral("unable to write into socketpair, %1").arg(strerror(errno));
qCritical("unable to write into socketpair: %s", strerror(errno));
}
public:
......@@ -153,7 +153,7 @@ namespace
{
if (0 != socketpair(AF_UNIX, SOCK_STREAM, 0, mSignalSock))
{
qCritical() << QStringLiteral("unable to create socketpair for correct signal handling: %1)").arg(strerror(errno));
qCritical("unable to create socketpair for correct signal handling: %s", strerror(errno));
return;
}
......@@ -162,7 +162,7 @@ namespace
int signo = 0;
int ret = read(mSignalSock[1], &signo, sizeof (int));
if (sizeof (int) != ret)
qCritical() << QStringLiteral("unable to read signal from socketpair, %1").arg(strerror(errno));
qCritical("unable to read signal from socketpair, %s", strerror(errno));
signalEmitter(signo);
});
}
......
......@@ -41,7 +41,7 @@ AutostartEntry::AutostartEntry(const QString& name):
const QStringList& dirs = XdgDirs::autostartDirs();
for (const QString& dir : dirs)
{
const QString path = QString("%1/%2").arg(dir, name);
const QString path = QString::fromLatin1("%1/%2").arg(dir, name);
if (QFile(path).exists())
{
mSystemFile.load(path);
......@@ -50,7 +50,7 @@ AutostartEntry::AutostartEntry(const QString& name):
}
}
const QString path = QString("%1/%2").arg(XdgDirs::autostartHome(), name);
const QString path = QString::fromLatin1("%1/%2").arg(XdgDirs::autostartHome(), name);
if (QFile(path).exists())
{
mLocalFile.load(path);
......@@ -102,16 +102,16 @@ void AutostartEntry::setEnabled(bool enable)
{
XdgDesktopFile f = file();
if (enable)
f.removeEntry("Hidden");
f.removeEntry(QL1S("Hidden"));
else
f.setValue("Hidden", true);
f.setValue(QL1S("Hidden"), true);
setFile(f);
}
bool AutostartEntry::isEnabled() const
{
return !isEmpty() && !file().value("Hidden", false).toBool();
return !isEmpty() && !file().value(QL1S("Hidden"), false).toBool();
}
bool AutostartEntry::commit()
......
......@@ -25,7 +25,7 @@ namespace LXQt {
Backlight::Backlight(QObject *parent):QObject(parent)
{
m_backend = (VirtualBackEnd *) new LinuxBackend(this);
connect(m_backend, SIGNAL(backlightChanged(int)), this, SLOT(backlightChangedSlot(int)));
connect(m_backend, &VirtualBackEnd::backlightChanged, this, &Backlight::backlightChangedSlot);
}
Backlight::~Backlight()
......
project(lxqt-backlight_backend)
set(C_FILES
......@@ -10,10 +9,6 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
if(NOT CMAKE_BUILD_TYPE)
set( CMAKE_BUILD_TYPE Release )
endif (NOT CMAKE_BUILD_TYPE)
add_executable(${PROJECT_NAME}
${C_FILES}
)
......
......@@ -55,6 +55,7 @@
* in order to write in /sys/class/backlight/driver/brightness file.
*******************************************************************************/
#include <limits.h>
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
......@@ -67,15 +68,16 @@
#define True 1
#define False 0
static int read_backlight(char *driver);
static int read_max_backlight(char *driver);
static int read_bl_power(char *driver);
static FILE* open_driver_file(const char *file, const char *driver, const char *mode);
static int read_backlight(const char *driver);
static int read_max_backlight(const char *driver);
static int read_bl_power(const char *driver);
static const char *sysfs_backlight_dir = "/sys/class/backlight";
int lxqt_backlight_backend_get()
{
char *driver = lxqt_backlight_backend_get_driver();
if( driver == NULL ) {
fprintf(stderr, "Error: /sys/class/backlight is empty.");
return -1;
}
int value = read_backlight(driver);
......@@ -87,7 +89,6 @@ int lxqt_backlight_backend_get_max()
{
char *driver = lxqt_backlight_backend_get_driver();
if( driver == NULL ) {
fprintf(stderr, "Error: /sys/class/backlight is empty.");
return -1;
}
int value = read_max_backlight(driver);
......@@ -106,7 +107,6 @@ int lxqt_backlight_is_backlight_off()
{
char *driver = lxqt_backlight_backend_get_driver();
if( driver == NULL ) {
fprintf(stderr, "Error: /sys/class/backlight is empty.");
return -1;
}
int bl_power = read_bl_power(driver);
......@@ -114,13 +114,10 @@ int lxqt_backlight_is_backlight_off()
return bl_power;
}
static int read_int(char *path)
static int read_int(const char *file, const char *driver)
{
FILE *in = fopen(path, "r");
FILE *in = open_driver_file(file, driver, "r");
if( in == NULL ) {
char buffer[1024];
sprintf(buffer, "Couldn't open %s", path);
perror(buffer);
return -1;
}
int value;
......@@ -132,25 +129,40 @@ static int read_int(char *path)
return value;
}
static int read_backlight(char *driver)
static FILE* open_driver_file(const char *file, const char *driver, const char *mode)
{
char path[1024];
sprintf(path, "/sys/class/backlight/%s/actual_brightness", driver);
return read_int(path);
char path[PATH_MAX];
int res;
res = snprintf(path, PATH_MAX, "%s/%s/%s", sysfs_backlight_dir, driver, file);
if( res <= 0 || res >= PATH_MAX ) {
path[0] = '\0';
return NULL;
}
FILE *ret = fopen(path, mode);
if( ret == NULL ) {
fprintf(stderr, "Couldn't open %s: %s\n", path, strerror(errno));
}
return ret;
}
static int read_max_backlight(char *driver)
static int read_backlight(const char *driver)
{
char path[1024];
sprintf(path, "/sys/class/backlight/%s/max_brightness", driver);
return read_int(path);
return read_int("actual_brightness", driver);
}
static int read_bl_power(char *driver)
static int read_max_backlight(const char *driver)
{
char path[1024];
sprintf(path, "/sys/class/backlight/%s/bl_power", driver);
return read_int(path);
return read_int("max_brightness", driver);
}
static int read_bl_power(const char *driver)
{
return read_int("bl_power", driver);
}
typedef enum {FIRMWARE, PLATFORM, RAW, OTHER, N_BACKLIGHT} BackligthTypes;
......@@ -159,17 +171,17 @@ char *lxqt_backlight_backend_get_driver()
{
DIR *dirp;
struct dirent *dp;
char *drivers[N_BACKLIGHT];
char *driver;
int n;
char path[1024], type[1024];
char type[1024];
for(n=0;n<N_BACKLIGHT;n++)
drivers[n] = NULL;
if ((dirp = opendir("/sys/class/backlight")) == NULL) {
perror("Couldn't open /sys/class/backlight");
if ((dirp = opendir(sysfs_backlight_dir)) == NULL) {
fprintf(stderr, "Couldn't open %s: %s\n", sysfs_backlight_dir, strerror(errno));
return NULL;
}
......@@ -179,11 +191,11 @@ char *lxqt_backlight_backend_get_driver()
if( !strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..") )
continue;
driver = dp->d_name;
sprintf(path, "/sys/class/backlight/%s/type", driver);
FILE *in = fopen(path, "r");
FILE *in = open_driver_file("type", driver, "r");
if( in == NULL )
continue;
int ok = fscanf(in, "%s", type);
// the maximum field width does not include '\0'!
int ok = fscanf(in, "%1023s", type);
fclose(in);
if( ok != EOF ) {
// firmware control should be preferred to platform control should be preferred to raw control.
......@@ -202,9 +214,10 @@ char *lxqt_backlight_backend_get_driver()
closedir(dirp);
if (errno != 0)
perror("Error reading directory");
if (errno != 0) {
fprintf(stderr, "Error reading directory %s: %s\n", sysfs_backlight_dir, strerror(errno));
}
driver = NULL;
for(n=0;n<N_BACKLIGHT;n++) {
if( drivers[n] != NULL && driver == NULL )
......@@ -213,6 +226,11 @@ char *lxqt_backlight_backend_get_driver()
free(drivers[n]);
}
if( driver == NULL )
{
fprintf(stderr, "Error: %s is empty (no driver found).\n", sysfs_backlight_dir);
}
return driver;
}
......
......@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include "libbacklight_backend.h"
#include "libbacklight_backend.c"
......@@ -33,31 +34,23 @@
* @param driver is the driver to use
* @param value 0 turns on backlight, 4 turns off backlight
*/
static void set_bl_power(char *driver, int value)
static void set_bl_power(const char *driver, int value)
{
char path[1024];
sprintf(path, "/sys/class/backlight/%s/bl_power", driver);
FILE *out = fopen(path, "w");
FILE *out = open_driver_file("bl_power", driver, "w");
if( out != NULL ) {
fprintf(out, "%d", value);
fclose(out);
} else {
perror("Couldn't open /sys/class/backlight/driver/bl_power");
}
}
static void set_backlight(char *driver, int value)
static void set_backlight(const char *driver, int value)
{
if(value>0) {
char path[1024];
sprintf(path, "/sys/class/backlight/%s/brightness", driver);
FILE *out = fopen(path, "w");
FILE *out = open_driver_file("brightness", driver, "w");
if( out != NULL ) {
fprintf(out, "%d", value);
fclose(out);
} else {
perror("Couldn't open /sys/class/backlight/driver/brightness");
}
if(read_bl_power(driver) > 0)
set_bl_power(driver, 0);
......@@ -66,40 +59,6 @@ static void set_backlight(char *driver, int value)
}
}
// static int read_int(char *path)
// {
// FILE *in = fopen(path, "r");
// if( in == NULL ) {
// char buffer[1024];
// sprintf(buffer, "Couldn't open %s", path);
// perror(buffer);
// return -1;
// }
// int value;
// int ok = fscanf(in, "%d", &value);
// fclose(in);
// if( ok == EOF ) {
// value = 0;
// }
// return value;
// }
// static int read_backlight(char *driver)
// {
// char path[1024];
// sprintf(path, "/sys/class/backlight/%s/actual_brightness", driver);
// return read_int(path);
// }
// static int read_max_backlight(char *driver)
// {
// char path[1024];
// sprintf(path, "/sys/class/backlight/%s/max_brightness", driver);
// return read_int(path);
// }
static char *get_driver()
{
return lxqt_backlight_backend_get_driver();
......@@ -110,7 +69,6 @@ static void show_blacklight()
{
char *driver = get_driver();
if( driver == NULL ) {
fprintf(stderr, "Error: /sys/class/backlight is empty.");
return;
}
int max_value = read_max_backlight(driver);
......@@ -123,13 +81,17 @@ static void change_blacklight(int value, int percent_ok)
{
char *driver = get_driver();
if( driver == NULL ) {
fprintf(stderr, "Error: /sys/class/backlight is empty.");
return;
}
int max_value = read_max_backlight(driver);
if(percent_ok)
if(percent_ok) {
value = (float)(max_value*value)/100.0;
if(value<max_value && value>0) {
if( value == 0 ) {
// avoid switching off backlight but support zero as lowest value
value = 1;
}
}
if(value<=max_value && value>0) {
set_backlight(driver, value);
}
free(driver);
......@@ -139,7 +101,6 @@ static void increases_blacklight()
{
char *driver = get_driver();
if( driver == NULL ) {
fprintf(stderr, "Error: /sys/class/backlight is empty.");
return;
}
int max_value = read_max_backlight(driver);
......@@ -160,7 +121,6 @@ static void decreases_blacklight()
{
char *driver = get_driver();
if( driver == NULL ) {
fprintf(stderr, "Error: /sys/class/backlight is empty.");
return;
}
int max_value = read_max_backlight(driver);
......@@ -182,6 +142,9 @@ static void set_backlight_from_stdin()
char *driver = get_driver();
int ok = True, value;
int max_value = read_max_backlight(driver);
if( driver == NULL ) {
return;
}
while(ok && !feof(stdin)) {
ok = scanf("%d", &value);
if( ok != EOF && value > 0 && value <= max_value) {
......@@ -225,26 +188,26 @@ int main(int argc, char *argv[])
return 0;
} if( !strcmp(argv[n], "--dec") ) {
decreases_blacklight();
return 0;
return 0;
} if( !strcmp(argv[n], "--stdin") ) {
set_backlight_from_stdin();
return 0;
} else if ( argv[n][0] != '-' ) {