2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
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.
10 #include "client_fb.h"
12 #include <l4/mag-gfx/clip_guard>
13 #include <l4/mag-gfx/texture>
15 #include <l4/mag/server/view_stack>
18 #include <l4/re/event_enums.h>
19 #include <l4/re/error_helper>
20 #include <l4/sys/factory>
21 #include <l4/re/util/meta>
22 #include <l4/re/console>
24 #include <l4/mag/server/user_state>
28 namespace Mag_server {
33 Client_fb::Client_fb(Core_api const *core, Rect const &pos, Point const &offs,
34 Texture *fb, L4::Cap<L4Re::Dataspace> const &fb_ds)
35 : View(pos, F_need_frame),
37 _core(core), _offs(offs), _fb(fb),
38 _bar_size(pos.w(), 16)
40 using L4Re::Video::View;
41 using L4Re::Video::Color_component;
42 using L4Re::Video::Goos;
45 _view_info.flags = View::F_none;
47 _view_info.view_index = 0;
50 _view_info.width = fb->size().w();
51 _view_info.height = fb->size().h();
52 _view_info.buffer_offset = 0;
53 _view_info.buffer_index = 0;
54 _view_info.bytes_per_line = _view_info.width * fb->type()->bytes_per_pixel();
55 _view_info.pixel_info = *fb->type();
57 _screen_info.flags = Goos::F_pointer;
58 _screen_info.width = _view_info.width;
59 _screen_info.height = _view_info.height;
60 _screen_info.num_static_views = 1;
61 _screen_info.num_static_buffers = 1;
62 _screen_info.pixel_info = _view_info.pixel_info;
65 L4Re::Env const *e = L4Re::Env::env();
66 _ev_ds = L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>();
68 chksys(e->mem_alloc()->alloc(L4_PAGESIZE, _ev_ds.get()));
69 chksys(e->rm()->attach(&_ev_ds_m, L4_PAGESIZE, L4Re::Rm::Search_addr, _ev_ds.get(), 0, L4_PAGESHIFT));
71 _events = L4Re::Event_buffer(_ev_ds_m.get(), L4_PAGESIZE);
75 Client_fb::draw(Canvas *canvas, View_stack const *, Mode mode, bool focused) const
77 /* use dimming in x-ray mode */
78 Canvas::Mix_mode op = mode.flat() ? Canvas::Solid : Canvas::Mixed;
80 /* is this the currently focused view? */
81 Rgb32::Color frame_color = focused ? Rgb32::White : View::frame_color();
83 /* do not dim the focused view in x-ray mode */
84 if (mode.xray() && !mode.kill() && focused)
88 * The view content and label should never overdraw the
89 * frame of the view in non-flat Nitpicker modes. The frame
90 * is located outside the view area. By shrinking the
91 * clipping area to the view area, we protect the frame.
93 Clip_guard clip_guard(canvas, *this);
96 * If the clipping area shrinked to zero,
97 * we do not process drawing operations.
99 if (!canvas->clip_valid()/* || !_session*/)
102 /* draw view content */
103 Rgb32::Color mix_color = mode.kill() ? kill_color() : Rgb32::Black;
105 canvas->draw_box(Rect(p1(), _bar_size), Rgb32::Color(56, 68,88));
107 canvas->draw_texture(_fb, mix_color, _offs + p1() + Point(0, _bar_size.h()), op);
114 draw_label(canvas, _label_rect.p1(), _session->label(), WHITE, _title, frame_color);
119 Client_fb::handle_event(L4Re::Event_buffer::Event const &e,
122 static Point left_drag;
124 if (e.payload.type == L4RE_EV_MAX && left_drag != Point())
126 Rect npos = Rect(p1() + mouse - left_drag, size());
128 _core->user_state()->vstack()->viewport(this, npos, true);
132 if (e.payload.type == L4RE_EV_KEY)
134 View_stack *_stack = _core->user_state()->vstack();
135 if (e.payload.code == L4RE_BTN_LEFT && e.payload.value == 1 &&
136 !_stack->on_top(this))
137 _stack->push_top(this);
139 if (e.payload.code == L4RE_BTN_LEFT && Rect(p1(), _bar_size).contains(mouse))
141 if (e.payload.value == 1)
143 else if (e.payload.value == 0)
149 if (e.payload.type == L4RE_EV_MAX)
151 Rect r = (*this - Rect(p1(), _bar_size)).b;
152 if (!r.contains(mouse))
155 L4Re::Event_buffer::Event ne;
157 ne.payload.type = L4RE_EV_ABS;
158 ne.payload.code = L4RE_ABS_X;
159 ne.payload.value = mouse.x() - p1().x();
160 ne.payload.stream_id = 0;
162 ne.payload.code = L4RE_ABS_Y;
163 ne.payload.value = mouse.y() - p1().y() - _bar_size.h();
176 Client_fb::refresh(int x, int y, int w, int h)
178 _core->user_state()->vstack()->refresh_view(this, 0, Rect(p1() + Point(x, y + _bar_size.h()), Area(w, h)));
183 Client_fb::dispatch(l4_umword_t obj, L4::Ipc_iostream &s)
190 case L4::Meta::Protocol:
191 return L4Re::Util::handle_meta_request<L4Re::Console>(s);
193 return Icu_svr::dispatch(obj, s);
194 case L4Re::Protocol::Goos:
195 return L4Re::Util::Video::Goos_svr::dispatch(obj, s);
196 case L4Re::Protocol::Event:
202 case L4Re::Event_::Get:
210 return -L4_EBADPROTO;
218 _core->user_state()->forget_view(this);