Fix Shadow warnings

This commit is contained in:
Tasos Sahanidis
2020-09-03 02:54:27 +03:00
parent e961dd02df
commit c44bb1c5bd
24 changed files with 147 additions and 148 deletions
+14 -14
View File
@@ -42,15 +42,15 @@ int setactive_kb(usbdevice* kb, int active){
DELAY_MEDIUM(kb);
// Set input mode on the keys. They must be grouped into packets of 60 bytes (+ 4 bytes header)
// Keys are referenced in byte pairs, with the first byte representing the key and the second byte representing the mode.
for(int key = 0; key < N_KEYS_HW; ){
for(int k = 0; k < N_KEYS_HW; ){
int pair;
for(pair = 0; pair < 30 && key < N_KEYS_HW; pair++, key++){
for(pair = 0; pair < 30 && k < N_KEYS_HW; pair++, k++){
// Select both standard and Corsair input. The standard input will be ignored except in BIOS mode.
uchar action = IN_HID | IN_CORSAIR;
// Additionally, make MR activate the MR ring (this is disabled for now, may be back later)
//if(kb->keymap[key].name && !strcmp(kb->keymap[key].name, "mr"))
//if(kb->kmap[k].name && !strcmp(kb->kmap[k].name, "mr"))
// action |= ACT_MR_RING;
msg[1][4 + pair * 2] = key;
msg[1][4 + pair * 2] = k;
msg[1][5 + pair * 2] = action;
}
// Byte 2 = pair count (usually 30, less on final message)
@@ -73,26 +73,26 @@ int setactive_kb(usbdevice* kb, int active){
DELAY_MEDIUM(kb);
#ifdef OS_LINUX
// On OSX the default key mappings are fine. On Linux, the G keys will freeze the keyboard. Set the keyboard entirely to HID input.
for(int key = 0; key < N_KEYS_HW; ){
for(int k = 0; k < N_KEYS_HW; ){
int pair;
for(pair = 0; pair < 30 && key < N_KEYS_HW; pair++, key++){
for(pair = 0; pair < 30 && k < N_KEYS_HW; pair++, k++){
uchar action = IN_HID;
// Enable hardware actions
if(kb->keymap[key].name){
if(!strcmp(kb->keymap[key].name, "mr"))
if(kb->keymap[k].name){
if(!strcmp(kb->keymap[k].name, "mr"))
action = ACT_MR_RING;
else if(!strcmp(kb->keymap[key].name, "m1"))
else if(!strcmp(kb->keymap[k].name, "m1"))
action = ACT_M1;
else if(!strcmp(kb->keymap[key].name, "m2"))
else if(!strcmp(kb->keymap[k].name, "m2"))
action = ACT_M2;
else if(!strcmp(kb->keymap[key].name, "m3"))
else if(!strcmp(kb->keymap[k].name, "m3"))
action = ACT_M3;
else if(!strcmp(kb->keymap[key].name, "light"))
else if(!strcmp(kb->keymap[k].name, "light"))
action = ACT_LIGHT;
else if(!strcmp(kb->keymap[key].name, "lock"))
else if(!strcmp(kb->keymap[k].name, "lock"))
action = ACT_LOCK;
}
msg[1][4 + pair * 2] = key;
msg[1][4 + pair * 2] = k;
msg[1][5 + pair * 2] = action;
}
// Byte 2 = pair count (usually 30, less on final message)
+10 -10
View File
@@ -261,21 +261,21 @@ int loaddpi(usbdevice* kb, dpiset* dpi, lighting* light){
// Get X/Y DPIs
for(int i = 0; i < DPI_COUNT; i++){
uchar data_pkt[MSG_SIZE] = { CMD_GET, FIELD_MOUSE, MOUSE_DPIPROF, 1 };
uchar in_pkt[MSG_SIZE];
data_pkt[2] |= i;
if(!usbrecv(kb, data_pkt, in_pkt))
uchar dpi_pkt[MSG_SIZE] = { CMD_GET, FIELD_MOUSE, MOUSE_DPIPROF, 1 };
uchar dpi_in_pkt[MSG_SIZE];
dpi_pkt[2] |= i;
if(!usbrecv(kb, dpi_pkt, dpi_in_pkt))
return -2;
if(memcmp(in_pkt, data_pkt, 4)){
if(memcmp(dpi_in_pkt, dpi_pkt, 4)){
ckb_err("Bad input header");
return -3;
}
// Copy to profile
dpi->x[i] = (in_pkt[6] << 8) | in_pkt[5];
dpi->y[i] = (in_pkt[8] << 8) | in_pkt[7];
light->r[LED_MOUSE + N_MOUSE_ZONES + i] = in_pkt[9];
light->g[LED_MOUSE + N_MOUSE_ZONES + i] = in_pkt[10];
light->b[LED_MOUSE + N_MOUSE_ZONES + i] = in_pkt[11];
dpi->x[i] = (dpi_in_pkt[6] << 8) | dpi_in_pkt[5];
dpi->y[i] = (dpi_in_pkt[8] << 8) | dpi_in_pkt[7];
light->r[LED_MOUSE + N_MOUSE_ZONES + i] = dpi_in_pkt[9];
light->g[LED_MOUSE + N_MOUSE_ZONES + i] = dpi_in_pkt[10];
light->b[LED_MOUSE + N_MOUSE_ZONES + i] = dpi_in_pkt[11];
}
// Finished. Set SW DPI light to the current hardware level
light->r[LED_MOUSE + 2] = light->r[LED_MOUSE + N_MOUSE_ZONES + dpi->current];
+2 -2
View File
@@ -112,8 +112,8 @@ void os_inputclose(usbdevice* kb){
struct input_event event;
memset(&event, 0, sizeof(event));
event.type = EV_KEY;
for(int key = 0; key < KEY_CNT; key++){
event.code = key;
for(int k = 0; k < KEY_CNT; k++){
event.code = k;
if(write(kb->uinput_kb - 1, &event, sizeof(event)) <= 0)
ckb_warn("uinput write failed: %s", strerror(errno));
if(write(kb->uinput_mouse - 1, &event, sizeof(event)) <= 0)
+3 -3
View File
@@ -167,11 +167,11 @@ char* printrgb(const lighting* light, const usbdevice* kb){
snprintf(buffer + length, BUFFER_LEN - length, length == 0 ? "%s%n" : " %s%n", names[i], &newlen);
length += newlen;
// Look ahead to see if any other keys have this color. If so, print them here as well.
uchar kr = r[i], kg = g[i], kb = b[i];
uchar k_r = r[i], k_g = g[i], k_b = b[i];
for(int j = i + 1; j < N_KEYS_EXTENDED; j++){
if(!names[j][0])
continue;
if(r[j] != kr || g[j] != kg || b[j] != kb)
if(r[j] != k_r || g[j] != k_g || b[j] != k_b)
continue;
snprintf(buffer + length, BUFFER_LEN - length, ",%s%n", names[j], &newlen);
length += newlen;
@@ -179,7 +179,7 @@ char* printrgb(const lighting* light, const usbdevice* kb){
names[j][0] = 0;
}
// Print the color
snprintf(buffer + length, BUFFER_LEN - length, ":%02x%02x%02x%n", kr, kg, kb, &newlen);
snprintf(buffer + length, BUFFER_LEN - length, ":%02x%02x%02x%n", k_r, k_g, k_b, &newlen);
length += newlen;
}
return buffer;
+4 -4
View File
@@ -186,8 +186,8 @@ bool AnimScript::load(){
// Don't allow predefined params
if(name == "trigger" || name == "kptrigger" || name == "kpmode" || name == "duration" || name == "delay" || name == "kpdelay" || name == "repeat" || name == "kprepeat" || name == "stop" || name == "kpstop" || name == "kpmodestop" || name == "kprelease")
continue;
Param param = { type, name, prefix, postfix, def, minimum, maximum };
_info.params.append(param);
Param parsed_param = { type, name, prefix, postfix, def, minimum, maximum };
_info.params.append(parsed_param);
} else if(param == "preset"){
// Add preset
QString name = urlParam(components.at(1));
@@ -198,9 +198,9 @@ bool AnimScript::load(){
QStringList sComponents = setting.split("=");
if(sComponents.count() != 2)
continue;
QString param = sComponents.first().trimmed();
QString sParam = sComponents.first().trimmed();
QString value = urlParam(sComponents.last());
preset[param] = value;
preset[sParam] = value;
}
// If the preset contains a duration, set the repeat time to the same value
if(preset.contains("duration")){
+1 -1
View File
@@ -166,7 +166,7 @@ bool CkbSettingsBase::containsGroup(const QString& group){
QStringList components = group.split("/");
if(components.length() > 1){
// Find sub-group
SGroup group(*this, components[0]);
SGroup g(*this, components[0]);
return containsGroup(QStringList(components.mid(1)).join('/'));
}
return childGroups().contains(group);
+4 -4
View File
@@ -41,15 +41,15 @@ void GradientButton::fromString(const QString& string){
_stops.clear();
// Parse string with sscanf
QByteArray cString = string.toLatin1();
const char* data = cString.data();
const char* dataStr = cString.data();
char pos = -1;
uchar a, r, g, b;
while(1){
int scanned = 0;
signed char newpos;
if(sscanf(data, "%hhd:%2hhx%2hhx%2hhx%2hhx%n", &newpos, &a, &r, &g, &b, &scanned) != 5)
if(sscanf(dataStr, "%hhd:%2hhx%2hhx%2hhx%2hhx%n", &newpos, &a, &r, &g, &b, &scanned) != 5)
break;
data += scanned;
dataStr += scanned;
// Don't allow stops out-of-order or past 100
if(newpos <= pos || newpos > 100)
break;
@@ -60,7 +60,7 @@ void GradientButton::fromString(const QString& string){
}
if(_stops.count() == 0){
// If nothing was read, try a single ARGB constant.
if(sscanf(data, "%2hhx%2hhx%2hhx%2hhx", &a, &r, &g, &b) == 4){
if(sscanf(dataStr, "%2hhx%2hhx%2hhx%2hhx", &a, &r, &g, &b) == 4){
_stops.append(QGradientStop(0., QColor(r, g, b, a)));
_stops.append(QGradientStop(1., QColor(r, g, b, 0.)));
}
-1
View File
@@ -682,7 +682,6 @@ void Kb::readNotify(QString line){
lightColor = color;
if(key.startsWith("dpi") && key.length() > 3){
// DPI levels go to the KbPerf object instead of KbLight
bool ok = false;
int index = key.mid(3).toInt(&ok);
if(ok)
kbmode->perf()->dpiColor(index, color);
+5 -5
View File
@@ -35,7 +35,7 @@ KbAnim::KbAnim(QObject* parent, const KeyMap& map, const QUuid id, CkbSettingsBa
_scriptName = settings.value("ScriptName").toString().trimmed();
_scriptGuid = settings.value("ScriptGuid").toString();
{
SGroup group(settings, "Parameters");
SGroup subgroup(settings, "Parameters");
foreach(const QString& param, settings.childKeys())
_parameters[param.toLower()] = settings.value(param);
}
@@ -374,7 +374,7 @@ void KbAnim::blend(ColorMap& animMap, quint64 timestamp){
// Blend the script's map with the current map
int blendMode = (int)_mode;
blendFunc blend = functions[blendMode];
blendFunc blendF = functions[blendMode];
float fOpacity = _opacity / 255.f; // save some math by pre-dividing the 255 for qAlpha
const ColorMap& scriptMap = _script->colors();
@@ -409,9 +409,9 @@ void KbAnim::blend(ColorMap& animMap, quint64 timestamp){
// Use blend function
float r = qRed(bg) / 255.f, g = qGreen(bg) / 255.f, b = qBlue(bg) / 255.f;
float a = alpha * fOpacity;
r = r * (1.f - a) + blend(r, qRed(fg) / 255.f) * a;
g = g * (1.f - a) + blend(g, qGreen(fg) / 255.f) * a;
b = b * (1.f - a) + blend(b, qBlue(fg) / 255.f) * a;
r = r * (1.f - a) + blendF(r, qRed(fg) / 255.f) * a;
g = g * (1.f - a) + blendF(g, qGreen(fg) / 255.f) * a;
b = b * (1.f - a) + blendF(b, qBlue(fg) / 255.f) * a;
bg = qRgb(round(r * 255.f), round(g * 255.f), round(b * 255.f));
}
}
+4 -4
View File
@@ -149,14 +149,14 @@ void KbAnimWidget::setSelectedKeys(const QStringList& keys){
ui->keyButton->setVisible(true);
}
void KbAnimWidget::on_animList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous){
if(!current)
void KbAnimWidget::on_animList_currentItemChanged(QListWidgetItem* cur, QListWidgetItem* prev){
if(!cur)
setCurrent(0);
else
setCurrent(animations[current->data(Qt::UserRole).toUuid()]);
setCurrent(animations[cur->data(Qt::UserRole).toUuid()]);
}
void KbAnimWidget::on_animList_itemChanged(QListWidgetItem *item){
void KbAnimWidget::on_animList_itemChanged(QListWidgetItem* item){
if(item){
KbAnim* anim = animations[item->data(Qt::UserRole).toUuid()];
if(anim){
+1 -1
View File
@@ -33,7 +33,7 @@ signals:
void didUpdateSelection(QStringList keys);
private slots:
void on_animList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
void on_animList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *prev);
void on_animList_itemChanged(QListWidgetItem *item);
void on_animList_customContextMenuRequested(const QPoint &pos);
void on_nameBox_textEdited(const QString &arg1);
+2 -2
View File
@@ -65,7 +65,7 @@ void KbBind::load(CkbSettingsBase& settings){
bool useReal = settings.value("UseRealNames").toBool();
_bind.clear();
{
SGroup group(settings, "Keys");
SGroup subgroup(settings, "Keys");
foreach(QString key, settings.childKeys()){
QString name = key.toLower();
if(!useReal)
@@ -87,7 +87,7 @@ void KbBind::save(CkbSettingsBase& settings){
// Save key settings
settings.setValue("UseRealNames", true);
{
SGroup group(settings, "Keys");
SGroup subgroup(settings, "Keys");
foreach(QString key, _bind.keys()){
KeyAction* act = _bind.value(key);
if(act && act->value() != KeyAction::defaultAction(key, devParent()->model()))
+8 -8
View File
@@ -65,10 +65,10 @@ void KbLight::color(const QString& key, const QColor& newColor){
void KbLight::color(const QColor& newColor){
QRgb newRgb = newColor.rgb();
QMutableColorMapIterator i(_qColorMap);
while(i.hasNext()){
i.next();
i.value() = newRgb;
QMutableColorMapIterator iter(_qColorMap);
while(iter.hasNext()){
iter.next();
iter.value() = newRgb;
}
_needsSave = true;
// Reset flat map
@@ -431,7 +431,7 @@ void KbLight::load(CkbSettingsBase& settings){
// Load RGB settings
bool useReal = settings.value("UseRealNames").toBool();
{
SGroup group(settings, "Keys");
SGroup subGroup(settings, "Keys");
foreach(QString key, settings.childKeys()){
QString name = key.toLower();
if(!useReal)
@@ -448,7 +448,7 @@ void KbLight::load(CkbSettingsBase& settings){
anim->deleteLater();
_animList.clear();
{
SGroup group(settings, "Animations");
SGroup subGroup(settings, "Animations");
foreach(QString anim, settings.value("List").toStringList()){
QUuid id = anim;
_animList.append(new KbAnim(this, _map, id, settings));
@@ -467,7 +467,7 @@ void KbLight::save(CkbSettingsBase& settings){
settings.setValue("UseRealNames", true);
{
// Save RGB settings
SGroup group(settings, "Keys");
SGroup subGroup(settings, "Keys");
QMutableColorMapIterator i(_qColorMap);
while(i.hasNext()){
i.next();
@@ -476,7 +476,7 @@ void KbLight::save(CkbSettingsBase& settings){
}
{
// Save animations
SGroup group(settings, "Animations");
SGroup subGroup(settings, "Animations");
QStringList aList;
foreach(KbAnim* anim, _animList){
aList << anim->guid().toString().toUpper();
+14 -14
View File
@@ -4,13 +4,13 @@
KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const QString &guid, const QString& modified) :
QObject(parent),
_name("Unnamed"), _id(guid, modified),
_name("Unnamed"), _usbId(guid, modified),
_light(new KbLight(this, keyMap)), _bind(new KbBind(this, parent, keyMap)), _perf(new KbPerf(this)),
_needsSave(true)
{
connect(_light, SIGNAL(updated()), this, SLOT(doUpdate()));
if(_id.guid.isNull())
_id.guid = QUuid::createUuid();
if(_usbId.guid.isNull())
_usbId.guid = QUuid::createUuid();
}
///
@@ -21,7 +21,7 @@ KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const QString &guid, const QStr
/// Constructor to copy an existing Keyboard-Mode KbMode &other
KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const KbMode& other) :
QObject(parent),
_name(other._name), _id(other._id),
_name(other._name), _usbId(other._usbId),
_light(new KbLight(this, keyMap, *other._light)), _bind(new KbBind(this, parent, keyMap, *other._bind)), _perf(new KbPerf(this, *other._perf)),
_needsSave(true)
{
@@ -31,18 +31,18 @@ KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const KbMode& other) :
KbMode::KbMode(Kb* parent, const KeyMap& keyMap, CkbSettingsBase& settings) :
QObject(parent),
_name(settings.value("Name").toString().trimmed()),
_id(settings.value("GUID").toString().trimmed(), settings.value("Modified").toString().trimmed()),
_usbId(settings.value("GUID").toString().trimmed(), settings.value("Modified").toString().trimmed()),
_light(new KbLight(this, keyMap)), _bind(new KbBind(this, parent, keyMap)), _perf(new KbPerf(this)),
_needsSave(false)
{
if(settings.contains("HwModified"))
_id.hwModifiedString(settings.value("HwModified").toString());
_usbId.hwModifiedString(settings.value("HwModified").toString());
else
_id.hwModified = _id.modified;
_usbId.hwModified = _usbId.modified;
connect(_light, SIGNAL(updated()), this, SLOT(doUpdate()));
if(_id.guid.isNull())
_id.guid = QUuid::createUuid();
if(_usbId.guid.isNull())
_usbId.guid = QUuid::createUuid();
if(_name == "")
_name = "Unnamed";
_light->load(settings);
@@ -52,7 +52,7 @@ KbMode::KbMode(Kb* parent, const KeyMap& keyMap, CkbSettingsBase& settings) :
void KbMode::newId(){
_needsSave = true;
_id = UsbId();
_usbId = UsbId();
// Create new IDs for animations
foreach(KbAnim* anim, _light->animList())
anim->newId();
@@ -67,11 +67,11 @@ void KbMode::keyMap(const KeyMap &keyMap){
void KbMode::save(CkbSettingsBase& settings){
if(typeid(settings) == typeid(CkbSettings)){
_needsSave = false;
_id.newModified();
_usbId.newModified();
}
settings.setValue("GUID", _id.guidString());
settings.setValue("Modified", _id.modifiedString());
settings.setValue("HwModified", _id.hwModifiedString());
settings.setValue("GUID", _usbId.guidString());
settings.setValue("Modified", _usbId.modifiedString());
settings.setValue("HwModified", _usbId.hwModifiedString());
settings.setValue("Name", _name);
_light->save(settings);
_bind->save(settings);
+3 -3
View File
@@ -50,8 +50,8 @@ public:
// Mode properties
inline const QString& name() const { return _name; }
inline void name(const QString& newName) { _needsSave = true; _name = newName.trimmed(); if(_name == "") _name = "Unnamed"; }
inline UsbId& id() { return _id; }
inline void id(const UsbId& newId) { _needsSave = true; _id = newId; }
inline UsbId& id() { return _usbId; }
inline void id(const UsbId& newId) { _needsSave = true; _usbId = newId; }
void newId();
// Device key map
@@ -73,7 +73,7 @@ signals:
private:
QString _name;
UsbId _id;
UsbId _usbId;
KbLight* _light;
KbBind* _bind;
+6 -6
View File
@@ -135,7 +135,7 @@ void KbPerf::load(CkbSettingsBase& settings){
SGroup group(settings, "Performance");
// Read DPI settings
{
SGroup group(settings, "DPI");
SGroup subGroup(settings, "DPI");
for(int i = 0; i < DPI_COUNT; i++){
QString iStr = QString::number(i);
QPoint value = settings.value(iStr).toPoint();
@@ -194,10 +194,10 @@ void KbPerf::load(CkbSettingsBase& settings){
}
// Read indicator settings
if(readIndicators){
SGroup group(settings, "Indicators");
SGroup subGroup(settings, "Indicators");
_iOpacity = settings.value("Opacity", 100).toInt() / 100.f;
for(int i = 0; i < I_COUNT; i++){
SGroup group(settings, QString::number(i));
SGroup subGroup_(settings, QString::number(i));
QColor color = settings.value("RGB0").toString();
if(color.isValid())
iColor[i][0] = color;
@@ -229,7 +229,7 @@ void KbPerf::save(CkbSettingsBase& settings){
_needsSave = false;
SGroup group(settings, "Performance");
{
SGroup group(settings, "DPI");
SGroup subGroup(settings, "DPI");
for(int i = 0; i < DPI_COUNT; i++){
QString iStr = QString::number(i);
settings.setValue(iStr, QPoint(dpiX[i], dpiY[i]));
@@ -244,10 +244,10 @@ void KbPerf::save(CkbSettingsBase& settings){
settings.setValue("LiftHeight", _liftHeight);
settings.setValue("AngleSnap", _angleSnap);
{
SGroup group(settings, "Indicators");
SGroup subGroup(settings, "Indicators");
settings.setValue("DPI", _dpiIndicator);
for(int i = 0; i < I_COUNT; i++){
SGroup group(settings, QString::number(i));
SGroup subGroup_(settings, QString::number(i));
settings.setValue("RGB0", iColor[i][0].name(QColor::HexArgb));
settings.setValue("RGB1", iColor[i][1].name(QColor::HexArgb));
if(i == LIGHT)
+14 -14
View File
@@ -3,7 +3,7 @@
#include <typeinfo>
KbProfile::KbProfile(Kb* parent, const KeyMap& keyMap, const KbProfile& other) :
QObject(parent), _currentMode(0), _name(other._name), _id(other._id), _keyMap(keyMap), _needsSave(true)
QObject(parent), _currentMode(0), _name(other._name), _usbId(other._usbId), _keyMap(keyMap), _needsSave(true)
{
foreach(KbMode* mode, other.modes()){
KbMode* newMode = new KbMode(parent, keyMap, *mode);
@@ -14,14 +14,14 @@ KbProfile::KbProfile(Kb* parent, const KeyMap& keyMap, const KbProfile& other) :
}
KbProfile::KbProfile(Kb* parent, const KeyMap& keyMap, const QString& guid, const QString& modified) :
QObject(parent), _currentMode(0), _id(guid, modified.toUInt(0, 16)), _keyMap(keyMap), _needsSave(true)
QObject(parent), _currentMode(0), _usbId(guid, modified.toUInt(0, 16)), _keyMap(keyMap), _needsSave(true)
{
if(_id.guid.isNull())
_id.guid = QUuid::createUuid();
if(_usbId.guid.isNull())
_usbId.guid = QUuid::createUuid();
}
KbProfile::KbProfile(Kb* parent, const KeyMap& keyMap, CkbSettingsBase& settings, const QString& guid) :
QObject(parent), _currentMode(0), _id(guid, 0), _keyMap(keyMap), _needsSave(false)
QObject(parent), _currentMode(0), _usbId(guid, 0), _keyMap(keyMap), _needsSave(false)
{
// Load data from preferences
// If we're importing external profiles, then always read the GUID from the first group.
@@ -31,16 +31,16 @@ KbProfile::KbProfile(Kb* parent, const KeyMap& keyMap, CkbSettingsBase& settings
_name = settings.value("Name").toString().trimmed();
if(_name == "")
_name = "Unnamed";
_id.modifiedString(settings.value("Modified").toString());
_usbId.modifiedString(settings.value("Modified").toString());
if(settings.contains("HwModified"))
_id.hwModifiedString(settings.value("HwModified").toString());
_usbId.hwModifiedString(settings.value("HwModified").toString());
else
_id.hwModified = _id.modified;
_usbId.hwModified = _usbId.modified;
QUuid current = settings.value("CurrentMode").toString().trimmed();
// Load modes
uint count = settings.value("ModeCount").toUInt();
for(uint i = 0; i < count; i++){
SGroup group(settings, QString::number(i));
SGroup subGroup(settings, QString::number(i));
KbMode* mode = new KbMode(parent, _keyMap, settings);
_modes.append(mode);
// Set currentMode to the mode matching the current GUID, or the first mode in case it's not found
@@ -52,20 +52,20 @@ KbProfile::KbProfile(Kb* parent, const KeyMap& keyMap, CkbSettingsBase& settings
void KbProfile::save(CkbSettingsBase& settings){
if(typeid(settings) == typeid(CkbSettings)){
_needsSave = false;
_id.newModified();
_usbId.newModified();
}
// Save data to preferences
SGroup group(settings, id().guidString());
settings.setValue("Name", name());
settings.setValue("Modified", _id.modifiedString());
settings.setValue("HwModified", _id.hwModifiedString());
settings.setValue("Modified", _usbId.modifiedString());
settings.setValue("HwModified", _usbId.hwModifiedString());
if(_currentMode)
settings.setValue("CurrentMode", _currentMode->id().guidString());
// Save modes
uint count = modeCount();
settings.setValue("ModeCount", count);
for(uint i = 0; i < count; i++){
SGroup group(settings, QString::number(i));
SGroup subGroup(settings, QString::number(i));
KbMode* mode = _modes.at(i);
mode->save(settings);
}
@@ -83,7 +83,7 @@ bool KbProfile::needsSave() const {
void KbProfile::newId(){
_needsSave = true;
_id = UsbId();
_usbId = UsbId();
foreach(KbMode* mode, _modes)
mode->newId();
}
+3 -3
View File
@@ -27,8 +27,8 @@ public:
// Profile properties
inline QString name() const { return _name; }
inline void name(const QString& newName) { _needsSave = true; _name = newName.trimmed(); if(_name == "") _name = "Unnamed"; }
inline UsbId& id() { return _id; }
inline void id(const UsbId& newId) { _needsSave = true; _id = newId; }
inline UsbId& id() { return _usbId; }
inline void id(const UsbId& newId) { _needsSave = true; _usbId = newId; }
// Creates a new ID for the profile and all of its modes
void newId();
@@ -57,7 +57,7 @@ public:
private:
KbMode* _currentMode;
QString _name;
UsbId _id;
UsbId _usbId;
KeyMap _keyMap;
ModeList _modes;
bool _needsSave;
+6 -6
View File
@@ -169,11 +169,11 @@ void KbProfileDialog::on_profileList_customContextMenuRequested(const QPoint &po
// Refresh item icons
int count = ui->profileList->count();
for(int i = 0; i < count; i++){
QListWidgetItem* item = ui->profileList->item(i);
if(item->data(NEW_FLAG).toUInt() == 1)
QListWidgetItem* hwitem = ui->profileList->item(i);
if(hwitem->data(NEW_FLAG).toUInt() == 1)
continue;
KbProfile* profile = device->find(item->data(GUID).toUuid());
item->setIcon(QIcon((profile == device->hwProfile()) ? ":/img/icon_profile_hardware.png" : ":/img/icon_profile.png"));
KbProfile* profile = device->find(hwitem->data(GUID).toUuid());
hwitem->setIcon(QIcon((profile == device->hwProfile()) ? ":/img/icon_profile_hardware.png" : ":/img/icon_profile.png"));
}
// No need to repopulate here either
return;
@@ -464,11 +464,11 @@ void KbProfileDialog::on_importButton_clicked(){
QMessageBox::warning(this, tr("Error"), tr("Selected package contains some corrupt profiles.\n\nAn attempt will be made to import as many as possible."), QMessageBox::Ok);
QString profilestrf(profilestr.join("\n• "));
int ret = QMessageBox::information(this, tr("Profile Import"),
int msgret = QMessageBox::information(this, tr("Profile Import"),
tr("The following profiles will be imported.\n\n• ").append(profilestrf),
QMessageBox::Ok,
QMessageBox::Cancel);
if(ret == QMessageBox::Cancel){
if(msgret == QMessageBox::Cancel){
importCleanup(extracted, profileptrs);
return;
}
+16 -16
View File
@@ -307,12 +307,12 @@ void KeyWidget::paintEvent(QPaintEvent*){
decPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
if(_rgbMode){
// Draw key colors (RGB mode)
QHashIterator<QString, Key> k(keyMap);
uint i = -1;
while(k.hasNext()){
k.next();
i++;
const Key& key = k.value();
QHashIterator<QString, Key> keyIter(keyMap);
uint cnt = -1;
while(keyIter.hasNext()){
keyIter.next();
cnt++;
const Key& key = keyIter.value();
if(!key.hasLed)
continue;
float x = key.x + offX - 1.8f;
@@ -338,7 +338,7 @@ void KeyWidget::paintEvent(QPaintEvent*){
color = *inDisplay;
else {
// Otherwise, read from base map
color = _colorMap.value(k.key());
color = _colorMap.value(keyIter.key());
if(_monochrome)
color = monoRgb(qRed(color), qGreen(color), qBlue(color));
}
@@ -404,12 +404,12 @@ void KeyWidget::paintEvent(QPaintEvent*){
font.setBold(true);
font.setPixelSize(5.25f * scale);
QFont font0 = font;
QHashIterator<QString, Key> k(keyMap);
uint i = -1;
while(k.hasNext()){
k.next();
i++;
const Key& key = k.value();
QHashIterator<QString, Key> keyIter(keyMap);
uint cnt = -1;
while(keyIter.hasNext()){
keyIter.next();
cnt++;
const Key& key = keyIter.value();
if(!key.hasScan)
continue;
float x = key.x + offX - key.width / 2.f + 1.f;
@@ -435,9 +435,9 @@ void KeyWidget::paintEvent(QPaintEvent*){
{"rmenu", "▤"}, {"up", "▲"}, {"left", "◀"}, {"down", "▼"}, {"right", "▶"}, {"fn","Fn"},
{"mouse1", ""}, {"mouse2", ""}, {"mouse3", "∙"}, {"dpiup", "▲"}, {"dpidn", "▼"}, {"wheelup", "▲"}, {"wheeldn", "▼"}, {"dpi", "◉"}, {"mouse5", "▲"}, {"mouse4", "▼"}, {"sniper", "⊕"}
};
for(uint k = 0; k < sizeof(names) / sizeof(names[0]); k++){
if(keyName == names[k].keyName){
name = names[k].displayName;
for(uint l = 0; l < sizeof(names) / sizeof(names[0]); l++){
if(keyName == names[l].keyName){
name = names[l].displayName;
break;
}
}
+15 -15
View File
@@ -629,13 +629,13 @@ void KStatusNotifierItemPrivate::registerToDaemon()
QObject::connect(extwatcher, &QDBusPendingCallWatcher::finished, q,
[this, extwatcher] {
extwatcher->deleteLater();
QDBusPendingReply<QString> reply = *extwatcher;
if (reply.isError()) {
QDBusPendingReply<QString> pendingWatcherReply = *extwatcher;
if (pendingWatcherReply.isError()) {
// Failed, fall back
qDebug() << "Failed to get KStatusNotifierWatcher protocol version:" << reply.error();
qDebug() << "Failed to get KStatusNotifierWatcher protocol version:" << pendingWatcherReply.error();
setLegacySystemTrayEnabled(true);
} else {
qDebug() << "Detected non compliant KStatusNotifierWatcher implementation:" << reply.value();
qDebug() << "Detected non compliant KStatusNotifierWatcher implementation:" << pendingWatcherReply.value();
statusNotifierWatcher->RegisterStatusNotifierItem(statusNotifierItemDBus->service());
setLegacySystemTrayEnabled(false);
}
@@ -810,38 +810,38 @@ void KStatusNotifierItemPrivate::minimizeRestore(bool show)
KDbusImageStruct KStatusNotifierItemPrivate::imageToStruct(const QImage &image)
{
KDbusImageStruct icon;
icon.width = image.size().width();
icon.height = image.size().height();
KDbusImageStruct structIcon;
structIcon.width = image.size().width();
structIcon.height = image.size().height();
if (image.format() == QImage::Format_ARGB32) {
icon.data = QByteArray((char *)image.bits(), QIMAGE_SIZE(image));
structIcon.data = QByteArray((char *)image.bits(), QIMAGE_SIZE(image));
} else {
QImage image32 = image.convertToFormat(QImage::Format_ARGB32);
icon.data = QByteArray((char *)image32.bits(), QIMAGE_SIZE(image32));
structIcon.data = QByteArray((char *)image32.bits(), QIMAGE_SIZE(image32));
}
//swap to network byte order if we are little endian
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
quint32 *uintBuf = (quint32 *) icon.data.data();
for (uint i = 0; i < icon.data.size() / sizeof(quint32); ++i) {
quint32 *uintBuf = (quint32 *) structIcon.data.data();
for (uint i = 0; i < structIcon.data.size() / sizeof(quint32); ++i) {
*uintBuf = qToBigEndian(*uintBuf);
++uintBuf;
}
}
return icon;
return structIcon;
}
KDbusImageVector KStatusNotifierItemPrivate::iconToVector(const QIcon &icon)
KDbusImageVector KStatusNotifierItemPrivate::iconToVector(const QIcon &icn)
{
KDbusImageVector iconVector;
QPixmap iconPixmap;
//if an icon exactly that size wasn't found don't add it to the vector
const auto lstSizes = icon.availableSizes();
const auto lstSizes = icn.availableSizes();
for (QSize size : lstSizes) {
iconPixmap = icon.pixmap(size);
iconPixmap = icn.pixmap(size);
iconVector.append(imageToStruct(iconPixmap.toImage()));
}
return iconVector;
@@ -122,7 +122,7 @@ public:
void legacyActivated(QSystemTrayIcon::ActivationReason reason);
KDbusImageStruct imageToStruct(const QImage &image);
KDbusImageVector iconToVector(const QIcon &icon);
KDbusImageVector iconToVector(const QIcon &icn);
bool checkVisibility(QPoint pos, bool perform = true);
static const int s_protocolVersion;
+2 -2
View File
@@ -378,8 +378,8 @@ void MainWindow::closeEvent(QCloseEvent *event){
void MainWindow::timerTick(){
// Check shared memory for changes
if(appShare.lock()){
void* data = appShare.data();
QStringList commands = QString((const char*)data).split("\n");
void* shmData = appShare.data();
QStringList commands = QString((const char*)shmData).split("\n");
// Restore PID, remove all other data
snprintf((char*)appShare.data(), appShare.size(), "PID %ld", (long)getpid());
appShare.unlock();
+9 -9
View File
@@ -23,12 +23,12 @@ void RListWidget::timerTick(){
int c = count();
for(int i = 0; i < c; i++){
QListWidgetItem* itm = item(i);
QVariant data = itm->data(DATA_ROLE);
newItems.append(data);
if(i >= previousItems.count() || data != previousItems[i])
QVariant itmdata = itm->data(DATA_ROLE);
newItems.append(itmdata);
if(i >= previousItems.count() || itmdata != previousItems[i])
reordered = true;
// Re-select the dragged item (if any)
if(data == dragged)
if(itmdata == dragged)
reselect = itm;
}
if(previousItems.length() != newItems.length())
@@ -60,13 +60,13 @@ void RListWidget::rescanItems(){
QList<QVariant> newItems;
int c = count();
for(int i = 0; i < c; i++){
QVariant data = this->item(i)->data(DATA_ROLE);
if(data.isNull()){
QVariant itmdata = this->item(i)->data(DATA_ROLE);
if(itmdata.isNull()){
// Generate the ID for this item if it doesn't already exist
data = QUuid::createUuid();
this->item(i)->setData(DATA_ROLE, data);
itmdata = QUuid::createUuid();
this->item(i)->setData(DATA_ROLE, itmdata);
}
newItems.append(data);
newItems.append(itmdata);
}
previousItems = newItems;
}