nit_fb: Respond to config changes at runtime
This patch enables 'nit_fb' to respond to dynamic changes of its configuration, in particular the view position and refresh rate.
This commit is contained in:
parent
fca8994584
commit
7217ea14d8
|
@ -119,6 +119,22 @@ long config_arg(const char *attr, long default_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct Config_args
|
||||||
|
{
|
||||||
|
long xpos, ypos, width, height;
|
||||||
|
unsigned refresh_rate;
|
||||||
|
|
||||||
|
Config_args()
|
||||||
|
:
|
||||||
|
xpos(config_arg("xpos", 0)),
|
||||||
|
ypos(config_arg("ypos", 0)),
|
||||||
|
width(config_arg("width", 0)),
|
||||||
|
height(config_arg("height", 0)),
|
||||||
|
refresh_rate(config_arg("refresh_rate", 0))
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
@ -126,9 +142,9 @@ int main(int argc, char **argv)
|
||||||
/*
|
/*
|
||||||
* Read arguments from config
|
* Read arguments from config
|
||||||
*/
|
*/
|
||||||
long view_x = config_arg("xpos", 0), view_y = config_arg("ypos", 0),
|
Config_args cfg;
|
||||||
view_w = config_arg("width", 0), view_h = config_arg("height", 0),
|
long view_x = cfg.xpos, view_y = cfg.ypos,
|
||||||
refresh_rate = config_arg("refresh_rate", 0);
|
view_w = cfg.width, view_h = cfg.height;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open Nitpicker session
|
* Open Nitpicker session
|
||||||
|
@ -144,8 +160,8 @@ int main(int argc, char **argv)
|
||||||
view_w = mode.width(), view_h = mode.height();
|
view_w = mode.width(), view_h = mode.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
PINF("using xywh=(%ld,%ld,%ld,%ld) refresh_rate=%ld",
|
PINF("using xywh=(%ld,%ld,%ld,%ld) refresh_rate=%u",
|
||||||
view_x, view_y, view_w, view_h, refresh_rate);
|
view_x, view_y, view_w, view_h, cfg.refresh_rate);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create Nitpicker view and bring it to front
|
* Create Nitpicker view and bring it to front
|
||||||
|
@ -183,14 +199,45 @@ int main(int argc, char **argv)
|
||||||
env()->parent()->announce(ep.manage(&fb_root));
|
env()->parent()->announce(ep.manage(&fb_root));
|
||||||
env()->parent()->announce(ep.manage(&input_root));
|
env()->parent()->announce(ep.manage(&input_root));
|
||||||
|
|
||||||
if (!refresh_rate)
|
/*
|
||||||
sleep_forever();
|
* Register signal handler for config changes
|
||||||
|
*/
|
||||||
|
Signal_receiver sig_rec;
|
||||||
|
Signal_context sig_ctx;
|
||||||
|
config()->sigh(sig_rec.manage(&sig_ctx));
|
||||||
|
|
||||||
static Timer::Connection timer;
|
for (;;) {
|
||||||
static Framebuffer::Session_client nit_fb(nitpicker.framebuffer_session());
|
|
||||||
while (true) {
|
bool reload_config = false;
|
||||||
timer.msleep(refresh_rate);
|
|
||||||
nit_fb.refresh(0, 0, view_w, view_h);
|
if (!cfg.refresh_rate) {
|
||||||
|
|
||||||
|
sig_rec.wait_for_signal();
|
||||||
|
reload_config = true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
static Timer::Connection timer;
|
||||||
|
static Framebuffer::Session_client nit_fb(nitpicker.framebuffer_session());
|
||||||
|
|
||||||
|
timer.msleep(cfg.refresh_rate);
|
||||||
|
nit_fb.refresh(0, 0, view_w, view_h);
|
||||||
|
|
||||||
|
if (sig_rec.pending()) {
|
||||||
|
sig_rec.wait_for_signal();
|
||||||
|
reload_config = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reload_config) {
|
||||||
|
try {
|
||||||
|
config()->reload();
|
||||||
|
cfg = Config_args();
|
||||||
|
view.viewport(cfg.xpos, cfg.ypos, cfg.width, cfg.height, 0, 0, true);
|
||||||
|
} catch (...) {
|
||||||
|
PERR("Error while reloading config");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
TARGET = nit_fb
|
TARGET = nit_fb
|
||||||
SRC_CC = main.cc
|
SRC_CC = main.cc
|
||||||
LIBS = cxx env server
|
LIBS = cxx env server signal
|
||||||
|
|
Loading…
Reference in New Issue