chore: use auto or (const auto) where possible

This commit is contained in:
sithlord48 2025-05-19 23:08:59 -04:00 committed by Nick Bolton
parent c224cd4661
commit 52b0c1f061
6 changed files with 40 additions and 40 deletions

View file

@ -88,7 +88,7 @@ void EventQueue::adoptBuffer(IEventQueueBuffer *buffer)
// discard old buffer and old events
delete m_buffer;
for (EventTable::iterator i = m_events.begin(); i != m_events.end(); ++i) {
for (auto i = m_events.begin(); i != m_events.end(); ++i) {
Event::deleteData(i->second);
}
m_events.clear();
@ -200,7 +200,7 @@ void EventQueue::addEventToBuffer(const Event &event)
ArchMutexLock lock(m_mutex);
// store the event's data locally
uint32_t eventID = saveEvent(event);
auto eventID = saveEvent(event);
// add it
if (!m_buffer->addEvent(eventID)) {

View file

@ -403,7 +403,7 @@ std::string Unicode::doUCS4ToUTF8(const uint8_t *data, uint32_t n, bool *errors)
// convert each character
for (; n > 0; --n) {
uint32_t c = decode32(data, byteSwapped);
auto c = decode32(data, byteSwapped);
toUTF8(dst, c, errors);
data += 4;
}
@ -496,7 +496,7 @@ std::string Unicode::doUTF32ToUTF8(const uint8_t *data, uint32_t n, bool *errors
// convert each character
for (; n > 0; --n) {
uint32_t c = decode32(data, byteSwapped);
auto c = decode32(data, byteSwapped);
if (c >= 0x00110000) {
setError(errors);
c = s_replacement;

View file

@ -41,7 +41,7 @@ void KeyMap::swap(KeyMap &x)
m_modifierKeys.swap(x.m_modifierKeys);
m_halfDuplex.swap(x.m_halfDuplex);
m_halfDuplexMods.swap(x.m_halfDuplexMods);
int32_t tmp1 = m_numGroups;
auto tmp1 = m_numGroups;
m_numGroups = x.m_numGroups;
x.m_numGroups = tmp1;
bool tmp2 = m_composeAcrossGroups;
@ -57,7 +57,7 @@ void KeyMap::addKeyEntry(const KeyItem &item)
}
// resize number of groups for key
int32_t numGroups = item.m_group + 1;
auto numGroups = item.m_group + 1;
if (getNumGroups() > numGroups) {
numGroups = getNumGroups();
}
@ -105,7 +105,7 @@ void KeyMap::addKeyAliasEntry(
// find a compatible source, preferably in the same group
for (int32_t gd = 0, n = getNumGroups(); gd < n; ++gd) {
int32_t eg = getEffectiveGroup(group, gd);
auto eg = getEffectiveGroup(group, gd);
const KeyItemList *sourceEntry = findCompatibleKey(sourceID, eg, sourceRequired, sourceSensitive);
if (sourceEntry != nullptr && sourceEntry->size() == 1) {
KeyMap::KeyItem targetItem = sourceEntry->back();
@ -155,7 +155,7 @@ bool KeyMap::addKeyCombinationEntry(KeyID id, int32_t group, const KeyID *keys,
bool found = false;
for (int32_t gd = 0; gd < n && !found; ++gd) {
int32_t eg = (group + gd) % getNumGroups();
const auto eg = (group + gd) % getNumGroups();
const KeyEntryList &entries = groupTable[eg];
for (size_t j = 0; j < entries.size(); ++j) {
if (entries[j].size() == 1) {
@ -301,7 +301,7 @@ void KeyMap::setLanguageData(std::vector<std::string> layouts)
int32_t KeyMap::getLanguageGroupID(int32_t group, const std::string &lang) const
{
int32_t id = group;
auto id = group;
if (auto it = std::find(m_keyboardLayouts.begin(), m_keyboardLayouts.end(), lang); it != m_keyboardLayouts.end()) {
id = static_cast<int>(std::distance(m_keyboardLayouts.begin(), it));
@ -487,9 +487,9 @@ const KeyMap::KeyItem *KeyMap::mapCommandKey(
// find the first key that generates this KeyID
const KeyItem *keyItem = nullptr;
int32_t numGroups = getNumGroups();
const auto numGroups = getNumGroups();
for (int32_t groupOffset = 0; groupOffset < numGroups; ++groupOffset) {
int32_t effectiveGroup = getEffectiveGroup(group, groupOffset);
const auto effectiveGroup = getEffectiveGroup(group, groupOffset);
const KeyEntryList &entryList = keyGroupTable[effectiveGroup];
for (size_t i = 0; i < entryList.size(); ++i) {
if (entryList[i].size() != 1) {
@ -525,7 +525,7 @@ const KeyMap::KeyItem *KeyMap::mapCommandKey(
// make working copy of modifiers
ModifierToKeys newModifiers = activeModifiers;
KeyModifierMask newState = currentState;
int32_t newGroup = group;
auto newGroup = group;
// don't try to change CapsLock
desiredMask = (desiredMask & ~KeyModifierCapsLock) | (currentState & KeyModifierCapsLock);
@ -560,7 +560,7 @@ KeyMap::getKeyItemList(const KeyMap::KeyGroupTable &keyGroupTable, int32_t group
// find best key in any group, starting with the active group
for (int32_t groupOffset = 0; groupOffset < getNumGroups(); ++groupOffset) {
auto effectiveGroup = getEffectiveGroup(group, groupOffset);
const auto effectiveGroup = getEffectiveGroup(group, groupOffset);
auto keyIndex = findBestKey(keyGroupTable[effectiveGroup], desiredMask);
if (keyIndex != -1) {
LOG((CLOG_DEBUG1 "found key in group %d", effectiveGroup));
@ -587,7 +587,7 @@ const KeyMap::KeyItem *KeyMap::mapCharacterKey(
}
// get keys to press for key
auto itemList = getKeyItemList(i->second, getLanguageGroupID(group, lang), desiredMask);
const auto itemList = getKeyItemList(i->second, getLanguageGroupID(group, lang), desiredMask);
if (!itemList || itemList->empty()) {
// no mapping for this keysym
LOG((CLOG_DEBUG1 "no mapping for key %04x", id));
@ -793,7 +793,7 @@ bool KeyMap::keysToRestoreModifiers(
// press wanted keys
for (auto i = desiredModifiers.begin(); i != desiredModifiers.end(); ++i) {
KeyButton button = i->second.m_button;
const KeyButton button = i->second.m_button;
if (button != keyItem.m_button && oldKeys.count(button) == 0) {
EKeystroke type = kKeystrokePress;
if (i->second.m_lock) {
@ -909,8 +909,8 @@ void KeyMap::addKeystrokes(
Keystrokes &keystrokes
) const
{
KeyButton button = keyItem.m_button;
uint32_t data = keyItem.m_client;
const auto button = keyItem.m_button;
const auto data = keyItem.m_client;
switch (type) {
case kKeystrokePress:
keystrokes.push_back(Keystroke(button, true, false, data));

View file

@ -75,7 +75,7 @@ void ProtocolUtil::writef(deskflow::IStream *stream, const char *fmt, ...)
va_list args;
va_start(args, fmt);
uint32_t size = getLength(fmt, args);
auto size = getLength(fmt, args);
va_end(args);
va_start(args, fmt);
vwritef(stream, fmt, size, args);
@ -138,7 +138,7 @@ void ProtocolUtil::vreadf(deskflow::IStream *stream, const char *fmt, va_list ar
if (*fmt == '%') {
// format specifier. determine argument size.
++fmt;
uint32_t len = eatLength(&fmt);
auto len = eatLength(&fmt);
switch (*fmt) {
case 'i': {
void *destination = va_arg(args, void *);
@ -234,7 +234,7 @@ uint32_t ProtocolUtil::getLength(const char *fmt, va_list args)
if (*fmt == '%') {
// format specifier. determine argument size.
++fmt;
uint32_t len = eatLength(&fmt);
auto len = eatLength(&fmt);
switch (*fmt) {
case 'i':
assert(len == 1 || len == 2 || len == 4);
@ -295,7 +295,7 @@ void ProtocolUtil::writef(std::vector<uint8_t> &buffer, const char *fmt, va_list
if (*fmt == '%') {
// format specifier. determine argument size.
++fmt;
uint32_t len = eatLength(&fmt);
auto len = eatLength(&fmt);
switch (*fmt) {
case 'i': {
const uint32_t v = va_arg(args, uint32_t);
@ -475,31 +475,31 @@ uint32_t ProtocolUtil::read4BytesInt(deskflow::IStream *stream)
void ProtocolUtil::readVector1ByteInt(deskflow::IStream *stream, std::vector<uint8_t> &destination)
{
uint32_t size = readVectorSize(stream);
for (uint32_t i = 0; i < size; ++i) {
auto size = readVectorSize(stream);
for (auto i = 0; i < size; ++i) {
destination.push_back(read1ByteInt(stream));
}
}
void ProtocolUtil::readVector2BytesInt(deskflow::IStream *stream, std::vector<uint16_t> &destination)
{
uint32_t size = readVectorSize(stream);
for (uint32_t i = 0; i < size; ++i) {
auto size = readVectorSize(stream);
for (auto i = 0; i < size; ++i) {
destination.push_back(read2BytesInt(stream));
}
}
void ProtocolUtil::readVector4BytesInt(deskflow::IStream *stream, std::vector<uint32_t> &destination)
{
uint32_t size = readVectorSize(stream);
for (uint32_t i = 0; i < size; ++i) {
auto size = readVectorSize(stream);
for (auto i = 0; i < size; ++i) {
destination.push_back(read4BytesInt(stream));
}
}
uint32_t ProtocolUtil::readVectorSize(deskflow::IStream *stream)
{
uint32_t size = read4BytesInt(stream);
auto size = read4BytesInt(stream);
if (size > PROTOCOL_MAX_LIST_LENGTH) {
LOG((CLOG_ERR "readVectorSize: vector length exceeds maximum allowed size: %u", size));

View file

@ -558,7 +558,7 @@ bool EiScreen::on_hotkey(KeyID keyid, bool is_pressed, KeyModifierMask mask)
void EiScreen::on_key_event(ei_event *event)
{
uint32_t keycode = ei_event_keyboard_get_key(event);
auto keycode = ei_event_keyboard_get_key(event);
uint32_t keyval = keycode + 8;
bool pressed = ei_event_keyboard_get_key_is_press(event);
KeyID keyid = key_state_->map_key_from_keyval(keyval);
@ -582,20 +582,20 @@ void EiScreen::on_button_event(ei_event *event)
{
assert(is_primary_);
ButtonID button = map_button_from_evdev(event);
auto buttonID = map_button_from_evdev(event);
bool pressed = ei_event_button_get_is_press(event);
KeyModifierMask mask = key_state_->pollActiveModifiers();
LOG_DEBUG1("event: button %s button=%d mask=0x%x", pressed ? "press" : "release", button, mask);
LOG_DEBUG1("event: button %s button=%d mask=0x%x", pressed ? "press" : "release", buttonID, mask);
if (button == kButtonNone) {
if (buttonID == kButtonNone) {
LOG_DEBUG("event: button not recognized");
return;
}
auto eventType = pressed ? EventTypes::PrimaryScreenButtonDown : EventTypes::PrimaryScreenButtonUp;
sendEvent(eventType, ButtonInfo::alloc(button, mask));
sendEvent(eventType, ButtonInfo::alloc(buttonID, mask));
}
void EiScreen::on_pointer_scroll_event(ei_event *event)
@ -611,8 +611,8 @@ void EiScreen::on_pointer_scroll_event(ei_event *event)
assert(is_primary_);
double dx = ei_event_scroll_get_dx(event);
double dy = ei_event_scroll_get_dy(event);
auto dx = ei_event_scroll_get_dx(event);
auto dy = ei_event_scroll_get_dy(event);
struct ei_device *device = ei_event_get_device(event);
LOG_DEBUG1("event: scroll (%.2f, %.2f)", dx, dy);
@ -655,8 +655,8 @@ void EiScreen::on_pointer_scroll_discrete_event(ei_event *event)
assert(is_primary_);
std::int32_t dx = ei_event_scroll_get_discrete_dx(event);
std::int32_t dy = ei_event_scroll_get_discrete_dy(event);
auto dx = ei_event_scroll_get_discrete_dx(event);
auto dy = ei_event_scroll_get_discrete_dy(event);
LOG_DEBUG1("event: scroll discrete (%d, %d)", dx, dy);
@ -670,8 +670,8 @@ void EiScreen::on_motion_event(ei_event *event)
{
assert(is_primary_);
double dx = ei_event_pointer_get_dx(event);
double dy = ei_event_pointer_get_dy(event);
auto dx = ei_event_pointer_get_dx(event);
auto dy = ei_event_pointer_get_dy(event);
if (is_on_screen_) {
LOG_DEBUG("event: motion on primary x=%i y=%i)", cursor_x_, cursor_y_);

View file

@ -1062,7 +1062,7 @@ void Server::sendOptions(BaseClientProxy *client) const
if (options != nullptr) {
// convert options to a more convenient form for sending
optionsList.reserve(2 * options->size());
for (Config::ScreenOptions::const_iterator index = options->begin(); index != options->end(); ++index) {
for (auto index = options->begin(); index != options->end(); ++index) {
optionsList.push_back(index->first);
optionsList.push_back(static_cast<uint32_t>(index->second));
}