Skip to content

Commit

Permalink
window size scale factor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Gagis committed Jan 9, 2024
1 parent 208ed8d commit 534839e
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/mordavokne/glue/linux/glue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,28 @@ struct window_wrapper : public utki::destructable {

window_wrapper(const window_params& wp)
{
// set scale factor
{
// GDK-4 version commented out because GDK-4 is not available in Debian 11

// auto display_name = DisplayString(ww.display.display);
// std::cout << "display name = " << display_name << std::endl;
// auto disp = gdk_display_open(display_name);
// utki::assert(disp, SL);
// std::cout << "gdk display name = " << gdk_display_get_name(disp) << std::endl;
// auto surf = gdk_surface_new_toplevel (disp);
// utki::assert(surf, SL);
// auto mon = gdk_display_get_monitor_at_surface (disp, surf);
// utki::assert(mon, SL);
// int sf = gdk_monitor_get_scale_factor(mon);

// GDK-3 version
int sf = gdk_window_get_scale_factor(gdk_get_default_root_window());
this->scale_factor = morda::real(sf);

std::cout << "display scale factor = " << this->scale_factor << std::endl;
}

#ifdef MORDAVOKNE_RENDER_OPENGL
{
int glx_ver_major = 0;
Expand Down Expand Up @@ -452,14 +474,16 @@ struct window_wrapper : public utki::destructable {
PointerMotionMask | ButtonMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask;
unsigned long fields = CWBorderPixel | CWColormap | CWEventMask;

auto dims = (this->scale_factor * wp.dims.to<morda::real>()).to<unsigned>();

this->window = XCreateWindow(
this->display.display,
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
RootWindow(this->display.display, visual_info->screen),
0,
0,
wp.dims.x(),
wp.dims.y(),
dims.x(),
dims.y(),
0,
visual_info->depth,
InputOutput,
Expand Down Expand Up @@ -715,26 +739,6 @@ struct window_wrapper : public utki::destructable {
# error "Unknown graphics API"
#endif

// set scale factor
{
// GDK-4 version commented out because GDK-4 is not available in Debian 11

// auto display_name = DisplayString(ww.display.display);
// std::cout << "display name = " << display_name << std::endl;
// auto disp = gdk_display_open(display_name);
// utki::assert(disp, SL);
// std::cout << "gdk display name = " << gdk_display_get_name(disp) << std::endl;
// auto surf = gdk_surface_new_toplevel (disp);
// utki::assert(surf, SL);
// auto mon = gdk_display_get_monitor_at_surface (disp, surf);
// utki::assert(mon, SL);
// int sf = gdk_monitor_get_scale_factor(mon);

// GDK-3 version
int sf = gdk_window_get_scale_factor(gdk_get_default_root_window());
this->scale_factor = morda::real(sf);
}

// initialize input method

this->inputMethod = XOpenIM(this->display.display, nullptr, nullptr, nullptr);
Expand Down

0 comments on commit 534839e

Please sign in to comment.