2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Nitpicker session interface
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-08-09
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SESSION_H_
|
|
|
|
#define _SESSION_H_
|
|
|
|
|
2013-09-06 17:34:16 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <util/list.h>
|
2013-09-07 12:14:52 +02:00
|
|
|
#include <util/string.h>
|
2013-09-07 23:48:40 +02:00
|
|
|
#include <nitpicker_gfx/color.h>
|
|
|
|
#include <nitpicker_gfx/geometry.h>
|
|
|
|
#include <nitpicker_gfx/canvas.h>
|
2013-09-09 22:39:54 +02:00
|
|
|
#include <nitpicker_gfx/string.h>
|
|
|
|
#include <os/session_policy.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
class Texture;
|
|
|
|
class View;
|
2013-09-06 17:34:16 +02:00
|
|
|
class Session;
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
namespace Input { class Event; }
|
|
|
|
|
2013-09-06 17:34:16 +02:00
|
|
|
typedef Genode::List<Session> Session_list;
|
|
|
|
|
|
|
|
class Session : public Session_list::Element
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2013-09-09 22:39:54 +02:00
|
|
|
Genode::Session_label const _label;
|
|
|
|
Color _color;
|
|
|
|
Texture const &_texture;
|
|
|
|
View *_background = 0;
|
|
|
|
int _v_offset;
|
|
|
|
unsigned char const *_input_mask;
|
|
|
|
bool const _stay_top;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2013-09-09 22:39:54 +02:00
|
|
|
* \param label session label
|
2011-12-22 16:19:25 +01:00
|
|
|
* \param texture texture containing the session's pixel
|
|
|
|
* representation
|
|
|
|
* \param v_offset vertical screen offset of session
|
|
|
|
* \param input_mask input mask buffer containing a byte value per
|
|
|
|
* texture pixel, which describes the policy of
|
|
|
|
* handling user input referring to the pixel.
|
|
|
|
* If set to zero, the input is passed through
|
|
|
|
* the view such that it can be handled by one of
|
|
|
|
* the subsequent views in the view stack. If set
|
|
|
|
* to one, the input is consumed by the view. If
|
|
|
|
* 'input_mask' is a null pointer, user input is
|
|
|
|
* unconditionally consumed by the view.
|
|
|
|
*/
|
2013-09-09 22:39:54 +02:00
|
|
|
Session(Genode::Session_label const &label, Texture const &texture,
|
|
|
|
int v_offset, unsigned char const *input_mask = 0,
|
2011-12-22 16:19:25 +01:00
|
|
|
bool stay_top = false)
|
|
|
|
:
|
2013-09-09 22:39:54 +02:00
|
|
|
_label(label), _texture(texture), _v_offset(v_offset),
|
|
|
|
_input_mask(input_mask), _stay_top(stay_top)
|
|
|
|
{ }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
virtual ~Session() { }
|
|
|
|
|
2013-09-07 02:02:26 +02:00
|
|
|
virtual void submit_input_event(Input::Event ev) = 0;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-09-09 22:39:54 +02:00
|
|
|
Genode::Session_label const &label() const { return _label; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-09-07 02:02:26 +02:00
|
|
|
Texture const &texture() const { return _texture; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-09-07 02:02:26 +02:00
|
|
|
Color color() const { return _color; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
View *background() const { return _background; }
|
|
|
|
|
|
|
|
void background(View *background) { _background = background; }
|
|
|
|
|
|
|
|
bool stay_top() const { return _stay_top; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if session uses an alpha channel
|
|
|
|
*/
|
2013-09-07 02:02:26 +02:00
|
|
|
bool uses_alpha() const { return _texture.alpha(); }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return vertical offset of session
|
|
|
|
*/
|
|
|
|
int v_offset() const { return _v_offset; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return input mask value at specified buffer position
|
|
|
|
*/
|
2013-09-07 02:02:26 +02:00
|
|
|
unsigned char input_mask_at(Point p) const
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
if (!_input_mask) return 0;
|
|
|
|
|
|
|
|
/* check boundaries */
|
2013-09-07 02:02:26 +02:00
|
|
|
if (p.x() < 0 || p.x() >= _texture.w()
|
|
|
|
|| p.y() < 0 || p.y() >= _texture.h())
|
2011-12-22 16:19:25 +01:00
|
|
|
return 0;
|
|
|
|
|
2013-09-07 02:02:26 +02:00
|
|
|
return _input_mask[p.y()*_texture.w() + p.x()];
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2013-09-09 22:39:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set session color according to the list of configured policies
|
|
|
|
*
|
|
|
|
* Select the policy that matches the label. If multiple policies
|
|
|
|
* match, select the one with the largest number of characters.
|
|
|
|
*/
|
|
|
|
void apply_session_color()
|
|
|
|
{
|
|
|
|
/* use white by default */
|
|
|
|
_color = WHITE;
|
|
|
|
|
|
|
|
try {
|
|
|
|
Genode::Session_policy policy(_label);
|
|
|
|
|
|
|
|
/* read color attribute */
|
|
|
|
policy.attribute("color").value(&_color);
|
|
|
|
} catch (...) { }
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|