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:
Norman Feske 2013-01-12 23:34:49 +01:00
parent 267817c2c5
commit af66043b79
20 changed files with 115 additions and 92 deletions

View File

@ -45,7 +45,7 @@ namespace Input {
* Input event call-back function * Input event call-back function
*/ */
static void input_callback(enum input_event_type type, static void input_callback(enum input_event_type type,
unsigned keycode, unsigned code,
int absolute_x, int absolute_y, int absolute_x, int absolute_y,
int relative_x, int relative_y) int relative_x, int relative_y)
{ {
@ -58,7 +58,7 @@ static void input_callback(enum input_event_type type,
} }
try { try {
ev_queue.add(Input::Event(t, keycode, ev_queue.add(Input::Event(t, code,
absolute_x, absolute_y, absolute_x, absolute_y,
relative_x, relative_y)); relative_x, relative_y));
} catch (Input_ring_buffer::Overflow) { } catch (Input_ring_buffer::Overflow) {

View File

@ -3036,7 +3036,7 @@ struct input_handle;
* Input event callback * Input event callback
* *
* \param type input event type * \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 * EVENT_TYPE_RELEASE
* \param absolute_x absolute horizontal coordinate if type is * \param absolute_x absolute horizontal coordinate if type is
* EVENT_TYPE_MOTION * EVENT_TYPE_MOTION
@ -3054,7 +3054,7 @@ struct input_handle;
* 0. * 0.
*/ */
typedef void (*genode_input_event_cb)(enum input_event_type type, typedef void (*genode_input_event_cb)(enum input_event_type type,
unsigned keycode, unsigned code,
int absolute_x, int absolute_y, int absolute_x, int absolute_y,
int relative_x, int relative_y); int relative_x, int relative_y);

View File

@ -159,14 +159,14 @@ class Timer_thread : public Thread<4096>
_mx = e.ax(); _mx = e.ax();
_my = e.ay(); _my = e.ay();
ev.assign(e.type() == Input::Event::PRESS ? Event::PRESS : Event::RELEASE, 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); _evqueue.add(&ev);
} }
if (e.type() == Input::Event::MOTION) { if (e.type() == Input::Event::MOTION) {
_mx = e.ax(); _mx = e.ax();
_my = e.ay(); _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); _evqueue.add(&ev);
} }
} }

View File

@ -994,7 +994,7 @@ int main(int, char **)
bool press = (event->type() == Input::Event::PRESS ? true : false); bool press = (event->type() == Input::Event::PRESS ? true : false);
bool release = (event->type() == Input::Event::RELEASE ? true : false); bool release = (event->type() == Input::Event::RELEASE ? true : false);
int keycode = event->keycode(); int keycode = event->code();
if (press || release) if (press || release)
scancode_tracker.submit(keycode, press); scancode_tracker.submit(keycode, press);

View File

@ -329,9 +329,9 @@ int main(int, char **)
if (ev.type() == Input::Event::PRESS && key_cnt == 1) { 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) if (ascii)
pdf_view.handle_key(ascii); pdf_view.handle_key(ascii);
} }

View File

@ -72,25 +72,25 @@ extern "C" {
SDL_PrivateMouseMotion(0, 1, curr.rx(), curr.ry()); SDL_PrivateMouseMotion(0, 1, curr.rx(), curr.ry());
break; break;
case Input::Event::PRESS: case Input::Event::PRESS:
if(curr.keycode() >= Input::BTN_MISC && if(curr.code() >= Input::BTN_MISC &&
curr.keycode() <= Input::BTN_GEAR_UP) curr.code() <= Input::BTN_GEAR_UP)
SDL_PrivateMouseButton(SDL_PRESSED, SDL_PrivateMouseButton(SDL_PRESSED,
buttonmap[curr.keycode()], buttonmap[curr.code()],
0, 0); 0, 0);
else else
SDL_PrivateKeyboard(SDL_PRESSED, SDL_PrivateKeyboard(SDL_PRESSED,
Genode_Fb_TranslateKey(curr.keycode(), Genode_Fb_TranslateKey(curr.code(),
&ksym)); &ksym));
break; break;
case Input::Event::RELEASE: case Input::Event::RELEASE:
if(curr.keycode() >= Input::BTN_MISC && if(curr.code() >= Input::BTN_MISC &&
curr.keycode() <= Input::BTN_GEAR_UP) curr.code() <= Input::BTN_GEAR_UP)
SDL_PrivateMouseButton(SDL_RELEASED, SDL_PrivateMouseButton(SDL_RELEASED,
buttonmap[curr.keycode()], buttonmap[curr.code()],
0, 0); 0, 0);
else else
SDL_PrivateKeyboard(SDL_RELEASED, SDL_PrivateKeyboard(SDL_RELEASED,
Genode_Fb_TranslateKey(curr.keycode(), Genode_Fb_TranslateKey(curr.code(),
&ksym)); &ksym));
break; break;
case Input::Event::WHEEL: case Input::Event::WHEEL:

View File

@ -20,14 +20,27 @@ namespace Input {
{ {
public: public:
enum Type { INVALID, MOTION, PRESS, RELEASE, WHEEL, LEAVE }; enum Type { INVALID, MOTION, PRESS, RELEASE, WHEEL, FOCUS, LEAVE };
private: private:
Type _type; 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: public:
@ -35,21 +48,21 @@ namespace Input {
* Constructors * Constructors
*/ */
Event(): 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): Event(Type type, int code, int ax, int ay, int rx, int ry):
_type(type), _keycode(keycode), _type(type), _code(code),
_ax(ax), _ay(ay), _rx(rx), _ry(ry) { } _ax(ax), _ay(ay), _rx(rx), _ry(ry) { }
/** /**
* Accessors * Accessors
*/ */
Type type() const { return _type; } Type type() const { return _type; }
int keycode() const { return _keycode; } int code() const { return _code; }
int ax() const { return _ax; } int ax() const { return _ax; }
int ay() const { return _ay; } int ay() const { return _ay; }
int rx() const { return _rx; } int rx() const { return _rx; }
int ry() const { return _ry; } int ry() const { return _ry; }
bool is_absolute_motion() const { return _type == MOTION && !_rx && !_ry; } bool is_absolute_motion() const { return _type == MOTION && !_rx && !_ry; }
bool is_relative_motion() const { return _type == MOTION && (_rx || _ry); } bool is_relative_motion() const { return _type == MOTION && (_rx || _ry); }

View File

@ -1,6 +1,5 @@
SRC_CC = xev_track.cc SRC_CC = xev_track.cc
REQUIRES = x11 xdamage REQUIRES = x11 xdamage
LIBS = lx_hybrid
STDINC = yes
vpath xev_track.cc $(REP_DIR)/src/lib/xev_track vpath xev_track.cc $(REP_DIR)/src/lib/xev_track

View File

@ -74,21 +74,21 @@ void inject_input_event(Display *dpy, Input::Event &ev)
break; break;
case Input::Event::PRESS: case Input::Event::PRESS:
if (ev.keycode() == Input::BTN_LEFT) if (ev.code() == Input::BTN_LEFT)
XTestFakeButtonEvent(dpy, 1, 1, CurrentTime); XTestFakeButtonEvent(dpy, 1, 1, CurrentTime);
if (ev.keycode() == Input::BTN_RIGHT) if (ev.code() == Input::BTN_RIGHT)
XTestFakeButtonEvent(dpy, 2, 1, CurrentTime); XTestFakeButtonEvent(dpy, 2, 1, CurrentTime);
else else
XTestFakeKeyEvent(dpy, convert_keycode(ev.keycode()), 1, CurrentTime); XTestFakeKeyEvent(dpy, convert_keycode(ev.code()), 1, CurrentTime);
break; break;
case Input::Event::RELEASE: case Input::Event::RELEASE:
if (ev.keycode() == Input::BTN_LEFT) if (ev.code() == Input::BTN_LEFT)
XTestFakeButtonEvent(dpy, 1, 0, CurrentTime); XTestFakeButtonEvent(dpy, 1, 0, CurrentTime);
if (ev.keycode() == Input::BTN_RIGHT) if (ev.code() == Input::BTN_RIGHT)
XTestFakeButtonEvent(dpy, 2, 0, CurrentTime); XTestFakeButtonEvent(dpy, 2, 0, CurrentTime);
else else
XTestFakeKeyEvent(dpy, convert_keycode(ev.keycode()), 0, CurrentTime); XTestFakeKeyEvent(dpy, convert_keycode(ev.code()), 0, CurrentTime);
break; break;
default: break; default: break;

View File

@ -1,9 +1,6 @@
TARGET = xvfb TARGET = xvfb
REQUIRES = linux x11 xtest xdamage REQUIRES = linux x11 xtest xdamage
SRC_CC = main.cc inject_input.cc 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 EXT_OBJECTS += -lX11 -lXdamage /usr/lib/libXtst.so.6

View File

@ -80,14 +80,14 @@ namespace Input {
Input::Event &ev = _ev_buf[i]; Input::Event &ev = _ev_buf[i];
if ((ev.type() == Input::Event::MOTION) if ((ev.type() == Input::Event::MOTION)
|| (ev.type() == Input::Event::WHEEL) || (ev.type() == Input::Event::WHEEL)
|| (ev.keycode() == Input::BTN_LEFT) || (ev.code() == Input::BTN_LEFT)
|| (ev.keycode() == Input::BTN_RIGHT) || (ev.code() == Input::BTN_RIGHT)
|| (ev.keycode() == Input::BTN_MIDDLE)) { || (ev.code() == Input::BTN_MIDDLE)) {
ev = Input::Event(ev.type(), ev = Input::Event(ev.type(),
ev.keycode(), ev.code(),
ev.ax() - delta.x, ev.ax() - delta.x,
ev.ay() - delta.y, ev.ay() - delta.y,
ev.rx(), ev.rx(),

View File

@ -97,7 +97,7 @@ namespace Input {
/* apply view offset to absolute motion events */ /* apply view offset to absolute motion events */
if (e.is_absolute_motion()) 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); e.ax() + _dx, e.ay() + _dy, 0, 0);
_to_ev_buf[i] = e; _to_ev_buf[i] = e;
} }

View File

@ -51,12 +51,12 @@ void User_state::handle_event(Input::Event ev)
* Mangle incoming events * Mangle incoming events
*/ */
int keycode = ev.keycode(); int keycode = ev.code();
int ax = _mouse_pos.x(), ay = _mouse_pos.y(); int ax = _mouse_pos.x(), ay = _mouse_pos.y();
int rx = 0, ry = 0; /* skip info about relative motion per default */ int rx = 0, ry = 0; /* skip info about relative motion per default */
/* KEY_PRINT and KEY_SYSRQ both enter kill mode */ /* 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; keycode = KEY_PRINT;
/* transparently handle absolute and relative motion events */ /* 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 * Detect mouse press event in kill mode, used to select the session
* to lock out. * 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()) if (pointed_view && pointed_view->session())
lock_out_session(pointed_view->session()); lock_out_session(pointed_view->session());
@ -120,16 +120,35 @@ void User_state::handle_event(Input::Event ev)
/* update focused view */ /* update focused view */
if (pointed_view != 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 * Update the whole screen when the focus change results in
* view of the already focused session. * changing the focus to another session.
*/ */
if (flat() && _focused_view && pointed_view if (flat() && !focus_stays_in_session)
&& _focused_view->session() != pointed_view->session())
update_all = true; 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) if (!flat() || !_focused_view || !pointed_view)
update_all = true; update_all = true;
@ -137,9 +156,9 @@ void User_state::handle_event(Input::Event ev)
} }
/* toggle kill and xray modes */ /* 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; update_all = true;
} }
} }
@ -186,7 +205,7 @@ void User_state::handle_event(Input::Event ev)
/* deliver press/release event to session with focused view */ /* deliver press/release event to session with focused view */
if (ev.type() == Event::PRESS || ev.type() == Event::RELEASE) 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); focused_view()->session()->submit_input_event(&ev);
} }

View File

@ -513,7 +513,7 @@ namespace Nitpicker {
*/ */
Event e = *ev; Event e = *ev;
if (e.ax() || e.ay()) 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()); max(0, e.ay() - v_offset()), e.rx(), e.ry());
_input_session_component.submit(&e); _input_session_component.submit(&e);

View File

@ -51,9 +51,9 @@ int main(int argc, char **argv)
if (ev->type() == Input::Event::RELEASE) key_cnt--; if (ev->type() == Input::Event::RELEASE) key_cnt--;
/* log event */ /* log event */
PLOG("Input event type=%d\tkeycode=%d\trx=%d\try=%d\tkey_cnt=%d\t%s", PLOG("Input event type=%d\tcode=%d\trx=%d\try=%d\tkey_cnt=%d\t%s",
ev->type(), ev->keycode(), ev->rx(), ev->ry(), key_cnt, ev->type(), ev->code(), ev->rx(), ev->ry(), key_cnt,
key_strings[ev->keycode()]); key_strings[ev->code()]);
} }
} }

View File

@ -107,18 +107,18 @@ extern "C" {
} }
case Event::PRESS: case Event::PRESS:
{ {
if (ev->keycode() < BTN_MISC) if (ev->code() < BTN_MISC)
genode_input_event(keyb, EV_KEY, ev->keycode(), 1); genode_input_event(keyb, EV_KEY, ev->code(), 1);
else else
genode_input_event(mouse, EV_KEY, ev->keycode(), 1); genode_input_event(mouse, EV_KEY, ev->code(), 1);
return; return;
} }
case Event::RELEASE: case Event::RELEASE:
{ {
if (ev->keycode() < BTN_MISC) if (ev->code() < BTN_MISC)
genode_input_event(keyb, EV_KEY, ev->keycode(), 0); genode_input_event(keyb, EV_KEY, ev->code(), 0);
else else
genode_input_event(mouse, EV_KEY, ev->keycode(), 0); genode_input_event(mouse, EV_KEY, ev->code(), 0);
return; return;
} }
case Event::WHEEL: case Event::WHEEL:

View File

@ -99,18 +99,18 @@ extern "C" {
} }
case Event::PRESS: case Event::PRESS:
{ {
if (ev->keycode() < BTN_MISC) if (ev->code() < BTN_MISC)
genode_input_event(keyb, EV_KEY, ev->keycode(), 1); genode_input_event(keyb, EV_KEY, ev->code(), 1);
else else
genode_input_event(mouse, EV_KEY, ev->keycode(), 1); genode_input_event(mouse, EV_KEY, ev->code(), 1);
return; return;
} }
case Event::RELEASE: case Event::RELEASE:
{ {
if (ev->keycode() < BTN_MISC) if (ev->code() < BTN_MISC)
genode_input_event(keyb, EV_KEY, ev->keycode(), 0); genode_input_event(keyb, EV_KEY, ev->code(), 0);
else else
genode_input_event(mouse, EV_KEY, ev->keycode(), 0); genode_input_event(mouse, EV_KEY, ev->code(), 0);
return; return;
} }
case Event::WHEEL: case Event::WHEEL:

View File

@ -77,20 +77,17 @@ void QNitpickerInputHandler::readInputData()
Input::Event *ev = &ev_buf[i]; Input::Event *ev = &ev_buf[i];
// qDebug() << "QNitpickerInputHandler: received input event: keycode == " if (ev->type() == Input::Event::MOTION
// << ev->keycode(); || ev->type() == Input::Event::WHEEL
|| ev->code() == Input::BTN_LEFT
if (ev->type() == Input::Event::MOTION || || ev->code() == Input::BTN_RIGHT
ev->type() == Input::Event::WHEEL || || ev->code() == Input::BTN_MIDDLE) {
ev->keycode() == Input::BTN_LEFT ||
ev->keycode() == Input::BTN_RIGHT ||
ev->keycode() == Input::BTN_MIDDLE) {
#ifndef QT_NO_QWS_MOUSE_NITPICKER #ifndef QT_NO_QWS_MOUSE_NITPICKER
mouse->processMouseEvent(ev); mouse->processMouseEvent(ev);
#endif #endif
} else if (ev->keycode() < 128) { } else if (ev->code() < 128) {
#ifndef QT_NO_QWS_KEYBOARD_NITPICKER #ifndef QT_NO_QWS_KEYBOARD_NITPICKER
keyboard->processKeyEvent(ev); keyboard->processKeyEvent(ev);

View File

@ -58,14 +58,12 @@ QNitpickerKeyboardHandler::~QNitpickerKeyboardHandler()
void QNitpickerKeyboardHandler::processKeyEvent(Input::Event *ev) void QNitpickerKeyboardHandler::processKeyEvent(Input::Event *ev)
{ {
// qDebug() << "processKeyEvent(): keycode ==" << ev->keycode(); int keycode = ev->code();
int keycode = ev->keycode();
if (ev->type() == Input::Event::RELEASE) { if (ev->type() == Input::Event::RELEASE) {
keycode |= 0x80; keycode |= 0x80;
} }
doKey(keycode); doKey(keycode);
} }

View File

@ -76,7 +76,7 @@ void QNitpickerMouseHandler::processMouseEvent(Input::Event *ev)
switch (ev->type()) { switch (ev->type()) {
case Input::Event::PRESS: case Input::Event::PRESS:
switch (ev->keycode()) { switch (ev->code()) {
case Input::BTN_LEFT: case Input::BTN_LEFT:
state |= Qt::LeftButton; state |= Qt::LeftButton;
break; break;
@ -95,7 +95,7 @@ void QNitpickerMouseHandler::processMouseEvent(Input::Event *ev)
} }
break; break;
case Input::Event::RELEASE: case Input::Event::RELEASE:
switch (ev->keycode()) { switch (ev->code()) {
case Input::BTN_LEFT: case Input::BTN_LEFT:
state &= ~Qt::LeftButton; state &= ~Qt::LeftButton;
break; break;