chore: use c++17 style if,switch init-initilizer where possible

chore: correct spelling of "colon" in NetworkAddresses variables
chore: correct some multi line defines near needed init-initilizers
This commit is contained in:
sithlord48 2025-05-02 08:03:44 -04:00 committed by Nick Bolton
parent bdffda9a2f
commit 0ff72441e6
43 changed files with 102 additions and 171 deletions

View file

@ -55,8 +55,7 @@ int IArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, boo
len += mblen; len += mblen;
++scan; ++scan;
} }
ptrdiff_t mblen = wctomb(dummy, L'\0'); if (ptrdiff_t mblen = wctomb(dummy, L'\0'); mblen != -1) {
if (mblen != -1) {
len += mblen - 1; len += mblen - 1;
} }
} else { } else {
@ -72,8 +71,7 @@ int IArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, boo
} }
++scan; ++scan;
} }
ptrdiff_t mblen = wctomb(dst, L'\0'); if (ptrdiff_t mblen = wctomb(dst, L'\0'); mblen != -1) {
if (mblen != -1) {
// don't include nul terminator // don't include nul terminator
dst += mblen - 1; dst += mblen - 1;
} }
@ -104,8 +102,7 @@ int IArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, boo
if (dst == nullptr) { if (dst == nullptr) {
const char *scan = src; const char *scan = src;
while (n > 0) { while (n > 0) {
ptrdiff_t mblen = mbtowc(&dummy, scan, n); switch (ptrdiff_t mblen = mbtowc(&dummy, scan, n); mblen) {
switch (mblen) {
case -2: case -2:
// incomplete last character. convert to unknown character. // incomplete last character. convert to unknown character.
*errors = true; *errors = true;
@ -140,8 +137,7 @@ int IArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, boo
wchar_t *dst0 = dst; wchar_t *dst0 = dst;
const char *scan = src; const char *scan = src;
while (n > 0) { while (n > 0) {
ptrdiff_t mblen = mbtowc(dst, scan, n); switch (ptrdiff_t mblen = mbtowc(dst, scan, n); mblen) {
switch (mblen) {
case -2: case -2:
// incomplete character. convert to unknown character. // incomplete character. convert to unknown character.
*errors = true; *errors = true;

View file

@ -74,8 +74,7 @@ int ArchDaemonUnix::daemonize(const char *name, DaemonFunc const &func)
// NB: don't run chdir on apple; causes strange behaviour. // NB: don't run chdir on apple; causes strange behaviour.
// chdir to root so we don't keep mounted filesystems points busy // chdir to root so we don't keep mounted filesystems points busy
// TODO: this is a bit of a hack - can we find a better solution? // TODO: this is a bit of a hack - can we find a better solution?
int chdirErr = chdir("/"); if (int chdirErr = chdir("/"); chdirErr)
if (chdirErr)
// NB: file logging actually isn't working at this point! // NB: file logging actually isn't working at this point!
LOG((CLOG_ERR "chdir error: %i", chdirErr)); LOG((CLOG_ERR "chdir error: %i", chdirErr));
#endif #endif
@ -93,9 +92,7 @@ int ArchDaemonUnix::daemonize(const char *name, DaemonFunc const &func)
open("/dev/null", O_RDONLY); open("/dev/null", O_RDONLY);
open("/dev/null", O_RDWR); open("/dev/null", O_RDWR);
int dupErr = dup(1); if (int dupErr = dup(1); dupErr < 0) {
if (dupErr < 0) {
// NB: file logging actually isn't working at this point! // NB: file logging actually isn't working at this point!
LOG((CLOG_ERR "dup error: %i", dupErr)); LOG((CLOG_ERR "dup error: %i", dupErr));
} }

View file

@ -204,8 +204,7 @@ bool ArchMultithreadPosix::waitCondVar(ArchCond cond, ArchMutex mutex, double ti
// so we have to return to the caller. since the caller will // so we have to return to the caller. since the caller will
// always check for spurious wakeups the only drawback here is // always check for spurious wakeups the only drawback here is
// performance: we're waking up a lot more than desired. // performance: we're waking up a lot more than desired.
static const double maxCancellationLatency = 0.1; if (static const double maxCancellationLatency = 0.1; timeout < 0.0 || timeout > maxCancellationLatency) {
if (timeout < 0.0 || timeout > maxCancellationLatency) {
timeout = maxCancellationLatency; timeout = maxCancellationLatency;
} }

View file

@ -404,8 +404,8 @@ void ArchNetworkBSD::throwErrorOnSocket(ArchSocket s)
// get the error from the socket layer // get the error from the socket layer
int err = 0; int err = 0;
auto size = static_cast<socklen_t>(sizeof(err)); if (auto size = static_cast<socklen_t>(sizeof(err));
if (getsockopt(s->m_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<optval_t *>(&err), &size) == -1) { getsockopt(s->m_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<optval_t *>(&err), &size) == -1) {
err = errno; err = errno;
} }
@ -545,8 +545,8 @@ std::vector<ArchNetAddress> ArchNetworkBSD::nameToAddr(const std::string &name)
// done with static buffer // done with static buffer
ARCH->lockMutex(m_mutex); ARCH->lockMutex(m_mutex);
struct addrinfo *pResult = nullptr; struct addrinfo *pResult = nullptr;
int ret = getaddrinfo(name.c_str(), nullptr, &hints, &pResult);
if (ret != 0) { if (int ret = getaddrinfo(name.c_str(), nullptr, &hints, &pResult); ret != 0) {
ARCH->unlockMutex(m_mutex); ARCH->unlockMutex(m_mutex);
throwNameError(ret); throwNameError(ret);
} }
@ -585,9 +585,10 @@ std::string ArchNetworkBSD::addrToName(ArchNetAddress addr)
ARCH->lockMutex(m_mutex); ARCH->lockMutex(m_mutex);
char host[1024]; char host[1024];
char service[20]; char service[20];
int ret =
getnameinfo(TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host), service, sizeof(service), 0); if (int ret =
if (ret != 0) { getnameinfo(TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host), service, sizeof(service), 0);
ret != 0) {
ARCH->unlockMutex(m_mutex); ARCH->unlockMutex(m_mutex);
throwNameError(ret); throwNameError(ret);
} }

View file

@ -121,8 +121,8 @@ retry:
// get time until next timer expires. if there is a timer // get time until next timer expires. if there is a timer
// and it'll expire before the client's timeout then use // and it'll expire before the client's timeout then use
// that duration for our timeout instead. // that duration for our timeout instead.
double timerTimeout = getNextTimerTimeout(); if (double timerTimeout = getNextTimerTimeout();
if (timeout < 0.0 || (timerTimeout >= 0.0 && timerTimeout < timeLeft)) { timeout < 0.0 || (timerTimeout >= 0.0 && timerTimeout < timeLeft)) {
timeLeft = timerTimeout; timeLeft = timerTimeout;
} }
@ -253,8 +253,7 @@ void EventQueue::deleteTimer(EventQueueTimer *timer)
break; break;
} }
} }
Timers::iterator index = m_timers.find(timer); if (Timers::iterator index = m_timers.find(timer); index != m_timers.end()) {
if (index != m_timers.end()) {
m_timers.erase(index); m_timers.erase(index);
} }
m_buffer->deleteTimer(timer); m_buffer->deleteTimer(timer);
@ -316,8 +315,7 @@ bool EventQueue::isEmpty() const
IEventJob *EventQueue::getHandler(EventTypes type, void *target) const IEventJob *EventQueue::getHandler(EventTypes type, void *target) const
{ {
ArchMutexLock lock(m_mutex); ArchMutexLock lock(m_mutex);
HandlerTable::const_iterator index = m_handlers.find(target); if (HandlerTable::const_iterator index = m_handlers.find(target); index != m_handlers.end()) {
if (index != m_handlers.end()) {
const TypeHandlerTable &typeHandlers = index->second; const TypeHandlerTable &typeHandlers = index->second;
TypeHandlerTable::const_iterator index2 = typeHandlers.find(type); TypeHandlerTable::const_iterator index2 = typeHandlers.find(type);
if (index2 != typeHandlers.end()) { if (index2 != typeHandlers.end()) {

View file

@ -439,8 +439,7 @@ std::string Unicode::doUTF16ToUTF8(const uint8_t *data, uint32_t n, bool *errors
// convert each character // convert each character
while (n > 0) { while (n > 0) {
uint32_t c = decode16(data, byteSwapped); if (uint32_t c = decode16(data, byteSwapped); c < 0x0000d800 || c > 0x0000dfff) {
if (c < 0x0000d800 || c > 0x0000dfff) {
toUTF8(dst, c, errors); toUTF8(dst, c, errors);
} else if (n == 1) { } else if (n == 1) {
// error -- missing second word // error -- missing second word
@ -449,8 +448,7 @@ std::string Unicode::doUTF16ToUTF8(const uint8_t *data, uint32_t n, bool *errors
} else if (c >= 0x0000d800 && c <= 0x0000dbff) { } else if (c >= 0x0000d800 && c <= 0x0000dbff) {
data += 2; data += 2;
--n; --n;
uint32_t c2 = decode16(data, byteSwapped); if (uint32_t c2 = decode16(data, byteSwapped); c2 < 0x0000dc00 || c2 > 0x0000dfff) {
if (c2 < 0x0000dc00 || c2 > 0x0000dfff) {
// error -- [d800,dbff] not followed by [dc00,dfff] // error -- [d800,dbff] not followed by [dc00,dfff]
setError(errors); setError(errors);
toUTF8(dst, s_replacement, nullptr); toUTF8(dst, s_replacement, nullptr);
@ -644,8 +642,8 @@ uint32_t Unicode::fromUTF8(const uint8_t *&data, uint32_t &n)
} }
// check for characters that didn't use the smallest possible encoding // check for characters that didn't use the smallest possible encoding
static uint32_t s_minChar[] = {0, 0x00000000, 0x00000080, 0x00000800, 0x00010000, 0x00200000, 0x04000000}; if (static uint32_t s_minChar[] = {0, 0x00000000, 0x00000080, 0x00000800, 0x00010000, 0x00200000, 0x04000000};
if (c < s_minChar[size]) { c < s_minChar[size]) {
return s_invalid; return s_invalid;
} }

View file

@ -218,9 +218,7 @@ bool ArgParser::isArg(
int argi, int argc, const char *const *argv, const char *name1, const char *name2, int minRequiredParameters int argi, int argc, const char *const *argv, const char *name1, const char *name2, int minRequiredParameters
) )
{ {
const auto match1 = (name1 != nullptr && strcmp(argv[argi], name1) == 0); if ((name1 != nullptr && strcmp(argv[argi], name1) == 0) || (name2 != nullptr && strcmp(argv[argi], name2) == 0)) {
const auto match2 = (name2 != nullptr && strcmp(argv[argi], name2) == 0);
if (match1 || match2) {
// match. check args left. // match. check args left.
if (argi + minRequiredParameters >= argc) { if (argi + minRequiredParameters >= argc) {
LOG((CLOG_PRINT "%s: missing arguments for `%s'" BYE, argsBase().m_pname, argv[argi], argsBase().m_pname)); LOG((CLOG_PRINT "%s: missing arguments for `%s'" BYE, argsBase().m_pname, argv[argi], argsBase().m_pname));

View file

@ -303,8 +303,7 @@ int32_t KeyMap::getLanguageGroupID(int32_t group, const std::string &lang) const
{ {
int32_t id = group; int32_t id = group;
auto it = std::find(m_keyboardLayouts.begin(), m_keyboardLayouts.end(), lang); if (auto it = std::find(m_keyboardLayouts.begin(), m_keyboardLayouts.end(), lang); it != m_keyboardLayouts.end()) {
if (it != m_keyboardLayouts.end()) {
id = static_cast<int>(std::distance(m_keyboardLayouts.begin(), it)); id = static_cast<int>(std::distance(m_keyboardLayouts.begin(), it));
LOG((CLOG_DEBUG1 "language %s has group id %d", lang.c_str(), id)); LOG((CLOG_DEBUG1 "language %s has group id %d", lang.c_str(), id));
} else { } else {

View file

@ -319,11 +319,7 @@ bool Screen::isOnScreen() const
bool Screen::isLockedToScreen() const bool Screen::isLockedToScreen() const
{ {
// check for pressed mouse buttons if (uint32_t buttonID = 0; m_screen->isAnyMouseButtonDown(buttonID)) {
// HACK: commented out as it breaks new drag drop feature
uint32_t buttonID = 0;
if (m_screen->isAnyMouseButtonDown(buttonID)) {
LOG((CLOG_DEBUG "locked by mouse buttonID: %d", buttonID)); LOG((CLOG_DEBUG "locked by mouse buttonID: %d", buttonID));
return true; return true;
} }

View file

@ -638,8 +638,7 @@ int ServerApp::mainLoop()
} }
// canonicalize the primary screen name // canonicalize the primary screen name
std::string primaryName = args().m_config->getCanonicalName(args().m_name); if (std::string primaryName = args().m_config->getCanonicalName(args().m_name); primaryName.empty()) {
if (primaryName.empty()) {
LOG((CLOG_CRIT "unknown screen name `%s'", args().m_name.c_str())); LOG((CLOG_CRIT "unknown screen name `%s'", args().m_name.c_str()));
return kExitFailed; return kExitFailed;
} }

View file

@ -118,8 +118,8 @@ std::string AppUtilUnix::getCurrentLanguageCode()
continue; continue;
} }
auto group = rawLayouts.substr(groupStartI, strI - groupStartI); if (auto group = rawLayouts.substr(groupStartI, strI - groupStartI);
if (group.find("group", 0, 5) == std::string::npos && group.find("inet", 0, 4) == std::string::npos && group.find("group", 0, 5) == std::string::npos && group.find("inet", 0, 4) == std::string::npos &&
group.find("pc", 0, 2) == std::string::npos) { group.find("pc", 0, 2) == std::string::npos) {
if (nedeedGroupIndex == groupIdx) { if (nedeedGroupIndex == groupIdx) {
result = group.substr(0, std::min(group.find('(', 0), group.find(':', 0))); result = group.substr(0, std::min(group.find('(', 0), group.find(':', 0)));

View file

@ -41,12 +41,10 @@ bool X11LayoutsParser::readXMLConfigItemElem(const QDomNode &node, std::vector<L
} }
langList.emplace_back(); langList.emplace_back();
auto nameElem = configItemElem.firstChildElement("name"); if (auto nameElem = configItemElem.firstChildElement("name"); !nameElem.isNull())
if (!nameElem.isNull())
langList.back().name = nameElem.toElement().text().toStdString(); langList.back().name = nameElem.toElement().text().toStdString();
auto languageListElem = configItemElem.elementsByTagName("languageList"); if (auto languageListElem = configItemElem.elementsByTagName("languageList"); !languageListElem.isEmpty()) {
if (!languageListElem.isEmpty()) {
for (int i = 0; i < languageListElem.count(); i++) { for (int i = 0; i < languageListElem.count(); i++) {
const auto isoElem = languageListElem.at(i).namedItem("iso639Id").toElement(); const auto isoElem = languageListElem.at(i).namedItem("iso639Id").toElement();
langList.back().layoutBaseISO639_2.emplace_back(isoElem.text().toStdString()); langList.back().layoutBaseISO639_2.emplace_back(isoElem.text().toStdString());

View file

@ -405,8 +405,7 @@ void MainWindow::settingsChanged(const QString &key)
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) || if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
(key == Settings::Security::TlsEnabled) || (key == Settings::Security::CheckPeers)) { (key == Settings::Security::TlsEnabled) || (key == Settings::Security::CheckPeers)) {
const auto certificate = Settings::value(Settings::Security::Certificate).toString(); if (m_tlsUtility.isEnabled() && !QFile::exists(Settings::value(Settings::Security::Certificate).toString())) {
if (m_tlsUtility.isEnabled() && !QFile::exists(certificate)) {
m_tlsUtility.generateCertificate(); m_tlsUtility.generateCertificate();
} }
updateSecurityIcon(m_lblSecurityStatus->isVisible()); updateSecurityIcon(m_lblSecurityStatus->isVisible());
@ -1130,8 +1129,7 @@ bool MainWindow::regenerateLocalFingerprints()
return false; return false;
} }
TlsCertificate tls; if (TlsCertificate tls; !tls.generateFingerprint(certificate)) {
if (!tls.generateFingerprint(certificate)) {
return false; return false;
} }

View file

@ -514,8 +514,7 @@ bool CoreProcess::addServerArgs(QStringList &args, QString &app)
// since it's not clear why (it is only needed for the server), this has now // since it's not clear why (it is only needed for the server), this has now
// been moved to server args. // been moved to server args.
if (Settings::value(Settings::Security::TlsEnabled).toBool()) { if (Settings::value(Settings::Security::TlsEnabled).toBool()) {
TlsUtility tlsUtility(this); if (TlsUtility tlsUtility(this); !tlsUtility.persistCertificate()) {
if (!tlsUtility.persistCertificate()) {
qCritical("failed to persist tls certificate"); qCritical("failed to persist tls certificate");
return false; return false;
} }

View file

@ -62,9 +62,7 @@ void ServerConnection::handleLogLine(const QString &logLine)
return; return;
} }
const auto client = message.getClientName(); if (const auto client = message.getClientName(); m_receivedClients.contains(client)) {
if (m_receivedClients.contains(client)) {
qDebug("already got request, skipping new client prompt for: %s", qPrintable(client)); qDebug("already got request, skipping new client prompt for: %s", qPrintable(client));
return; return;
} }

View file

@ -40,10 +40,10 @@ const QString &ServerMessage::getClientName() const
QString ServerMessage::parseClientName(const QString &line) const QString ServerMessage::parseClientName(const QString &line) const
{ {
QString clientName("Unknown"); QString clientName("Unknown");
auto nameStart = line.indexOf('"') + 1;
auto nameEnd = line.indexOf('"', nameStart);
if (nameEnd > nameStart) { auto nameStart = line.indexOf('"') + 1;
if (auto nameEnd = line.indexOf('"', nameStart); nameEnd > nameStart) {
clientName = line.mid(nameStart, nameEnd - nameStart); clientName = line.mid(nameStart, nameEnd - nameStart);
} }

View file

@ -485,8 +485,7 @@ bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent)
bool isAccepted = false; bool isAccepted = false;
Screen newScreen(clientName); Screen newScreen(clientName);
ScreenSettingsDialog dlg(this, &newScreen, &model().m_Screens); if (ScreenSettingsDialog dlg(this, &newScreen, &model().m_Screens); doSilent || dlg.exec() == QDialog::Accepted) {
if (doSilent || dlg.exec() == QDialog::Accepted) {
model().addScreen(newScreen); model().addScreen(newScreen);
isAccepted = true; isAccepted = true;
} }

View file

@ -88,14 +88,12 @@ bool TlsCertificate::isCertificateValid(const QString &path)
} }
auto pubkeyFree = deskflow::finally([pubkey]() { EVP_PKEY_free(pubkey); }); auto pubkeyFree = deskflow::finally([pubkey]() { EVP_PKEY_free(pubkey); });
auto type = EVP_PKEY_type(EVP_PKEY_id(pubkey)); if (auto type = EVP_PKEY_type(EVP_PKEY_id(pubkey)); type != EVP_PKEY_RSA && type != EVP_PKEY_DSA) {
if (type != EVP_PKEY_RSA && type != EVP_PKEY_DSA) {
qWarning() << tr("public key in default certificate key file is not RSA or DSA"); qWarning() << tr("public key in default certificate key file is not RSA or DSA");
return false; return false;
} }
auto bits = EVP_PKEY_bits(pubkey); if (EVP_PKEY_bits(pubkey) < 2048) {
if (bits < 2048) {
// We could have small keys in old barrier installations // We could have small keys in old barrier installations
qWarning() << tr("public key in default certificate key file is too small"); qWarning() << tr("public key in default certificate key file is too small");
return false; return false;

View file

@ -52,10 +52,11 @@ Fingerprint Fingerprint::fromDbLine(const QString &line)
result.data = QByteArray::fromHex(sLine.at(2).toLower().toLatin1()); result.data = QByteArray::fromHex(sLine.at(2).toLower().toLatin1());
} else { } else {
// v1 fallback // v1 fallback
const auto kSha1ColonCount = 19; static const auto kSha1ColonCount = 19;
const auto kSha1HexCharCount = 40; static const auto kSha1HexCharCount = 40;
const auto kSha1ExpectedSize = kSha1HexCharCount + kSha1ColonCount; static const auto kSha1ExpectedSize = kSha1HexCharCount + kSha1ColonCount;
if (line.size() != kSha1ExpectedSize || line.count(':') != kSha1ColonCount) const bool wrongSize = line.size() != kSha1ExpectedSize;
if (bool badColonCount = line.count(':') != kSha1ColonCount; wrongSize || badColonCount)
return result; return result;
result.type = Fingerprint::Type::SHA1; result.type = Fingerprint::Type::SHA1;
auto l2 = line; auto l2 = line;

View file

@ -34,11 +34,10 @@ NetworkAddress::NetworkAddress(const NetworkAddress &addr) : m_hostname(addr.m_h
NetworkAddress::NetworkAddress(const std::string &hostname, int port) : m_hostname(hostname), m_port(port) NetworkAddress::NetworkAddress(const std::string &hostname, int port) : m_hostname(hostname), m_port(port)
{ {
// detect internet protocol version with colom count // detect internet protocol version with colon count
auto isColomPredicate = [](char c) { return c == ':'; }; auto isColon = [](char c) { return c == ':'; };
auto colomCount = std::count_if(m_hostname.begin(), m_hostname.end(), isColomPredicate);
if (colomCount == 1) { if (auto colonCount = std::count_if(m_hostname.begin(), m_hostname.end(), isColon); colonCount == 1) {
// ipv4 with port part // ipv4 with port part
auto hostIt = m_hostname.find(':'); auto hostIt = m_hostname.find(':');
try { try {
@ -49,7 +48,7 @@ NetworkAddress::NetworkAddress(const std::string &hostname, int port) : m_hostna
auto endHostnameIt = static_cast<int>(hostIt); auto endHostnameIt = static_cast<int>(hostIt);
m_hostname = m_hostname.substr(0, endHostnameIt > 0 ? endHostnameIt : 0); m_hostname = m_hostname.substr(0, endHostnameIt > 0 ? endHostnameIt : 0);
} else if (colomCount > 1) { } else if (colonCount > 1) {
// ipv6 part // ipv6 part
if (m_hostname[0] == '[') { if (m_hostname[0] == '[') {
// ipv6 with port part // ipv6 with port part

View file

@ -50,8 +50,7 @@ IDataSocket *SecureListenSocket::accept()
certificateFilename = ArgParser::argsBase().m_tlsCertFile; certificateFilename = ArgParser::argsBase().m_tlsCertFile;
} }
bool loaded = socket->loadCertificates(certificateFilename); if (!socket->loadCertificates(certificateFilename)) {
if (!loaded) {
delete socket; delete socket;
return nullptr; return nullptr;
} }

View file

@ -54,9 +54,8 @@ Fingerprint sslCertFingerprint(X509 *cert, Fingerprint::Type type)
unsigned char digest[EVP_MAX_MD_SIZE]; unsigned char digest[EVP_MAX_MD_SIZE];
unsigned int digestLength = 0; unsigned int digestLength = 0;
int result = X509_digest(cert, digestForType(type), digest, &digestLength);
if (result <= 0) { if (int result = X509_digest(cert, digestForType(type), digest, &digestLength); result <= 0) {
throw std::runtime_error("failed to calculate fingerprint, digest result: " + std::to_string(result)); throw std::runtime_error("failed to calculate fingerprint, digest result: " + std::to_string(result));
} }

View file

@ -77,8 +77,7 @@ void SocketMultiplexer::addSocket(ISocket *socket, ISocketMultiplexerJob *job)
lockJobList(); lockJobList();
// insert/replace job // insert/replace job
SocketJobMap::iterator i = m_socketJobMap.find(socket); if (SocketJobMap::iterator i = m_socketJobMap.find(socket); i == m_socketJobMap.end()) {
if (i == m_socketJobMap.end()) {
// we *must* put the job at the end so the order of jobs in // we *must* put the job at the end so the order of jobs in
// the list continue to match the order of jobs in pfds in // the list continue to match the order of jobs in pfds in
// serviceThread(). // serviceThread().
@ -86,8 +85,7 @@ void SocketMultiplexer::addSocket(ISocket *socket, ISocketMultiplexerJob *job)
m_update = true; m_update = true;
m_socketJobMap.insert(std::make_pair(socket, j)); m_socketJobMap.insert(std::make_pair(socket, j));
} else { } else {
JobCursor j = i->second; if (JobCursor j = i->second; *j != job) {
if (*j != job) {
delete *j; delete *j;
*j = job; *j = job;
} }
@ -114,8 +112,7 @@ void SocketMultiplexer::removeSocket(ISocket *socket)
// remove job. rather than removing it from the map we put nullptr // remove job. rather than removing it from the map we put nullptr
// in the list instead so the order of jobs in the list continues // in the list instead so the order of jobs in the list continues
// to match the order of jobs in pfds in serviceThread(). // to match the order of jobs in pfds in serviceThread().
SocketJobMap::iterator i = m_socketJobMap.find(socket); if (SocketJobMap::iterator i = m_socketJobMap.find(socket); i != m_socketJobMap.end()) {
if (i != m_socketJobMap.end()) {
if (*(i->second) != nullptr) { if (*(i->second) != nullptr) {
delete *(i->second); delete *(i->second);
*(i->second) = nullptr; *(i->second) = nullptr;
@ -157,8 +154,7 @@ void SocketMultiplexer::serviceThread(void *)
JobCursor cursor = newCursor(); JobCursor cursor = newCursor();
JobCursor jobCursor = nextCursor(cursor); JobCursor jobCursor = nextCursor(cursor);
while (jobCursor != m_socketJobs.end()) { while (jobCursor != m_socketJobs.end()) {
ISocketMultiplexerJob *job = *jobCursor; if (ISocketMultiplexerJob *job = *jobCursor; job) {
if (job != nullptr) {
pfd.m_socket = job->getSocket(); pfd.m_socket = job->getSocket();
pfd.m_events = 0; pfd.m_events = 0;
if (job->isReadable()) { if (job->isReadable()) {
@ -203,10 +199,9 @@ void SocketMultiplexer::serviceThread(void *)
// run job // run job
ISocketMultiplexerJob *job = *jobCursor; ISocketMultiplexerJob *job = *jobCursor;
ISocketMultiplexerJob *newJob = job->run(read, write, error);
// save job, if different // save job, if different
if (newJob != job) { if (ISocketMultiplexerJob *newJob = job->run(read, write, error); newJob != job) {
Lock lock(m_mutex); Lock lock(m_mutex);
delete job; delete job;
*jobCursor = newJob; *jobCursor = newJob;

View file

@ -22,8 +22,7 @@ void showCipherStackDesc(STACK_OF(SSL_CIPHER) * stack)
SSL_CIPHER_description(cipher, msg, sizeof(msg)); SSL_CIPHER_description(cipher, msg, sizeof(msg));
// SSL puts a newline in the description // SSL puts a newline in the description
auto pos = strnlen(msg, sizeof(msg)) - 1; if (auto pos = strnlen(msg, sizeof(msg)) - 1; msg[pos] == '\n') {
if (msg[pos] == '\n') {
msg[pos] = '\0'; msg[pos] = '\0';
} }

View file

@ -122,8 +122,7 @@ uint32_t TCPSocket::read(void *buffer, uint32_t n)
{ {
// copy data directly from our input buffer // copy data directly from our input buffer
Lock lock(&m_mutex); Lock lock(&m_mutex);
uint32_t size = m_inputBuffer.getSize(); if (uint32_t size = m_inputBuffer.getSize(); n > size) {
if (n > size) {
n = size; n = size;
} }
if (buffer != nullptr && n != 0) { if (buffer != nullptr && n != 0) {

View file

@ -62,8 +62,7 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
int timeout = (timeout_in_ms < 0.0) ? -1 : static_cast<int>(1000.0 * timeout_in_ms); int timeout = (timeout_in_ms < 0.0) ? -1 : static_cast<int>(1000.0 * timeout_in_ms);
int retval = poll(pfds, POLLFD_COUNT, timeout); if (int retval = poll(pfds, POLLFD_COUNT, timeout); retval > 0) {
if (retval > 0) {
if (pfds[EIFD].revents & POLLIN) { if (pfds[EIFD].revents & POLLIN) {
std::lock_guard lock(mutex_); std::lock_guard lock(mutex_);

View file

@ -50,9 +50,8 @@ void EiKeyState::init(int fd, size_t len)
{ {
auto buffer = std::make_unique<char[]>(len + 1); auto buffer = std::make_unique<char[]>(len + 1);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
auto sz = read(fd, buffer.get(), len);
if ((size_t)sz < len) { if (auto sz = read(fd, buffer.get(), len); (size_t)sz < len) {
LOG_WARN("failed to create xkb context: %s", strerror(errno)); LOG_WARN("failed to create xkb context: %s", strerror(errno));
return; return;
} }
@ -143,9 +142,8 @@ void EiKeyState::assign_generated_modifiers(std::uint32_t keycode, deskflow::Key
{ {
std::uint32_t mods_generates = 0; std::uint32_t mods_generates = 0;
auto state = xkb_state_new(xkb_keymap_); auto state = xkb_state_new(xkb_keymap_);
enum xkb_state_component changed = xkb_state_update_key(state, keycode, XKB_KEY_DOWN);
if (changed) { if (enum xkb_state_component changed = xkb_state_update_key(state, keycode, XKB_KEY_DOWN); changed) {
for (xkb_mod_index_t m = 0; m < xkb_keymap_num_mods(xkb_keymap_); m++) { for (xkb_mod_index_t m = 0; m < xkb_keymap_num_mods(xkb_keymap_); m++) {
if (xkb_state_mod_index_is_active(state, m, XKB_STATE_MODS_LOCKED)) if (xkb_state_mod_index_is_active(state, m, XKB_STATE_MODS_LOCKED))
item.m_lock = true; item.m_lock = true;

View file

@ -459,8 +459,8 @@ void EiScreen::add_device(struct ei_device *device)
if (!ei_keyboard_ && ei_device_has_capability(device, EI_DEVICE_CAP_KEYBOARD)) { if (!ei_keyboard_ && ei_device_has_capability(device, EI_DEVICE_CAP_KEYBOARD)) {
ei_keyboard_ = ei_device_ref(device); ei_keyboard_ = ei_device_ref(device);
struct ei_keymap *keymap = ei_device_keyboard_get_keymap(device); if (auto keymap = ei_device_keyboard_get_keymap(device);
if (keymap && ei_keymap_get_type(keymap) == EI_KEYMAP_TYPE_XKB) { keymap && ei_keymap_get_type(keymap) == EI_KEYMAP_TYPE_XKB) {
int fd = ei_keymap_get_fd(keymap); int fd = ei_keymap_get_fd(keymap);
size_t len = ei_keymap_get_size(keymap); size_t len = ei_keymap_get_size(keymap);
key_state_->init(fd, len); key_state_->init(fd, len);
@ -516,9 +516,7 @@ void EiScreen::sendEvent(EventTypes type, void *data)
ButtonID EiScreen::map_button_from_evdev(ei_event *event) const ButtonID EiScreen::map_button_from_evdev(ei_event *event) const
{ {
uint32_t button = ei_event_button_get_button(event); switch (ei_event_button_get_button(event)) {
switch (button) {
case 0x110: case 0x110:
return kButtonLeft; return kButtonLeft;
case 0x111: case 0x111:
@ -547,8 +545,7 @@ bool EiScreen::on_hotkey(KeyID keyid, bool is_pressed, KeyModifierMask mask)
// Note: our mask (see on_key_event) only contains some modifiers // Note: our mask (see on_key_event) only contains some modifiers
// but we don't put a limitation on modifiers in the hotkeys. So some // but we don't put a limitation on modifiers in the hotkeys. So some
// key combinations may not work correctly, more effort is needed here. // key combinations may not work correctly, more effort is needed here.
auto id = it->second.find_by_mask(mask); if (auto id = it->second.find_by_mask(mask); id != 0) {
if (id != 0) {
EventTypes type = is_pressed ? EventTypes::PrimaryScreenHotkeyDown : EventTypes::PrimaryScreenHotkeyUp; EventTypes type = is_pressed ? EventTypes::PrimaryScreenHotkeyDown : EventTypes::PrimaryScreenHotkeyUp;
sendEvent(type, HotKeyInfo::alloc(id)); sendEvent(type, HotKeyInfo::alloc(id));
return true; return true;

View file

@ -98,8 +98,7 @@ int PortalInputCapture::fake_eis_fd()
}; };
std::snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); std::snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
auto result = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); if (auto result = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); result != 0) {
if (result != 0) {
LOG_DEBUG("faked eis fd failed: %s", strerror(errno)); LOG_DEBUG("faked eis fd failed: %s", strerror(errno));
} }

View file

@ -83,8 +83,7 @@ void PortalRemoteDesktop::cb_session_started(GObject *object, GAsyncResult *res)
{ {
g_autoptr(GError) error = nullptr; g_autoptr(GError) error = nullptr;
auto session = XDP_SESSION(object); auto session = XDP_SESSION(object);
auto success = xdp_session_start_finish(session, res, &error); if (!xdp_session_start_finish(session, res, &error)) {
if (!success) {
LOG_ERR("failed to start portal remote desktop session, quitting: %s", error->message); LOG_ERR("failed to start portal remote desktop session, quitting: %s", error->message);
g_main_loop_quit(glib_main_loop_); g_main_loop_quit(glib_main_loop_);
events_->addEvent(EventTypes::Quit); events_->addEvent(EventTypes::Quit);

View file

@ -581,8 +581,7 @@ void XWindowsClipboard::motifUnlockClipboard() const
LOG((CLOG_DEBUG1 "unlocked motif clipboard")); LOG((CLOG_DEBUG1 "unlocked motif clipboard"));
// fail if we don't own the lock // fail if we don't own the lock
Window lockOwner = XGetSelectionOwner(m_display, m_atomMotifClipLock); if (Window lockOwner = XGetSelectionOwner(m_display, m_atomMotifClipLock); lockOwner != m_window) {
if (lockOwner != m_window) {
return; return;
} }
@ -606,8 +605,8 @@ bool XWindowsClipboard::motifOwnsClipboard() const
Atom target; Atom target;
int32_t format; int32_t format;
std::string data; std::string data;
Window root = RootWindow(m_display, DefaultScreen(m_display)); if (Window root = RootWindow(m_display, DefaultScreen(m_display));
if (!XWindowsUtil::getWindowProperty(m_display, root, m_atomMotifClipHeader, &data, &target, &format, False)) { !XWindowsUtil::getWindowProperty(m_display, root, m_atomMotifClipHeader, &data, &target, &format, False)) {
return false; return false;
} }

View file

@ -66,10 +66,9 @@ void XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
// clear out the pipe in preparation for waiting. // clear out the pipe in preparation for waiting.
char buf[16]; char buf[16];
ssize_t read_response = read(m_pipefd[0], buf, 15);
// with linux automake, warnings are treated as errors by default // with linux automake, warnings are treated as errors by default
if (read_response < 0) { if (ssize_t read_response = read(m_pipefd[0], buf, 15); read_response < 0) {
// todo: handle read response // todo: handle read response
} }

View file

@ -611,8 +611,7 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
} }
// note half-duplex keys // note half-duplex keys
const XkbBehavior &b = m_xkb->server->behaviors[keycode]; if (const XkbBehavior &b = m_xkb->server->behaviors[keycode]; (b.type & XkbKB_OpMask) == XkbKB_Lock) {
if ((b.type & XkbKB_OpMask) == XkbKB_Lock) {
keyMap.addHalfDuplexButton(item.m_button); keyMap.addHalfDuplexButton(item.m_button);
} }
@ -697,8 +696,8 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
// record the modifier mask for this key. don't bother // record the modifier mask for this key. don't bother
// for keys that change the group. // for keys that change the group.
item.m_generates = 0; item.m_generates = 0;
uint32_t modifierBit = XWindowsUtil::getModifierBitForKeySym(keysym); if (uint32_t modifierBit = XWindowsUtil::getModifierBitForKeySym(keysym);
if (isModifier && modifierBit != kKeyModifierBitNone) { isModifier && modifierBit != kKeyModifierBitNone) {
item.m_generates = (1u << modifierBit); item.m_generates = (1u << modifierBit);
for (int32_t j = 0; j < 8; ++j) { for (int32_t j = 0; j < 8; ++j) {
// skip modifiers this key doesn't generate // skip modifiers this key doesn't generate
@ -819,8 +818,7 @@ int XWindowsKeyState::getEffectiveGroup(KeyCode keycode, int group) const
(void)keycode; (void)keycode;
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
// get effective group for key // get effective group for key
int numGroups = XkbKeyNumGroups(m_xkb, keycode); if (int numGroups = XkbKeyNumGroups(m_xkb, keycode); group >= numGroups) {
if (group >= numGroups) {
unsigned char groupInfo = XkbKeyGroupInfo(m_xkb, keycode); unsigned char groupInfo = XkbKeyGroupInfo(m_xkb, keycode);
switch (XkbOutOfRangeGroupAction(groupInfo)) { switch (XkbOutOfRangeGroupAction(groupInfo)) {
case XkbClampIntoRange: case XkbClampIntoRange:

View file

@ -19,9 +19,7 @@ namespace {
bool sleepInhibitCall(bool state, XWindowsPowerManager::InhibitScreenServices serviceID) bool sleepInhibitCall(bool state, XWindowsPowerManager::InhibitScreenServices serviceID)
{ {
std::string error; if (std::string error; !XWindowsPowerManager::inhibitScreenCall(serviceID, state, error)) {
if (!XWindowsPowerManager::inhibitScreenCall(serviceID, state, error)) {
LOG((CLOG_DEBUG "dbus inhibit error %s", error.c_str())); LOG((CLOG_DEBUG "dbus inhibit error %s", error.c_str()));
return false; return false;
} }

View file

@ -282,9 +282,8 @@ void XWindowsScreen::enter()
// actually cause physical hardware input to trigger it // actually cause physical hardware input to trigger it
int dummy; int dummy;
CARD16 powerlevel; CARD16 powerlevel;
BOOL enabled; if (BOOL enabled; DPMSQueryExtension(m_display, &dummy, &dummy) && DPMSCapable(m_display) &&
if (DPMSQueryExtension(m_display, &dummy, &dummy) && DPMSCapable(m_display) && DPMSInfo(m_display, &powerlevel, &enabled)) {
DPMSInfo(m_display, &powerlevel, &enabled)) {
if (enabled && powerlevel != DPMSModeOn) if (enabled && powerlevel != DPMSModeOn)
DPMSForceLevel(m_display, DPMSModeOn); DPMSForceLevel(m_display, DPMSModeOn);
} }
@ -591,8 +590,7 @@ uint32_t XWindowsScreen::registerHotKey(KeyID key, KeyModifierMask mask)
// skip with error if we can't map remaining modifiers // skip with error if we can't map remaining modifiers
unsigned int modifiers2; unsigned int modifiers2;
KeyModifierMask mask2 = (mask & ~s_hotKeyModifiers[j]); if (KeyModifierMask mask2 = (mask & ~s_hotKeyModifiers[j]); !m_keyState->mapModifiersToX(mask2, modifiers2)) {
if (!m_keyState->mapModifiersToX(mask2, modifiers2)) {
err = true; err = true;
continue; continue;
} }
@ -769,8 +767,8 @@ bool XWindowsScreen::isAnyMouseButtonDown(uint32_t &buttonID) const
// query the pointer to get the button state // query the pointer to get the button state
Window root, window; Window root, window;
int xRoot, yRoot, xWindow, yWindow; int xRoot, yRoot, xWindow, yWindow;
unsigned int state; if (unsigned int state;
if (XQueryPointer(m_display, m_root, &root, &window, &xRoot, &yRoot, &xWindow, &yWindow, &state)) { XQueryPointer(m_display, m_root, &root, &window, &xRoot, &yRoot, &xWindow, &yWindow, &state)) {
return ((state & (Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask)) != 0); return ((state & (Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask)) != 0);
} }
@ -1566,9 +1564,8 @@ void XWindowsScreen::onMouseMove(const XMotionEvent &xmotion)
// pixel) but the latter is a PITA. to work around // pixel) but the latter is a PITA. to work around
// it we only warp when the mouse has moved more // it we only warp when the mouse has moved more
// than s_size pixels from the center. // than s_size pixels from the center.
static const int32_t s_size = 32; if (static const int32_t s_size = 32; xmotion.x_root - m_xCenter < -s_size || xmotion.x_root - m_xCenter > s_size ||
if (xmotion.x_root - m_xCenter < -s_size || xmotion.x_root - m_xCenter > s_size || xmotion.y_root - m_yCenter < -s_size || xmotion.y_root - m_yCenter > s_size) {
xmotion.y_root - m_yCenter < -s_size || xmotion.y_root - m_yCenter > s_size) {
warpCursorNoFlush(m_xCenter, m_yCenter); warpCursorNoFlush(m_xCenter, m_yCenter);
} }

View file

@ -406,8 +406,8 @@ void XWindowsScreenSaver::watchForXScreenSaver()
// add every child of the root to the list of windows to watch // add every child of the root to the list of windows to watch
Window root = DefaultRootWindow(m_display); Window root = DefaultRootWindow(m_display);
Window rw, pw, *cw; Window rw, pw, *cw;
unsigned int nc;
if (XQueryTree(m_display, root, &rw, &pw, &cw, &nc)) { if (unsigned int nc; XQueryTree(m_display, root, &rw, &pw, &cw, &nc)) {
for (unsigned int i = 0; i < nc; ++i) { for (unsigned int i = 0; i < nc; ++i) {
addWatchXScreenSaver(cw[i]); addWatchXScreenSaver(cw[i]);
} }

View file

@ -1748,8 +1748,7 @@ KeyID XWindowsUtil::mapKeySymToKeyID(KeySym k)
default: { default: {
// lookup character in table // lookup character in table
KeySymMap::const_iterator index = s_keySymToUCS4.find(k); if (KeySymMap::const_iterator index = s_keySymToUCS4.find(k); index != s_keySymToUCS4.end()) {
if (index != s_keySymToUCS4.end()) {
return static_cast<KeyID>(index->second); return static_cast<KeyID>(index->second);
} }

View file

@ -180,8 +180,7 @@ void ClientListener::handleUnknownClient(const Event &, void *vclient)
assert(m_newClients.count(unknownClient) == 1); assert(m_newClients.count(unknownClient) == 1);
// get the real client proxy and install it // get the real client proxy and install it
auto client = unknownClient->orphanClientProxy(); if (auto client = unknownClient->orphanClientProxy(); client) {
if (client) {
// handshake was successful // handshake was successful
m_waitingClients.push_back(client); m_waitingClients.push_back(client);
m_events->addEvent(Event(EventTypes::ClientListenerAccepted, this)); m_events->addEvent(Event(EventTypes::ClientListenerAccepted, this));

View file

@ -57,9 +57,7 @@ bool ClientProxy1_6::recvClipboard()
ClipboardID id; ClipboardID id;
uint32_t seq; uint32_t seq;
int r = ClipboardChunk::assemble(getStream(), dataCached, id, seq); if (int r = ClipboardChunk::assemble(getStream(), dataCached, id, seq); r == kStart) {
if (r == kStart) {
size_t size = ClipboardChunk::getExpectedSize(); size_t size = ClipboardChunk::getExpectedSize();
LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size)); LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size));
} else if (r == kFinish) { } else if (r == kFinish) {

View file

@ -213,16 +213,14 @@ void ClientProxyUnknown::handleData(const Event &, void *)
try { try {
// limit the maximum length of the hello // limit the maximum length of the hello
uint32_t n = m_stream->getSize(); if (uint32_t n = m_stream->getSize(); n > kMaxHelloLength) {
if (n > kMaxHelloLength) {
LOG((CLOG_DEBUG1 "hello reply too long")); LOG((CLOG_DEBUG1 "hello reply too long"));
throw XBadClient(); throw XBadClient();
} }
// parse the reply to hello // parse the reply to hello
int16_t major, minor; int16_t major, minor;
std::string protocolName; if (std::string protocolName; !ProtocolUtil::readf(m_stream, kMsgHelloBack, &protocolName, &major, &minor, &name)) {
if (!ProtocolUtil::readf(m_stream, kMsgHelloBack, &protocolName, &major, &minor, &name)) {
throw XBadClient(); throw XBadClient();
} }

View file

@ -1647,8 +1647,7 @@ std::ostream &operator<<(std::ostream &s, const Config &config)
// options section // options section
s << "section: options" << std::endl; s << "section: options" << std::endl;
const Config::ScreenOptions *options = config.getOptions(""); if (const Config::ScreenOptions *options = config.getOptions(""); options && options->size() > 0) {
if (options != nullptr && options->size() > 0) {
for (auto option = options->begin(); option != options->end(); ++option) { for (auto option = options->begin(); option != options->end(); ++option) {
const char *name = Config::getOptionName(option->first); const char *name = Config::getOptionName(option->first);
std::string value = Config::getOptionValue(option->first, option->second); std::string value = Config::getOptionValue(option->first, option->second);

View file

@ -73,8 +73,7 @@ InputFilter::EFilterStatus InputFilter::KeystrokeCondition::match(const Event &e
EFilterStatus status; EFilterStatus status;
// check for hotkey events // check for hotkey events
EventTypes type = event.getType(); if (EventTypes type = event.getType(); type == EventTypes::PrimaryScreenHotkeyDown) {
if (type == EventTypes::PrimaryScreenHotkeyDown) {
status = kActivate; status = kActivate;
} else if (type == EventTypes::PrimaryScreenHotkeyUp) { } else if (type == EventTypes::PrimaryScreenHotkeyUp) {
status = kDeactivate; status = kDeactivate;
@ -83,8 +82,7 @@ InputFilter::EFilterStatus InputFilter::KeystrokeCondition::match(const Event &e
} }
// check if it's our hotkey // check if it's our hotkey
auto *kinfo = static_cast<IPlatformScreen::HotKeyInfo *>(event.getData()); if (auto *kinfo = static_cast<IPlatformScreen::HotKeyInfo *>(event.getData()); kinfo->m_id != m_id) {
if (kinfo->m_id != m_id) {
return kNoMatch; return kNoMatch;
} }
@ -150,8 +148,7 @@ InputFilter::EFilterStatus InputFilter::MouseButtonCondition::match(const Event
EFilterStatus status; EFilterStatus status;
// check for hotkey events // check for hotkey events
EventTypes type = event.getType(); if (EventTypes type = event.getType(); type == EventTypes::PrimaryScreenButtonDown) {
if (type == EventTypes::PrimaryScreenButtonDown) {
status = kActivate; status = kActivate;
} else if (type == EventTypes::PrimaryScreenButtonUp) { } else if (type == EventTypes::PrimaryScreenButtonUp) {
status = kDeactivate; status = kDeactivate;
@ -161,8 +158,8 @@ InputFilter::EFilterStatus InputFilter::MouseButtonCondition::match(const Event
// check if it's the right button and modifiers. ignore modifiers // check if it's the right button and modifiers. ignore modifiers
// that cannot be combined with a mouse button. // that cannot be combined with a mouse button.
auto *minfo = static_cast<IPlatformScreen::ButtonInfo *>(event.getData()); if (auto *minfo = static_cast<IPlatformScreen::ButtonInfo *>(event.getData());
if (minfo->m_button != m_button || (minfo->m_mask & ~s_ignoreMask) != m_mask) { minfo->m_button != m_button || (minfo->m_mask & ~s_ignoreMask) != m_mask) {
return kNoMatch; return kNoMatch;
} }

View file

@ -599,8 +599,7 @@ BaseClientProxy *Server::getNeighbor(BaseClientProxy *src, EDirection dir, int32
// look up neighbor cell. if the screen is connected and // look up neighbor cell. if the screen is connected and
// ready then we can stop. // ready then we can stop.
ClientList::const_iterator index = m_clients.find(dstName); if (ClientList::const_iterator index = m_clients.find(dstName); index != m_clients.end()) {
if (index != m_clients.end()) {
LOG((CLOG_DEBUG2 "\"%s\" is on %s of \"%s\" at %f", dstName.c_str(), Config::dirName(dir), srcName.c_str(), t)); LOG((CLOG_DEBUG2 "\"%s\" is on %s of \"%s\" at %f", dstName.c_str(), Config::dirName(dir), srcName.c_str(), t));
mapToPixel(index->second, dir, tTmp, x, y); mapToPixel(index->second, dir, tTmp, x, y);
return index->second; return index->second;
@ -843,9 +842,8 @@ bool Server::isSwitchOkay(
} }
// check for optional needed modifiers // check for optional needed modifiers
KeyModifierMask mods = this->m_primaryClient->getToggleMask(); if (KeyModifierMask mods = this->m_primaryClient->getToggleMask();
!preventSwitch && ((this->m_switchNeedsShift && ((mods & KeyModifierShift) != KeyModifierShift)) ||
if (!preventSwitch && ((this->m_switchNeedsShift && ((mods & KeyModifierShift) != KeyModifierShift)) ||
(this->m_switchNeedsControl && ((mods & KeyModifierControl) != KeyModifierControl)) || (this->m_switchNeedsControl && ((mods & KeyModifierControl) != KeyModifierControl)) ||
(this->m_switchNeedsAlt && ((mods & KeyModifierAlt) != KeyModifierAlt)))) { (this->m_switchNeedsAlt && ((mods & KeyModifierAlt) != KeyModifierAlt)))) {
LOG((CLOG_DEBUG1 "need modifiers to switch")); LOG((CLOG_DEBUG1 "need modifiers to switch"));
@ -1687,8 +1685,7 @@ bool Server::onMouseMovePrimary(int32_t x, int32_t y)
void Server::onMouseMoveSecondary(int32_t dx, int32_t dy) void Server::onMouseMoveSecondary(int32_t dx, int32_t dy)
{ {
LOG((CLOG_DEBUG2 "onMouseMoveSecondary initial %+d,%+d", dx, dy)); LOG((CLOG_DEBUG2 "onMouseMoveSecondary initial %+d,%+d", dx, dy));
const char *envVal = std::getenv("DESKFLOW_MOUSE_ADJUSTMENT"); if (const char *envVal = std::getenv("DESKFLOW_MOUSE_ADJUSTMENT"); envVal) {
if (envVal != nullptr) {
try { try {
double multiplier = std::stod(envVal); // Convert to double double multiplier = std::stod(envVal); // Convert to double
auto adjustedDx = static_cast<int32_t>(std::round(dx * multiplier)); // Apply multiplier and round auto adjustedDx = static_cast<int32_t>(std::round(dx * multiplier)); // Apply multiplier and round
@ -2004,8 +2001,7 @@ void Server::removeOldClient(BaseClientProxy *client)
void Server::forceLeaveClient(BaseClientProxy *client) void Server::forceLeaveClient(BaseClientProxy *client)
{ {
BaseClientProxy *active = (m_activeSaver != nullptr) ? m_activeSaver : m_active; if (BaseClientProxy *active = (m_activeSaver != nullptr) ? m_activeSaver : m_active; active == client) {
if (active == client) {
// record new position (center of primary screen) // record new position (center of primary screen)
m_primaryClient->getCursorCenter(m_x, m_y); m_primaryClient->getCursorCenter(m_x, m_y);