Skip to content

Commit

Permalink
directvt#571 WIP: Inherit wincoor, winsize, fontname, fontsize
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Apr 24, 2024
1 parent 7075991 commit cba3db7
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/netxs/apps/calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ int main(int argc, char* argv[])
else
{
auto config = app::shared::load::settings(defaults, cfpath, os::dtvt::config);
app::shared::start(params, app::calc::id, os::dtvt::vtmode, os::dtvt::win_sz, config);
app::shared::start(params, app::calc::id, os::dtvt::vtmode, os::dtvt::window.size, config);
}
}
2 changes: 1 addition & 1 deletion src/netxs/apps/term.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ int main(int argc, char* argv[])
else
{
auto config = app::shared::load::settings(defaults, cfpath, os::dtvt::config);
app::shared::start(params, app::terminal::id, os::dtvt::vtmode, os::dtvt::win_sz, config);
app::shared::start(params, app::terminal::id, os::dtvt::vtmode, os::dtvt::window.size, config);
}
}
21 changes: 13 additions & 8 deletions src/netxs/desktopio/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace netxs::gui
hr = surf->DrawGlyphRun(s.baselineOriginX, s.baselineOriginY,
measuringMode,
&s.glyphRun,
conf.pNaturalRendering, // Emojis are broken without antialiasing.
conf.pNaturalRendering, // Emojis are broken without AA (antialiasing).
argb::swap_rb(s.paletteIndex == -1 ? fgc.token : color.token),
&dirtyRect);
}
Expand Down Expand Up @@ -267,12 +267,13 @@ namespace netxs::gui
gcfg conf;
bool initialized;

w32renderer()
w32renderer(text font_name, twod cell_size)
: initialized{ faux }
{
set_dpi_awareness();
//auto s = 96;//::GetDeviceCaps(hdc, LOGPIXELSY);
auto height = -16;//::MulDiv(24, s, 96);
auto font_utf16 = utf::to_utf(font_name);
auto height = -cell_size.y;
auto hfont = ::CreateFontW(height, //_In_ int cHeight
0, // _In_ int cWidth
0, // _In_ int cEscapement
Expand All @@ -286,9 +287,9 @@ namespace netxs::gui
0, // _In_ DWORD iClipPrecision
0, // _In_ DWORD iQuality
FIXED_PITCH, // _In_ DWORD iPitchAndFamily
font_utf16.c_str()); // _In_opt_ LPCWSTR pszFaceName
//L"Courier New"); // _In_opt_ LPCWSTR pszFaceName
//L"Lucida Console"); // _In_opt_ LPCWSTR pszFaceName
L"Consolas"); // _In_opt_ LPCWSTR pszFaceName
//L"Segoe UI Emoji"); // _In_opt_ LPCWSTR pszFaceName
//L"Monotty"); // _In_opt_ LPCWSTR pszFaceName

Expand Down Expand Up @@ -507,8 +508,9 @@ namespace netxs::gui
{
for (auto& w : layers) w.reset();
}
window(rect win_coor_px_size_cell, twod cell_size = { 10, 20 }, twod grip_cell = { 2, 1 })
window(rect win_coor_px_size_cell, text font, twod cell_size = { 10, 20 }, twod grip_cell = { 2, 1 })
: //dx3d{ faux }, //dx3d specific
engine{ font, cell_size },
grid_size{ std::max(dot_11, win_coor_px_size_cell.size) },
cell_size{ cell_size },
grip_cell{ grip_cell },
Expand Down Expand Up @@ -1034,10 +1036,13 @@ namespace netxs::gui
::DispatchMessageW(&msg);
}
}
void show()
void show(si32 win_state)
{
auto mode = SW_SHOWNORMAL;
for (auto& w : layers) { ::ShowWindow(w.hWnd, mode); }
if (win_state == 0 || win_state == 2) //todo fullscreen mode (=2). 0 - normal, 1 - minimized, 2 - fullscreen
{
auto mode = SW_SHOWNORMAL;
for (auto& w : layers) { ::ShowWindow(w.hWnd, mode); }
}
}
};
}
57 changes: 37 additions & 20 deletions src/netxs/desktopio/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3350,7 +3350,9 @@ namespace netxs::os
static auto config = text{}; // dtvt: DirectVT configuration XML data.
static auto leadin = text{}; // dtvt: The first block read from stdin.
static auto backup = tios{}; // dtvt: Saved console state to restore at exit.
static auto win_sz = twod{}; // dtvt: Initial window size.
static auto window = rect{}; // dtvt: Initial window area.
static auto windpi = si32{}; // dtvt: Initial window dpi.
static auto iconic = si32{}; // dtvt: Initial window state (normal = 0, minimized = 1, fullscreen = 2).
static auto client = xipc{}; // dtvt: Internal IO link.
static auto uifont = text{}; // dtvt: Font name for gui console.
static auto fontsz = twod{}; // dtvt: Font size for gui console.
Expand All @@ -3365,9 +3367,9 @@ namespace netxs::os
if (ok(::GetConsoleScreenBufferInfo(os::stdout_fd, &cinfo), "::GetConsoleScreenBufferInfo", os::unexpected))
{
nt::console::buffer = { cinfo.dwSize.X, cinfo.dwSize.Y };
winsz = dtvt::scroll ? nt::console::buffer
: twod{ cinfo.srWindow.Right - cinfo.srWindow.Left + 1,
cinfo.srWindow.Bottom - cinfo.srWindow.Top + 1 };
if (dtvt::scroll) winsz = nt::console::buffer;
else winsz = { cinfo.srWindow.Right - cinfo.srWindow.Left + 1,
cinfo.srWindow.Bottom - cinfo.srWindow.Top + 1 };
}
#else
auto size = ::winsize{};
Expand Down Expand Up @@ -3413,7 +3415,7 @@ namespace netxs::os
if (::PeekNamedPipe(os::stdin_fd, buffer.data(), (DWORD)buffer.size(), &length, NULL, NULL)
&& length)
{
dtvt::active = buffer.size() == length && buffer.get(cfsize, dtvt::win_sz);
dtvt::active = buffer.size() == length && buffer.get(cfsize, dtvt::window.size);
if (dtvt::active)
{
io::recv(os::stdin_fd, buffer);
Expand All @@ -3424,7 +3426,7 @@ namespace netxs::os
{
auto header = io::recv(os::stdin_fd, buffer);
length = (DWORD)header.size();
dtvt::active = buffer.size() == length && buffer.get(cfsize, dtvt::win_sz);
dtvt::active = buffer.size() == length && buffer.get(cfsize, dtvt::window.size);
if (!dtvt::active)
{
dtvt::leadin = header;
Expand All @@ -3442,7 +3444,7 @@ namespace netxs::os
auto length = header.length();
if (length)
{
dtvt::active = buffer.size() == length && buffer.get(cfsize, dtvt::win_sz);
dtvt::active = buffer.size() == length && buffer.get(cfsize, dtvt::window.size);
if (!dtvt::active)
{
dtvt::leadin = header;
Expand Down Expand Up @@ -3495,8 +3497,7 @@ namespace netxs::os
}
else
{
dtvt::win_sz = dtvt::consize();
//trygui = faux; //todo Not implemented.
dtvt::window.size = dtvt::consize();
if (trygui)
{
#if defined(_WIN32)
Expand All @@ -3507,20 +3508,36 @@ namespace netxs::os
{
auto modeflags = DWORD{};
::GetConsoleDisplayMode(&modeflags);

auto r = RECT{};
auto h = ::GetConsoleWindow();
dtvt::windpi = (si32)::GetDpiForWindow(h);
if (dtvt::windpi == 0) dtvt::windpi = 96;
ok(::GetWindowRect(h, &r));

dtvt::iconic = modeflags == CONSOLE_FULLSCREEN ? 2 : ::IsIconic(h);

auto maximized = modeflags == CONSOLE_FULLSCREEN;
auto font_info = CONSOLE_FONT_INFOEX{ sizeof(CONSOLE_FONT_INFOEX) };
if (::GetCurrentConsoleFontEx(os::stdout_fd, maximized, &font_info))
if (ok(::GetCurrentConsoleFontEx(os::stdout_fd, maximized, &font_info)))
{
dtvt::uifont = utf::to_utf(font_info.FaceName);
dtvt::fontsz = { font_info.dwFontSize.X, font_info.dwFontSize.Y };
}
if (dtvt::fontsz == dot_00) dtvt::fontsz = { 8, 16 };
if (dtvt::uifont == text{}) dtvt::uifont = "Consolas";
// Centrify window.
dtvt::window.coor = { r.left + (r.right - r.left - dtvt::fontsz.x * dtvt::window.size.x) / 2,
r.top + (r.bottom - r.top - dtvt::fontsz.y * dtvt::window.size.y) / 2 };
dtvt::fontsz = dtvt::fontsz * dtvt::windpi / 96;;
dtvt::window.coor = dtvt::window.coor * dtvt::windpi / 96;;

::FreeConsole();
os::stdin_fd = os::invalid_fd;
os::stdout_fd = os::invalid_fd;
os::stderr_fd = os::invalid_fd;
dtvt::vtmode |= ui::console::gui;
if (dtvt::fontsz == dot_00) dtvt::fontsz = { 8, 16 };
if (dtvt::uifont == text{}) dtvt::uifont = "Consolas";

auto term = "Native GUI console";
log("%%Terminal type: %term%, %font% %w%×%h%", prompt::os, term, dtvt::uifont, dtvt::fontsz.x, dtvt::fontsz.y);
return;
Expand Down Expand Up @@ -4509,7 +4526,7 @@ namespace netxs::os
if (item.form == mime::disabled) input::board::normalize(item);
else item.set();
os::clipboard::set(item);
auto crop = utf::trunc(item.utf8, dtvt::win_sz.y / 2); // Trim preview before sending.
auto crop = utf::trunc(item.utf8, dtvt::window.size.y / 2); // Trim preview before sending.
s11n::sysboard.send(dtvt::client, id_t{}, item.size, crop.str(), item.form);
}
void handle(s11n::xs::clipdata_request lock)
Expand Down Expand Up @@ -4628,7 +4645,7 @@ namespace netxs::os
m.coordxy = { si16min, si16min };
c.fast = true;
f.state = true;
w.winsize = os::dtvt::win_sz;
w.winsize = os::dtvt::window.size;
focus(f);

#if defined(_WIN32)
Expand Down Expand Up @@ -5499,8 +5516,8 @@ namespace netxs::os
}
}
auto clipdata = proxy.clipdata.freeze();
input::board::normalize(clipdata.thing, id_t{}, datetime::now(), dtvt::win_sz / 2, utf8, form, meta);
auto crop = utf::trunc(clipdata.thing.utf8, dtvt::win_sz.y / 2); // Trim preview before sending.
input::board::normalize(clipdata.thing, id_t{}, datetime::now(), dtvt::window.size / 2, utf8, form, meta);
auto crop = utf::trunc(clipdata.thing.utf8, dtvt::window.size.y / 2); // Trim preview before sending.
proxy.sysboard.send(dtvt::client, id_t{}, clipdata.thing.size, crop.str(), clipdata.thing.form);
};
switch (uMsg)
Expand Down Expand Up @@ -5658,7 +5675,7 @@ namespace netxs::os
if (dtvt::vtmode & ui::console::nt16)
{
auto c16 = palette;
c16.srWindow = { .Right = (si16)dtvt::win_sz.x, .Bottom = (si16)dtvt::win_sz.y }; // Suppress unexpected scrollbars.
c16.srWindow = { .Right = (si16)dtvt::window.size.x, .Bottom = (si16)dtvt::window.size.y }; // Suppress unexpected scrollbars.
argb::set_vtm16_palette([&](auto index, auto color){ c16.ColorTable[index] = argb::swap_rb(color); }); // conhost crashes if alpha non zero.
ok(::SetConsoleScreenBufferInfoEx(os::stdout_fd, &c16), "::SetConsoleScreenBufferInfoEx()", os::unexpected);
}
Expand Down Expand Up @@ -5707,7 +5724,7 @@ namespace netxs::os
if (dtvt::vtmode & ui::console::nt16) // Restore pelette.
{
auto count = DWORD{};
ok(::FillConsoleOutputAttribute(os::stdout_fd, 0, dtvt::win_sz.x * dtvt::win_sz.y, {}, &count), "::FillConsoleOutputAttribute()", os::unexpected); // To avoid palette flickering.
ok(::FillConsoleOutputAttribute(os::stdout_fd, 0, dtvt::window.size.x * dtvt::window.size.y, {}, &count), "::FillConsoleOutputAttribute()", os::unexpected); // To avoid palette flickering.
ok(::SetConsoleScreenBufferInfoEx(os::stdout_fd, &palette), "::SetConsoleScreenBufferInfoEx()", os::unexpected);
}
if (saved_fd != os::invalid_fd)
Expand All @@ -5734,9 +5751,9 @@ namespace netxs::os
{
#if defined(WIN32)
using window = gui::window<gui::w32renderer>;
if (auto w = window{{{ 200, 200 }, { 80, 20 }}, { 11, 22 }})
if (auto w = window{ dtvt::window, dtvt::uifont, dtvt::fontsz })
{
w.show();
w.show(dtvt::iconic);
w.dispatch();
}
#else
Expand Down
4 changes: 2 additions & 2 deletions src/vtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ int main(int argc, char* argv[])
}
log("%appname% %version%", apname, app::shared::version);
params = utf::remain(params, ' ');
app::shared::start(params, aptype, os::dtvt::vtmode, os::dtvt::win_sz, config);
app::shared::start(params, aptype, os::dtvt::vtmode, os::dtvt::window.size, config);
}
else
{
Expand Down Expand Up @@ -394,7 +394,7 @@ int main(int argc, char* argv[])
auto cwd = os::env::cwd();
auto cmd = script;
auto cfg = config.utf8();
auto win = os::dtvt::win_sz;
auto win = os::dtvt::window.size;
userinit.send(client, userid.first, os::dtvt::vtmode, env, cwd, cmd, cfg, win);
os::tty::splice(client);
return 0;
Expand Down

0 comments on commit cba3db7

Please sign in to comment.