mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-21 10:01:57 +00:00
New Input::Event::FOCUS, rename keycode to code
This patch introduces keyboard-focus events to the 'Input::Event' class and changes the name 'Input::Event::keycode' to 'code'. The 'code' represents the key code for PRESS/RELEASE events, and the focus state for FOCUS events (0 - unfocused, 1 - focused). Furthermore, nitpicker has been adapted to deliver FOCUS events to its clients. Fixes #609
This commit is contained in:
parent
267817c2c5
commit
af66043b79
@ -45,7 +45,7 @@ namespace Input {
|
||||
* Input event call-back function
|
||||
*/
|
||||
static void input_callback(enum input_event_type type,
|
||||
unsigned keycode,
|
||||
unsigned code,
|
||||
int absolute_x, int absolute_y,
|
||||
int relative_x, int relative_y)
|
||||
{
|
||||
@ -58,7 +58,7 @@ static void input_callback(enum input_event_type type,
|
||||
}
|
||||
|
||||
try {
|
||||
ev_queue.add(Input::Event(t, keycode,
|
||||
ev_queue.add(Input::Event(t, code,
|
||||
absolute_x, absolute_y,
|
||||
relative_x, relative_y));
|
||||
} catch (Input_ring_buffer::Overflow) {
|
||||
|
@ -3036,7 +3036,7 @@ struct input_handle;
|
||||
* Input event callback
|
||||
*
|
||||
* \param type input event type
|
||||
* \param keycode key code if type is EVENT_TYPE_PRESS or
|
||||
* \param code key code if type is EVENT_TYPE_PRESS or
|
||||
* EVENT_TYPE_RELEASE
|
||||
* \param absolute_x absolute horizontal coordinate if type is
|
||||
* EVENT_TYPE_MOTION
|
||||
@ -3054,7 +3054,7 @@ struct input_handle;
|
||||
* 0.
|
||||
*/
|
||||
typedef void (*genode_input_event_cb)(enum input_event_type type,
|
||||
unsigned keycode,
|
||||
unsigned code,
|
||||
int absolute_x, int absolute_y,
|
||||
int relative_x, int relative_y);
|
||||
|
||||
|
@ -159,14 +159,14 @@ class Timer_thread : public Thread<4096>
|
||||
_mx = e.ax();
|
||||
_my = e.ay();
|
||||
ev.assign(e.type() == Input::Event::PRESS ? Event::PRESS : Event::RELEASE,
|
||||
e.ax(), e.ay(), e.keycode());
|
||||
e.ax(), e.ay(), e.code());
|
||||
_evqueue.add(&ev);
|
||||
}
|
||||
|
||||
if (e.type() == Input::Event::MOTION) {
|
||||
_mx = e.ax();
|
||||
_my = e.ay();
|
||||
ev.assign(Event::MOTION, e.ax(), e.ay(), e.keycode());
|
||||
ev.assign(Event::MOTION, e.ax(), e.ay(), e.code());
|
||||
_evqueue.add(&ev);
|
||||
}
|
||||
}
|
||||
|
@ -994,7 +994,7 @@ int main(int, char **)
|
||||
|
||||
bool press = (event->type() == Input::Event::PRESS ? true : false);
|
||||
bool release = (event->type() == Input::Event::RELEASE ? true : false);
|
||||
int keycode = event->keycode();
|
||||
int keycode = event->code();
|
||||
|
||||
if (press || release)
|
||||
scancode_tracker.submit(keycode, press);
|
||||
|
@ -329,9 +329,9 @@ int main(int, char **)
|
||||
|
||||
if (ev.type() == Input::Event::PRESS && key_cnt == 1) {
|
||||
|
||||
PDBG("key %d pressed", ev.keycode());
|
||||
PDBG("key %d pressed", ev.code());
|
||||
|
||||
int const ascii = keycode_to_ascii(ev.keycode());
|
||||
int const ascii = keycode_to_ascii(ev.code());
|
||||
if (ascii)
|
||||
pdf_view.handle_key(ascii);
|
||||
}
|
||||
|
@ -72,25 +72,25 @@ extern "C" {
|
||||
SDL_PrivateMouseMotion(0, 1, curr.rx(), curr.ry());
|
||||
break;
|
||||
case Input::Event::PRESS:
|
||||
if(curr.keycode() >= Input::BTN_MISC &&
|
||||
curr.keycode() <= Input::BTN_GEAR_UP)
|
||||
if(curr.code() >= Input::BTN_MISC &&
|
||||
curr.code() <= Input::BTN_GEAR_UP)
|
||||
SDL_PrivateMouseButton(SDL_PRESSED,
|
||||
buttonmap[curr.keycode()],
|
||||
buttonmap[curr.code()],
|
||||
0, 0);
|
||||
else
|
||||
SDL_PrivateKeyboard(SDL_PRESSED,
|
||||
Genode_Fb_TranslateKey(curr.keycode(),
|
||||
Genode_Fb_TranslateKey(curr.code(),
|
||||
&ksym));
|
||||
break;
|
||||
case Input::Event::RELEASE:
|
||||
if(curr.keycode() >= Input::BTN_MISC &&
|
||||
curr.keycode() <= Input::BTN_GEAR_UP)
|
||||
if(curr.code() >= Input::BTN_MISC &&
|
||||
curr.code() <= Input::BTN_GEAR_UP)
|
||||
SDL_PrivateMouseButton(SDL_RELEASED,
|
||||
buttonmap[curr.keycode()],
|
||||
buttonmap[curr.code()],
|
||||
0, 0);
|
||||
else
|
||||
SDL_PrivateKeyboard(SDL_RELEASED,
|
||||
Genode_Fb_TranslateKey(curr.keycode(),
|
||||
Genode_Fb_TranslateKey(curr.code(),
|
||||
&ksym));
|
||||
break;
|
||||
case Input::Event::WHEEL:
|
||||
|
@ -20,14 +20,27 @@ namespace Input {
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type { INVALID, MOTION, PRESS, RELEASE, WHEEL, LEAVE };
|
||||
enum Type { INVALID, MOTION, PRESS, RELEASE, WHEEL, FOCUS, LEAVE };
|
||||
|
||||
private:
|
||||
|
||||
Type _type;
|
||||
int _keycode;
|
||||
int _ax, _ay;
|
||||
int _rx, _ry;
|
||||
|
||||
/*
|
||||
* For PRESS and RELEASE events, '_code' contains the key code.
|
||||
* For FOCUS events, '_code' is set to 1 (focus) or 0 (unfocus).
|
||||
*/
|
||||
int _code;
|
||||
|
||||
/*
|
||||
* Absolute pointer position coordinates
|
||||
*/
|
||||
int _ax, _ay;
|
||||
|
||||
/*
|
||||
* Relative pointer motion vector
|
||||
*/
|
||||
int _rx, _ry;
|
||||
|
||||
public:
|
||||
|
||||
@ -35,21 +48,21 @@ namespace Input {
|
||||
* Constructors
|
||||
*/
|
||||
Event():
|
||||
_type(INVALID), _keycode(0), _ax(0), _ay(0), _rx(0), _ry(0) { }
|
||||
_type(INVALID), _code(0), _ax(0), _ay(0), _rx(0), _ry(0) { }
|
||||
|
||||
Event(Type type, int keycode, int ax, int ay, int rx, int ry):
|
||||
_type(type), _keycode(keycode),
|
||||
Event(Type type, int code, int ax, int ay, int rx, int ry):
|
||||
_type(type), _code(code),
|
||||
_ax(ax), _ay(ay), _rx(rx), _ry(ry) { }
|
||||
|
||||
/**
|
||||
* Accessors
|
||||
*/
|
||||
Type type() const { return _type; }
|
||||
int keycode() const { return _keycode; }
|
||||
int ax() const { return _ax; }
|
||||
int ay() const { return _ay; }
|
||||
int rx() const { return _rx; }
|
||||
int ry() const { return _ry; }
|
||||
Type type() const { return _type; }
|
||||
int code() const { return _code; }
|
||||
int ax() const { return _ax; }
|
||||
int ay() const { return _ay; }
|
||||
int rx() const { return _rx; }
|
||||
int ry() const { return _ry; }
|
||||
|
||||
bool is_absolute_motion() const { return _type == MOTION && !_rx && !_ry; }
|
||||
bool is_relative_motion() const { return _type == MOTION && (_rx || _ry); }
|
||||
|
@ -1,6 +1,5 @@
|
||||
SRC_CC = xev_track.cc
|
||||
REQUIRES = x11 xdamage
|
||||
|
||||
STDINC = yes
|
||||
LIBS = lx_hybrid
|
||||
|
||||
vpath xev_track.cc $(REP_DIR)/src/lib/xev_track
|
||||
|
@ -74,21 +74,21 @@ void inject_input_event(Display *dpy, Input::Event &ev)
|
||||
break;
|
||||
|
||||
case Input::Event::PRESS:
|
||||
if (ev.keycode() == Input::BTN_LEFT)
|
||||
if (ev.code() == Input::BTN_LEFT)
|
||||
XTestFakeButtonEvent(dpy, 1, 1, CurrentTime);
|
||||
if (ev.keycode() == Input::BTN_RIGHT)
|
||||
if (ev.code() == Input::BTN_RIGHT)
|
||||
XTestFakeButtonEvent(dpy, 2, 1, CurrentTime);
|
||||
else
|
||||
XTestFakeKeyEvent(dpy, convert_keycode(ev.keycode()), 1, CurrentTime);
|
||||
XTestFakeKeyEvent(dpy, convert_keycode(ev.code()), 1, CurrentTime);
|
||||
break;
|
||||
|
||||
case Input::Event::RELEASE:
|
||||
if (ev.keycode() == Input::BTN_LEFT)
|
||||
if (ev.code() == Input::BTN_LEFT)
|
||||
XTestFakeButtonEvent(dpy, 1, 0, CurrentTime);
|
||||
if (ev.keycode() == Input::BTN_RIGHT)
|
||||
if (ev.code() == Input::BTN_RIGHT)
|
||||
XTestFakeButtonEvent(dpy, 2, 0, CurrentTime);
|
||||
else
|
||||
XTestFakeKeyEvent(dpy, convert_keycode(ev.keycode()), 0, CurrentTime);
|
||||
XTestFakeKeyEvent(dpy, convert_keycode(ev.code()), 0, CurrentTime);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
|
@ -1,9 +1,6 @@
|
||||
TARGET = xvfb
|
||||
REQUIRES = linux x11 xtest xdamage
|
||||
SRC_CC = main.cc inject_input.cc
|
||||
LIBS = env syscall blit xev_track
|
||||
LIBS = env syscall blit xev_track lx_hybrid
|
||||
|
||||
# we need X11 headers, so let us use standard includes and standard libs
|
||||
STDINC = yes
|
||||
STDLIB = yes
|
||||
EXT_OBJECTS += -lX11 -lXdamage /usr/lib/libXtst.so.6
|
||||
|
@ -80,14 +80,14 @@ namespace Input {
|
||||
|
||||
Input::Event &ev = _ev_buf[i];
|
||||
|
||||
if ((ev.type() == Input::Event::MOTION)
|
||||
|| (ev.type() == Input::Event::WHEEL)
|
||||
|| (ev.keycode() == Input::BTN_LEFT)
|
||||
|| (ev.keycode() == Input::BTN_RIGHT)
|
||||
|| (ev.keycode() == Input::BTN_MIDDLE)) {
|
||||
if ((ev.type() == Input::Event::MOTION)
|
||||
|| (ev.type() == Input::Event::WHEEL)
|
||||
|| (ev.code() == Input::BTN_LEFT)
|
||||
|| (ev.code() == Input::BTN_RIGHT)
|
||||
|| (ev.code() == Input::BTN_MIDDLE)) {
|
||||
|
||||
ev = Input::Event(ev.type(),
|
||||
ev.keycode(),
|
||||
ev.code(),
|
||||
ev.ax() - delta.x,
|
||||
ev.ay() - delta.y,
|
||||
ev.rx(),
|
||||
|
@ -97,7 +97,7 @@ namespace Input {
|
||||
|
||||
/* apply view offset to absolute motion events */
|
||||
if (e.is_absolute_motion())
|
||||
e = Event(e.type(), e.keycode(),
|
||||
e = Event(e.type(), e.code(),
|
||||
e.ax() + _dx, e.ay() + _dy, 0, 0);
|
||||
_to_ev_buf[i] = e;
|
||||
}
|
||||
|
@ -51,12 +51,12 @@ void User_state::handle_event(Input::Event ev)
|
||||
* Mangle incoming events
|
||||
*/
|
||||
|
||||
int keycode = ev.keycode();
|
||||
int keycode = ev.code();
|
||||
int ax = _mouse_pos.x(), ay = _mouse_pos.y();
|
||||
int rx = 0, ry = 0; /* skip info about relative motion per default */
|
||||
|
||||
/* KEY_PRINT and KEY_SYSRQ both enter kill mode */
|
||||
if ((ev.type() == Event::PRESS) && (ev.keycode() == KEY_SYSRQ))
|
||||
if ((ev.type() == Event::PRESS) && (ev.code() == KEY_SYSRQ))
|
||||
keycode = KEY_PRINT;
|
||||
|
||||
/* transparently handle absolute and relative motion events */
|
||||
@ -106,7 +106,7 @@ void User_state::handle_event(Input::Event ev)
|
||||
* Detect mouse press event in kill mode, used to select the session
|
||||
* to lock out.
|
||||
*/
|
||||
if (kill() && ev.type() == Event::PRESS && ev.keycode() == Input::BTN_LEFT) {
|
||||
if (kill() && ev.type() == Event::PRESS && ev.code() == Input::BTN_LEFT) {
|
||||
if (pointed_view && pointed_view->session())
|
||||
lock_out_session(pointed_view->session());
|
||||
|
||||
@ -120,16 +120,35 @@ void User_state::handle_event(Input::Event ev)
|
||||
|
||||
/* update focused view */
|
||||
if (pointed_view != focused_view()
|
||||
&& _mouse_button(ev.keycode())) {
|
||||
&& _mouse_button(ev.code())) {
|
||||
|
||||
bool const focus_stays_in_session =
|
||||
(_focused_view && pointed_view &&
|
||||
_focused_view->session() == pointed_view->session());
|
||||
|
||||
/*
|
||||
* Do not update the whole screen when clicking on another
|
||||
* view of the already focused session.
|
||||
* Update the whole screen when the focus change results in
|
||||
* changing the focus to another session.
|
||||
*/
|
||||
if (flat() && _focused_view && pointed_view
|
||||
&& _focused_view->session() != pointed_view->session())
|
||||
if (flat() && !focus_stays_in_session)
|
||||
update_all = true;
|
||||
|
||||
/*
|
||||
* Notify both the old focussed session and the new one.
|
||||
*/
|
||||
if (!focus_stays_in_session) {
|
||||
|
||||
if (_focused_view) {
|
||||
Input::Event unfocus_ev(Input::Event::FOCUS, 0, ax, ay, 0, 0);
|
||||
_focused_view->session()->submit_input_event(&unfocus_ev);
|
||||
}
|
||||
|
||||
if (pointed_view) {
|
||||
Input::Event focus_ev(Input::Event::FOCUS, 1, ax, ay, 0, 0);
|
||||
pointed_view->session()->submit_input_event(&focus_ev);
|
||||
}
|
||||
}
|
||||
|
||||
if (!flat() || !_focused_view || !pointed_view)
|
||||
update_all = true;
|
||||
|
||||
@ -137,9 +156,9 @@ void User_state::handle_event(Input::Event ev)
|
||||
}
|
||||
|
||||
/* toggle kill and xray modes */
|
||||
if (ev.keycode() == KILL_KEY || ev.keycode() == XRAY_KEY) {
|
||||
if (ev.code() == KILL_KEY || ev.code() == XRAY_KEY) {
|
||||
|
||||
Mode::_mode ^= ev.keycode() == KILL_KEY ? KILL : XRAY;
|
||||
Mode::_mode ^= ev.code() == KILL_KEY ? KILL : XRAY;
|
||||
update_all = true;
|
||||
}
|
||||
}
|
||||
@ -186,7 +205,7 @@ void User_state::handle_event(Input::Event ev)
|
||||
|
||||
/* deliver press/release event to session with focused view */
|
||||
if (ev.type() == Event::PRESS || ev.type() == Event::RELEASE)
|
||||
if (!_masked_key(ev.keycode()) && focused_view())
|
||||
if (!_masked_key(ev.code()) && focused_view())
|
||||
focused_view()->session()->submit_input_event(&ev);
|
||||
}
|
||||
|
||||
|
@ -513,7 +513,7 @@ namespace Nitpicker {
|
||||
*/
|
||||
Event e = *ev;
|
||||
if (e.ax() || e.ay())
|
||||
e = Event(e.type(), e.keycode(), e.ax(),
|
||||
e = Event(e.type(), e.code(), e.ax(),
|
||||
max(0, e.ay() - v_offset()), e.rx(), e.ry());
|
||||
|
||||
_input_session_component.submit(&e);
|
||||
|
@ -51,9 +51,9 @@ int main(int argc, char **argv)
|
||||
if (ev->type() == Input::Event::RELEASE) key_cnt--;
|
||||
|
||||
/* log event */
|
||||
PLOG("Input event type=%d\tkeycode=%d\trx=%d\try=%d\tkey_cnt=%d\t%s",
|
||||
ev->type(), ev->keycode(), ev->rx(), ev->ry(), key_cnt,
|
||||
key_strings[ev->keycode()]);
|
||||
PLOG("Input event type=%d\tcode=%d\trx=%d\try=%d\tkey_cnt=%d\t%s",
|
||||
ev->type(), ev->code(), ev->rx(), ev->ry(), key_cnt,
|
||||
key_strings[ev->code()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,18 +107,18 @@ extern "C" {
|
||||
}
|
||||
case Event::PRESS:
|
||||
{
|
||||
if (ev->keycode() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->keycode(), 1);
|
||||
if (ev->code() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->code(), 1);
|
||||
else
|
||||
genode_input_event(mouse, EV_KEY, ev->keycode(), 1);
|
||||
genode_input_event(mouse, EV_KEY, ev->code(), 1);
|
||||
return;
|
||||
}
|
||||
case Event::RELEASE:
|
||||
{
|
||||
if (ev->keycode() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->keycode(), 0);
|
||||
if (ev->code() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->code(), 0);
|
||||
else
|
||||
genode_input_event(mouse, EV_KEY, ev->keycode(), 0);
|
||||
genode_input_event(mouse, EV_KEY, ev->code(), 0);
|
||||
return;
|
||||
}
|
||||
case Event::WHEEL:
|
||||
|
@ -99,18 +99,18 @@ extern "C" {
|
||||
}
|
||||
case Event::PRESS:
|
||||
{
|
||||
if (ev->keycode() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->keycode(), 1);
|
||||
if (ev->code() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->code(), 1);
|
||||
else
|
||||
genode_input_event(mouse, EV_KEY, ev->keycode(), 1);
|
||||
genode_input_event(mouse, EV_KEY, ev->code(), 1);
|
||||
return;
|
||||
}
|
||||
case Event::RELEASE:
|
||||
{
|
||||
if (ev->keycode() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->keycode(), 0);
|
||||
if (ev->code() < BTN_MISC)
|
||||
genode_input_event(keyb, EV_KEY, ev->code(), 0);
|
||||
else
|
||||
genode_input_event(mouse, EV_KEY, ev->keycode(), 0);
|
||||
genode_input_event(mouse, EV_KEY, ev->code(), 0);
|
||||
return;
|
||||
}
|
||||
case Event::WHEEL:
|
||||
|
@ -77,20 +77,17 @@ void QNitpickerInputHandler::readInputData()
|
||||
|
||||
Input::Event *ev = &ev_buf[i];
|
||||
|
||||
// qDebug() << "QNitpickerInputHandler: received input event: keycode == "
|
||||
// << ev->keycode();
|
||||
|
||||
if (ev->type() == Input::Event::MOTION ||
|
||||
ev->type() == Input::Event::WHEEL ||
|
||||
ev->keycode() == Input::BTN_LEFT ||
|
||||
ev->keycode() == Input::BTN_RIGHT ||
|
||||
ev->keycode() == Input::BTN_MIDDLE) {
|
||||
if (ev->type() == Input::Event::MOTION
|
||||
|| ev->type() == Input::Event::WHEEL
|
||||
|| ev->code() == Input::BTN_LEFT
|
||||
|| ev->code() == Input::BTN_RIGHT
|
||||
|| ev->code() == Input::BTN_MIDDLE) {
|
||||
|
||||
#ifndef QT_NO_QWS_MOUSE_NITPICKER
|
||||
mouse->processMouseEvent(ev);
|
||||
#endif
|
||||
|
||||
} else if (ev->keycode() < 128) {
|
||||
} else if (ev->code() < 128) {
|
||||
|
||||
#ifndef QT_NO_QWS_KEYBOARD_NITPICKER
|
||||
keyboard->processKeyEvent(ev);
|
||||
|
@ -58,14 +58,12 @@ QNitpickerKeyboardHandler::~QNitpickerKeyboardHandler()
|
||||
|
||||
void QNitpickerKeyboardHandler::processKeyEvent(Input::Event *ev)
|
||||
{
|
||||
// qDebug() << "processKeyEvent(): keycode ==" << ev->keycode();
|
||||
|
||||
int keycode = ev->keycode();
|
||||
|
||||
int keycode = ev->code();
|
||||
|
||||
if (ev->type() == Input::Event::RELEASE) {
|
||||
keycode |= 0x80;
|
||||
}
|
||||
|
||||
|
||||
doKey(keycode);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ void QNitpickerMouseHandler::processMouseEvent(Input::Event *ev)
|
||||
|
||||
switch (ev->type()) {
|
||||
case Input::Event::PRESS:
|
||||
switch (ev->keycode()) {
|
||||
switch (ev->code()) {
|
||||
case Input::BTN_LEFT:
|
||||
state |= Qt::LeftButton;
|
||||
break;
|
||||
@ -95,7 +95,7 @@ void QNitpickerMouseHandler::processMouseEvent(Input::Event *ev)
|
||||
}
|
||||
break;
|
||||
case Input::Event::RELEASE:
|
||||
switch (ev->keycode()) {
|
||||
switch (ev->code()) {
|
||||
case Input::BTN_LEFT:
|
||||
state &= ~Qt::LeftButton;
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user