]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/mag/include/server/user_state
Update
[l4.git] / l4 / pkg / mag / include / server / user_state
1 // vi:ft=cpp
2 /*
3  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11
12 #include <l4/mag-gfx/geometry>
13 #include <l4/mag/server/view_stack>
14
15 #include <l4/re/video/view>
16 #include <l4/re/event>
17 #include <l4/mag/server/hid_report>
18
19 struct lua_State;
20 struct luaL_Reg;
21
22 namespace Mag_server {
23
24 using namespace Mag_gfx;
25
26 class User_state;
27
28 class View_proxy
29 {
30 private:
31   friend class User_state;
32
33   View_proxy(View_proxy const &);
34   void operator = (View_proxy const &);
35
36   View *_v;
37   View_proxy **_pn;
38   View_proxy *_n;
39
40 public:
41   explicit View_proxy(User_state *ust);
42
43   ~View_proxy()
44   {
45     *_pn = _n;
46     _n->_pn = _pn;
47   }
48
49   View *view() const { return _v; }
50   void view(View *v) { _v = v; }
51   void forget(View *v) { if (_v == v) _v = 0; }
52 };
53
54
55 class User_state
56 {
57 public:
58   friend class View_proxy;
59
60 private:
61   View_stack *_vstack;
62   Point _mouse_pos;
63   View *_keyboard_focus;
64   View_proxy *_view_proxies;
65   View *_mouse_cursor;
66
67   lua_State *_l;
68
69 public:
70   static char const *const _class;
71   static luaL_Reg const _ops[];
72
73   User_state(lua_State *lua, View_stack *_vstack, View *cursor);
74   virtual ~User_state();
75
76   void forget_view(View *v);
77
78   View_stack *vstack() { return _vstack; }
79   View_stack const *vstack() const { return _vstack; }
80
81   void set_mode(Mode::Mode_flag m, bool on = true)
82   { vstack()->set_mode(m, on); }
83
84   void toggle_mode(Mode::Mode_flag m)
85   { vstack()->toggle_mode(m); }
86
87   bool set_focus(View *v);
88   View *kbd_focus() const { return _keyboard_focus; }
89
90   typedef L4Re::Event_buffer::Event Event;
91   typedef L4Re::Event_stream_info Input_info;
92   typedef L4Re::Event_absinfo Input_absinfo;
93
94   void set_pointer(int x, int y, bool hide);
95   void move_pointer(int x, int y)
96   { set_pointer(_mouse_pos.x() + x, _mouse_pos.y() + y, false); }
97   Point const &mouse_pos() const { return _mouse_pos; }
98
99   int get_input_stream_info_for_id(l4_umword_t id, Input_info *info) const;
100   int get_input_axis_info(l4_umword_t id, unsigned naxes, unsigned const *axis,
101                           Input_absinfo *info, unsigned char *ax_mode) const;
102 };
103
104 inline
105 View_proxy::View_proxy(User_state *ust)
106 : _v(0), _pn(&ust->_view_proxies), _n(ust->_view_proxies)
107 {
108   ust->_view_proxies = this;
109   if (_n)
110     _n->_pn = &_n;
111 }
112
113 }