From 96f7b7aa14b3af9cf26b36d21c6ec0c2c0d19453 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 15:42:57 +0600 Subject: [PATCH 01/26] Add Wacom SD-510C tablet emulation --- src/86box.c | 4 +- src/config.c | 8 + src/device.c | 2 +- src/device/CMakeLists.txt | 3 +- src/device/mouse.c | 13 +- src/device/mouse_bus.c | 2 +- src/device/mouse_ps2.c | 2 +- src/device/mouse_serial.c | 2 +- src/device/mouse_wacom_tablet.c | 392 ++++++++++++++++++++++++++++++++ src/include/86box/device.h | 2 +- src/include/86box/mouse.h | 6 + src/include/86box/ui.h | 1 + src/qt/qt_mainwindow.cpp | 31 ++- src/qt/qt_mainwindow.hpp | 7 + src/qt/qt_mainwindow.ui | 24 ++ src/qt/qt_rendererstack.cpp | 52 ++++- src/qt/qt_rendererstack.hpp | 7 + src/qt/qt_ui.cpp | 6 + src/unix/unix.c | 5 + src/win/Makefile.mingw | 1 + src/win/win_ui.c | 6 + 21 files changed, 558 insertions(+), 18 deletions(-) create mode 100644 src/device/mouse_wacom_tablet.c diff --git a/src/86box.c b/src/86box.c index 147233b21..c98b26185 100644 --- a/src/86box.c +++ b/src/86box.c @@ -1118,6 +1118,8 @@ pc_reset_hard_init(void) #endif update_mouse_msg(); + + ui_hard_reset_completed(); } void @@ -1265,7 +1267,7 @@ pc_run(void) } if (title_update) { - mouse_msg_idx = (mouse_type == MOUSE_TYPE_NONE) ? 2 : !!mouse_capture; + mouse_msg_idx = (mouse_type == MOUSE_TYPE_NONE || mouse_mode >= 1) ? 2 : !!mouse_capture; swprintf(temp, sizeof_w(temp), mouse_msg[mouse_msg_idx], fps); #ifdef __APPLE__ /* Needed due to modifying the UI on the non-main thread is a big no-no. */ diff --git a/src/config.c b/src/config.c index 8e2b5c292..49e6afca9 100644 --- a/src/config.c +++ b/src/config.c @@ -650,6 +650,8 @@ load_input_devices(void) } } } + + tablet_tool_type = !!ini_section_get_int(cat, "tablet_tool_type", 1); } /* Load "Sound" section. */ @@ -2287,6 +2289,12 @@ save_input_devices(void) } } + if (tablet_tool_type != 1) { + ini_section_set_int(cat, "tablet_tool_type", tablet_tool_type); + } else { + ini_section_delete_var(cat, "tablet_tool_type"); + } + ini_delete_section_if_empty(config, cat); } diff --git a/src/device.c b/src/device.c index a13825307..95c62624c 100644 --- a/src/device.c +++ b/src/device.c @@ -412,7 +412,7 @@ device_poll(const device_t *d, int x, int y, int z, int b) if (devices[c] != NULL) { if (devices[c] == d) { if (devices[c]->poll) - return (devices[c]->poll(x, y, z, b, device_priv[c])); + return (devices[c]->poll(x, y, z, b, 0, 0, device_priv[c])); } } } diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index 7fd0b20d0..27e854387 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -17,7 +17,8 @@ add_library(dev OBJECT bugger.c cassette.c cartridge.c hasp.c hwm.c hwm_lm75.c h hwm_vt82c686.c ibm_5161.c isamem.c isartc.c ../lpt.c pci_bridge.c postcard.c serial.c clock_ics9xxx.c isapnp.c i2c.c i2c_gpio.c smbus_piix4.c smbus_ali7101.c keyboard.c keyboard_xt.c keyboard_at.c - mouse.c mouse_bus.c mouse_serial.c mouse_ps2.c phoenix_486_jumper.c) + mouse.c mouse_bus.c mouse_serial.c mouse_ps2.c phoenix_486_jumper.c + mouse_wacom_tablet.c) if(ISAMEM_RAMPAGE) target_compile_definitions(dev PRIVATE USE_ISAMEM_RAMPAGE) diff --git a/src/device/mouse.c b/src/device/mouse.c index 422161a83..23046bdbc 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -37,7 +37,14 @@ int mouse_type = 0; int mouse_x, mouse_y, mouse_z, - mouse_buttons; + mouse_buttons, + mouse_mode, + mouse_tablet_in_proximity = 0, + tablet_tool_type = 0; /* 0 = Puck/Cursor, 1 = Pen */ + +double mouse_x_abs, + mouse_y_abs; + static const device_t mouse_none_device = { .name = "None", @@ -80,6 +87,7 @@ static mouse_t mouse_devices[] = { { &mouse_msserial_device }, { &mouse_ltserial_device }, { &mouse_ps2_device }, + { &mouse_wacom_device }, { NULL } // clang-format on }; @@ -146,6 +154,7 @@ mouse_reset(void) /* Clear local data. */ mouse_x = mouse_y = mouse_z = 0; mouse_buttons = 0x00; + mouse_mode = 0; /* If no mouse configured, we're done. */ if (mouse_type == 0) @@ -174,7 +183,7 @@ mouse_process(void) if ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL)) { if (mouse_curr->poll != NULL) - mouse_curr->poll(mouse_x, mouse_y, mouse_z, mouse_buttons, mouse_priv); + mouse_curr->poll(mouse_x, mouse_y, mouse_z, mouse_buttons, mouse_x_abs, mouse_y_abs, mouse_priv); else mouse_dev_poll(mouse_x, mouse_y, mouse_z, mouse_buttons, mouse_priv); diff --git a/src/device/mouse_bus.c b/src/device/mouse_bus.c index 802ae6d45..c0c57b7d0 100644 --- a/src/device/mouse_bus.c +++ b/src/device/mouse_bus.c @@ -449,7 +449,7 @@ ms_write(uint16_t port, uint8_t val, void *priv) /* The emulator calls us with an update on the host mouse device. */ static int -bm_poll(int x, int y, int z, int b, void *priv) +bm_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) { mouse_t *dev = (mouse_t *) priv; int xor ; diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index e7670b2fc..870d9ae5f 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -261,7 +261,7 @@ mouse_reset: } static int -ps2_poll(int x, int y, int z, int b, void *priv) +ps2_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) { mouse_t *dev = (mouse_t *) priv; diff --git a/src/device/mouse_serial.c b/src/device/mouse_serial.c index 2edc342e9..f5e532101 100644 --- a/src/device/mouse_serial.c +++ b/src/device/mouse_serial.c @@ -511,7 +511,7 @@ sermouse_command_timer(void *priv) } static int -sermouse_poll(int x, int y, int z, int b, void *priv) +sermouse_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) { mouse_t *dev = (mouse_t *) priv; diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c new file mode 100644 index 000000000..0aaa4cf53 --- /dev/null +++ b/src/device/mouse_wacom_tablet.c @@ -0,0 +1,392 @@ +#include +#include +#include +#include +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/timer.h> +#include <86box/mouse.h> +#include <86box/serial.h> +#include <86box/plat.h> + +#define FLAG_3BTN 0x20 /* enable 3-button mode */ + +enum wacom_modes +{ + WACOM_MODE_SUPPRESSED = 0, + WACOM_MODE_POINT = 1, + WACOM_MODE_STREAM = 2, + WACOM_MODE_SWITCH = 3, +}; + +enum { + REPORT_PHASE_PREPARE, + REPORT_PHASE_TRANSMIT +}; + +typedef struct { + const char *name; /* name of this device */ + int8_t type, /* type of this device */ + port; + uint8_t flags, but, /* device flags */ + status, format, + data_len, data[64], + data_rec[0x200]; + int abs_x, abs_y, + rel_x, rel_y, + oldb, lastb, b; + + int data_pos, data_rec_pos, mode, transmission_ongoing, transmission_format, interval; + int increment, suppressed_increment; + int transmission_stopped; + int reset; + int transmit_id, transmit_id_pending; + int pressure_mode; + int suppressed, measurement, always_report; + + int last_abs_x, last_abs_y; /* Suppressed/Increment Mode. */ + + double transmit_period, report_period; + double old_tsc; + pc_timer_t command_timer, report_timer; + + serial_t *serial; +} mouse_wacom_t; + +static double +wacom_transmit_period(mouse_wacom_t *dev, int bps, int rps) +{ + double dbps = (double) bps; + double temp = 0.0; + int word_len = 10; + + if (rps == -1) + temp = (double) word_len; + else { + temp = (double) rps; + temp = (9600.0 - (temp * 33.0)); + temp /= rps; + } + temp = (1000000.0 / dbps) * temp; + + return temp; +} + +static void +wacom_reset(mouse_wacom_t* wacom) +{ + wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); + wacom->mode = WACOM_MODE_POINT; + wacom->data_pos = 0; + wacom->transmission_ongoing = 0; + wacom->mode = 0; + wacom->transmission_stopped = 0; + wacom->interval = 0; + wacom->transmit_id = 0; + wacom->format = 0; /* ASCII */ + wacom->measurement = 1; + + mouse_mode = 1; +} + +static void +wacom_callback(struct serial_s *serial, void *priv) +{ + mouse_wacom_t* wacom = (mouse_wacom_t*)priv; + + wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); + timer_stop(&wacom->report_timer); + timer_on_auto(&wacom->report_timer, wacom->transmit_period); +} + +static void +wacom_write(struct serial_s *serial, void *priv, uint8_t data) +{ + mouse_wacom_t* wacom = (mouse_wacom_t*)priv; + static int special_command = 0; + + if (data == '~') { + special_command = 1; + return; + } + if (special_command) { + switch (data) { + case '#': + { + if (!wacom->transmission_ongoing) wacom->transmit_id++; + break; + } + } + special_command = 0; + return; + } + if (data == '$') { + wacom_reset(wacom); + } + if (data == 0x13) { + wacom->transmission_stopped = 1; + pclog("WACOM: transmission stopped\n"); + } + if (data == 0x11) { + wacom->transmission_stopped = 0; + pclog("WACOM: transmission started\n"); + } + wacom->data_rec[wacom->data_rec_pos++] = data; + if (data == '\r') { + wacom->data_rec[wacom->data_rec_pos] = 0; + wacom->data_rec_pos = 0; + + if (!memcmp(wacom->data_rec, "AS", 2)) { + wacom->format = (wacom->data_rec[2] == '1'); + wacom->transmission_ongoing = 0; + } else if (!memcmp(wacom->data_rec, "SR", 2)) { + wacom->mode = WACOM_MODE_STREAM; + wacom->suppressed_increment = 0; + } else if (!memcmp(wacom->data_rec, "IN", 2)) { + sscanf((const char*)wacom->data_rec, "IN%d", &wacom->increment); + } else if (!memcmp(wacom->data_rec, "RE", 2)) { + wacom_reset(wacom); + } else if (!memcmp(wacom->data_rec, "IT", 2)) { + sscanf((const char*)wacom->data_rec, "IT%d", &wacom->interval); + } else if (!memcmp(wacom->data_rec, "DE", 2)) { + sscanf((const char*)wacom->data_rec, "DE%d", &mouse_mode); + mouse_mode = !mouse_mode; + plat_mouse_capture(0); + } else if (!memcmp(wacom->data_rec, "SU", 2)) { + sscanf((const char*)wacom->data_rec, "SU%d", &wacom->suppressed_increment); + } else if (!memcmp(wacom->data_rec, "PH", 2)) { + sscanf((const char*)wacom->data_rec, "PH%d", &wacom->pressure_mode); + } else if (!memcmp(wacom->data_rec, "IC", 2)) { + sscanf((const char*)wacom->data_rec, "IC%d", &wacom->measurement); + } else if (!memcmp(wacom->data_rec, "AL", 2)) { + sscanf((const char*)wacom->data_rec, "AL%d", &wacom->always_report); + } else { + pclog("Unknown command: %s\n", wacom->data_rec); + } + } +} + +static int +wacom_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) +{ + mouse_wacom_t* wacom = (mouse_wacom_t*)priv; + if (abs_x > 1.0l) abs_x = 1.0l; + if (abs_y > 1.0l) abs_y = 1.0l; + if (abs_x < 0.l) abs_x = 0.l; + if (abs_y < 0.l) abs_y = 0.l; + wacom->abs_x = abs_x * (wacom->measurement ? 4566. : 5800.); + wacom->abs_y = abs_y * (wacom->measurement ? 2972. : 3774.); + wacom->rel_x = x; + wacom->rel_y = y; + if (wacom->b != b) wacom->oldb = wacom->b; + wacom->b = b; + return (0); +} + +static int +wacom_switch_off_to_on(int b, int oldb) +{ + if (!(oldb & 0x1) && (b & 1)) return 1; + if (!(oldb & 0x2) && (b & 2)) return 1; + if (!(oldb & 0x4) && (b & 4)) return 1; + + return 0; +} + +static uint8_t +wacom_get_switch(int b) +{ + if (b & 0x4) return 0x23; + if (b & 0x2) return 0x22; + if (b & 0x1) return 0x21; + + return 0x00; +} + +extern double cpuclock; +static void +sermouse_report_timer(void *priv) +{ + mouse_wacom_t* wacom = (mouse_wacom_t*)priv; + uint32_t transmitted = 0; + double milisecond_diff = ((double)(tsc - wacom->old_tsc)) / cpuclock * 1000.0; + int x = (mouse_mode == 0 ? wacom->rel_x : wacom->abs_x), y = (mouse_mode == 0 ? wacom->rel_y : wacom->abs_y); + + timer_on_auto(&wacom->report_timer, wacom->transmit_id ? (wacom->transmit_period / 8.0) : wacom->transmit_period); + if (wacom->transmit_id && !wacom->transmission_ongoing) + goto transmit_prepare; + if (wacom->transmission_ongoing) + goto transmit; + else { + int x_diff = (mouse_mode == 0 ? wacom->rel_x : (wacom->last_abs_x - wacom->abs_x)); + int y_diff = (mouse_mode == 0 ? wacom->rel_y : (wacom->last_abs_y - wacom->abs_y)); + + if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->always_report)) return; + if (milisecond_diff >= (wacom->interval * 5)) { + transmitted = 1; + wacom->old_tsc = tsc; + } else transmitted = 0; + if (!transmitted) + return; + if (wacom->increment && !(x_diff >= wacom->increment || y_diff >= wacom->increment || wacom_switch_off_to_on(wacom->b, wacom->oldb))) + return; + + if (wacom->suppressed_increment && !(x_diff >= wacom->suppressed_increment || y_diff >= wacom->suppressed_increment || (wacom->b != wacom->oldb))) + return; + + switch (wacom->mode) { + case WACOM_MODE_STREAM: + default: + break; + + case WACOM_MODE_POINT: + { + if (!(wacom_switch_off_to_on(wacom->b, wacom->oldb))) + return; + break; + } + + case WACOM_MODE_SWITCH: + { + if (!wacom->b) + return; + + break; + } + } + } + +transmit_prepare: + if (wacom->transmit_id) { + wacom->transmission_format = 0; + wacom->transmission_ongoing = 1; + wacom->data_pos = 0; + memset(wacom->data, 0, sizeof(wacom->data)); + strcat((char*)wacom->data, "~#SD51C V3.2.1.01\r"); + goto transmit; + } + wacom->transmission_ongoing = 1; + wacom->transmission_format = wacom->format; + wacom->data_pos = 0; + wacom->last_abs_x = wacom->abs_x; + wacom->last_abs_y = wacom->abs_y; + wacom->oldb = wacom->b; + if (wacom->format == 1) { + memset(wacom->data, 0, 7); + wacom->data[0] = 0xC0; + wacom->data[6] = wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t)31 : (uint8_t)-31) : wacom_get_switch(wacom->b); + + wacom->data[5] = (y & 0x7F); + wacom->data[4] = ((y & 0x3F80) >> 7) & 0x7F; + wacom->data[3] = (((y & 0xC000) >> 14) & 3); + + wacom->data[2] = (x & 0x7F); + wacom->data[1] = ((x & 0x3F80) >> 7) & 0x7F; + wacom->data[0] |= (((x & 0xC000) >> 14) & 3); + + if (mouse_mode == 0) { + wacom->data[0] |= (!!(x < 0)) << 2; + wacom->data[3] |= (!!(y < 0)) << 2; + } + if (wacom->pressure_mode) { + wacom->data[0] |= 0x10; + wacom->data[6] &= 0x7F; + } + if (tablet_tool_type == 1) { + wacom->data[0] |= 0x20; + } + + if (!mouse_tablet_in_proximity) { + wacom->data[0] &= ~0x40; + } + } else { + wacom->data[0] = 0; + snprintf((char*)wacom->data, sizeof(wacom->data), "*,%05d,%05d,%d\r\n", wacom->abs_x, wacom->abs_y, wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t)-31 : (uint8_t)15) : ((wacom->b & 0x1) ? 0x21 : 0x00)); + } +transmit: + serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); + if ((wacom->transmission_format == 0 && wacom->data[wacom->data_pos] == 0) + || (wacom->transmission_format == 1 && wacom->data_pos == 7)) { + wacom->transmission_ongoing = 0; + wacom->transmit_id = 0; + wacom->data_pos = 0; + wacom->old_tsc = tsc; + } + return; +} + +static void * +wacom_init(const device_t *info) +{ + mouse_wacom_t *dev; + + dev = (mouse_wacom_t *) calloc(1, sizeof(mouse_wacom_t)); + dev->name = info->name; + dev->but = 3; + + dev->port = device_get_config_int("port"); + + dev->serial = serial_attach(dev->port, wacom_callback, wacom_write, dev); + timer_add(&dev->report_timer, sermouse_report_timer, dev, 0); + mouse_set_buttons(dev->but); + + wacom_reset(dev); + + return dev; +} + +static void +wacom_speed_changed(void *priv) +{ + mouse_wacom_t *dev = (mouse_wacom_t *) priv; + + wacom_callback(dev->serial, dev); +} + +static void +wacom_close(void *priv) +{ + mouse_wacom_t *dev = (mouse_wacom_t *) priv; + + /* Detach serial port from the mouse. */ + if (dev && dev->serial && dev->serial->sd) + memset(dev->serial->sd, 0, sizeof(serial_device_t)); + + free(dev); +} + +static const device_config_t wacom_config[] = { + // clang-format off + { + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "COM1", .value = 0 }, + { .description = "COM2", .value = 1 }, + { .description = "COM3", .value = 2 }, + { .description = "COM4", .value = 3 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t mouse_wacom_device = { + .name = "Wacom SD-510C", + .internal_name = "wacom_serial", + .flags = DEVICE_COM, + .local = MOUSE_TYPE_WACOM, + .init = wacom_init, + .close = wacom_close, + .reset = NULL, + { .poll = wacom_poll }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = wacom_config +}; diff --git a/src/include/86box/device.h b/src/include/86box/device.h index ca4e6bdf2..18e2a4455 100644 --- a/src/include/86box/device.h +++ b/src/include/86box/device.h @@ -122,7 +122,7 @@ typedef struct _device_ { void (*reset)(void *priv); union { int (*available)(void); - int (*poll)(int x, int y, int z, int b, void *priv); + int (*poll)(int x, int y, int z, int b, double abs_x, double abs_y, void *priv); void (*register_pci_slot)(int device, int type, int inta, int intb, int intc, int intd, void *priv); }; void (*speed_changed)(void *priv); diff --git a/src/include/86box/mouse.h b/src/include/86box/mouse.h index 434360589..5e56a365e 100644 --- a/src/include/86box/mouse.h +++ b/src/include/86box/mouse.h @@ -34,6 +34,7 @@ #define MOUSE_TYPE_LOGITECH 9 /* Logitech 2-button Serial Mouse */ #define MOUSE_TYPE_LT3BUTTON 10 /* Logitech 3-button Serial Mouse */ #define MOUSE_TYPE_PS2 11 /* PS/2 series Bus Mouse */ +#define MOUSE_TYPE_WACOM 12 /* WACOM tablet */ #define MOUSE_TYPE_ONBOARD 0x80 /* Mouse is an on-board version of one of the above. */ @@ -43,7 +44,11 @@ extern "C" { extern int mouse_type; extern int mouse_x, mouse_y, mouse_z; +extern int mouse_mode; /* 1 = Absolute, 0 = Relative */ +extern int mouse_tablet_in_proximity; +extern double mouse_x_abs, mouse_y_abs; extern int mouse_buttons; +extern int tablet_tool_type; #ifdef EMU_DEVICE_H extern const device_t *mouse_get_device(int mouse); @@ -59,6 +64,7 @@ extern const device_t mouse_mssystems_device; extern const device_t mouse_msserial_device; extern const device_t mouse_ltserial_device; extern const device_t mouse_ps2_device; +extern const device_t mouse_wacom_device; #endif extern void mouse_init(void); diff --git a/src/include/86box/ui.h b/src/include/86box/ui.h index 5eb15a08d..70971ce19 100644 --- a/src/include/86box/ui.h +++ b/src/include/86box/ui.h @@ -61,6 +61,7 @@ extern void ui_check_menu_item(int id, int checked); extern wchar_t *ui_window_title(wchar_t *s); extern void ui_status_update(void); +extern void ui_hard_reset_completed(void); extern void ui_init_monitor(int monitor_index); extern void ui_deinit_monitor(int monitor_index); extern int ui_sb_find_part(int tag); diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 1c2ae6097..f3072706d 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -42,6 +42,7 @@ extern "C" { #include <86box/discord.h> #include <86box/device.h> #include <86box/video.h> +#include <86box/mouse.h> #include <86box/machine.h> #include <86box/vid_ega.h> #include <86box/version.h> @@ -188,6 +189,12 @@ MainWindow::MainWindow(QWidget *parent) vmname.truncate(vmname.size() - 1); this->setWindowTitle(QString("%1 - %2 %3").arg(vmname, EMU_NAME, EMU_VERSION_FULL)); + connect(this, &MainWindow::hardResetCompleted, this, [this]() { + ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); + QApplication::setOverrideCursor(Qt::ArrowCursor); + ui->menuTablet_tool->menuAction()->setVisible(mouse_mode >= 1); + }); + connect(this, &MainWindow::showMessageForNonQtThread, this, &MainWindow::showMessage_, Qt::BlockingQueuedConnection); connect(this, &MainWindow::setTitle, this, [this, toolbar_label](const QString &title) { @@ -622,6 +629,16 @@ MainWindow::MainWindow(QWidget *parent) } }); #endif + + actGroup = new QActionGroup(this); + actGroup->addAction(ui->actionCursor_Puck); + actGroup->addAction(ui->actionPen); + + if (tablet_tool_type == 1) { + ui->actionPen->setChecked(true); + } else { + ui->actionCursor_Puck->setChecked(true); + } } void @@ -1671,7 +1688,6 @@ MainWindow::refreshMediaMenu() { mm->refresh(ui->menuMedia); status->refresh(ui->statusbar); - ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); } void @@ -2411,3 +2427,16 @@ MainWindow::on_actionApply_fullscreen_stretch_mode_when_maximized_triggered(bool device_force_redraw(); config_save(); } + +void MainWindow::on_actionCursor_Puck_triggered() +{ + tablet_tool_type = 0; + config_save(); +} + +void MainWindow::on_actionPen_triggered() +{ + tablet_tool_type = 1; + config_save(); +} + diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 6ad4c9beb..fb05a4588 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -50,6 +50,7 @@ signals: void destroyRendererMonitor(int monitor_index); void initRendererMonitorForNonQtThread(int monitor_index); void destroyRendererMonitorForNonQtThread(int monitor_index); + void hardResetCompleted(); void setTitle(const QString &title); void setFullscreen(bool state); @@ -134,6 +135,12 @@ protected: void closeEvent(QCloseEvent *event) override; void changeEvent(QEvent *event) override; +private slots: + void on_actionPen_triggered(); + +private slots: + void on_actionCursor_Puck_triggered(); + private slots: void on_actionShow_non_primary_monitors_triggered(); diff --git a/src/qt/qt_mainwindow.ui b/src/qt/qt_mainwindow.ui index 6a86b632e..1a00df27a 100644 --- a/src/qt/qt_mainwindow.ui +++ b/src/qt/qt_mainwindow.ui @@ -61,8 +61,16 @@ &Action + + + Tablet tool + + + + + @@ -851,6 +859,22 @@ Apply fullscreen stretch mode when maximized + + + true + + + Cursor/Puck + + + + + true + + + Pen + + diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index d36a88f86..0436112d1 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -58,8 +58,10 @@ double mouse_x_error = 0.0, mouse_y_error = 0.0; } struct mouseinputdata { - atomic_int deltax, deltay, deltaz; - atomic_int mousebuttons; + atomic_int deltax, deltay, deltaz; + atomic_int mousebuttons; + atomic_bool mouse_tablet_in_proximity; + std::atomic x_abs, y_abs; }; static mouseinputdata mousedata; @@ -116,6 +118,7 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index) RendererStack::~RendererStack() { + QApplication::restoreOverrideCursor(); delete ui; } @@ -142,9 +145,12 @@ void RendererStack::mousePoll() { #ifndef __APPLE__ - mouse_x = mousedata.deltax; - mouse_y = mousedata.deltay; - mouse_z = mousedata.deltaz; + mouse_x = mousedata.deltax; + mouse_y = mousedata.deltay; + mouse_z = mousedata.deltaz; + mouse_x_abs = mousedata.x_abs; + mouse_y_abs = mousedata.y_abs; + mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; mouse_buttons = mousedata.mousebuttons; @@ -166,7 +172,7 @@ int ignoreNextMouseEvent = 1; void RendererStack::mouseReleaseEvent(QMouseEvent *event) { - if (this->geometry().contains(event->pos()) && event->button() == Qt::LeftButton && !mouse_capture && (isMouseDown & 1) && (mouse_get_buttons() != 0)) { + if (this->geometry().contains(event->pos()) && event->button() == Qt::LeftButton && !mouse_capture && (isMouseDown & 1) && (mouse_get_buttons() != 0) && mouse_mode == 0) { plat_mouse_capture(1); this->setCursor(Qt::BlankCursor); if (!ignoreNextMouseEvent) @@ -180,7 +186,7 @@ RendererStack::mouseReleaseEvent(QMouseEvent *event) isMouseDown &= ~1; return; } - if (mouse_capture) { + if (mouse_capture || mouse_mode >= 1) { mousedata.mousebuttons &= ~event->button(); } isMouseDown &= ~1; @@ -190,7 +196,7 @@ void RendererStack::mousePressEvent(QMouseEvent *event) { isMouseDown |= 1; - if (mouse_capture) { + if (mouse_capture || mouse_mode >= 1) { mousedata.mousebuttons |= event->button(); } event->accept(); @@ -238,9 +244,26 @@ RendererStack::mouseMoveEvent(QMouseEvent *event) #endif } + +void +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +RendererStack::enterEvent(QEnterEvent *event) +#else +RendererStack::enterEvent(QEvent *event) +#endif +{ + mousedata.mouse_tablet_in_proximity = 1; + + if (mouse_mode == 1) + QApplication::setOverrideCursor(Qt::BlankCursor); +} + void RendererStack::leaveEvent(QEvent *event) { + mousedata.mouse_tablet_in_proximity = 0; + if (mouse_mode == 1) + QApplication::setOverrideCursor(Qt::ArrowCursor); if (QApplication::platformName().contains("wayland")) { event->accept(); return; @@ -501,3 +524,16 @@ RendererStack::changeEvent(QEvent *event) config_save(); } } + +bool +RendererStack::event(QEvent* event) +{ + if (event->type() == QEvent::MouseMove) { + QMouseEvent* mouse_event = (QMouseEvent*)event; + if (mouse_mode >= 1) { + mousedata.x_abs = (mouse_event->localPos().x()) / (long double)width(); + mousedata.y_abs = (mouse_event->localPos().y()) / (long double)height(); + } + } + return QStackedWidget::event(event); +} diff --git a/src/qt/qt_rendererstack.hpp b/src/qt/qt_rendererstack.hpp index baee5ea9f..27e07747c 100644 --- a/src/qt/qt_rendererstack.hpp +++ b/src/qt/qt_rendererstack.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,11 @@ public: void mouseReleaseEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void wheelEvent(QWheelEvent *event) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + void enterEvent(QEnterEvent *event) override; +#else + void enterEvent(QEvent *event) override; +#endif void leaveEvent(QEvent *event) override; void closeEvent(QCloseEvent *event) override; void changeEvent(QEvent *event) override; @@ -45,6 +51,7 @@ public: { event->ignore(); } + bool event(QEvent* event) override; enum class Renderer { Software, diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index a2864f3ea..305ec9ed5 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -74,6 +74,12 @@ ui_window_title(wchar_t *str) return str; } +void +ui_hard_reset_completed() +{ + emit main_window->hardResetCompleted(); +} + extern "C" void qt_blit(int x, int y, int w, int h, int monitor_index) { diff --git a/src/unix/unix.c b/src/unix/unix.c index 296da5e14..04c9de48b 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -1319,3 +1319,8 @@ void ui_sb_mt32lcd(char *str) { } + +void +ui_hard_reset_completed(void) +{ +} diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 040b14aee..a743db40c 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -596,6 +596,7 @@ DEVOBJ := bugger.o cartridge.o cassette.o hasp.o hwm.o hwm_lm75.o hwm_lm78.o hwm mouse.o \ mouse_bus.o \ mouse_serial.o mouse_ps2.o \ + mouse_wacom_tablet.o \ phoenix_486_jumper.o SIOOBJ := sio_acc3221.o sio_ali5123.o \ diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 38d7e161c..0e1ca6700 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -1582,7 +1582,13 @@ void ui_init_monitor(int monitor_index) { } + void ui_deinit_monitor(int monitor_index) { } + +void +ui_hard_reset_completed(void) +{ +} From 6bb26b7f7456398996ab4d2f83ad7843f5656440 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 21:42:35 +0600 Subject: [PATCH 02/26] wacom: Clamp coordinates after conversion --- src/device/mouse_wacom_tablet.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 0aaa4cf53..099f9c5c8 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -170,12 +170,10 @@ static int wacom_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) { mouse_wacom_t* wacom = (mouse_wacom_t*)priv; - if (abs_x > 1.0l) abs_x = 1.0l; - if (abs_y > 1.0l) abs_y = 1.0l; - if (abs_x < 0.l) abs_x = 0.l; - if (abs_y < 0.l) abs_y = 0.l; wacom->abs_x = abs_x * (wacom->measurement ? 4566. : 5800.); wacom->abs_y = abs_y * (wacom->measurement ? 2972. : 3774.); + if (wacom->abs_x > (wacom->measurement ? 4566 : 5800)) wacom->abs_x = (wacom->measurement ? 4566 : 5800); + if (wacom->abs_y > (wacom->measurement ? 2972 : 3774)) wacom->abs_x = (wacom->measurement ? 2972 : 3774); wacom->rel_x = x; wacom->rel_y = y; if (wacom->b != b) wacom->oldb = wacom->b; From b9f8e09db0628bc89cc84d705021e96ccb59e6af Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 21:42:49 +0600 Subject: [PATCH 03/26] Made absolute mouse coordinates work under macOS --- src/qt/macos_event_filter.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/macos_event_filter.mm b/src/qt/macos_event_filter.mm index 6f84beee5..28c0e5de7 100644 --- a/src/qt/macos_event_filter.mm +++ b/src/qt/macos_event_filter.mm @@ -96,6 +96,8 @@ macos_poll_mouse() mouse_x = mousedata.deltax; mouse_y = mousedata.deltay; mouse_z = mousedata.deltaz; + mouse_abs_x = mousedata.x_abs; + mouse_abs_y = mousedata.y_abs; mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; mouse_buttons = mousedata.mousebuttons; } From ef18a27bc92137156b2a82335ef72c121e01d00e Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 21:43:10 +0600 Subject: [PATCH 04/26] Made absolute mouse coordinates work under Windows as well --- src/qt/qt_main.cpp | 1 - src/qt/qt_rendererstack.cpp | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 1ae545227..b162e6abc 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -246,7 +246,6 @@ main(int argc, char *argv[]) auto rawInputFilter = WindowsRawInputFilter::Register(main_window); if (rawInputFilter) { app.installNativeEventFilter(rawInputFilter.get()); - QObject::disconnect(main_window, &MainWindow::pollMouse, 0, 0); QObject::connect(main_window, &MainWindow::pollMouse, (WindowsRawInputFilter *) rawInputFilter.get(), &WindowsRawInputFilter::mousePoll, Qt::DirectConnection); main_window->setSendKeyboardInput(false); } diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 0436112d1..bf9098592 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -144,6 +144,11 @@ qt_mouse_capture(int on) void RendererStack::mousePoll() { +#ifdef Q_OS_WINDOWS + mouse_x_abs = mousedata.x_abs; + mouse_y_abs = mousedata.y_abs; + return; +#endif #ifndef __APPLE__ mouse_x = mousedata.deltax; mouse_y = mousedata.deltay; From 3e1ef68a5fdd734e4a84533dffab13c6c1991657 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 21:46:40 +0600 Subject: [PATCH 05/26] 86box.c: Parenthesis addition --- src/86box.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/86box.c b/src/86box.c index c98b26185..0e1e49fd2 100644 --- a/src/86box.c +++ b/src/86box.c @@ -1267,7 +1267,7 @@ pc_run(void) } if (title_update) { - mouse_msg_idx = (mouse_type == MOUSE_TYPE_NONE || mouse_mode >= 1) ? 2 : !!mouse_capture; + mouse_msg_idx = ((mouse_type == MOUSE_TYPE_NONE) || (mouse_mode >= 1)) ? 2 : !!mouse_capture; swprintf(temp, sizeof_w(temp), mouse_msg[mouse_msg_idx], fps); #ifdef __APPLE__ /* Needed due to modifying the UI on the non-main thread is a big no-no. */ From 0ea498d9ce10120245b5b5a5048c8f28ae9afa9f Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 22:20:30 +0600 Subject: [PATCH 06/26] wacom: Account for negative coordinate overflows --- src/device/mouse_wacom_tablet.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 099f9c5c8..8ea807bd7 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -174,6 +174,8 @@ wacom_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) wacom->abs_y = abs_y * (wacom->measurement ? 2972. : 3774.); if (wacom->abs_x > (wacom->measurement ? 4566 : 5800)) wacom->abs_x = (wacom->measurement ? 4566 : 5800); if (wacom->abs_y > (wacom->measurement ? 2972 : 3774)) wacom->abs_x = (wacom->measurement ? 2972 : 3774); + if (wacom->abs_x < 0) wacom->abs_x = 0; + if (wacom->abs_y < 0) wacom->abs_y = 0; wacom->rel_x = x; wacom->rel_y = y; if (wacom->b != b) wacom->oldb = wacom->b; From e4180603e0498504bb10e5267a8f098503669e96 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 22:22:33 +0600 Subject: [PATCH 07/26] Revert "Made absolute mouse coordinates work under macOS" This reverts commit b9f8e09db0628bc89cc84d705021e96ccb59e6af. --- src/qt/macos_event_filter.mm | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qt/macos_event_filter.mm b/src/qt/macos_event_filter.mm index 28c0e5de7..6f84beee5 100644 --- a/src/qt/macos_event_filter.mm +++ b/src/qt/macos_event_filter.mm @@ -96,8 +96,6 @@ macos_poll_mouse() mouse_x = mousedata.deltax; mouse_y = mousedata.deltay; mouse_z = mousedata.deltaz; - mouse_abs_x = mousedata.x_abs; - mouse_abs_y = mousedata.y_abs; mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; mouse_buttons = mousedata.mousebuttons; } From efda203365e1d353adc0cce3de447b40e560cd43 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 22:23:43 +0600 Subject: [PATCH 08/26] Process absolute coordinates on macOS --- src/qt/qt_rendererstack.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index bf9098592..4ff1866a2 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -153,9 +153,6 @@ RendererStack::mousePoll() mouse_x = mousedata.deltax; mouse_y = mousedata.deltay; mouse_z = mousedata.deltaz; - mouse_x_abs = mousedata.x_abs; - mouse_y_abs = mousedata.y_abs; - mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; mouse_buttons = mousedata.mousebuttons; @@ -163,6 +160,10 @@ RendererStack::mousePoll() #endif this->mouse_poll_func(); + mouse_x_abs = mousedata.x_abs; + mouse_y_abs = mousedata.y_abs; + mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; + double scaled_x = mouse_x * mouse_sensitivity + mouse_x_error; double scaled_y = mouse_y * mouse_sensitivity + mouse_y_error; From e229f9e22cfb3ca6bff8623cdb2e622b63f3e571 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 3 Jan 2023 23:27:12 +0600 Subject: [PATCH 09/26] wacom: Properly implement suppressed/increment mode --- src/device/mouse_wacom_tablet.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 8ea807bd7..5b52887e3 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -2,6 +2,7 @@ #include #include #include +#include #include <86box/86box.h> #include <86box/device.h> #include <86box/timer.h> @@ -85,6 +86,7 @@ wacom_reset(mouse_wacom_t* wacom) wacom->transmit_id = 0; wacom->format = 0; /* ASCII */ wacom->measurement = 1; + wacom->increment = wacom->suppressed_increment = 0; mouse_mode = 1; } @@ -211,6 +213,8 @@ sermouse_report_timer(void *priv) uint32_t transmitted = 0; double milisecond_diff = ((double)(tsc - wacom->old_tsc)) / cpuclock * 1000.0; int x = (mouse_mode == 0 ? wacom->rel_x : wacom->abs_x), y = (mouse_mode == 0 ? wacom->rel_y : wacom->abs_y); + int x_diff = abs(mouse_mode == 0 ? wacom->rel_x : (wacom->abs_x - wacom->last_abs_x)); + int y_diff = abs(mouse_mode == 0 ? wacom->rel_y : (wacom->abs_y - wacom->last_abs_y)); timer_on_auto(&wacom->report_timer, wacom->transmit_id ? (wacom->transmit_period / 8.0) : wacom->transmit_period); if (wacom->transmit_id && !wacom->transmission_ongoing) @@ -218,9 +222,6 @@ sermouse_report_timer(void *priv) if (wacom->transmission_ongoing) goto transmit; else { - int x_diff = (mouse_mode == 0 ? wacom->rel_x : (wacom->last_abs_x - wacom->abs_x)); - int y_diff = (mouse_mode == 0 ? wacom->rel_y : (wacom->last_abs_y - wacom->abs_y)); - if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->always_report)) return; if (milisecond_diff >= (wacom->interval * 5)) { transmitted = 1; @@ -228,12 +229,13 @@ sermouse_report_timer(void *priv) } else transmitted = 0; if (!transmitted) return; + if (wacom->increment && !(x_diff >= wacom->increment || y_diff >= wacom->increment || wacom_switch_off_to_on(wacom->b, wacom->oldb))) return; if (wacom->suppressed_increment && !(x_diff >= wacom->suppressed_increment || y_diff >= wacom->suppressed_increment || (wacom->b != wacom->oldb))) return; - + switch (wacom->mode) { case WACOM_MODE_STREAM: default: @@ -268,8 +270,11 @@ transmit_prepare: wacom->transmission_ongoing = 1; wacom->transmission_format = wacom->format; wacom->data_pos = 0; - wacom->last_abs_x = wacom->abs_x; - wacom->last_abs_y = wacom->abs_y; + if (!((wacom->increment && !(x_diff >= wacom->increment || y_diff >= wacom->increment || wacom_switch_off_to_on(wacom->b, wacom->oldb))) || + (wacom->suppressed_increment && !(x_diff >= wacom->suppressed_increment || y_diff >= wacom->suppressed_increment || (wacom->b != wacom->oldb))))) { + wacom->last_abs_x = wacom->abs_x; + wacom->last_abs_y = wacom->abs_y; + } wacom->oldb = wacom->b; if (wacom->format == 1) { memset(wacom->data, 0, 7); From 3cb903c29e87b33052d3a9fde1e2d079234c08b3 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 00:10:43 +0600 Subject: [PATCH 10/26] wacom: Don't transmit anything for 10 miliseconds after reset --- src/device/mouse_wacom_tablet.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 5b52887e3..0a99d1d89 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -48,7 +48,7 @@ typedef struct { int last_abs_x, last_abs_y; /* Suppressed/Increment Mode. */ double transmit_period, report_period; - double old_tsc; + double old_tsc, reset_tsc; pc_timer_t command_timer, report_timer; serial_t *serial; @@ -87,6 +87,7 @@ wacom_reset(mouse_wacom_t* wacom) wacom->format = 0; /* ASCII */ wacom->measurement = 1; wacom->increment = wacom->suppressed_increment = 0; + wacom->reset_tsc = tsc; mouse_mode = 1; } @@ -217,6 +218,8 @@ sermouse_report_timer(void *priv) int y_diff = abs(mouse_mode == 0 ? wacom->rel_y : (wacom->abs_y - wacom->last_abs_y)); timer_on_auto(&wacom->report_timer, wacom->transmit_id ? (wacom->transmit_period / 8.0) : wacom->transmit_period); + if ((((double)(tsc - wacom->reset_tsc)) / cpuclock * 1000.0) <= 10) + return; if (wacom->transmit_id && !wacom->transmission_ongoing) goto transmit_prepare; if (wacom->transmission_ongoing) From 8e91b23e358e1c5955f519091516d23d45fa71ec Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 01:42:14 +0600 Subject: [PATCH 11/26] Partial revert of suppressed/increment mode changes --- src/device/mouse_wacom_tablet.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 0a99d1d89..9183d5264 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -46,6 +46,7 @@ typedef struct { int suppressed, measurement, always_report; int last_abs_x, last_abs_y; /* Suppressed/Increment Mode. */ + uint32_t settings; /* Settings DWORD */ double transmit_period, report_period; double old_tsc, reset_tsc; @@ -273,11 +274,9 @@ transmit_prepare: wacom->transmission_ongoing = 1; wacom->transmission_format = wacom->format; wacom->data_pos = 0; - if (!((wacom->increment && !(x_diff >= wacom->increment || y_diff >= wacom->increment || wacom_switch_off_to_on(wacom->b, wacom->oldb))) || - (wacom->suppressed_increment && !(x_diff >= wacom->suppressed_increment || y_diff >= wacom->suppressed_increment || (wacom->b != wacom->oldb))))) { - wacom->last_abs_x = wacom->abs_x; - wacom->last_abs_y = wacom->abs_y; - } + wacom->last_abs_x = wacom->abs_x; + wacom->last_abs_y = wacom->abs_y; + wacom->oldb = wacom->b; if (wacom->format == 1) { memset(wacom->data, 0, 7); From 49795ce81f4aebd60dd094a55c44ed2a55199aac Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 01:59:57 +0600 Subject: [PATCH 12/26] Transmit ID at normal speed --- src/device/mouse_wacom_tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 9183d5264..5cce333be 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -218,7 +218,7 @@ sermouse_report_timer(void *priv) int x_diff = abs(mouse_mode == 0 ? wacom->rel_x : (wacom->abs_x - wacom->last_abs_x)); int y_diff = abs(mouse_mode == 0 ? wacom->rel_y : (wacom->abs_y - wacom->last_abs_y)); - timer_on_auto(&wacom->report_timer, wacom->transmit_id ? (wacom->transmit_period / 8.0) : wacom->transmit_period); + timer_on_auto(&wacom->report_timer, wacom->transmit_period); if ((((double)(tsc - wacom->reset_tsc)) / cpuclock * 1000.0) <= 10) return; if (wacom->transmit_id && !wacom->transmission_ongoing) From 5c5e26960afc1b60ce32f5f640f06217943559d7 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 02:07:27 +0600 Subject: [PATCH 13/26] Properly process single-byte commands --- src/device/mouse_wacom_tablet.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 5cce333be..70463b2ea 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -126,14 +126,17 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) } if (data == '$') { wacom_reset(wacom); + return; } if (data == 0x13) { wacom->transmission_stopped = 1; pclog("WACOM: transmission stopped\n"); + return; } if (data == 0x11) { wacom->transmission_stopped = 0; pclog("WACOM: transmission started\n"); + return; } wacom->data_rec[wacom->data_rec_pos++] = data; if (data == '\r') { From e5dd58e23faef3c23a2b8a445b68ab75a0cd5f44 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 13:46:06 +0600 Subject: [PATCH 14/26] wacom: Support Remote request mode and line feed-terminated commands --- src/device/mouse_wacom_tablet.c | 50 ++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 70463b2ea..62aeb6fc0 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -44,6 +44,7 @@ typedef struct { int transmit_id, transmit_id_pending; int pressure_mode; int suppressed, measurement, always_report; + int remote_req, remote_mode; int last_abs_x, last_abs_y; /* Suppressed/Increment Mode. */ uint32_t settings; /* Settings DWORD */ @@ -89,6 +90,7 @@ wacom_reset(mouse_wacom_t* wacom) wacom->measurement = 1; wacom->increment = wacom->suppressed_increment = 0; wacom->reset_tsc = tsc; + wacom->remote_mode = wacom->remote_req = 0; mouse_mode = 1; } @@ -124,22 +126,23 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) special_command = 0; return; } - if (data == '$') { - wacom_reset(wacom); + + if (data == '@') { + wacom->remote_req = 1; + wacom->remote_mode = 1; + wacom->transmission_stopped = 0; return; } if (data == 0x13) { wacom->transmission_stopped = 1; - pclog("WACOM: transmission stopped\n"); return; } if (data == 0x11) { wacom->transmission_stopped = 0; - pclog("WACOM: transmission started\n"); return; } wacom->data_rec[wacom->data_rec_pos++] = data; - if (data == '\r') { + if (data == '\r' || data == '\n') { wacom->data_rec[wacom->data_rec_pos] = 0; wacom->data_rec_pos = 0; @@ -151,7 +154,7 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) wacom->suppressed_increment = 0; } else if (!memcmp(wacom->data_rec, "IN", 2)) { sscanf((const char*)wacom->data_rec, "IN%d", &wacom->increment); - } else if (!memcmp(wacom->data_rec, "RE", 2)) { + } else if (!memcmp(wacom->data_rec, "RE", 2) || wacom->data_rec[0] == '$' || wacom->data_rec[0] == '#') { wacom_reset(wacom); } else if (!memcmp(wacom->data_rec, "IT", 2)) { sscanf((const char*)wacom->data_rec, "IT%d", &wacom->interval); @@ -167,8 +170,14 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) sscanf((const char*)wacom->data_rec, "IC%d", &wacom->measurement); } else if (!memcmp(wacom->data_rec, "AL", 2)) { sscanf((const char*)wacom->data_rec, "AL%d", &wacom->always_report); - } else { - pclog("Unknown command: %s\n", wacom->data_rec); + } else if (!memcmp(wacom->data_rec, "RQ", 2)) { + wacom->transmission_stopped = 0; + sscanf((const char*)wacom->data_rec, "RQ%d", &wacom->remote_mode); + if (wacom->remote_mode) wacom->remote_req = 1; + } else if (!memcmp(wacom->data_rec, "SP", 2)) { + wacom->transmission_stopped = 1; + } else if (!memcmp(wacom->data_rec, "ST", 2)){ + wacom->transmission_stopped = 0; } } } @@ -228,6 +237,8 @@ sermouse_report_timer(void *priv) goto transmit_prepare; if (wacom->transmission_ongoing) goto transmit; + else if (wacom->remote_mode && !wacom->remote_req) + return; else { if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->always_report)) return; if (milisecond_diff >= (wacom->interval * 5)) { @@ -236,13 +247,7 @@ sermouse_report_timer(void *priv) } else transmitted = 0; if (!transmitted) return; - - if (wacom->increment && !(x_diff >= wacom->increment || y_diff >= wacom->increment || wacom_switch_off_to_on(wacom->b, wacom->oldb))) - return; - if (wacom->suppressed_increment && !(x_diff >= wacom->suppressed_increment || y_diff >= wacom->suppressed_increment || (wacom->b != wacom->oldb))) - return; - switch (wacom->mode) { case WACOM_MODE_STREAM: default: @@ -263,6 +268,11 @@ sermouse_report_timer(void *priv) break; } } + + if (wacom->increment && !(x_diff >= wacom->increment || y_diff >= wacom->increment || wacom_switch_off_to_on(wacom->b, wacom->oldb))) + return; + if (wacom->suppressed_increment && !(x_diff >= wacom->suppressed_increment || y_diff >= wacom->suppressed_increment || (wacom->b != wacom->oldb))) + return; } transmit_prepare: @@ -314,7 +324,15 @@ transmit_prepare: snprintf((char*)wacom->data, sizeof(wacom->data), "*,%05d,%05d,%d\r\n", wacom->abs_x, wacom->abs_y, wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t)-31 : (uint8_t)15) : ((wacom->b & 0x1) ? 0x21 : 0x00)); } transmit: - serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); + if (wacom->transmit_id) { + uint8_t i = 0; + + for (i = 0; i < 9; i++) { + serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); + if (wacom->data[wacom->data_pos] == 0) break; + } + } else + serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); if ((wacom->transmission_format == 0 && wacom->data[wacom->data_pos] == 0) || (wacom->transmission_format == 1 && wacom->data_pos == 7)) { wacom->transmission_ongoing = 0; @@ -396,7 +414,7 @@ const device_t mouse_wacom_device = { .close = wacom_close, .reset = NULL, { .poll = wacom_poll }, - .speed_changed = NULL, + .speed_changed = wacom_speed_changed, .force_redraw = NULL, .config = wacom_config }; From 695f5befa18b13f30b35989737aaf1029c457830 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 19:30:14 +0600 Subject: [PATCH 15/26] ST cancels remote mode --- src/device/mouse_wacom_tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 62aeb6fc0..6083eaa99 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -130,7 +130,6 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) if (data == '@') { wacom->remote_req = 1; wacom->remote_mode = 1; - wacom->transmission_stopped = 0; return; } if (data == 0x13) { @@ -139,6 +138,7 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) } if (data == 0x11) { wacom->transmission_stopped = 0; + wacom->remote_mode = wacom->remote_req = 0; return; } wacom->data_rec[wacom->data_rec_pos++] = data; @@ -171,13 +171,13 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) } else if (!memcmp(wacom->data_rec, "AL", 2)) { sscanf((const char*)wacom->data_rec, "AL%d", &wacom->always_report); } else if (!memcmp(wacom->data_rec, "RQ", 2)) { - wacom->transmission_stopped = 0; sscanf((const char*)wacom->data_rec, "RQ%d", &wacom->remote_mode); if (wacom->remote_mode) wacom->remote_req = 1; } else if (!memcmp(wacom->data_rec, "SP", 2)) { wacom->transmission_stopped = 1; } else if (!memcmp(wacom->data_rec, "ST", 2)){ wacom->transmission_stopped = 0; + wacom->remote_mode = wacom->remote_req = 0; } } } From e538a28895a528eefe135ca8109b79ee7ee0ec5e Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 19:43:15 +0600 Subject: [PATCH 16/26] Don't transmit coordinates continuously in remote mode --- src/device/mouse_wacom_tablet.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 6083eaa99..c3e8498bf 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -289,6 +289,7 @@ transmit_prepare: wacom->data_pos = 0; wacom->last_abs_x = wacom->abs_x; wacom->last_abs_y = wacom->abs_y; + wacom->remote_req = 0; wacom->oldb = wacom->b; if (wacom->format == 1) { From 6a78eca1ff20494de38053c26dc42215413a2770 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 4 Jan 2023 23:01:30 +0600 Subject: [PATCH 17/26] wacom: Cleanup and splits --- src/device/mouse_wacom_tablet.c | 140 ++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 62 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index c3e8498bf..951ec9c0e 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -35,7 +35,7 @@ typedef struct { data_rec[0x200]; int abs_x, abs_y, rel_x, rel_y, - oldb, lastb, b; + oldb, b; int data_pos, data_rec_pos, mode, transmission_ongoing, transmission_format, interval; int increment, suppressed_increment; @@ -49,9 +49,9 @@ typedef struct { int last_abs_x, last_abs_y; /* Suppressed/Increment Mode. */ uint32_t settings; /* Settings DWORD */ - double transmit_period, report_period; + double transmit_period; double old_tsc, reset_tsc; - pc_timer_t command_timer, report_timer; + pc_timer_t report_timer; serial_t *serial; } mouse_wacom_t; @@ -146,6 +146,8 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) wacom->data_rec[wacom->data_rec_pos] = 0; wacom->data_rec_pos = 0; + if (data == '\n') pclog("Wacom: written %s", wacom->data_rec); + else pclog("Wacom: written %s\n", wacom->data_rec); if (!memcmp(wacom->data_rec, "AS", 2)) { wacom->format = (wacom->data_rec[2] == '1'); wacom->transmission_ongoing = 0; @@ -219,16 +221,72 @@ wacom_get_switch(int b) return 0x00; } +static void +wacom_transmit_prepare(mouse_wacom_t* wacom, int x, int y) +{ + wacom->transmission_ongoing = 1; + wacom->data_pos = 0; + memset(wacom->data, 0, sizeof(wacom->data)); + if (wacom->transmit_id) { + wacom->transmission_format = 0; + strcat((char*)wacom->data, "~#SD51C V3.2.1.01\r"); + return; + } + wacom->transmission_format = wacom->format; + wacom->last_abs_x = wacom->abs_x; + wacom->last_abs_y = wacom->abs_y; + wacom->remote_req = 0; + + wacom->oldb = wacom->b; + if (wacom->format == 1) { + wacom->data[0] = 0xC0; + wacom->data[6] = wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t)31 : (uint8_t)-31) : wacom_get_switch(wacom->b); + + wacom->data[5] = (y & 0x7F); + wacom->data[4] = ((y & 0x3F80) >> 7) & 0x7F; + wacom->data[3] = (((y & 0xC000) >> 14) & 3); + + wacom->data[2] = (x & 0x7F); + wacom->data[1] = ((x & 0x3F80) >> 7) & 0x7F; + wacom->data[0] |= (((x & 0xC000) >> 14) & 3); + + if (mouse_mode == 0) { + wacom->data[0] |= (!!(x < 0)) << 2; + wacom->data[3] |= (!!(y < 0)) << 2; + } + + if (wacom->pressure_mode) { + wacom->data[0] |= 0x10; + wacom->data[6] &= 0x7F; + } + + if (tablet_tool_type == 1) { + wacom->data[0] |= 0x20; + } + + if (!mouse_tablet_in_proximity) { + wacom->data[0] &= ~0x40; + } + } else { + wacom->data[0] = 0; + snprintf((char*)wacom->data, sizeof(wacom->data), "*,%05d,%05d,%d\r\n", + wacom->abs_x, wacom->abs_y, + wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t)-31 : (uint8_t)15) : ((wacom->b & 0x1) ? 21 : 00)); + } +} + extern double cpuclock; static void -sermouse_report_timer(void *priv) +wacom_report_timer(void *priv) { mouse_wacom_t* wacom = (mouse_wacom_t*)priv; - uint32_t transmitted = 0; double milisecond_diff = ((double)(tsc - wacom->old_tsc)) / cpuclock * 1000.0; - int x = (mouse_mode == 0 ? wacom->rel_x : wacom->abs_x), y = (mouse_mode == 0 ? wacom->rel_y : wacom->abs_y); - int x_diff = abs(mouse_mode == 0 ? wacom->rel_x : (wacom->abs_x - wacom->last_abs_x)); - int y_diff = abs(mouse_mode == 0 ? wacom->rel_y : (wacom->abs_y - wacom->last_abs_y)); + int relative_mode = (mouse_mode == 0); + int x = (relative_mode ? wacom->rel_x : wacom->abs_x); + int y = (relative_mode ? wacom->rel_y : wacom->abs_y); + int x_diff = abs(relative_mode ? wacom->rel_x : (wacom->abs_x - wacom->last_abs_x)); + int y_diff = abs(relative_mode ? wacom->rel_y : (wacom->abs_y - wacom->last_abs_y)); + int increment = wacom->suppressed_increment ? wacom->suppressed_increment : wacom->increment; timer_on_auto(&wacom->report_timer, wacom->transmit_period); if ((((double)(tsc - wacom->reset_tsc)) / cpuclock * 1000.0) <= 10) @@ -240,12 +298,12 @@ sermouse_report_timer(void *priv) else if (wacom->remote_mode && !wacom->remote_req) return; else { - if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->always_report)) return; + if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->always_report)) + return; + if (milisecond_diff >= (wacom->interval * 5)) { - transmitted = 1; wacom->old_tsc = tsc; - } else transmitted = 0; - if (!transmitted) + } else return; switch (wacom->mode) { @@ -269,61 +327,19 @@ sermouse_report_timer(void *priv) } } - if (wacom->increment && !(x_diff >= wacom->increment || y_diff >= wacom->increment || wacom_switch_off_to_on(wacom->b, wacom->oldb))) + if (increment && !(x_diff > increment || y_diff > increment)) return; - if (wacom->suppressed_increment && !(x_diff >= wacom->suppressed_increment || y_diff >= wacom->suppressed_increment || (wacom->b != wacom->oldb))) + + if (wacom->increment && !wacom_switch_off_to_on(wacom->b, wacom->oldb)) + return; + + if (wacom->suppressed_increment && (wacom->b == wacom->oldb)) return; } transmit_prepare: - if (wacom->transmit_id) { - wacom->transmission_format = 0; - wacom->transmission_ongoing = 1; - wacom->data_pos = 0; - memset(wacom->data, 0, sizeof(wacom->data)); - strcat((char*)wacom->data, "~#SD51C V3.2.1.01\r"); - goto transmit; - } - wacom->transmission_ongoing = 1; - wacom->transmission_format = wacom->format; - wacom->data_pos = 0; - wacom->last_abs_x = wacom->abs_x; - wacom->last_abs_y = wacom->abs_y; - wacom->remote_req = 0; + wacom_transmit_prepare(wacom, x, y); - wacom->oldb = wacom->b; - if (wacom->format == 1) { - memset(wacom->data, 0, 7); - wacom->data[0] = 0xC0; - wacom->data[6] = wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t)31 : (uint8_t)-31) : wacom_get_switch(wacom->b); - - wacom->data[5] = (y & 0x7F); - wacom->data[4] = ((y & 0x3F80) >> 7) & 0x7F; - wacom->data[3] = (((y & 0xC000) >> 14) & 3); - - wacom->data[2] = (x & 0x7F); - wacom->data[1] = ((x & 0x3F80) >> 7) & 0x7F; - wacom->data[0] |= (((x & 0xC000) >> 14) & 3); - - if (mouse_mode == 0) { - wacom->data[0] |= (!!(x < 0)) << 2; - wacom->data[3] |= (!!(y < 0)) << 2; - } - if (wacom->pressure_mode) { - wacom->data[0] |= 0x10; - wacom->data[6] &= 0x7F; - } - if (tablet_tool_type == 1) { - wacom->data[0] |= 0x20; - } - - if (!mouse_tablet_in_proximity) { - wacom->data[0] &= ~0x40; - } - } else { - wacom->data[0] = 0; - snprintf((char*)wacom->data, sizeof(wacom->data), "*,%05d,%05d,%d\r\n", wacom->abs_x, wacom->abs_y, wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t)-31 : (uint8_t)15) : ((wacom->b & 0x1) ? 0x21 : 0x00)); - } transmit: if (wacom->transmit_id) { uint8_t i = 0; @@ -356,7 +372,7 @@ wacom_init(const device_t *info) dev->port = device_get_config_int("port"); dev->serial = serial_attach(dev->port, wacom_callback, wacom_write, dev); - timer_add(&dev->report_timer, sermouse_report_timer, dev, 0); + timer_add(&dev->report_timer, wacom_report_timer, dev, 0); mouse_set_buttons(dev->but); wacom_reset(dev); From b0b92a84e6aedfd134805112bff5a8655cb12a43 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 6 Jan 2023 23:23:40 +0600 Subject: [PATCH 18/26] wacom: Fix increment modes --- src/device/mouse_wacom_tablet.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 951ec9c0e..03aa28bd5 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -327,14 +327,13 @@ wacom_report_timer(void *priv) } } - if (increment && !(x_diff > increment || y_diff > increment)) - return; + if (increment && !(x_diff > increment || y_diff > increment)) { + if (wacom->increment && !wacom_switch_off_to_on(wacom->b, wacom->oldb)) + return; - if (wacom->increment && !wacom_switch_off_to_on(wacom->b, wacom->oldb)) - return; - - if (wacom->suppressed_increment && (wacom->b == wacom->oldb)) - return; + if (wacom->suppressed_increment && (wacom->b == wacom->oldb)) + return; + } } transmit_prepare: From a91015fe0417345fe2e4dc21c0a948fdfd1a0027 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 7 Jan 2023 00:04:48 +0600 Subject: [PATCH 19/26] wacom: Check suppressed increment first --- src/device/mouse_wacom_tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 03aa28bd5..19e5b53cc 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -328,10 +328,10 @@ wacom_report_timer(void *priv) } if (increment && !(x_diff > increment || y_diff > increment)) { - if (wacom->increment && !wacom_switch_off_to_on(wacom->b, wacom->oldb)) + if (wacom->suppressed_increment && (wacom->b == wacom->oldb)) return; - if (wacom->suppressed_increment && (wacom->b == wacom->oldb)) + if (wacom->increment && !wacom_switch_off_to_on(wacom->b, wacom->oldb)) return; } } From 64becf5d137ff827a3169166365675fdceed7114 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 7 Feb 2023 17:18:12 +0600 Subject: [PATCH 20/26] Fix erased line --- src/qt/qt_mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 41c363744..65af4d8d3 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -2462,9 +2462,9 @@ void MainWindow::on_actionPen_triggered() { tablet_tool_type = 1; config_save(); +} void MainWindow::on_actionACPI_Shutdown_triggered() { acpi_pwrbut_pressed = 1; - } From efaca1b10662786d270496d91489d45e091f7fb6 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 16 Feb 2023 10:25:05 +0600 Subject: [PATCH 21/26] wacom: Get rid of ID transmission hacks --- src/device/mouse_wacom_tablet.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 19e5b53cc..386e89042 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -340,15 +340,7 @@ transmit_prepare: wacom_transmit_prepare(wacom, x, y); transmit: - if (wacom->transmit_id) { - uint8_t i = 0; - - for (i = 0; i < 9; i++) { - serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); - if (wacom->data[wacom->data_pos] == 0) break; - } - } else - serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); + serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); if ((wacom->transmission_format == 0 && wacom->data[wacom->data_pos] == 0) || (wacom->transmission_format == 1 && wacom->data_pos == 7)) { wacom->transmission_ongoing = 0; From a96f40e5ef84c0fdf8f3aac7d5d5dbe4406658af Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 17 Feb 2023 01:48:29 +0600 Subject: [PATCH 22/26] mouse_wacom_tablet: Change to snprintf for ID transmission --- src/device/mouse_wacom_tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 386e89042..d613bcc1b 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -229,7 +229,7 @@ wacom_transmit_prepare(mouse_wacom_t* wacom, int x, int y) memset(wacom->data, 0, sizeof(wacom->data)); if (wacom->transmit_id) { wacom->transmission_format = 0; - strcat((char*)wacom->data, "~#SD51C V3.2.1.01\r"); + snprintf((char*)wacom->data, sizeof(wacom->data), "~#SD51C V3.2.1.01\r\0"); return; } wacom->transmission_format = wacom->format; From 29d7a7f2651d453d5af137a6f8fb300712a0d687 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 17 Feb 2023 11:04:24 +0600 Subject: [PATCH 23/26] mouse_wacom_tablet: Reset "always_report" to 0 as well Fixes Windows 95 drivers --- src/device/mouse_wacom_tablet.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index d613bcc1b..84459efa7 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -91,6 +91,7 @@ wacom_reset(mouse_wacom_t* wacom) wacom->increment = wacom->suppressed_increment = 0; wacom->reset_tsc = tsc; wacom->remote_mode = wacom->remote_req = 0; + wacom->always_report = 0; mouse_mode = 1; } From 7f66f8334e7ea3c6a4453cac029ce32d1db5bade Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 17 Feb 2023 11:36:13 +0600 Subject: [PATCH 24/26] mouse_wacom_tablet: Always transmit coordinates when requested in remote mode --- src/device/mouse_wacom_tablet.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 84459efa7..2d324effb 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -230,7 +230,7 @@ wacom_transmit_prepare(mouse_wacom_t* wacom, int x, int y) memset(wacom->data, 0, sizeof(wacom->data)); if (wacom->transmit_id) { wacom->transmission_format = 0; - snprintf((char*)wacom->data, sizeof(wacom->data), "~#SD51C V3.2.1.01\r\0"); + snprintf((char*)wacom->data, sizeof(wacom->data), "~#SD51C V3.2.1.01\r"); return; } wacom->transmission_format = wacom->format; @@ -299,6 +299,9 @@ wacom_report_timer(void *priv) else if (wacom->remote_mode && !wacom->remote_req) return; else { + if (wacom->remote_mode && wacom->remote_req) { + goto transmit_prepare; + } if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->always_report)) return; From f9cd6c9b5f3863628a98b3102be9a6ca11d811de Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 18 Feb 2023 01:16:16 +0600 Subject: [PATCH 25/26] Set default tablet tool to Pen --- src/device/mouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device/mouse.c b/src/device/mouse.c index 12531e3ce..93384e063 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -40,7 +40,7 @@ int mouse_x, mouse_buttons, mouse_mode, mouse_tablet_in_proximity = 0, - tablet_tool_type = 0; /* 0 = Puck/Cursor, 1 = Pen */ + tablet_tool_type = 1; /* 0 = Puck/Cursor, 1 = Pen */ double mouse_x_abs, mouse_y_abs; From 0395ea02a1caab163b67eac6948c787571cfcf80 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 24 Feb 2023 16:50:38 +0600 Subject: [PATCH 26/26] qt: Poll from Qt code instead of RawInput code on Windows when absolute mode is used Fixes tablet input --- src/qt/qt_rendererstack.cpp | 8 +++++--- src/qt/qt_winrawinputfilter.cpp | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 3d5faff34..9ebd891c3 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -145,9 +145,11 @@ void RendererStack::mousePoll() { #ifdef Q_OS_WINDOWS - mouse_x_abs = mousedata.x_abs; - mouse_y_abs = mousedata.y_abs; - return; + if (mouse_mode == 0) { + mouse_x_abs = mousedata.x_abs; + mouse_y_abs = mousedata.y_abs; + return; + } #endif #ifndef __APPLE__ mouse_x = mousedata.deltax; diff --git a/src/qt/qt_winrawinputfilter.cpp b/src/qt/qt_winrawinputfilter.cpp index 6690a08eb..309f7b2d0 100644 --- a/src/qt/qt_winrawinputfilter.cpp +++ b/src/qt/qt_winrawinputfilter.cpp @@ -373,6 +373,7 @@ WindowsRawInputFilter::mouse_handle(PRAWINPUT raw) void WindowsRawInputFilter::mousePoll() { + if (mouse_mode >= 1) return; if (mouse_capture || video_fullscreen) { static int b = 0;