Skip to content

Commit

Permalink
fix: cin hang on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
kamui-fin committed Oct 20, 2023
1 parent 26c1c80 commit 7dd023f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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<int>(bytesRead));
}
}
}
#endif

if (argc > 1 || !stdinImageData->isEmpty()) {
QCoreApplication app(argc, argv);
Expand Down
4 changes: 4 additions & 0 deletions src/selectorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7dd023f

Please sign in to comment.