mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-20 09:46:20 +00:00
gui_session,nitpicker,testnit: update coding style
- Replace 'typedef' by 'using' - Avoid plain pointers - Import Genode namespace into Gui:: - Use enum class - Use Attr struct for passing multiple attributes - Turn testnit into proper Genode::Component - Use distinct types for top-level and child views - Remove dependency from timer - Use util/geometry.h
This commit is contained in:
parent
06d098052f
commit
b9594c2ae8
@ -150,7 +150,7 @@ struct Gui::Session_component : Rpc_object<Gui::Session>
|
||||
* Do not call 'Connection::buffer' to avoid paying session quota
|
||||
* from our own budget.
|
||||
*/
|
||||
_connection.Client::buffer(mode, use_alpha);
|
||||
_connection.Session_client::buffer(mode, use_alpha);
|
||||
}
|
||||
|
||||
void focus(Capability<Gui::Session> session) override {
|
||||
|
@ -154,7 +154,7 @@ struct Sandboxed_runtime::Gui_session : Session_object<Gui::Session>
|
||||
* Do not call 'Connection::buffer' to avoid paying session quota
|
||||
* from our own budget.
|
||||
*/
|
||||
_connection.Client::buffer(mode, use_alpha);
|
||||
_connection.Session_client::buffer(mode, use_alpha);
|
||||
}
|
||||
|
||||
void focus(Capability<Gui::Session> session) override {
|
||||
|
@ -1061,7 +1061,7 @@ class Wm::Gui::Session_component : public Rpc_object<Gui::Session>,
|
||||
};
|
||||
|
||||
|
||||
class Wm::Gui::Root : public Genode::Rpc_object<Genode::Typed_root<Session> >,
|
||||
class Wm::Gui::Root : public Genode::Rpc_object<Genode::Typed_root<Gui::Session> >,
|
||||
public Decorator_content_callback
|
||||
{
|
||||
private:
|
||||
@ -1247,7 +1247,7 @@ class Wm::Gui::Root : public Genode::Rpc_object<Genode::Typed_root<Session> >,
|
||||
}
|
||||
}
|
||||
|
||||
return Session_capability();
|
||||
return { };
|
||||
}
|
||||
|
||||
void upgrade(Genode::Session_capability session_cap, Upgrade_args const &args) override
|
||||
@ -1395,13 +1395,13 @@ class Wm::Gui::Root : public Genode::Rpc_object<Genode::Typed_root<Session> >,
|
||||
s->content_geometry(id, rect);
|
||||
}
|
||||
|
||||
Capability<Session> lookup_gui_session(unsigned win_id)
|
||||
Capability<Gui::Session> lookup_gui_session(unsigned win_id)
|
||||
{
|
||||
for (Session_component *s = _sessions.first(); s; s = s->next())
|
||||
if (s->has_win_id(win_id))
|
||||
return s->session();
|
||||
|
||||
return Capability<Session>();
|
||||
return { };
|
||||
}
|
||||
|
||||
void request_resize(unsigned win_id, Area size)
|
||||
|
@ -143,7 +143,7 @@ class Pdf_view
|
||||
_nit_mode.area.h/4);
|
||||
|
||||
typedef Gui::Session::Command Command;
|
||||
_gui.enqueue<Command::Geometry>(_view, Rect(Point(), _nit_mode.area));
|
||||
_gui.enqueue<Command::Geometry>(_view, Gui::Rect(Gui::Point(), _nit_mode.area));
|
||||
_gui.enqueue<Command::To_front>(_view, Gui::Session::View_handle());
|
||||
_gui.execute();
|
||||
}
|
||||
|
@ -21,11 +21,11 @@
|
||||
namespace Gui { struct Session_client; }
|
||||
|
||||
|
||||
class Gui::Session_client : public Genode::Rpc_client<Session>
|
||||
class Gui::Session_client : public Rpc_client<Session>
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Attached_dataspace _command_ds;
|
||||
Attached_dataspace _command_ds;
|
||||
|
||||
Command_buffer &_command_buffer;
|
||||
|
||||
@ -34,7 +34,7 @@ class Gui::Session_client : public Genode::Rpc_client<Session>
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Session_client(Genode::Region_map &rm, Session_capability session)
|
||||
Session_client(Region_map &rm, Session_capability session)
|
||||
:
|
||||
Rpc_client<Session>(session),
|
||||
_command_ds(rm, command_dataspace()),
|
||||
@ -65,7 +65,7 @@ class Gui::Session_client : public Genode::Rpc_client<Session>
|
||||
void release_view_handle(View_handle handle) override {
|
||||
call<Rpc_release_view_handle>(handle); }
|
||||
|
||||
Genode::Dataspace_capability command_dataspace() override {
|
||||
Dataspace_capability command_dataspace() override {
|
||||
return call<Rpc_command_dataspace>(); }
|
||||
|
||||
void execute() override
|
||||
@ -77,7 +77,7 @@ class Gui::Session_client : public Genode::Rpc_client<Session>
|
||||
Framebuffer::Mode mode() override {
|
||||
return call<Rpc_mode>(); }
|
||||
|
||||
void mode_sigh(Genode::Signal_context_capability sigh) override {
|
||||
void mode_sigh(Signal_context_capability sigh) override {
|
||||
call<Rpc_mode_sigh>(sigh); }
|
||||
|
||||
void buffer(Framebuffer::Mode mode, bool alpha) override {
|
||||
|
@ -29,14 +29,14 @@ class Gui::Connection : public Genode::Connection<Session>,
|
||||
|
||||
Framebuffer::Session_client _framebuffer;
|
||||
Input::Session_client _input;
|
||||
Genode::size_t _session_quota = 0;
|
||||
size_t _session_quota = 0;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Connection(Genode::Env &env, Label const &label = Label())
|
||||
Connection(Env &env, Label const &label = Label())
|
||||
:
|
||||
/* establish nitpicker session */
|
||||
Genode::Connection<Session>(env, label, Ram_quota { 36*1024 }, Args()),
|
||||
@ -49,8 +49,8 @@ class Gui::Connection : public Genode::Connection<Session>,
|
||||
|
||||
void buffer(Framebuffer::Mode mode, bool use_alpha) override
|
||||
{
|
||||
Genode::size_t const needed = ram_quota(mode, use_alpha);
|
||||
Genode::size_t const upgrade = needed > _session_quota
|
||||
size_t const needed = ram_quota(mode, use_alpha);
|
||||
size_t const upgrade = needed > _session_quota
|
||||
? needed - _session_quota
|
||||
: 0;
|
||||
if (upgrade > 0) {
|
||||
|
@ -22,20 +22,17 @@
|
||||
|
||||
namespace Gui {
|
||||
|
||||
using Genode::size_t;
|
||||
using namespace Genode;
|
||||
|
||||
struct Session_client;
|
||||
struct View;
|
||||
struct Session;
|
||||
|
||||
typedef Genode::Capability<View> View_capability;
|
||||
using View_capability = Capability<View>;
|
||||
|
||||
typedef Genode::Surface_base::Rect Rect;
|
||||
typedef Genode::Surface_base::Point Point;
|
||||
typedef Genode::Surface_base::Area Area;
|
||||
|
||||
typedef Genode::Out_of_ram Out_of_ram;
|
||||
typedef Genode::Out_of_caps Out_of_caps;
|
||||
using Rect = Surface_base::Rect;
|
||||
using Point = Surface_base::Point;
|
||||
using Area = Surface_base::Area;
|
||||
}
|
||||
|
||||
|
||||
@ -55,15 +52,13 @@ struct Gui::Session : Genode::Session
|
||||
static constexpr unsigned CAP_QUOTA = Framebuffer::Session::CAP_QUOTA
|
||||
+ Input::Session::CAP_QUOTA + 3;
|
||||
|
||||
typedef Session_client Client;
|
||||
|
||||
/**
|
||||
* Session-local view handle
|
||||
*
|
||||
* When issuing commands to nitpicker via the 'execute' method, views
|
||||
* are referenced by session-local handles.
|
||||
*/
|
||||
typedef Genode::Handle<View> View_handle;
|
||||
using View_handle = Handle<View>;
|
||||
|
||||
|
||||
struct Command
|
||||
@ -72,10 +67,6 @@ struct Gui::Session : Genode::Session
|
||||
OP_TO_FRONT, OP_TO_BACK, OP_BACKGROUND,
|
||||
OP_TITLE, OP_NOP };
|
||||
|
||||
/*
|
||||
* Argument structures for nitpicker's command interface
|
||||
*/
|
||||
|
||||
struct Nop { static Opcode opcode() { return OP_NOP; } };
|
||||
|
||||
struct Geometry
|
||||
@ -116,7 +107,7 @@ struct Gui::Session : Genode::Session
|
||||
{
|
||||
static Opcode opcode() { return OP_TITLE; }
|
||||
View_handle view;
|
||||
Genode::String<64> title;
|
||||
String<64> title;
|
||||
};
|
||||
|
||||
Opcode opcode;
|
||||
@ -183,17 +174,14 @@ struct Gui::Session : Genode::Session
|
||||
|
||||
Command get(unsigned i)
|
||||
{
|
||||
if (i >= MAX_COMMANDS) return Command(Command::Nop());
|
||||
|
||||
return _commands[i];
|
||||
return (i < MAX_COMMANDS) ? _commands[i] : Command(Command::Nop());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Exception types
|
||||
*/
|
||||
struct Invalid_handle : Genode::Exception { };
|
||||
struct Invalid_handle : Exception { };
|
||||
|
||||
virtual ~Session() { }
|
||||
|
||||
@ -258,7 +246,7 @@ struct Gui::Session : Genode::Session
|
||||
/**
|
||||
* Request dataspace used for issuing view commands to nitpicker
|
||||
*/
|
||||
virtual Genode::Dataspace_capability command_dataspace() = 0;
|
||||
virtual Dataspace_capability command_dataspace() = 0;
|
||||
|
||||
/**
|
||||
* Execution batch of commands contained in the command dataspace
|
||||
@ -273,7 +261,7 @@ struct Gui::Session : Genode::Session
|
||||
/**
|
||||
* Register signal handler to be notified about mode changes
|
||||
*/
|
||||
virtual void mode_sigh(Genode::Signal_context_capability) = 0;
|
||||
virtual void mode_sigh(Signal_context_capability) = 0;
|
||||
|
||||
/**
|
||||
* Define dimensions of virtual framebuffer
|
||||
@ -297,9 +285,7 @@ struct Gui::Session : Genode::Session
|
||||
* referred to by its session capability, a common parent can manage the
|
||||
* focus among its children. But unrelated sessions cannot interfere.
|
||||
*/
|
||||
virtual void focus(Genode::Capability<Session> focused) = 0;
|
||||
|
||||
typedef Genode::String<160> Label;
|
||||
virtual void focus(Capability<Session> focused) = 0;
|
||||
|
||||
/**
|
||||
* Return number of bytes needed for virtual framebuffer of specified size
|
||||
@ -327,12 +313,12 @@ struct Gui::Session : Genode::Session
|
||||
GENODE_TYPE_LIST(Out_of_ram, Out_of_caps), View_capability, View_handle);
|
||||
GENODE_RPC(Rpc_view_capability, View_capability, view_capability, View_handle);
|
||||
GENODE_RPC(Rpc_release_view_handle, void, release_view_handle, View_handle);
|
||||
GENODE_RPC(Rpc_command_dataspace, Genode::Dataspace_capability, command_dataspace);
|
||||
GENODE_RPC(Rpc_command_dataspace, Dataspace_capability, command_dataspace);
|
||||
GENODE_RPC(Rpc_execute, void, execute);
|
||||
GENODE_RPC(Rpc_background, int, background, View_capability);
|
||||
GENODE_RPC(Rpc_mode, Framebuffer::Mode, mode);
|
||||
GENODE_RPC(Rpc_mode_sigh, void, mode_sigh, Genode::Signal_context_capability);
|
||||
GENODE_RPC(Rpc_focus, void, focus, Genode::Capability<Session>);
|
||||
GENODE_RPC(Rpc_mode_sigh, void, mode_sigh, Signal_context_capability);
|
||||
GENODE_RPC(Rpc_focus, void, focus, Capability<Session>);
|
||||
GENODE_RPC_THROW(Rpc_buffer, void, buffer, GENODE_TYPE_LIST(Out_of_ram, Out_of_caps),
|
||||
Framebuffer::Mode, bool);
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
#include <nitpicker_gfx/box_painter.h>
|
||||
|
||||
#include "gui_session.h"
|
||||
#include "clip_guard.h"
|
||||
#include <gui_session.h>
|
||||
#include <clip_guard.h>
|
||||
|
||||
namespace Nitpicker { struct Background; }
|
||||
|
||||
@ -37,7 +37,7 @@ struct Nitpicker::Background : private Texture_base, View
|
||||
Background(View_owner &owner, Area size)
|
||||
:
|
||||
Texture_base(Area(0, 0)),
|
||||
View(owner, _texture, View::NOT_TRANSPARENT, View::BACKGROUND, 0)
|
||||
View(owner, _texture, { .transparent = false, .background = true }, 0)
|
||||
{
|
||||
View::geometry(Rect(Point(0, 0), size));
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <framebuffer_session/framebuffer_session.h>
|
||||
|
||||
/* local includes */
|
||||
#include "types.h"
|
||||
#include <types.h>
|
||||
|
||||
|
||||
namespace Nitpicker { class Buffer; }
|
||||
|
@ -19,13 +19,13 @@
|
||||
#include <nitpicker_gfx/texture_painter.h>
|
||||
|
||||
/* local includes */
|
||||
#include "types.h"
|
||||
#include <types.h>
|
||||
|
||||
namespace Nitpicker {
|
||||
struct Canvas_base;
|
||||
template <typename PT> class Canvas;
|
||||
|
||||
typedef Text_painter::Font Font;
|
||||
using Font = Text_painter::Font;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#define _CHUNKY_TEXTURE_H_
|
||||
|
||||
/* local includes */
|
||||
#include "buffer.h"
|
||||
#include <buffer.h>
|
||||
|
||||
namespace Nitpicker { template <typename> class Chunky_texture; }
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#ifndef _CLIP_GUARD_H_
|
||||
#define _CLIP_GUARD_H_
|
||||
|
||||
#include "canvas.h"
|
||||
#include <canvas.h>
|
||||
|
||||
namespace Nitpicker { class Clip_guard; }
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#ifndef _DOMAIN_REGISTRY_
|
||||
#define _DOMAIN_REGISTRY_
|
||||
|
||||
#include "types.h"
|
||||
#include <types.h>
|
||||
|
||||
namespace Nitpicker { class Domain_registry; }
|
||||
|
||||
@ -27,22 +27,18 @@ class Nitpicker::Domain_registry
|
||||
{
|
||||
public:
|
||||
|
||||
typedef String<64> Name;
|
||||
using Name = String<64>;
|
||||
|
||||
enum Label { LABEL_NO, LABEL_YES };
|
||||
enum Content { CONTENT_CLIENT, CONTENT_TINTED };
|
||||
enum Hover { HOVER_FOCUSED, HOVER_ALWAYS };
|
||||
enum Focus { FOCUS_NONE, FOCUS_CLICK, FOCUS_TRANSIENT };
|
||||
enum class Label { NO, YES };
|
||||
enum class Content { CLIENT, TINTED };
|
||||
enum class Hover { FOCUSED, ALWAYS };
|
||||
enum class Focus { NONE, CLICK, TRANSIENT };
|
||||
|
||||
/**
|
||||
* Origin of the domain's coordiate system
|
||||
*/
|
||||
enum Origin {
|
||||
ORIGIN_POINTER,
|
||||
ORIGIN_TOP_LEFT,
|
||||
ORIGIN_TOP_RIGHT,
|
||||
ORIGIN_BOTTOM_LEFT,
|
||||
ORIGIN_BOTTOM_RIGHT };
|
||||
enum class Origin { POINTER, TOP_LEFT, TOP_RIGHT,
|
||||
BOTTOM_LEFT, BOTTOM_RIGHT };
|
||||
|
||||
private:
|
||||
|
||||
@ -71,12 +67,12 @@ class Nitpicker::Domain_registry
|
||||
Point _corner(Area const screen_area) const
|
||||
{
|
||||
switch (_origin) {
|
||||
case ORIGIN_POINTER: return Point(0, 0);
|
||||
case ORIGIN_TOP_LEFT: return Point(0, 0);
|
||||
case ORIGIN_TOP_RIGHT: return Point(screen_area.w, 0);
|
||||
case ORIGIN_BOTTOM_LEFT: return Point(0, screen_area.h);
|
||||
case ORIGIN_BOTTOM_RIGHT: return Point(screen_area.w,
|
||||
screen_area.h);
|
||||
case Origin::POINTER: return Point(0, 0);
|
||||
case Origin::TOP_LEFT: return Point(0, 0);
|
||||
case Origin::TOP_RIGHT: return Point(screen_area.w, 0);
|
||||
case Origin::BOTTOM_LEFT: return Point(0, screen_area.h);
|
||||
case Origin::BOTTOM_RIGHT: return Point(screen_area.w,
|
||||
screen_area.h);
|
||||
}
|
||||
return Point(0, 0);
|
||||
}
|
||||
@ -91,13 +87,13 @@ class Nitpicker::Domain_registry
|
||||
Content content() const { return _content; }
|
||||
Hover hover() const { return _hover; }
|
||||
|
||||
bool label_visible() const { return _label == LABEL_YES; }
|
||||
bool content_client() const { return _content == CONTENT_CLIENT; }
|
||||
bool hover_focused() const { return _hover == HOVER_FOCUSED; }
|
||||
bool hover_always() const { return _hover == HOVER_ALWAYS; }
|
||||
bool focus_click() const { return _focus == FOCUS_CLICK; }
|
||||
bool focus_transient() const { return _focus == FOCUS_TRANSIENT; }
|
||||
bool origin_pointer() const { return _origin == ORIGIN_POINTER; }
|
||||
bool label_visible() const { return _label == Label::YES; }
|
||||
bool content_client() const { return _content == Content::CLIENT; }
|
||||
bool hover_focused() const { return _hover == Hover::FOCUSED; }
|
||||
bool hover_always() const { return _hover == Hover::ALWAYS; }
|
||||
bool focus_click() const { return _focus == Focus::CLICK; }
|
||||
bool focus_transient() const { return _focus == Focus::TRANSIENT; }
|
||||
bool origin_pointer() const { return _origin == Origin::POINTER; }
|
||||
|
||||
Point phys_pos(Point pos, Area screen_area) const
|
||||
{
|
||||
@ -120,65 +116,65 @@ class Nitpicker::Domain_registry
|
||||
|
||||
static Entry::Label _label(Xml_node domain)
|
||||
{
|
||||
typedef String<32> Value;
|
||||
using Value = String<32>;
|
||||
Value const value = domain.attribute_value("label", Value("yes"));
|
||||
|
||||
if (value == "no") return Entry::LABEL_NO;
|
||||
if (value == "yes") return Entry::LABEL_YES;
|
||||
if (value == "no") return Entry::Label::NO;
|
||||
if (value == "yes") return Entry::Label::YES;
|
||||
|
||||
warning("invalid value of label attribute in <domain>");
|
||||
return Entry::LABEL_YES;
|
||||
return Entry::Label::YES;
|
||||
}
|
||||
|
||||
static Entry::Content _content(Xml_node domain)
|
||||
{
|
||||
typedef String<32> Value;
|
||||
using Value = String<32>;
|
||||
Value const value = domain.attribute_value("content", Value("tinted"));
|
||||
|
||||
if (value == "client") return Entry::CONTENT_CLIENT;
|
||||
if (value == "tinted") return Entry::CONTENT_TINTED;
|
||||
if (value == "client") return Entry::Content::CLIENT;
|
||||
if (value == "tinted") return Entry::Content::TINTED;
|
||||
|
||||
return Entry::CONTENT_TINTED;
|
||||
return Entry::Content::TINTED;
|
||||
}
|
||||
|
||||
static Entry::Hover _hover(Xml_node domain)
|
||||
{
|
||||
typedef String<32> Value;
|
||||
using Value = String<32>;
|
||||
Value const value = domain.attribute_value("hover", Value("focused"));
|
||||
|
||||
if (value == "focused") return Entry::HOVER_FOCUSED;
|
||||
if (value == "always") return Entry::HOVER_ALWAYS;
|
||||
if (value == "focused") return Entry::Hover::FOCUSED;
|
||||
if (value == "always") return Entry::Hover::ALWAYS;
|
||||
|
||||
warning("invalid value of hover attribute in <domain>");
|
||||
return Entry::HOVER_FOCUSED;
|
||||
return Entry::Hover::FOCUSED;
|
||||
}
|
||||
|
||||
static Entry::Focus _focus(Xml_node domain)
|
||||
{
|
||||
typedef String<32> Value;
|
||||
using Value = String<32>;
|
||||
Value const value = domain.attribute_value("focus", Value("none"));
|
||||
|
||||
if (value == "none") return Entry::FOCUS_NONE;
|
||||
if (value == "click") return Entry::FOCUS_CLICK;
|
||||
if (value == "transient") return Entry::FOCUS_TRANSIENT;
|
||||
if (value == "none") return Entry::Focus::NONE;
|
||||
if (value == "click") return Entry::Focus::CLICK;
|
||||
if (value == "transient") return Entry::Focus::TRANSIENT;
|
||||
|
||||
warning("invalid value of focus attribute in <domain>");
|
||||
return Entry::FOCUS_NONE;
|
||||
return Entry::Focus::NONE;
|
||||
}
|
||||
|
||||
static Entry::Origin _origin(Xml_node domain)
|
||||
{
|
||||
typedef String<32> Value;
|
||||
using Value = String<32>;
|
||||
Value const value = domain.attribute_value("origin", Value("top_left"));
|
||||
|
||||
if (value == "top_left") return Entry::ORIGIN_TOP_LEFT;
|
||||
if (value == "top_right") return Entry::ORIGIN_TOP_RIGHT;
|
||||
if (value == "bottom_left") return Entry::ORIGIN_BOTTOM_LEFT;
|
||||
if (value == "bottom_right") return Entry::ORIGIN_BOTTOM_RIGHT;
|
||||
if (value == "pointer") return Entry::ORIGIN_POINTER;
|
||||
if (value == "top_left") return Entry::Origin::TOP_LEFT;
|
||||
if (value == "top_right") return Entry::Origin::TOP_RIGHT;
|
||||
if (value == "bottom_left") return Entry::Origin::BOTTOM_LEFT;
|
||||
if (value == "bottom_right") return Entry::Origin::BOTTOM_RIGHT;
|
||||
if (value == "pointer") return Entry::Origin::POINTER;
|
||||
|
||||
warning("invalid value of origin attribute in <domain>");
|
||||
return Entry::ORIGIN_BOTTOM_LEFT;
|
||||
return Entry::Origin::BOTTOM_LEFT;
|
||||
}
|
||||
|
||||
void _insert(Xml_node domain)
|
||||
@ -200,13 +196,13 @@ class Nitpicker::Domain_registry
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned const layer = (unsigned)domain.attribute_value("layer", ~0UL);
|
||||
unsigned const layer = domain.attribute_value("layer", ~0U);
|
||||
|
||||
Point const offset((int)domain.attribute_value("xpos", 0L),
|
||||
(int)domain.attribute_value("ypos", 0L));
|
||||
Point const offset(domain.attribute_value("xpos", 0),
|
||||
domain.attribute_value("ypos", 0));
|
||||
|
||||
Point const area((int)domain.attribute_value("width", 0L),
|
||||
(int)domain.attribute_value("height", 0L));
|
||||
Point const area(domain.attribute_value("width", 0),
|
||||
domain.attribute_value("height", 0));
|
||||
|
||||
Color const color = domain.attribute_value("color", white());
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
#ifndef _DRAW_LABEL_H_
|
||||
#define _DRAW_LABEL_H_
|
||||
|
||||
#include "canvas.h"
|
||||
#include "types.h"
|
||||
#include <canvas.h>
|
||||
#include <types.h>
|
||||
|
||||
|
||||
namespace Nitpicker {
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <event_session/event_session.h>
|
||||
|
||||
/* local includes */
|
||||
#include "user_state.h"
|
||||
#include <user_state.h>
|
||||
|
||||
namespace Nitpicker { class Event_session; }
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
#ifndef _FOCUS_H_
|
||||
#define _FOCUS_H_
|
||||
|
||||
#include "types.h"
|
||||
#include "view.h"
|
||||
#include <types.h>
|
||||
#include <view.h>
|
||||
|
||||
namespace Nitpicker {
|
||||
struct Focus;
|
||||
|
@ -15,7 +15,7 @@
|
||||
#define _FRAMEBUFFER_SESSION_COMPONENT_H_
|
||||
|
||||
/* local includes */
|
||||
#include "buffer.h"
|
||||
#include <buffer.h>
|
||||
|
||||
namespace Framebuffer {
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
/* local includes */
|
||||
#include "global_keys.h"
|
||||
#include <global_keys.h>
|
||||
|
||||
using namespace Nitpicker;
|
||||
|
||||
@ -44,7 +44,7 @@ void Global_keys::apply_config(Xml_node config, Session_list &session_list)
|
||||
continue;
|
||||
}
|
||||
|
||||
typedef String<32> Name;
|
||||
using Name = String<32>;
|
||||
Name name = node.attribute_value("name", Name());
|
||||
Policy * policy = _lookup_policy(name.string());
|
||||
if (!policy) {
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <input/keycodes.h>
|
||||
|
||||
/* local includes */
|
||||
#include "gui_session.h"
|
||||
#include <gui_session.h>
|
||||
|
||||
namespace Nitpicker { class Global_keys; }
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include "view_stack.h"
|
||||
#include <view_stack.h>
|
||||
|
||||
using namespace Nitpicker;
|
||||
|
||||
@ -246,7 +246,7 @@ Gui_session::View_handle Gui_session::create_view(View_handle parent_handle)
|
||||
return View_handle();
|
||||
|
||||
view = new (_view_alloc)
|
||||
View(*this, _texture, View::NOT_TRANSPARENT, View::NOT_BACKGROUND, &(*parent));
|
||||
View(*this, _texture, { .transparent = false, .background = false }, &(*parent));
|
||||
|
||||
parent->add_child(*view);
|
||||
}
|
||||
@ -260,7 +260,7 @@ Gui_session::View_handle Gui_session::create_view(View_handle parent_handle)
|
||||
else {
|
||||
try {
|
||||
view = new (_view_alloc)
|
||||
View(*this, _texture, View::NOT_TRANSPARENT, View::NOT_BACKGROUND, nullptr);
|
||||
View(*this, _texture, { .transparent = false, .background = false }, nullptr);
|
||||
}
|
||||
catch (Allocator::Out_of_memory) { throw Out_of_ram(); }
|
||||
}
|
||||
@ -292,7 +292,7 @@ void Gui_session::apply_session_policy(Xml_node config,
|
||||
return;
|
||||
}
|
||||
|
||||
typedef Domain_registry::Entry::Name Name;
|
||||
using Name = Domain_registry::Entry::Name;
|
||||
|
||||
Name const name = policy.attribute_value("domain", Name());
|
||||
|
||||
|
@ -25,19 +25,19 @@
|
||||
#include <gui_session/gui_session.h>
|
||||
|
||||
/* local includes */
|
||||
#include "canvas.h"
|
||||
#include "domain_registry.h"
|
||||
#include "framebuffer_session.h"
|
||||
#include "input_session.h"
|
||||
#include "focus.h"
|
||||
#include "view.h"
|
||||
#include <canvas.h>
|
||||
#include <domain_registry.h>
|
||||
#include <framebuffer_session.h>
|
||||
#include <input_session.h>
|
||||
#include <focus.h>
|
||||
#include <view.h>
|
||||
|
||||
namespace Nitpicker {
|
||||
|
||||
class Gui_session;
|
||||
class View;
|
||||
|
||||
typedef List<Gui_session> Session_list;
|
||||
using Session_list = List<Gui_session>;
|
||||
}
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ class Nitpicker::Gui_session : public Session_object<Gui::Session>,
|
||||
|
||||
Command_buffer &_command_buffer = *_command_ds.local_addr<Command_buffer>();
|
||||
|
||||
typedef Handle_registry<View_handle, View> View_handle_registry;
|
||||
using View_handle_registry = Handle_registry<View_handle, View>;
|
||||
|
||||
View_handle_registry _view_handle_registry;
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <input/event.h>
|
||||
|
||||
/* local incudes */
|
||||
#include "types.h"
|
||||
#include <types.h>
|
||||
|
||||
namespace Input {
|
||||
using namespace Nitpicker;
|
||||
|
@ -26,14 +26,14 @@
|
||||
#include <util/dirty_rect.h>
|
||||
|
||||
/* local includes */
|
||||
#include "types.h"
|
||||
#include "user_state.h"
|
||||
#include "background.h"
|
||||
#include "clip_guard.h"
|
||||
#include "pointer_origin.h"
|
||||
#include "domain_registry.h"
|
||||
#include "capture_session.h"
|
||||
#include "event_session.h"
|
||||
#include <types.h>
|
||||
#include <user_state.h>
|
||||
#include <background.h>
|
||||
#include <clip_guard.h>
|
||||
#include <pointer_origin.h>
|
||||
#include <domain_registry.h>
|
||||
#include <capture_session.h>
|
||||
#include <event_session.h>
|
||||
|
||||
namespace Nitpicker {
|
||||
class Gui_root;
|
||||
@ -359,7 +359,7 @@ struct Nitpicker::Main : Focus_updater, Hover_updater,
|
||||
|
||||
Constructible<Input_connection> _input { };
|
||||
|
||||
typedef Pixel_rgb888 PT; /* physical pixel type */
|
||||
using PT = Pixel_rgb888; /* physical pixel type */
|
||||
|
||||
/*
|
||||
* Initialize framebuffer
|
||||
@ -379,7 +379,7 @@ struct Nitpicker::Main : Focus_updater, Hover_updater,
|
||||
|
||||
Area size = screen.size();
|
||||
|
||||
typedef Genode::Dirty_rect<Rect, 3> Dirty_rect;
|
||||
using Dirty_rect = Genode::Dirty_rect<Rect, 3>;
|
||||
|
||||
Dirty_rect dirty_rect { };
|
||||
|
||||
@ -791,7 +791,7 @@ void Nitpicker::Main::_handle_focus()
|
||||
|
||||
_focus_rom->update();
|
||||
|
||||
typedef Gui::Session::Label Label;
|
||||
using Label = String<160>;
|
||||
Label const label = _focus_rom->xml().attribute_value("label", Label());
|
||||
|
||||
/*
|
||||
|
@ -14,8 +14,8 @@
|
||||
#ifndef _POINTER_ORIGIN_H_
|
||||
#define _POINTER_ORIGIN_H_
|
||||
|
||||
#include "view.h"
|
||||
#include "gui_session.h"
|
||||
#include <view.h>
|
||||
#include <gui_session.h>
|
||||
|
||||
namespace Nitpicker { struct Pointer_origin; }
|
||||
|
||||
@ -26,7 +26,7 @@ struct Nitpicker::Pointer_origin : View
|
||||
|
||||
Pointer_origin(View_owner &owner)
|
||||
:
|
||||
View(owner, _texture, View::TRANSPARENT, View::NOT_BACKGROUND, 0)
|
||||
View(owner, _texture, { .transparent = true, .background = false }, 0)
|
||||
{ }
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <os/pixel_alpha8.h>
|
||||
|
||||
/* local includes */
|
||||
#include "chunky_texture.h"
|
||||
#include <chunky_texture.h>
|
||||
|
||||
namespace Nitpicker { template <typename> class Resizeable_texture; }
|
||||
|
||||
@ -85,7 +85,7 @@ class Nitpicker::Resizeable_texture
|
||||
/* copy alpha channel */
|
||||
if (_textures[_current]->alpha() && _textures[next]->alpha()) {
|
||||
|
||||
typedef Pixel_alpha8 AT;
|
||||
using AT = Pixel_alpha8;
|
||||
|
||||
Surface<AT> surface((AT *)_textures[next]->alpha(),
|
||||
_textures[next]->Texture_base::size());
|
||||
|
@ -2,3 +2,4 @@ TARGET = nitpicker
|
||||
LIBS = base blit
|
||||
SRC_CC = $(notdir $(wildcard $(PRG_DIR)/*.cc))
|
||||
SRC_BIN = default.tff
|
||||
INC_DIR += $(PRG_DIR)
|
||||
|
@ -18,21 +18,18 @@
|
||||
#include <util/xml_node.h>
|
||||
#include <util/color.h>
|
||||
#include <base/allocator.h>
|
||||
#include <base/log.h>
|
||||
#include <os/surface.h>
|
||||
#include <os/pixel_rgb888.h>
|
||||
|
||||
namespace Gui { }
|
||||
#include <gui_session/gui_session.h>
|
||||
|
||||
namespace Nitpicker {
|
||||
|
||||
using namespace Genode;
|
||||
using namespace Gui;
|
||||
|
||||
using Pixel = Pixel_rgb888;
|
||||
|
||||
typedef Surface_base::Point Point;
|
||||
typedef Surface_base::Area Area;
|
||||
typedef Surface_base::Rect Rect;
|
||||
using Point = Gui::Point;
|
||||
using Area = Gui::Area;
|
||||
using Rect = Gui::Rect;
|
||||
|
||||
static constexpr Color white() { return Color::rgb(255, 255, 255); }
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <input/event.h>
|
||||
#include <input/keycodes.h>
|
||||
|
||||
#include "user_state.h"
|
||||
#include <user_state.h>
|
||||
|
||||
using namespace Input;
|
||||
|
||||
|
@ -20,9 +20,9 @@
|
||||
|
||||
#include <util/xml_generator.h>
|
||||
|
||||
#include "focus.h"
|
||||
#include "view_stack.h"
|
||||
#include "global_keys.h"
|
||||
#include <focus.h>
|
||||
#include <view_stack.h>
|
||||
#include <global_keys.h>
|
||||
|
||||
namespace Nitpicker { class User_state; }
|
||||
|
||||
@ -150,7 +150,7 @@ class Nitpicker::User_state
|
||||
return (key <= Input::KEY_MAX) && _states[key].pressed;
|
||||
}
|
||||
|
||||
void report_state(Genode::Xml_generator &xml) const
|
||||
void report_state(Xml_generator &xml) const
|
||||
{
|
||||
for (unsigned i = 0; i <= Input::KEY_MAX; i++)
|
||||
if (_states[i].pressed)
|
||||
|
@ -16,10 +16,10 @@
|
||||
#include <nitpicker_gfx/texture_painter.h>
|
||||
#include <nitpicker_gfx/box_painter.h>
|
||||
|
||||
#include "view.h"
|
||||
#include "clip_guard.h"
|
||||
#include "gui_session.h"
|
||||
#include "draw_label.h"
|
||||
#include <view.h>
|
||||
#include <clip_guard.h>
|
||||
#include <gui_session.h>
|
||||
#include <draw_label.h>
|
||||
|
||||
|
||||
/***************
|
||||
|
@ -21,9 +21,9 @@
|
||||
#include <base/rpc_server.h>
|
||||
|
||||
/* local includes */
|
||||
#include "canvas.h"
|
||||
#include "view_owner.h"
|
||||
#include "resizeable_texture.h"
|
||||
#include <canvas.h>
|
||||
#include <view_owner.h>
|
||||
#include <resizeable_texture.h>
|
||||
|
||||
namespace Nitpicker {
|
||||
|
||||
@ -60,7 +60,7 @@ namespace Gui {
|
||||
* We use view capabilities as mere tokens to pass views between sessions.
|
||||
* There is no RPC interface associated with a view.
|
||||
*/
|
||||
struct View : Genode::Interface { GENODE_RPC_INTERFACE(); };
|
||||
struct View : Interface { GENODE_RPC_INTERFACE(); };
|
||||
}
|
||||
|
||||
|
||||
@ -73,10 +73,7 @@ class Nitpicker::View : private Same_buffer_list_elem,
|
||||
{
|
||||
public:
|
||||
|
||||
typedef String<32> Title;
|
||||
|
||||
enum Transparent { NOT_TRANSPARENT = 0, TRANSPARENT = 1 };
|
||||
enum Background { NOT_BACKGROUND = 0, BACKGROUND = 1 };
|
||||
using Title = String<32>;
|
||||
|
||||
using Weak_object<View>::weak_ptr;
|
||||
using Weak_object<View>::weak_ptr_const;
|
||||
@ -93,8 +90,8 @@ class Nitpicker::View : private Same_buffer_list_elem,
|
||||
View(View const &);
|
||||
View &operator = (View const &);
|
||||
|
||||
Transparent const _transparent; /* background is partly visible */
|
||||
Background _background; /* view is a background view */
|
||||
bool const _transparent; /* background is partly visible */
|
||||
bool _background; /* view is a background view */
|
||||
|
||||
View *_parent; /* parent view */
|
||||
Rect _geometry { }; /* position and size relative to parent */
|
||||
@ -130,11 +127,13 @@ class Nitpicker::View : private Same_buffer_list_elem,
|
||||
|
||||
public:
|
||||
|
||||
struct Attr { bool transparent, background; };
|
||||
|
||||
View(View_owner &owner, Resizeable_texture<Pixel> const &texture,
|
||||
Transparent transparent, Background bg, View *parent)
|
||||
Attr attr, View *parent)
|
||||
:
|
||||
_transparent(transparent), _background(bg), _parent(parent),
|
||||
_owner(owner), _texture(texture)
|
||||
_transparent(attr.transparent), _background(attr.background),
|
||||
_parent(parent), _owner(owner), _texture(texture)
|
||||
{ }
|
||||
|
||||
virtual ~View()
|
||||
@ -239,8 +238,7 @@ class Nitpicker::View : private Same_buffer_list_elem,
|
||||
*
|
||||
* \param bg true if view is background
|
||||
*/
|
||||
void background(bool bg) {
|
||||
_background = bg ? BACKGROUND : NOT_BACKGROUND; }
|
||||
void background(bool bg) { _background = bg; }
|
||||
|
||||
/**
|
||||
* Accessors
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <os/texture.h>
|
||||
|
||||
/* local includes */
|
||||
#include "types.h"
|
||||
#include <types.h>
|
||||
|
||||
|
||||
namespace Nitpicker { class View_owner; }
|
||||
|
@ -11,8 +11,8 @@
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include "view_stack.h"
|
||||
#include "clip_guard.h"
|
||||
#include <view_stack.h>
|
||||
#include <clip_guard.h>
|
||||
|
||||
using namespace Nitpicker;
|
||||
|
||||
@ -314,7 +314,7 @@ void View_stack::remove_view(View const &view, bool /* redraw */)
|
||||
|
||||
void View_stack::sort_views_by_layer()
|
||||
{
|
||||
Genode::List<View_stack_elem> sorted;
|
||||
List<View_stack_elem> sorted;
|
||||
|
||||
/* last element of the sorted list */
|
||||
View_stack_elem *at = nullptr;
|
||||
|
@ -14,9 +14,9 @@
|
||||
#ifndef _VIEW_STACK_H_
|
||||
#define _VIEW_STACK_H_
|
||||
|
||||
#include "view.h"
|
||||
#include "gui_session.h"
|
||||
#include "canvas.h"
|
||||
#include <view.h>
|
||||
#include <gui_session.h>
|
||||
#include <canvas.h>
|
||||
|
||||
namespace Nitpicker { class View_stack; }
|
||||
|
||||
|
323
repos/os/src/test/nitpicker/main.cc
Normal file
323
repos/os/src/test/nitpicker/main.cc
Normal file
@ -0,0 +1,323 @@
|
||||
/*
|
||||
* \brief Nitpicker test program
|
||||
* \author Norman Feske
|
||||
* \date 2006-08-23
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include <base/env.h>
|
||||
#include <util/list.h>
|
||||
#include <base/component.h>
|
||||
#include <gui_session/connection.h>
|
||||
#include <input/event.h>
|
||||
#include <os/pixel_rgb888.h>
|
||||
|
||||
namespace Test {
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
class View;
|
||||
struct Top_level_view;
|
||||
struct Child_view;
|
||||
class View_stack;
|
||||
struct Main;
|
||||
}
|
||||
|
||||
|
||||
class Test::View : private List<View>::Element, Interface
|
||||
{
|
||||
public:
|
||||
|
||||
using Title = String<32>;
|
||||
|
||||
struct Attr
|
||||
{
|
||||
Gui::Point pos;
|
||||
Gui::Area size;
|
||||
Title title;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
friend class View_stack;
|
||||
friend class List<View>;
|
||||
|
||||
using View_handle = Gui::Session::View_handle;
|
||||
using Command = Gui::Session::Command;
|
||||
|
||||
Gui::Connection &_gui;
|
||||
View_handle const _handle;
|
||||
Attr const _attr;
|
||||
Gui::Point _pos = _attr.pos;
|
||||
|
||||
public:
|
||||
|
||||
View(Gui::Connection &gui, Attr const attr, auto const &create_fn)
|
||||
:
|
||||
_gui(gui), _handle(create_fn()), _attr(attr)
|
||||
{
|
||||
using namespace Gui;
|
||||
|
||||
_gui.enqueue<Command::Geometry>(_handle, Gui::Rect { _pos, _attr.size });
|
||||
_gui.enqueue<Command::To_front>(_handle, View_handle());
|
||||
_gui.enqueue<Command::Title>(_handle, _attr.title);
|
||||
_gui.execute();
|
||||
}
|
||||
|
||||
Gui::View_capability view_cap()
|
||||
{
|
||||
return _gui.view_capability(_handle);
|
||||
}
|
||||
|
||||
void top()
|
||||
{
|
||||
_gui.enqueue<Command::To_front>(_handle, View_handle());
|
||||
_gui.execute();
|
||||
}
|
||||
|
||||
virtual void move(Gui::Point const pos)
|
||||
{
|
||||
_pos = pos;
|
||||
_gui.enqueue<Command::Geometry>(_handle, Gui::Rect { _pos, _attr.size });
|
||||
_gui.execute();
|
||||
}
|
||||
|
||||
virtual Gui::Point pos() const { return _pos; }
|
||||
|
||||
Gui::Rect rect() const { return { pos(), _attr.size }; }
|
||||
|
||||
bool contains(Gui::Point pos) { return rect().contains(pos); }
|
||||
};
|
||||
|
||||
|
||||
struct Test::Top_level_view : View
|
||||
{
|
||||
Top_level_view(Gui::Connection &gui, Attr const &attr)
|
||||
:
|
||||
View(gui, attr, [&] { return gui.create_view(); })
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
struct Test::Child_view : View
|
||||
{
|
||||
View &_parent;
|
||||
|
||||
Child_view(Gui::Connection &gui, View &parent, Attr const &attr)
|
||||
:
|
||||
View(gui, attr,
|
||||
[&] /* create_fn */ {
|
||||
using View_handle = Gui::Session::View_handle;
|
||||
View_handle const parent_handle = gui.view_handle(parent.view_cap());
|
||||
View_handle const handle = gui.create_view(parent_handle);
|
||||
gui.release_view_handle(parent_handle);
|
||||
return handle;
|
||||
}
|
||||
), _parent(parent)
|
||||
{ }
|
||||
|
||||
void move(Gui::Point const pos) override
|
||||
{
|
||||
View::move(pos - _parent.pos());
|
||||
}
|
||||
|
||||
Gui::Point pos() const override
|
||||
{
|
||||
return _parent.pos() + View::pos();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Test::View_stack : Noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
struct Input_mask_ptr
|
||||
{
|
||||
Gui::Area size;
|
||||
|
||||
uint8_t *ptr;
|
||||
|
||||
/**
|
||||
* Return true if input at given position is enabled
|
||||
*/
|
||||
bool hit(Gui::Point const at) const
|
||||
{
|
||||
return ptr
|
||||
&& Rect(Point(0, 0), size).contains(at)
|
||||
&& ptr[size.w*at.y + at.x];
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Input_mask_ptr const _input_mask_ptr;
|
||||
|
||||
List<View> _views { };
|
||||
|
||||
struct { View const *_dragged = nullptr; };
|
||||
|
||||
public:
|
||||
|
||||
View_stack(Input_mask_ptr input_mask) : _input_mask_ptr(input_mask) { }
|
||||
|
||||
void with_view_at(Gui::Point const pos, auto const &fn)
|
||||
{
|
||||
View *tv = _views.first();
|
||||
for ( ; tv; tv = tv->next()) {
|
||||
|
||||
if (!tv->contains(pos))
|
||||
continue;
|
||||
|
||||
Point const rel = pos - tv->pos();
|
||||
|
||||
if (_input_mask_ptr.hit(rel))
|
||||
break;
|
||||
}
|
||||
if (tv)
|
||||
fn(*tv);
|
||||
}
|
||||
|
||||
void with_dragged_view(auto const &fn)
|
||||
{
|
||||
for (View *tv = _views.first(); tv; tv = tv->next())
|
||||
if (_dragged == tv)
|
||||
fn(*tv);
|
||||
}
|
||||
|
||||
void insert(View &tv) { _views.insert(&tv); }
|
||||
|
||||
void top(View &tv)
|
||||
{
|
||||
_views.remove(&tv);
|
||||
tv.top();
|
||||
_views.insert(&tv);
|
||||
}
|
||||
|
||||
void drag(View const &tv) { _dragged = &tv; };
|
||||
|
||||
void release_dragged_view() { _dragged = nullptr; }
|
||||
};
|
||||
|
||||
|
||||
struct Test::Main
|
||||
{
|
||||
Env &_env;
|
||||
|
||||
struct Config { bool alpha; } _config { .alpha = false };
|
||||
|
||||
Gui::Connection _gui { _env, "testnit" };
|
||||
|
||||
Constructible<Attached_dataspace> _fb_ds { };
|
||||
|
||||
Constructible<View_stack> _view_stack { };
|
||||
|
||||
/*
|
||||
* View '_v1' is used as coordinate origin of '_v2' and '_v3'.
|
||||
*/
|
||||
Top_level_view _v1 { _gui, { .pos = { 150, 100 },
|
||||
.size = { 230, 200 },
|
||||
.title = "Eins" } };
|
||||
|
||||
Child_view _v2 { _gui, _v1, { .pos = { 20, 20 },
|
||||
.size = { 230, 210 },
|
||||
.title = "Zwei" } };
|
||||
|
||||
Child_view _v3 { _gui, _v1, { .pos = { 40, 40 },
|
||||
.size = { 230, 220 },
|
||||
.title = "Drei" } };
|
||||
|
||||
Signal_handler<Main> _input_handler { _env.ep(), *this, &Main::_handle_input };
|
||||
|
||||
int _mx = 0, _my = 0, _key_cnt = 0;
|
||||
|
||||
void _handle_input();
|
||||
|
||||
Main(Env &env);
|
||||
};
|
||||
|
||||
|
||||
Test::Main::Main(Genode::Env &env) : _env(env)
|
||||
{
|
||||
_gui.input()->sigh(_input_handler);
|
||||
|
||||
Gui::Area const size { 256, 256 };
|
||||
|
||||
Framebuffer::Mode const mode { .area = size };
|
||||
|
||||
log("screen is ", mode);
|
||||
|
||||
_gui.buffer(mode, _config.alpha);
|
||||
|
||||
_fb_ds.construct(_env.rm(), _gui.framebuffer()->dataspace());
|
||||
|
||||
/*
|
||||
* Paint into pixel buffer, fill alpha channel and input-mask buffer
|
||||
*
|
||||
* Input should refer to the view if the alpha value is more than 50%.
|
||||
*/
|
||||
|
||||
using PT = Pixel_rgb888;
|
||||
PT * const pixels = _fb_ds->local_addr<PT>();
|
||||
|
||||
uint8_t * const alpha = (uint8_t *)&pixels[size.count()];
|
||||
uint8_t * const input_mask = _config.alpha ? alpha + size.count() : 0;
|
||||
|
||||
for (unsigned i = 0; i < size.h; i++)
|
||||
for (unsigned j = 0; j < size.w; j++) {
|
||||
pixels[i*size.w + j] = PT((3*i)/8, j, i*j/32);
|
||||
if (_config.alpha) {
|
||||
alpha[i*size.w + j] = (uint8_t)((i*2) ^ (j*2));
|
||||
input_mask[i*size.w + j] = alpha[i*size.w + j] > 127;
|
||||
}
|
||||
}
|
||||
|
||||
_view_stack.construct(View_stack::Input_mask_ptr { .size = size,
|
||||
.ptr = input_mask });
|
||||
|
||||
_view_stack->insert(_v1);
|
||||
_view_stack->insert(_v2);
|
||||
_view_stack->insert(_v3);
|
||||
}
|
||||
|
||||
|
||||
void Test::Main::_handle_input()
|
||||
{
|
||||
while (_gui.input()->pending()) {
|
||||
|
||||
_gui.input()->for_each_event([&] (Input::Event const &ev) {
|
||||
|
||||
if (ev.press()) _key_cnt++;
|
||||
if (ev.release()) _key_cnt--;
|
||||
|
||||
ev.handle_absolute_motion([&] (int x, int y) {
|
||||
|
||||
/* move selected view */
|
||||
_view_stack->with_dragged_view([&] (View &tv) {
|
||||
tv.move(tv.pos() + Point(x, y) - Point(_mx, _my)); });
|
||||
|
||||
_mx = x; _my = y;
|
||||
});
|
||||
|
||||
/* find selected view and bring it to front */
|
||||
if (ev.press() && _key_cnt == 1) {
|
||||
_view_stack->with_view_at(Point(_mx, _my), [&] (View &tv) {
|
||||
_view_stack->top(tv);
|
||||
_view_stack->drag(tv);
|
||||
});
|
||||
}
|
||||
|
||||
if (ev.release() && _key_cnt == 0)
|
||||
_view_stack->release_dragged_view();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Component::construct(Genode::Env &env) { static Test::Main main { env }; }
|
@ -1,3 +1,3 @@
|
||||
TARGET = testnit
|
||||
SRC_CC = test.cc
|
||||
SRC_CC = main.cc
|
||||
LIBS = base
|
||||
|
@ -1,246 +0,0 @@
|
||||
/*
|
||||
* \brief Nitpicker test program
|
||||
* \author Norman Feske
|
||||
* \date 2006-08-23
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include <base/env.h>
|
||||
#include <util/list.h>
|
||||
#include <base/component.h>
|
||||
#include <base/log.h>
|
||||
#include <gui_session/connection.h>
|
||||
#include <timer_session/connection.h>
|
||||
#include <input/event.h>
|
||||
#include <os/pixel_rgb888.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
class Test_view : public List<Test_view>::Element
|
||||
{
|
||||
private:
|
||||
|
||||
using View_handle = Gui::Session::View_handle;
|
||||
using Command = Gui::Session::Command;
|
||||
|
||||
Gui::Session_client &_gui;
|
||||
View_handle _handle { };
|
||||
int _x, _y, _w, _h;
|
||||
const char *_title;
|
||||
Test_view *_parent_view;
|
||||
|
||||
public:
|
||||
|
||||
Test_view(Gui::Session_client *gui,
|
||||
int x, int y, int w, int h,
|
||||
const char *title,
|
||||
Test_view *parent_view = 0)
|
||||
:
|
||||
_gui(*gui),
|
||||
_x(x), _y(y), _w(w), _h(h), _title(title), _parent_view(parent_view)
|
||||
{
|
||||
using namespace Gui;
|
||||
|
||||
View_handle parent_handle;
|
||||
|
||||
if (_parent_view)
|
||||
parent_handle = _gui.view_handle(_parent_view->view_cap());
|
||||
|
||||
_handle = _gui.create_view(parent_handle);
|
||||
|
||||
if (parent_handle.valid())
|
||||
_gui.release_view_handle(parent_handle);
|
||||
|
||||
Gui::Rect rect(Gui::Point(_x, _y), Gui::Area(_w, _h));
|
||||
_gui.enqueue<Command::Geometry>(_handle, rect);
|
||||
_gui.enqueue<Command::To_front>(_handle, View_handle());
|
||||
_gui.enqueue<Command::Title>(_handle, _title);
|
||||
_gui.execute();
|
||||
}
|
||||
|
||||
Gui::View_capability view_cap()
|
||||
{
|
||||
return _gui.view_capability(_handle);
|
||||
}
|
||||
|
||||
void top()
|
||||
{
|
||||
_gui.enqueue<Command::To_front>(_handle, View_handle());
|
||||
_gui.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move view to absolute position
|
||||
*/
|
||||
void move(int x, int y)
|
||||
{
|
||||
/*
|
||||
* If the view uses a parent view as corrdinate origin, we need to
|
||||
* transform the absolute coordinates to parent-relative
|
||||
* coordinates.
|
||||
*/
|
||||
_x = _parent_view ? x - _parent_view->x() : x;
|
||||
_y = _parent_view ? y - _parent_view->y() : y;
|
||||
|
||||
Gui::Rect rect(Gui::Point(_x, _y), Gui::Area(_w, _h));
|
||||
_gui.enqueue<Command::Geometry>(_handle, rect);
|
||||
_gui.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessors
|
||||
*/
|
||||
const char *title() const { return _title; }
|
||||
int x() const { return _parent_view ? _parent_view->x() + _x : _x; }
|
||||
int y() const { return _parent_view ? _parent_view->y() + _y : _y; }
|
||||
int w() const { return _w; }
|
||||
int h() const { return _h; }
|
||||
};
|
||||
|
||||
|
||||
class Test_view_stack : public List<Test_view>
|
||||
{
|
||||
private:
|
||||
|
||||
unsigned char *_input_mask;
|
||||
unsigned _input_mask_w;
|
||||
public:
|
||||
|
||||
Test_view_stack(unsigned char *input_mask, unsigned input_mask_w)
|
||||
: _input_mask(input_mask), _input_mask_w(input_mask_w) { }
|
||||
|
||||
Test_view *find(int x, int y)
|
||||
{
|
||||
for (Test_view *tv = first(); tv; tv = tv->next()) {
|
||||
|
||||
if (x < tv->x() || x >= tv->x() + tv->w()
|
||||
|| y < tv->y() || y >= tv->y() + tv->h())
|
||||
continue;
|
||||
|
||||
if (!_input_mask)
|
||||
return tv;
|
||||
|
||||
if (_input_mask[(y - tv->y())*_input_mask_w + (x - tv->x())])
|
||||
return tv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void top(Test_view *tv)
|
||||
{
|
||||
remove(tv);
|
||||
tv->top();
|
||||
insert(tv);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void Component::construct(Genode::Env &env)
|
||||
{
|
||||
/*
|
||||
* Init sessions to the required external services
|
||||
*/
|
||||
enum { CONFIG_ALPHA = false };
|
||||
static Gui::Connection gui { env, "testnit" };
|
||||
static Timer::Connection timer { env };
|
||||
|
||||
Framebuffer::Mode const mode { .area = { 256, 256 } };
|
||||
gui.buffer(mode, false);
|
||||
|
||||
int const scr_w = mode.area.w, scr_h = mode.area.h;
|
||||
|
||||
log("screen is ", mode);
|
||||
if (!scr_w || !scr_h) {
|
||||
error("got invalid screen - sleeping forever");
|
||||
return;
|
||||
}
|
||||
|
||||
/* bad-case test */
|
||||
{
|
||||
/* issue #3232 */
|
||||
Gui::Session::View_handle handle { gui.create_view() };
|
||||
gui.destroy_view(handle);
|
||||
gui.destroy_view(handle);
|
||||
}
|
||||
|
||||
Genode::Attached_dataspace fb_ds(
|
||||
env.rm(), gui.framebuffer()->dataspace());
|
||||
|
||||
typedef Genode::Pixel_rgb888 PT;
|
||||
PT *pixels = fb_ds.local_addr<PT>();
|
||||
unsigned char *alpha = (unsigned char *)&pixels[scr_w*scr_h];
|
||||
unsigned char *input_mask = CONFIG_ALPHA ? alpha + scr_w*scr_h : 0;
|
||||
|
||||
/*
|
||||
* Paint into pixel buffer, fill alpha channel and input-mask buffer
|
||||
*
|
||||
* Input should refer to the view if the alpha value is more than 50%.
|
||||
*/
|
||||
for (int i = 0; i < scr_h; i++)
|
||||
for (int j = 0; j < scr_w; j++) {
|
||||
pixels[i*scr_w + j] = PT((3*i)/8, j, i*j/32);
|
||||
if (CONFIG_ALPHA) {
|
||||
alpha[i*scr_w + j] = (unsigned char)((i*2) ^ (j*2));
|
||||
input_mask[i*scr_w + j] = alpha[i*scr_w + j] > 127;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create views to display the buffer
|
||||
*/
|
||||
Test_view_stack tvs(input_mask, scr_w);
|
||||
|
||||
{
|
||||
/*
|
||||
* View 'v1' is used as coordinate origin of 'v2' and 'v3'.
|
||||
*/
|
||||
static Test_view v1(&gui, 150, 100, 230, 200, "Eins");
|
||||
static Test_view v2(&gui, 20, 20, 230, 210, "Zwei", &v1);
|
||||
static Test_view v3(&gui, 40, 40, 230, 220, "Drei", &v1);
|
||||
|
||||
tvs.insert(&v1);
|
||||
tvs.insert(&v2);
|
||||
tvs.insert(&v3);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle input events
|
||||
*/
|
||||
int mx = 0, my = 0, key_cnt = 0;
|
||||
Test_view *tv = nullptr;
|
||||
while (1) {
|
||||
|
||||
while (!gui.input()->pending()) timer.msleep(20);
|
||||
|
||||
gui.input()->for_each_event([&] (Input::Event const &ev) {
|
||||
|
||||
if (ev.press()) key_cnt++;
|
||||
if (ev.release()) key_cnt--;
|
||||
|
||||
ev.handle_absolute_motion([&] (int x, int y) {
|
||||
|
||||
/* move selected view */
|
||||
if (key_cnt > 0 && tv)
|
||||
tv->move(tv->x() + x - mx, tv->y() + y - my);
|
||||
|
||||
mx = x; my = y;
|
||||
});
|
||||
|
||||
/* find selected view and bring it to front */
|
||||
if (ev.press() && key_cnt == 1) {
|
||||
tv = tvs.find(mx, my);
|
||||
if (tv)
|
||||
tvs.top(tv);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
env.parent().exit(0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user