From cd7e3425ee77ff8e3abf4057a34b15a6fa0cb6a7 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 8 Feb 2018 19:03:32 +0100 Subject: [PATCH] nit_fb: allow screen-relative initial_width/height This change enables the use of negative values for the 'initial_width' and 'initial_height' attributes to specify values that are relative to the screen size. This is consistent with the meaning of the 'width' and 'height' attributes. --- repos/os/src/server/nit_fb/main.cc | 40 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/repos/os/src/server/nit_fb/main.cc b/repos/os/src/server/nit_fb/main.cc index 198f1a1efa..af8963cb84 100644 --- a/repos/os/src/server/nit_fb/main.cc +++ b/repos/os/src/server/nit_fb/main.cc @@ -231,30 +231,40 @@ struct Nit_fb::Main : View_updater struct Initial_size { - unsigned const width { 0 }; - unsigned const height { 0 }; + long const _width { 0 }; + long const _height { 0 }; bool set { false }; Initial_size(Genode::Xml_node config) : - width(config.attribute_value("initial_width", 0u)), - height(config.attribute_value("initial_height", 0u)) + _width (config.attribute_value("initial_width", 0L)), + _height(config.attribute_value("initial_height", 0L)) { } - bool valid() const { return width != 0 && height != 0; } + unsigned width(Framebuffer::Mode const &mode) const + { + if (_width > 0) return _width; + if (_width < 0) return mode.width() + _width; + return mode.width(); + } + + unsigned height(Framebuffer::Mode const &mode) const + { + if (_height > 0) return _height; + if (_height < 0) return mode.height() + _height; + return mode.height(); + } + + bool valid() const { return _width != 0 && _height != 0; } + } _initial_size { config_rom.xml() }; Framebuffer::Mode _initial_mode() { - unsigned const width = _initial_size.valid() - ? _initial_size.width - : (unsigned)nitpicker.mode().width(); - unsigned const height = _initial_size.valid() - ? _initial_size.height - : (unsigned)nitpicker.mode().height(); - - return Framebuffer::Mode(width, height, nitpicker.mode().format()); + return Framebuffer::Mode(_initial_size.width (nitpicker.mode()), + _initial_size.height(nitpicker.mode()), + nitpicker.mode().format()); } /* @@ -329,8 +339,8 @@ struct Nit_fb::Main : View_updater height = config.attribute_value("height", (long)nit_mode.height()); if (!_initial_size.set && _initial_size.valid()) { - width = _initial_size.width; - height = _initial_size.height; + width = _initial_size.width (nit_mode); + height = _initial_size.height(nit_mode); _initial_size.set = true; } else {