Commit e4a44363 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

clang-tidy: Force braces around statements

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent 402cf1d2
...@@ -40,8 +40,9 @@ void DisplayNumber::setWidth(int digits) ...@@ -40,8 +40,9 @@ void DisplayNumber::setWidth(int digits)
QString s(QStringLiteral("0123456789.+-")); QString s(QStringLiteral("0123456789.+-"));
int width = 0, charWidth = 0; int width = 0, charWidth = 0;
for (int i = 0; i < 11; i++, width = fm.boundingRect(s[i]).width()) for (int i = 0; i < 11; i++, width = fm.boundingRect(s[i]).width()) {
charWidth = (width > charWidth) ? width : charWidth; charWidth = (width > charWidth) ? width : charWidth;
}
dg = digits; dg = digits;
setMinimumWidth(dg * charWidth + charWidth / 2); setMinimumWidth(dg * charWidth + charWidth / 2);
......
...@@ -105,15 +105,16 @@ KGamma::~KGamma() ...@@ -105,15 +105,16 @@ KGamma::~KGamma()
if (GammaCorrection) { if (GammaCorrection) {
// Do not emit signals during destruction (bug 221611) // Do not emit signals during destruction (bug 221611)
bool blocked = blockSignals(true); bool blocked = blockSignals(true);
if (loadUserSettings()) if (loadUserSettings()) {
load(); load();
else if (!saved) } else if (!saved) {
for (int i = 0; i < ScreenCount; i++) { for (int i = 0; i < ScreenCount; i++) {
xv->setScreen(i); xv->setScreen(i);
xv->setGamma(XVidExtWrap::Red, rbak[i]); xv->setGamma(XVidExtWrap::Red, rbak[i]);
xv->setGamma(XVidExtWrap::Green, gbak[i]); xv->setGamma(XVidExtWrap::Green, gbak[i]);
xv->setGamma(XVidExtWrap::Blue, bbak[i]); xv->setGamma(XVidExtWrap::Blue, bbak[i]);
} }
}
delete rootProcess; delete rootProcess;
blockSignals(blocked); blockSignals(blocked);
} }
...@@ -244,13 +245,15 @@ void KGamma::setupUI() ...@@ -244,13 +245,15 @@ void KGamma::setupUI()
screenselect = new QComboBox(options); screenselect = new QComboBox(options);
optionsHBoxLayout->addWidget(screenselect); optionsHBoxLayout->addWidget(screenselect);
for (int i = 0; i < ScreenCount; i++) for (int i = 0; i < ScreenCount; i++) {
screenselect->addItem(i18n("Screen %1", i + 1)); screenselect->addItem(i18n("Screen %1", i + 1));
}
screenselect->setCurrentIndex(currentScreen); screenselect->setCurrentIndex(currentScreen);
if (ScreenCount <= 1) { if (ScreenCount <= 1) {
screenselect->setEnabled(false); screenselect->setEnabled(false);
} else } else {
connect(screenselect, QOverload<int>::of(&QComboBox::activated), this, &KGamma::changeScreen); connect(screenselect, QOverload<int>::of(&QComboBox::activated), this, &KGamma::changeScreen);
}
optionsHBoxLayout->setSpacing(10); optionsHBoxLayout->setSpacing(10);
optionsHBoxLayout->setStretchFactor(xf86cfgbox, 10); optionsHBoxLayout->setStretchFactor(xf86cfgbox, 10);
...@@ -276,29 +279,32 @@ void KGamma::load() ...@@ -276,29 +279,32 @@ void KGamma::load()
KConfigGroup group = config->group("ConfigFile"); KConfigGroup group = config->group("ConfigFile");
// save checkbox status // save checkbox status
if (xf86cfgbox->isChecked()) if (xf86cfgbox->isChecked()) {
group.writeEntry("use", "XF86Config"); group.writeEntry("use", "XF86Config");
else } else {
group.writeEntry("use", "kgammarc"); group.writeEntry("use", "kgammarc");
}
// load syncbox status // load syncbox status
group = config->group("SyncBox"); group = config->group("SyncBox");
if (group.readEntry("sync") == QLatin1String("yes")) if (group.readEntry("sync") == QLatin1String("yes")) {
syncbox->setChecked(true); syncbox->setChecked(true);
else } else {
syncbox->setChecked(false); syncbox->setChecked(false);
}
config->sync(); config->sync();
delete config; delete config;
for (int i = 0; i < ScreenCount; i++) { for (int i = 0; i < ScreenCount; i++) {
xv->setScreen(i); xv->setScreen(i);
if (rgamma[i] == ggamma[i] && rgamma[i] == bgamma[i]) if (rgamma[i] == ggamma[i] && rgamma[i] == bgamma[i]) {
if (i == currentScreen) if (i == currentScreen) {
gctrl->setGamma(rgamma[i]); gctrl->setGamma(rgamma[i]);
else } else {
xv->setGamma(XVidExtWrap::Value, rgamma[i].toFloat()); xv->setGamma(XVidExtWrap::Value, rgamma[i].toFloat());
else { }
} else {
if (i == currentScreen) { if (i == currentScreen) {
rgctrl->setGamma(rgamma[i]); rgctrl->setGamma(rgamma[i]);
ggctrl->setGamma(ggamma[i]); ggctrl->setGamma(ggamma[i]);
...@@ -330,10 +336,11 @@ void KGamma::save() ...@@ -330,10 +336,11 @@ void KGamma::save()
KConfig *config = new KConfig(QStringLiteral("kgammarc")); KConfig *config = new KConfig(QStringLiteral("kgammarc"));
KConfigGroup group = config->group("SyncBox"); KConfigGroup group = config->group("SyncBox");
if (syncbox->isChecked()) if (syncbox->isChecked()) {
group.writeEntry("sync", "yes"); group.writeEntry("sync", "yes");
else } else {
group.writeEntry("sync", "no"); group.writeEntry("sync", "no");
}
if (!xf86cfgbox->isChecked()) { // write gamma settings to the users config if (!xf86cfgbox->isChecked()) { // write gamma settings to the users config
for (int i = 0; i < ScreenCount; i++) { for (int i = 0; i < ScreenCount; i++) {
...@@ -350,8 +357,9 @@ void KGamma::save() ...@@ -350,8 +357,9 @@ void KGamma::save()
if (!(rootProcess->state() == QProcess::Running)) { if (!(rootProcess->state() == QProcess::Running)) {
QString Arguments = QStringLiteral("xf86gammacfg "); QString Arguments = QStringLiteral("xf86gammacfg ");
for (int i = 0; i < ScreenCount; i++) for (int i = 0; i < ScreenCount; i++) {
Arguments += rgamma[assign[i]] + QLatin1Char(' ') + ggamma[assign[i]] + QLatin1Char(' ') + bgamma[assign[i]] + QLatin1Char(' '); Arguments += rgamma[assign[i]] + QLatin1Char(' ') + ggamma[assign[i]] + QLatin1Char(' ') + bgamma[assign[i]] + QLatin1Char(' ');
}
rootProcess->setProgram(QStandardPaths::findExecutable(QStringLiteral("kdesu"))); rootProcess->setProgram(QStandardPaths::findExecutable(QStringLiteral("kdesu")));
rootProcess->setArguments(Arguments.split(QLatin1Char(' '))); rootProcess->setArguments(Arguments.split(QLatin1Char(' ')));
rootProcess->start(); rootProcess->start();
...@@ -383,8 +391,9 @@ bool KGamma::loadSettings() ...@@ -383,8 +391,9 @@ bool KGamma::loadSettings()
KConfigGroup grp = config->group("ConfigFile"); KConfigGroup grp = config->group("ConfigFile");
QString ConfigFile(grp.readEntry("use")); QString ConfigFile(grp.readEntry("use"));
KConfigGroup syncGroup = config->group("SyncBox"); KConfigGroup syncGroup = config->group("SyncBox");
if (syncGroup.readEntry("sync") == QLatin1String("yes")) if (syncGroup.readEntry("sync") == QLatin1String("yes")) {
syncbox->setChecked(true); syncbox->setChecked(true);
}
delete config; delete config;
if (ConfigFile == QLatin1String("XF86Config")) { // parse XF86Config if (ConfigFile == QLatin1String("XF86Config")) { // parse XF86Config
...@@ -430,8 +439,9 @@ bool KGamma::loadSystemSettings() ...@@ -430,8 +439,9 @@ bool KGamma::loadSystemSettings()
QStringList words = s.split(QLatin1Char(' ')); QStringList words = s.split(QLatin1Char(' '));
if (!words.empty()) { if (!words.empty()) {
if (words[0] == QLatin1String("Section") && words.size() > 1) { if (words[0] == QLatin1String("Section") && words.size() > 1) {
if ((Section = words[1]) == QLatin1String("\"Monitor\"")) if ((Section = words[1]) == QLatin1String("\"Monitor\"")) {
gm = false; gm = false;
}
} else if (words[0] == QLatin1String("EndSection")) { } else if (words[0] == QLatin1String("EndSection")) {
if (Section == QLatin1String("\"Monitor\"") && !gm) { if (Section == QLatin1String("\"Monitor\"") && !gm) {
Gamma << QString(); Gamma << QString();
...@@ -439,10 +449,11 @@ bool KGamma::loadSystemSettings() ...@@ -439,10 +449,11 @@ bool KGamma::loadSystemSettings()
} }
Section = QString(); Section = QString();
} else if (words[0] == QLatin1String("Identifier") && words.size() > 1) { } else if (words[0] == QLatin1String("Identifier") && words.size() > 1) {
if (Section == QLatin1String("\"Monitor\"")) if (Section == QLatin1String("\"Monitor\"")) {
Monitor << words[1]; Monitor << words[1];
else if (Section == QLatin1String("\"Screen\"")) } else if (Section == QLatin1String("\"Screen\"")) {
Screen << words[1]; Screen << words[1];
}
} else if (words[0] == QLatin1String("Screen") && words.size() > 1) { } else if (words[0] == QLatin1String("Screen") && words.size() > 1) {
if (Section == QLatin1String("\"ServerLayout\"")) { if (Section == QLatin1String("\"ServerLayout\"")) {
bool ok; bool ok;
...@@ -456,8 +467,9 @@ bool KGamma::loadSystemSettings() ...@@ -456,8 +467,9 @@ bool KGamma::loadSystemSettings()
} }
} }
} else if (words[0] == QLatin1String("Monitor") && words.size() > 1) { } else if (words[0] == QLatin1String("Monitor") && words.size() > 1) {
if (Section == QLatin1String("\"Screen\"")) if (Section == QLatin1String("\"Screen\"")) {
ScreenMonitor << words[1]; ScreenMonitor << words[1];
}
} else if (words[0] == QLatin1String("Gamma")) { } else if (words[0] == QLatin1String("Gamma")) {
if (Section == QLatin1String("\"Monitor\"")) { if (Section == QLatin1String("\"Monitor\"")) {
Gamma << s; Gamma << s;
...@@ -486,9 +498,9 @@ bool KGamma::loadSystemSettings() ...@@ -486,9 +498,9 @@ bool KGamma::loadSystemSettings()
QStringList words = Gamma[assign[i]].split(QLatin1Char(' ')); QStringList words = Gamma[assign[i]].split(QLatin1Char(' '));
QStringList::ConstIterator it = words.constBegin(); QStringList::ConstIterator it = words.constBegin();
if (words.size() < 4) if (words.size() < 4) {
rgamma[i] = ggamma[i] = bgamma[i] = *(++it); // single gamma value rgamma[i] = ggamma[i] = bgamma[i] = *(++it); // single gamma value
else { } else {
rgamma[i] = *(++it); // eventually rgb gamma values rgamma[i] = *(++it); // eventually rgb gamma values
ggamma[i] = *(++it); ggamma[i] = *(++it);
bgamma[i] = *(++it); bgamma[i] = *(++it);
...@@ -511,10 +523,11 @@ bool KGamma::validateGammaValues() ...@@ -511,10 +523,11 @@ bool KGamma::validateGammaValues()
bgamma[i].toFloat(&bOk); bgamma[i].toFloat(&bOk);
if (!(rOk && gOk && bOk)) { if (!(rOk && gOk && bOk)) {
if (rOk) if (rOk) {
ggamma[i] = bgamma[i] = rgamma[i]; ggamma[i] = bgamma[i] = rgamma[i];
else } else {
result = false; result = false;
}
} }
} }
return (result); return (result);
...@@ -524,10 +537,11 @@ void KGamma::changeConfig() ...@@ -524,10 +537,11 @@ void KGamma::changeConfig()
{ {
bool Ok = false; bool Ok = false;
if (xf86cfgbox->isChecked()) if (xf86cfgbox->isChecked()) {
Ok = loadSystemSettings(); Ok = loadSystemSettings();
else } else {
Ok = loadUserSettings(); Ok = loadUserSettings();
}
if (!Ok) { if (!Ok) {
for (int i = 0; i < ScreenCount; i++) { for (int i = 0; i < ScreenCount; i++) {
...@@ -575,8 +589,9 @@ void KGamma::changeScreen(int sn) ...@@ -575,8 +589,9 @@ void KGamma::changeScreen(int sn)
rgctrl->setControl(red); rgctrl->setControl(red);
ggctrl->setControl(green); ggctrl->setControl(green);
bgctrl->setControl(blue); bgctrl->setControl(blue);
if (red != green || red != blue) if (red != green || red != blue) {
gctrl->suspend(); gctrl->suspend();
}
} }
int KGamma::buttons() int KGamma::buttons()
...@@ -615,12 +630,15 @@ Q_DECL_EXPORT void kcminit_kgamma() ...@@ -615,12 +630,15 @@ Q_DECL_EXPORT void kcminit_kgamma()
xv.setScreen(i); xv.setScreen(i);
KConfigGroup screenGroup = config->group(QStringLiteral("Screen %1").arg(i)); KConfigGroup screenGroup = config->group(QStringLiteral("Screen %1").arg(i));
if ((rgamma = screenGroup.readEntry("rgamma").toFloat())) if ((rgamma = screenGroup.readEntry("rgamma").toFloat())) {
xv.setGamma(XVidExtWrap::Red, rgamma); xv.setGamma(XVidExtWrap::Red, rgamma);
if ((ggamma = screenGroup.readEntry("ggamma").toFloat())) }
if ((ggamma = screenGroup.readEntry("ggamma").toFloat())) {
xv.setGamma(XVidExtWrap::Green, ggamma); xv.setGamma(XVidExtWrap::Green, ggamma);
if ((bgamma = screenGroup.readEntry("bgamma").toFloat())) }
if ((bgamma = screenGroup.readEntry("bgamma").toFloat())) {
xv.setGamma(XVidExtWrap::Blue, bgamma); xv.setGamma(XVidExtWrap::Blue, bgamma);
}
} }
delete config; delete config;
} }
......
...@@ -33,9 +33,11 @@ XF86ConfigPath::XF86ConfigPath() ...@@ -33,9 +33,11 @@ XF86ConfigPath::XF86ConfigPath()
searchPaths.push_back("/usr/X11R6/lib/X11/xorg.conf"); searchPaths.push_back("/usr/X11R6/lib/X11/xorg.conf");
vector<string>::iterator it = searchPaths.begin(); vector<string>::iterator it = searchPaths.begin();
for (; it != searchPaths.end(); ++it) for (; it != searchPaths.end(); ++it) {
if (!access((Path = *it).c_str(), F_OK)) if (!access((Path = *it).c_str(), F_OK)) {
break; break;
}
}
} }
XF86ConfigPath::~XF86ConfigPath() XF86ConfigPath::~XF86ConfigPath()
......
...@@ -47,8 +47,9 @@ XVidExtWrap::XVidExtWrap(bool *OK, const char *displayname) ...@@ -47,8 +47,9 @@ XVidExtWrap::XVidExtWrap(bool *OK, const char *displayname)
XVidExtWrap::~XVidExtWrap() XVidExtWrap::~XVidExtWrap()
{ {
if (dpy) if (dpy) {
XCloseDisplay(dpy); XCloseDisplay(dpy);
}
} }
int XVidExtWrap::_DefaultScreen() int XVidExtWrap::_DefaultScreen()
...@@ -73,24 +74,29 @@ int XVidExtWrap::_ScreenCount() ...@@ -73,24 +74,29 @@ int XVidExtWrap::_ScreenCount()
while (getline(in, s, '\n')) { while (getline(in, s, '\n')) {
words.clear(); words.clear();
istringstream ss(s.c_str()); istringstream ss(s.c_str());
while (ss >> buf) while (ss >> buf) {
words.push_back(buf); // Split "s" into words words.push_back(buf); // Split "s" into words
}
if (!words.empty()) { if (!words.empty()) {
if (words[0] == "Section" && words.size() > 1) { if (words[0] == "Section" && words.size() > 1) {
if (words[1] == "\"ServerLayout\"") if (words[1] == "\"ServerLayout\"") {
section = true; section = true;
} else if (words[0] == "EndSection") }
} else if (words[0] == "EndSection") {
section = false; section = false;
if (section && words[0] == "Screen") }
if (section && words[0] == "Screen") {
++count; ++count;
}
} }
} // end while } // end while
in.close(); in.close();
} }
if (!count) if (!count) {
count = 1; // If failed,fill count with a valid value; count = 1; // If failed,fill count with a valid value;
}
return (count); return (count);
} }
...@@ -107,8 +113,9 @@ void XVidExtWrap::setGamma(int channel, float gam, bool *OK) ...@@ -107,8 +113,9 @@ void XVidExtWrap::setGamma(int channel, float gam, bool *OK)
if (gam >= mingamma && gam <= maxgamma) { if (gam >= mingamma && gam <= maxgamma) {
if (!XF86VidModeGetGamma(dpy, screen, &gamma)) { if (!XF86VidModeGetGamma(dpy, screen, &gamma)) {
qDebug() << "KGamma: Unable to query gamma correction"; qDebug() << "KGamma: Unable to query gamma correction";
if (OK) if (OK) {
*OK = false; *OK = false;
}
} else { } else {
switch (channel) { switch (channel) {
case Value: case Value:
...@@ -127,12 +134,14 @@ void XVidExtWrap::setGamma(int channel, float gam, bool *OK) ...@@ -127,12 +134,14 @@ void XVidExtWrap::setGamma(int channel, float gam, bool *OK)
}; };
if (!XF86VidModeSetGamma(dpy, screen, &gamma)) { if (!XF86VidModeSetGamma(dpy, screen, &gamma)) {
qDebug() << "KGamma: Unable to set gamma correction"; qDebug() << "KGamma: Unable to set gamma correction";
if (OK) if (OK) {
*OK = false; *OK = false;
}
} else { } else {
XFlush(dpy); XFlush(dpy);
if (OK) if (OK) {
*OK = true; *OK = true;
}
} }
} }
} }
...@@ -145,8 +154,9 @@ float XVidExtWrap::getGamma(int channel, bool *OK) ...@@ -145,8 +154,9 @@ float XVidExtWrap::getGamma(int channel, bool *OK)
if (!XF86VidModeGetGamma(dpy, screen, &gamma)) { if (!XF86VidModeGetGamma(dpy, screen, &gamma)) {
qDebug() << "KGamma: Unable to query gamma correction"; qDebug() << "KGamma: Unable to query gamma correction";
if (OK) if (OK) {
*OK = false; *OK = false;
}
} else { } else {
switch (channel) { switch (channel) {
case Value: case Value:
...@@ -161,8 +171,9 @@ float XVidExtWrap::getGamma(int channel, bool *OK) ...@@ -161,8 +171,9 @@ float XVidExtWrap::getGamma(int channel, bool *OK)
case Blue: case Blue:
gam = gamma.blue; gam = gamma.blue;
}; };
if (OK) if (OK) {
*OK = true; *OK = true;
}
} }
return (gam); return (gam);
} }
......
...@@ -69,8 +69,9 @@ int main(int argc, char *argv[]) ...@@ -69,8 +69,9 @@ int main(int argc, char *argv[])
if (!cpyonly) { if (!cpyonly) {
words.clear(); words.clear();
std::istringstream ss(s.c_str()); std::istringstream ss(s.c_str());
while (ss >> buf) while (ss >> buf) {
words.push_back(buf); words.push_back(buf);
}
if (!words.empty()) { if (!words.empty()) {
if (words[0] == "Section" && words.size() > 1) { if (words[0] == "Section" && words.size() > 1) {
...@@ -108,17 +109,19 @@ int main(int argc, char *argv[]) ...@@ -108,17 +109,19 @@ int main(int argc, char *argv[])
if (success) { if (success) {
rename((*it).c_str(), (*it + ".kgammaorig").c_str()); rename((*it).c_str(), (*it + ".kgammaorig").c_str());
rename((*it + ".tmp").c_str(), (*it).c_str()); rename((*it + ".tmp").c_str(), (*it).c_str());
} else } else {
remove((*it + ".tmp").c_str()); remove((*it + ".tmp").c_str());
}
break; break;
} }
} }
} }
} }
if (!success) if (!success) {
cerr << "Usage: xf86gammacfg RGAMMA GGAMMA " cerr << "Usage: xf86gammacfg RGAMMA GGAMMA "
"BGAMMA [RGAMMA GGAMMA BGAMMA [...]]" "BGAMMA [RGAMMA GGAMMA BGAMMA [...]]"
<< endl; << endl;
}
return !success; return !success;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment