From 7dd023fc78566f2911250f4b8550b0a33a943bb3 Mon Sep 17 00:00:00 2001 From: Kamui Date: Thu, 19 Oct 2023 22:33:13 -0500 Subject: [PATCH] fix: cin hang on win32 --- CMakeLists.txt | 9 ++++++++- src/main.cpp | 17 ++++++++++------- src/selectorwidget.cpp | 4 ++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20194bf..a33f507 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,14 @@ else() set(Gazou_MODEL_FOLDER ${CMAKE_INSTALL_PREFIX}/share/gazou/models) endif() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") -set(LIBS Qt5::Widgets Qt5::DBus tesseract leptonica) +set(LIBS Qt5::Widgets Qt5::DBus tesseract) + +if (UNIX) + list(APPEND LIBS leptonica) +else() + list(APPEND LIBS lept) +endif() + set(SRC src/main.cpp src/selectorwidget.cpp diff --git a/src/main.cpp b/src/main.cpp index 7a37446..7600151 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -189,14 +189,17 @@ int main(int argc, char **argv) { stdinImageData = new QByteArray(); - if (!isatty(fileno(stdin))) { - char buffer[4096]; - size_t bytesRead; - - while ((bytesRead = fread(buffer, 1, sizeof(buffer), stdin)) > 0) { - stdinImageData->append(buffer, static_cast(bytesRead)); + #ifdef Q_OS_LINUX + if (!isatty(fileno(stdin))) { + std::cout << "Reading from stdin" << std::endl; + char buffer[4096]; + size_t bytesRead; + + while ((bytesRead = fread(buffer, 1, sizeof(buffer), stdin)) > 0) { + stdinImageData->append(buffer, static_cast(bytesRead)); + } } - } + #endif if (argc > 1 || !stdinImageData->isEmpty()) { QCoreApplication app(argc, argv); diff --git a/src/selectorwidget.cpp b/src/selectorwidget.cpp index e231e5c..609b50b 100644 --- a/src/selectorwidget.cpp +++ b/src/selectorwidget.cpp @@ -17,6 +17,10 @@ SelectorWidget::SelectorWidget(QWidget *parent) if (!ok) { qCritical("Unable to screenshot"); exit(-1); + } else { + QFile file(getTempImage()); + file.open(QIODevice::WriteOnly); + desktopPixmap.save(&file, "PNG"); } setGeometry(activeScreen->geometry()); showFullScreen();