Skip to content

Commit

Permalink
directvt#571: Detect GUI mode (win32)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Feb 18, 2024
1 parent 5673542 commit 21a5536
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/netxs/desktopio/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3377,7 +3377,7 @@ namespace netxs::os
}
return winsz;
}
auto initialize()
auto initialize(bool trygui = faux)
{
#if defined(_WIN32)
os::stdin_fd = fd_t{ ptr::test(::GetStdHandle(STD_INPUT_HANDLE ), os::invalid_fd) };
Expand Down Expand Up @@ -3488,18 +3488,20 @@ namespace netxs::os
}
else
{
ok(::FreeConsole(), "::FreeConsole()", os::unexpected);
if (::AttachConsole(ATTACH_PARENT_PROCESS))
if (trygui)
{
os::stdin_fd = fd_t{ ptr::test(::GetStdHandle(STD_INPUT_HANDLE ), os::invalid_fd) };
os::stdout_fd = fd_t{ ptr::test(::GetStdHandle(STD_OUTPUT_HANDLE), os::invalid_fd) };
os::stderr_fd = fd_t{ ptr::test(::GetStdHandle(STD_ERROR_HANDLE ), os::invalid_fd) };
}
else
{
// Run gui console.
::MessageBoxW(NULL, L"Run GUI-console.", L"Run GUI-console.", MB_OK);
os::process::exit<true>(0);
if (::FreeConsole() && ::AttachConsole(ATTACH_PARENT_PROCESS)) // We are hosted by shell.
{
os::stdin_fd = fd_t{ ptr::test(::GetStdHandle(STD_INPUT_HANDLE ), os::invalid_fd) };
os::stdout_fd = fd_t{ ptr::test(::GetStdHandle(STD_OUTPUT_HANDLE), os::invalid_fd) };
os::stderr_fd = fd_t{ ptr::test(::GetStdHandle(STD_ERROR_HANDLE ), os::invalid_fd) };
}
else
{
// Run gui console.
::MessageBoxW(NULL, L"Run GUI-console.", L"Run GUI-console.", MB_OK);
os::process::exit<true>(0);
}
}

dtvt::win_sz = dtvt::consize();
Expand Down
3 changes: 2 additions & 1 deletion src/vtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ int main(int argc, char* argv[])
}
}

os::dtvt::initialize();
auto trygui = whoami == type::runapp || whoami == type::client;
os::dtvt::initialize(trygui);
os::dtvt::checkpoint();

if (os::dtvt::vtmode & ui::console::redirio && (whoami == type::runapp || whoami == type::client))
Expand Down

0 comments on commit 21a5536

Please sign in to comment.