| 413 | } |
| 414 | |
| 415 | void LogWindow::onInputEntered() |
| 416 | { |
| 417 | QString text = m_line_input->text(); |
| 418 | if (text.isEmpty() && !m_newline_on_enter) |
| 419 | return; |
| 420 | |
| 421 | if (m_newline_on_enter) |
| 422 | text.append('\n'); |
| 423 | |
| 424 | if (!m_line_input->isEnabled()) |
| 425 | return; |
| 426 | |
| 427 | bool focus = m_line_input->hasFocus(); |
| 428 | m_line_input->setDisabled(true); |
| 429 | |
| 430 | const QPointer<LogWindow> window(this); |
| 431 | std::string str = text.toUtf8().toStdString(); |
| 432 | |
| 433 | Host::RunOnCPUThread([str = std::move(str), focus, window]() { |
| 434 | bool success = true; |
| 435 | |
| 436 | if (!VMManager::HasValidVM()) |
| 437 | { |
| 438 | Console.Warning("Cannot write to EE SIO RX FIFO while there is no virtual machine running."); |
| 439 | success = false; |
| 440 | } |
| 441 | |
| 442 | if (success && Achievements::IsHardcoreModeActive()) |
| 443 | { |
| 444 | Console.Warning("Cannot write to EE SIO RX FIFO while RetroAchievements hardcore mode is active."); |
| 445 | success = false; |
| 446 | } |
| 447 | |
| 448 | if (success) |
| 449 | success = VMManager::WriteBytesToEESIORXFIFO({reinterpret_cast<const u8*>(str.data()), str.size()}); |
| 450 | |
| 451 | QtHost::RunOnUIThread([success, str = std::move(str), focus, window]() { |
| 452 | if (!window) |
| 453 | return; |
| 454 | |
| 455 | if (success) |
| 456 | { |
| 457 | window->m_line_input->clear(); |
| 458 | |
| 459 | if (window->m_local_echo) |
| 460 | { |
| 461 | // appendMessage expects a newline to be at the end of the string |
| 462 | QString text = QString::fromStdString(str); |
| 463 | window->appendMessage(0, 0, window->m_newline_on_enter ? text : (text + '\n')); |
| 464 | } |
| 465 | |
| 466 | QTextCursor cursor(window->m_text->textCursor()); |
| 467 | cursor.movePosition(QTextCursor::End); |
| 468 | window->m_text->setTextCursor(cursor); |
| 469 | } |
| 470 | |
| 471 | window->m_line_input->setDisabled(false); |
| 472 | if (focus) |