@@ -758,6 +758,12 @@ class output_wrapper
758
758
std::string description;
759
759
uint32_t scale = 1 ;
760
760
761
+ uint32_t get_dpi () const noexcept
762
+ {
763
+ auto dpi = (this ->resolution * utki::mm_per_inch).comp_div (this ->physical_size_mm );
764
+ return (dpi.x () + dpi.y ()) / 2 ;
765
+ }
766
+
761
767
output_wrapper (wl_registry& registry, uint32_t id, uint32_t interface_version) :
762
768
output ([&]() {
763
769
void * output = wl_registry_bind (®istry, id, &wl_output_interface, std::min (interface_version, 2u ));
@@ -1109,23 +1115,35 @@ struct surface_wrapper {
1109
1115
wl_surface_set_opaque_region (this ->sur , region.reg );
1110
1116
}
1111
1117
1112
- uint32_t find_max_scale (const std::map<uint32_t , output_wrapper>& outputs)
1118
+ struct scale_and_dpi {
1119
+ uint32_t scale = 1 ;
1120
+ uint32_t dpi = 96 ;
1121
+ };
1122
+
1123
+ scale_and_dpi find_scale_and_dpi (const std::map<uint32_t , output_wrapper>& outputs)
1113
1124
{
1114
- std::cout << " looking for max scale" << std::endl;
1125
+ LOG ([](auto & o) {
1126
+ o << " looking for max scale" << std::endl;
1127
+ })
1115
1128
1116
1129
// if surface did not enter any outputs yet, then just take scale of first available output
1117
1130
if (this ->outputs .empty ()) {
1118
- std::cout << " surface has not entered any outputs yet" << std::endl;
1119
- return 1 ;
1131
+ LOG ([](auto & o) {
1132
+ o << " surface has not entered any outputs yet" << std::endl;
1133
+ })
1134
+ return {};
1120
1135
}
1121
1136
1122
- uint32_t max_scale = 1 ;
1137
+ uint32_t max_scale;
1138
+ uint32_t dpi;
1123
1139
1124
1140
// go through outputs which the surface has entered
1125
1141
for (auto wlo : this ->outputs ) {
1126
1142
auto id = get_output_id (wlo);
1127
1143
1128
- std::cout << " check output id = " << id << std::endl;
1144
+ LOG ([&](auto & o) {
1145
+ o << " check output id = " << id << std::endl;
1146
+ })
1129
1147
1130
1148
auto i = outputs.find (id);
1131
1149
if (i == outputs.end ()) {
@@ -1136,12 +1154,20 @@ struct surface_wrapper {
1136
1154
continue ;
1137
1155
}
1138
1156
1139
- std::cout << " output found, scale = " << i->second . scale << std::endl ;
1157
+ auto & output = i->second ;
1140
1158
1141
- max_scale = std::max (i->second .scale , max_scale);
1159
+ LOG ([&](auto & o) {
1160
+ o << " output found, scale = " << output.scale << std::endl;
1161
+ })
1162
+
1163
+ max_scale = std::max (output.scale , max_scale);
1164
+ dpi = output.get_dpi ();
1142
1165
}
1143
1166
1144
- return max_scale;
1167
+ return {
1168
+ .scale = max_scale, //
1169
+ .dpi = dpi
1170
+ };
1145
1171
}
1146
1172
1147
1173
private:
@@ -2016,9 +2042,9 @@ struct window_wrapper : public utki::destructable {
2016
2042
o << " resize window to " << std::dec << dims << std::endl;
2017
2043
})
2018
2044
2019
- auto scale = this ->surface .find_max_scale (this ->registry .outputs );
2045
+ auto sd = this ->surface .find_scale_and_dpi (this ->registry .outputs );
2020
2046
2021
- dims *= scale;
2047
+ dims *= sd. scale ;
2022
2048
2023
2049
wl_egl_window_resize (this ->egl_window .win , int (dims.x ()), int (dims.y ()), 0 , 0 );
2024
2050
@@ -2031,16 +2057,17 @@ struct window_wrapper : public utki::destructable {
2031
2057
this ->surface .commit ();
2032
2058
2033
2059
LOG ([&](auto & o) {
2034
- o << " final window scale = " << scale << std::endl;
2060
+ o << " final window scale = " << sd. scale << std::endl;
2035
2061
})
2036
2062
2037
- this ->scale = ruis::real (scale);
2063
+ this ->scale = ruis::real (sd. scale );
2038
2064
2039
2065
auto & app = ruisapp::inst ();
2040
2066
2041
2067
// update ruis::context::units
2042
- app.gui .context .get ().units .set_dots_per_pp (this ->scale );
2043
- // TODO: update dots_per_inch
2068
+ auto & units = app.gui .context .get ().units ;
2069
+ units.set_dots_per_pp (this ->scale );
2070
+ units.set_dots_per_inch (ruis::real (sd.dpi ));
2044
2071
2045
2072
update_window_rect (app, ruis::rect (0 , dims.to <ruis::real>()));
2046
2073
}
0 commit comments