diff -Nru ckb-next-0.5.0-15/CMakeLists.txt ckb-next-0.5.0-17/CMakeLists.txt --- ckb-next-0.5.0-15/CMakeLists.txt 2022-06-30 21:28:10.000000000 +0000 +++ ckb-next-0.5.0-17/CMakeLists.txt 2022-07-04 11:00:03.000000000 +0000 @@ -65,7 +65,7 @@ # Get more precise version from git, fallback on release include(CkbNextDetermineVersion) find_package(Git) -set(ckb-next_VERSION "0.5.0-15-g1e1dc3e") +set(ckb-next_VERSION "0.5.0-17-g5452fc5") find_package(Sanitizers) diff -Nru ckb-next-0.5.0-15/debian/changelog ckb-next-0.5.0-17/debian/changelog --- ckb-next-0.5.0-15/debian/changelog 2022-06-30 21:28:25.000000000 +0000 +++ ckb-next-0.5.0-17/debian/changelog 2022-07-04 11:00:18.000000000 +0000 @@ -1,3 +1,9 @@ +ckb-next (0.5.0-17-g5452fc5~impish) impish; urgency=low + + * 0.5.0-17-g5452fc5 git upstream + + -- Tasos Sahanidis Mon, 04 Jul 2022 14:00:18 +0300 + ckb-next (0.5.0-15-g1e1dc3e~impish) impish; urgency=low * 0.5.0-15-g1e1dc3e git upstream diff -Nru ckb-next-0.5.0-15/src/daemon/firmware.c ckb-next-0.5.0-17/src/daemon/firmware.c --- ckb-next-0.5.0-15/src/daemon/firmware.c 2022-06-30 21:28:10.000000000 +0000 +++ ckb-next-0.5.0-17/src/daemon/firmware.c 2022-07-04 11:00:03.000000000 +0000 @@ -74,20 +74,22 @@ // Set firmware version // Don't overwrite it if it's 0 - if(version) + if(version){ kb->fwversion = version; - else - kb->needs_fw_update = true; - kb->bldversion = bootloader; - // Physical layout detection. - if (kb->layout == LAYOUT_UNKNOWN) { - kb->layout = in_pkt[23] + 1; - if (kb->layout > LAYOUT_DUBEOLSIK) { - ckb_warn("Got unknown physical layout byte value %d, please file a bug report mentioning your keyboard's physical layout", in_pkt[23]); - kb->layout = LAYOUT_UNKNOWN; + // Physical layout detection. + if (kb->layout == LAYOUT_UNKNOWN) { + kb->layout = in_pkt[23] + 1; + if (kb->layout > LAYOUT_DUBEOLSIK) { + ckb_warn("Got unknown physical layout byte value %d, please file a bug report mentioning your keyboard's physical layout", in_pkt[23]); + kb->layout = LAYOUT_UNKNOWN; + } } + } else { + kb->needs_fw_update = true; } + kb->bldversion = bootloader; + // Wireless requires extra handshake packets. if(IS_WIRELESS_DEV(kb)){ uchar wireless_pkt[5][MSG_SIZE] = { @@ -123,7 +125,8 @@ kb->features &= ~(FEAT_HWLOAD | FEAT_FWUPDATE); } } else if (in_pkt[1] == 0) { - ckb_warn("Device responded with 0e00 to 0e01 request"); // This happens when we're in bootloader mode + // This happens when we're in bootloader mode, but not on all devices + ckb_warn("Device responded with 0e00 to 0e01 request"); kb->bldversion = kb->fwversion; kb->needs_fw_update = true; } diff -Nru ckb-next-0.5.0-15/src/daemon/keymap.c ckb-next-0.5.0-17/src/daemon/keymap.c --- ckb-next-0.5.0-15/src/daemon/keymap.c 2022-04-06 19:09:54.000000000 +0000 +++ ckb-next-0.5.0-17/src/daemon/keymap.c 2022-07-04 11:00:03.000000000 +0000 @@ -566,6 +566,29 @@ } } +// We just need the first few buttons only, so realistically it doesn't matter +#define BUTTON_BLD_COUNT 5 + +static inline void hid_mouse_bld_translate(usbinput* input, int length, const unsigned char* urbinput){ + if(length < 4){ + ckb_err("Invalid length %d", length); + return; + } + // Byte 0 = mouse buttons (bitfield) + for(int bit = 0; bit < BUTTON_BLD_COUNT; bit++){ + if(urbinput[0] & (1 << bit)) + SET_KEYBIT(input->keys, MOUSE_BUTTON_FIRST + bit); + else + CLEAR_KEYBIT(input->keys, MOUSE_BUTTON_FIRST + bit); + } + // Bytes 1 - 2: movement + input->rel_x += (signed char)urbinput[1]; + input->rel_y += (signed char)urbinput[2]; + // Byte 3: wheel + input->whl_rel_y = (signed char)urbinput[3]; +} + + void process_input_urb(void* context, unsigned char* buffer, int urblen, ushort ep){ if(!urblen) return; @@ -666,7 +689,12 @@ hid_mouse_translate(&targetkb->input, urblen, buffer); } } else if(firstbyte == MOUSE_IN) { - hid_mouse_translate(&kb->input, urblen, buffer + 1); + // If we're in bootloader mode, parse the simplified reports + // This is only tested against an M65 with bld version 3 + if(kb->needs_fw_update) + hid_mouse_bld_translate(&kb->input, urblen - 1, buffer + 1); + else + hid_mouse_translate(&kb->input, urblen - 1, buffer + 1); } else if(firstbyte == CORSAIR_IN) { // Corsair Mouse Input corsair_mousecopy(kb->input.keys, buffer); } else if(firstbyte == 0x05 && urblen == 21) { // Seems to be on the Ironclaw RGB only @@ -756,7 +784,7 @@ int bytelen = (legacy ? 14 : 19); int start = !legacy; // Legacy packets start from 0x00, other ones start from 0x01 if(length < start + bytelen + 1){ - ckb_err("Invalid length %d in handle_nkro_key_input() legacy %d", length, legacy); + ckb_err("Invalid length %d legacy %d", length, legacy); return; } @@ -876,7 +904,11 @@ #define BUTTON_HID_COUNT 5 void hid_mouse_translate(usbinput* input, int length, const unsigned char* urbinput){ - // Byte 1 = mouse buttons (bitfield) + if(length < 9){ + ckb_err("Invalid length %d", length); + return; + } + // Byte 0 = mouse buttons (bitfield) for(int bit = 0; bit < BUTTON_HID_COUNT; bit++){ if(urbinput[0] & (1 << bit)) SET_KEYBIT(input->keys, MOUSE_BUTTON_FIRST + bit); @@ -887,7 +919,7 @@ input->rel_x += (urbinput[5] << 8) | urbinput[4]; input->rel_y += (urbinput[7] << 8) | urbinput[6]; // Byte 9: wheel - input->whl_rel_y = (char)urbinput[8]; + input->whl_rel_y = (signed char)urbinput[8]; } void corsair_mousecopy(unsigned char* kbinput, const unsigned char* urbinput){ @@ -932,7 +964,7 @@ kbinput->rel_x += (urbinput[3] << 8) | urbinput[2]; kbinput->rel_y += (urbinput[5] << 8) | urbinput[4]; - kbinput->whl_rel_y = (char)urbinput[6]; + kbinput->whl_rel_y = (signed char)urbinput[6]; } #define BRAGI_MOUSE_BUTTONS 16 diff -Nru ckb-next-0.5.0-15/src/gui/main.cpp ckb-next-0.5.0-17/src/gui/main.cpp --- ckb-next-0.5.0-15/src/gui/main.cpp 2021-02-02 23:37:49.000000000 +0000 +++ ckb-next-0.5.0-17/src/gui/main.cpp 2022-07-04 11:00:03.000000000 +0000 @@ -37,6 +37,7 @@ }; bool startDelay = false; +bool silent = false; /** * parseCommandLine - Setup options and parse command line arguments. @@ -72,13 +73,18 @@ parser.addOption(switchToModeOption); QCommandLineOption delayOption(QStringList() << "d" << "delay", QObject::tr("Delays application start for 5 seconds")); + QCommandLineOption silentOption(QStringList() << "s" << "silent", QObject::tr("Disables the daemon not running popup")); + // Sigh #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) delayOption.setFlags(QCommandLineOption::HiddenFromHelp); + silentOption.setFlags(QCommandLineOption::HiddenFromHelp); #elif QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) delayOption.setHidden(true); + silentOption.setHidden(true); #endif parser.addOption(delayOption); + parser.addOption(silentOption); /* parse arguments */ if (!parser.parse(QCoreApplication::arguments())) { @@ -102,6 +108,10 @@ startDelay = true; } + if(parser.isSet(silentOption)) { + silent = true; + } + if (parser.isSet(backgroundOption)) { // open application in background return CommandLineBackground; @@ -122,7 +132,7 @@ /* no explicit argument was passed */ return CommandLineOK; -}; +} // Scan shared memory for an active PID static bool pidActive(const QStringList& lines){ @@ -343,7 +353,7 @@ const char* shm_str = "Open"; if(qApp->isSessionRestored()) { - background = 1; + background = true; shm_str = nullptr; } // Check if the parent was Qt Creator. @@ -363,7 +373,7 @@ if(QtCreator) QThread::sleep(1); - MainWindow w; + MainWindow w(silent); if(!background) w.show(); diff -Nru ckb-next-0.5.0-15/src/gui/mainwindow.cpp ckb-next-0.5.0-17/src/gui/mainwindow.cpp --- ckb-next-0.5.0-15/src/gui/mainwindow.cpp 2022-06-12 00:40:50.000000000 +0000 +++ ckb-next-0.5.0-17/src/gui/mainwindow.cpp 2022-07-04 11:00:03.000000000 +0000 @@ -115,7 +115,7 @@ } #endif -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(const bool silent, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -198,7 +198,7 @@ // `.arg(0)` is necessary to interpolate the correct suffix into the path // see `./kbmanager.cpp` for details QFileInfo rootDevPath(devpath.arg(0)); - if (!rootDevPath.exists()) { + if (!(rootDevPath.exists() || silent)) { // set settings widget's status // show the main window (otherwise only the dialog will be visible) // finally show the dialog @@ -518,7 +518,7 @@ qDebug() << "\nSignal" << sig << "caught. Quitting..."; if(sig == SIGHUP){ // Restart, but with a delay - QProcess::startDetached(QCoreApplication::applicationFilePath(), QStringList() << "-b" << "-d"); + QProcess::startDetached(QCoreApplication::applicationFilePath(), QStringList() << "-b" << "-d" << "-s"); } this->quitApp(); sigNotifier->setEnabled(true); diff -Nru ckb-next-0.5.0-15/src/gui/mainwindow.h ckb-next-0.5.0-17/src/gui/mainwindow.h --- ckb-next-0.5.0-15/src/gui/mainwindow.h 2022-06-06 11:00:03.000000000 +0000 +++ ckb-next-0.5.0-17/src/gui/mainwindow.h 2022-07-04 11:00:03.000000000 +0000 @@ -25,7 +25,7 @@ Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(const bool silent, QWidget *parent = nullptr); ~MainWindow(); static MainWindow* mainWindow;