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.
This commit is contained in:
Josef Söntgen 2018-01-19 09:23:56 +01:00 committed by Norman Feske
parent 6575df84c5
commit fe6f616cf1
2 changed files with 55 additions and 14 deletions
repos/os/src/server/nit_fb

@ -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.

@ -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()