2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Launchpad main program
|
|
|
|
* \date 2006-08-30
|
|
|
|
* \author Norman Feske
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
2016-11-23 17:07:49 +01:00
|
|
|
#include <base/component.h>
|
2016-11-25 16:54:49 +01:00
|
|
|
#include <base/attached_rom_dataspace.h>
|
2017-01-11 16:06:26 +01:00
|
|
|
#include <base/heap.h>
|
2016-11-23 17:07:49 +01:00
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
#include <scout/platform.h>
|
|
|
|
#include <scout/tick.h>
|
|
|
|
#include <scout/user_state.h>
|
|
|
|
#include <scout/nitpicker_graphics_backend.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "elements.h"
|
|
|
|
#include "launchpad_window.h"
|
|
|
|
|
|
|
|
|
2017-01-11 16:06:26 +01:00
|
|
|
static Genode::Allocator *_alloc_ptr;
|
|
|
|
|
|
|
|
void *operator new (__SIZE_TYPE__ n) { return _alloc_ptr->alloc(n); }
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Scout;
|
|
|
|
using namespace Genode;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Facility to keep the available quota display up-to-date
|
|
|
|
*/
|
2013-12-30 01:21:53 +01:00
|
|
|
class Avail_quota_update : public Scout::Tick
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2019-01-21 14:27:12 +01:00
|
|
|
Pd_session &_pd;
|
|
|
|
Launchpad &_launchpad;
|
|
|
|
size_t _avail = 0;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2019-01-21 14:27:12 +01:00
|
|
|
Avail_quota_update(Pd_session &pd, Launchpad &launchpad)
|
2017-01-11 16:06:26 +01:00
|
|
|
:
|
2019-01-21 14:27:12 +01:00
|
|
|
_pd(pd), _launchpad(launchpad)
|
2017-01-11 16:06:26 +01:00
|
|
|
{
|
|
|
|
schedule(200);
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tick interface
|
|
|
|
*/
|
2019-02-14 22:39:08 +01:00
|
|
|
int on_tick() override
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2019-01-21 14:27:12 +01:00
|
|
|
size_t new_avail = _pd.avail_ram().value;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* update launchpad window if needed */
|
|
|
|
if (new_avail != _avail)
|
2017-01-11 16:06:26 +01:00
|
|
|
_launchpad.quota(new_avail);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
_avail = new_avail;
|
|
|
|
|
|
|
|
/* schedule next tick */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-23 17:07:49 +01:00
|
|
|
struct Main : Scout::Event_handler
|
|
|
|
{
|
2017-01-11 16:06:26 +01:00
|
|
|
Env &_env;
|
|
|
|
|
|
|
|
Heap _heap { _env.ram(), _env.rm() };
|
|
|
|
|
|
|
|
bool const _global_new_initialized = (_alloc_ptr = &_heap, true);
|
|
|
|
|
|
|
|
Nitpicker::Connection _nitpicker { _env };
|
|
|
|
|
|
|
|
Platform _platform { _env, *_nitpicker.input() };
|
|
|
|
|
|
|
|
bool const _event_handler_registered = (_platform.event_handler(*this), true);
|
|
|
|
|
|
|
|
Attached_rom_dataspace _config { _env, "config" };
|
|
|
|
|
|
|
|
int const _initial_x = _config.xml().attribute_value("xpos", 550U);
|
|
|
|
int const _initial_y = _config.xml().attribute_value("ypos", 150U);
|
|
|
|
unsigned const _initial_w = _config.xml().attribute_value("width", 400U);
|
|
|
|
unsigned const _initial_h = _config.xml().attribute_value("height", 400U);
|
|
|
|
|
|
|
|
Scout::Area const _max_size { 530, 620 };
|
|
|
|
Scout::Point const _initial_position { _initial_x, _initial_y };
|
|
|
|
Scout::Area const _initial_size { _initial_w, _initial_h };
|
|
|
|
|
|
|
|
Nitpicker_graphics_backend
|
|
|
|
_graphics_backend { _env.rm(), _nitpicker, _heap, _max_size,
|
|
|
|
_initial_position, _initial_size };
|
|
|
|
|
|
|
|
Launchpad_window<Pixel_rgb565>
|
|
|
|
_launchpad { _env, _graphics_backend, _initial_position, _initial_size,
|
2019-01-21 14:27:12 +01:00
|
|
|
_max_size, _env.pd().avail_ram().value };
|
2017-01-11 16:06:26 +01:00
|
|
|
|
|
|
|
void _process_config()
|
|
|
|
{
|
|
|
|
try { _launchpad.process_config(_config.xml()); } catch (...) { }
|
|
|
|
}
|
2016-11-23 17:07:49 +01:00
|
|
|
|
2017-01-11 16:06:26 +01:00
|
|
|
bool const _config_processed = (_process_config(), true);
|
2016-11-23 17:07:49 +01:00
|
|
|
|
2019-01-21 14:27:12 +01:00
|
|
|
Avail_quota_update _avail_quota_update { _env.pd(), _launchpad };
|
2017-01-11 16:06:26 +01:00
|
|
|
|
|
|
|
User_state _user_state { &_launchpad, &_launchpad,
|
|
|
|
_initial_position.x(), _initial_position.y() };
|
|
|
|
|
|
|
|
void _init_launchpad()
|
|
|
|
{
|
|
|
|
_launchpad.parent(&_user_state);
|
|
|
|
_launchpad.format(_initial_size);
|
|
|
|
_launchpad.ypos(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool const _launchpad_initialized = (_init_launchpad(), true);
|
|
|
|
|
2019-04-09 15:46:36 +02:00
|
|
|
Genode::uint64_t _old_time = _platform.timer_ticks();
|
2016-11-23 17:07:49 +01:00
|
|
|
|
|
|
|
void handle_event(Scout::Event const &event) override
|
|
|
|
{
|
|
|
|
using namespace Scout;
|
|
|
|
|
|
|
|
Event ev = event;
|
|
|
|
|
|
|
|
if (ev.type != Event::WHEEL)
|
|
|
|
ev.mouse_position = ev.mouse_position - _user_state.view_position();
|
|
|
|
|
|
|
|
_user_state.handle_event(ev);
|
|
|
|
|
|
|
|
if (ev.type == Event::TIMER)
|
2017-01-11 16:06:26 +01:00
|
|
|
Tick::handle(_platform.timer_ticks());
|
2016-11-23 17:07:49 +01:00
|
|
|
|
|
|
|
/* perform periodic redraw */
|
2019-04-09 15:46:36 +02:00
|
|
|
Genode::uint64_t const curr_time = _platform.timer_ticks();
|
2017-01-11 16:06:26 +01:00
|
|
|
if (!_platform.event_pending() && ((curr_time - _old_time > 20)
|
|
|
|
|| (curr_time < _old_time))) {
|
2016-11-23 17:07:49 +01:00
|
|
|
_old_time = curr_time;
|
|
|
|
_launchpad.process_redraw();
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-01-11 16:06:26 +01:00
|
|
|
Main(Env &env) : _env(env) { }
|
|
|
|
};
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2017-03-15 15:40:55 +01:00
|
|
|
void Component::construct(Genode::Env &env)
|
|
|
|
{
|
|
|
|
/* XXX execute constructors of global statics */
|
|
|
|
env.exec_static_constructors();
|
|
|
|
|
|
|
|
static Main main(env);
|
|
|
|
}
|