From fe6f616cf10ae8a3435a259b9b39a51e0e4b28f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Fri, 19 Jan 2018 09:23:56 +0100 Subject: [PATCH] nit_fb: add attribute for initial dimensions The 'initial_width' and 'initial_height' attributes were added to accomodate the use-case to set the initial dimensions whenever 'nit_fb' is used in a dynamic fashion, e.g, in combination with a window manager. These attributes may not be mixed with the 'width' and 'height' attributes, which are mostly used when a static size configuration is desired. --- repos/os/src/server/nit_fb/README | 5 +++ repos/os/src/server/nit_fb/main.cc | 64 +++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/repos/os/src/server/nit_fb/README b/repos/os/src/server/nit_fb/README index a87654ae53..3c638e3e2b 100644 --- a/repos/os/src/server/nit_fb/README +++ b/repos/os/src/server/nit_fb/README @@ -17,3 +17,8 @@ relative to the physical screen size. E.g., when using a screen size of 640x480, the effective width for a 'width' attribute value of "-100" would be 640 - 100 = 540. +In case 'nit_fb' is used in a dynamic fashion, e.g., in combination with a +window manager, the 'initial_width' and 'initial_height' attributes must be +used to set the initial dimensions of the frame buffer rather than 'width' +and 'height'. Mixing those attributes is not supported, 'width' or 'height' +will have priority. diff --git a/repos/os/src/server/nit_fb/main.cc b/repos/os/src/server/nit_fb/main.cc index c9ddfd78b9..198f1a1efa 100644 --- a/repos/os/src/server/nit_fb/main.cc +++ b/repos/os/src/server/nit_fb/main.cc @@ -229,12 +229,32 @@ struct Nit_fb::Main : View_updater Genode::Attached_dataspace input_ds { env.rm(), nitpicker.input()->dataspace() }; + struct Initial_size + { + unsigned const width { 0 }; + unsigned 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)) + { } + + bool valid() const { return width != 0 && height != 0; } + } _initial_size { config_rom.xml() }; + Framebuffer::Mode _initial_mode() { - return Framebuffer::Mode( - config_rom.xml().attribute_value("width", (unsigned)nitpicker.mode().width()), - config_rom.xml().attribute_value("height", (unsigned)nitpicker.mode().height()), - nitpicker.mode().format()); + 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()); } /* @@ -293,15 +313,35 @@ struct Nit_fb::Main : View_updater + Point(config.attribute_value("xpos", 0L), config.attribute_value("ypos", 0L)); + bool const attr = config.has_attribute("width") || + config.has_attribute("height"); + if (_initial_size.valid() && attr) { + Genode::warning("setting both inital and normal attributes not " + " supported, ignore initial size"); + /* force initial to disable check below */ + _initial_size.set = true; + } + + unsigned const nit_width = nit_mode.width(); + unsigned const nit_height = nit_mode.height(); + long width = config.attribute_value("width", (long)nit_mode.width()), height = config.attribute_value("height", (long)nit_mode.height()); - /* - * If configured width / height values are negative, the effective - * width / height is deduced from the screen size. - */ - if (width < 0) width = nit_mode.width() + width; - if (height < 0) height = nit_mode.height() + height; + if (!_initial_size.set && _initial_size.valid()) { + width = _initial_size.width; + height = _initial_size.height; + + _initial_size.set = true; + } else { + + /* + * If configured width / height values are negative, the effective + * width / height is deduced from the screen size. + */ + if (width < 0) width = nit_width + width; + if (height < 0) height = nit_height + height; + } fb_session.size(Area(width, height)); @@ -310,10 +350,6 @@ struct Nit_fb::Main : View_updater * initial mode the active mode. */ fb_session.mode(); - - Genode::log("using xywh=(", position.x(), ",", position.y(), - ",", fb_session.size().w(), - ",", fb_session.size().h(), ")"); } void handle_config_update()