+ dr.dispatched(true);
+}
+
+
+docstring GuiApplication::viewStatusMessage()
+{
+ // When meta-fake key is pressed, show the key sequence so far + "M-".
+ if (d->meta_fake_bit != NoModifier)
+ return d->keyseq.print(KeySequence::ForGui) + "M-";
+
+ // Else, when a non-complete key sequence is pressed,
+ // show the available options.
+ if (d->keyseq.length() > 0 && !d->keyseq.deleted())
+ return d->keyseq.printOptions(true);
+
+ return docstring();
+}
+
+
+void GuiApplication::handleKeyFunc(FuncCode action)
+{
+ char_type c = 0;
+
+ if (d->keyseq.length())
+ c = 0;
+ GuiView * gv = currentView();
+ LASSERT(gv && gv->currentBufferView(), return);
+ BufferView * bv = gv->currentBufferView();
+ bv->getIntl().getTransManager().deadkey(
+ c, get_accent(action).accent, bv->cursor().innerText(),
+ bv->cursor());
+ // Need to clear, in case the minibuffer calls these
+ // actions
+ d->keyseq.clear();
+ // copied verbatim from do_accent_char
+ bv->cursor().resetAnchor();
+ bv->processUpdateFlags(Update::FitCursor);
+}
+
+
+void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state)
+{
+ LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
+
+ GuiView * lv = currentView();
+
+ // Do nothing if we have nothing (JMarc)
+ if (!keysym.isOK()) {
+ LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
+ lv->restartCursor();
+ return;
+ }
+
+ if (keysym.isModifier()) {
+ LYXERR(Debug::KEY, "isModifier true");
+ if (lv)
+ lv->restartCursor();
+ return;
+ }
+
+ char_type encoded_last_key = keysym.getUCSEncoded();
+
+ // Do a one-deep top-level lookup for
+ // cancel and meta-fake keys. RVDK_PATCH_5
+ d->cancel_meta_seq.reset();
+
+ FuncRequest func = d->cancel_meta_seq.addkey(keysym, state);
+ LYXERR(Debug::KEY, "action first set to [" << func.action << ']');
+
+ // When not cancel or meta-fake, do the normal lookup.
+ // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
+ // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5.
+ if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
+ // remove Caps Lock and Mod2 as a modifiers
+ func = d->keyseq.addkey(keysym, (state | d->meta_fake_bit));
+ LYXERR(Debug::KEY, "action now set to [" << func.action << ']');
+ }
+
+ // Dont remove this unless you know what you are doing.
+ d->meta_fake_bit = NoModifier;
+
+ // Can this happen now ?
+ if (func.action == LFUN_NOACTION)
+ func = FuncRequest(LFUN_COMMAND_PREFIX);
+
+ LYXERR(Debug::KEY, " Key [action=" << func.action << "]["
+ << d->keyseq.print(KeySequence::Portable) << ']');
+
+ // already here we know if it any point in going further
+ // why not return already here if action == -1 and
+ // num_bytes == 0? (Lgb)
+
+ if (d->keyseq.length() > 1)
+ lv->message(d->keyseq.print(KeySequence::ForGui));
+
+
+ // Maybe user can only reach the key via holding down shift.
+ // Let's see. But only if shift is the only modifier
+ if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
+ LYXERR(Debug::KEY, "Trying without shift");
+ func = d->keyseq.addkey(keysym, NoModifier);
+ LYXERR(Debug::KEY, "Action now " << func.action);
+ }
+
+ if (func.action == LFUN_UNKNOWN_ACTION) {
+ // Hmm, we didn't match any of the keysequences. See
+ // if it's normal insertable text not already covered
+ // by a binding
+ if (keysym.isText() && d->keyseq.length() == 1) {
+ LYXERR(Debug::KEY, "isText() is true, inserting.");
+ func = FuncRequest(LFUN_SELF_INSERT,
+ FuncRequest::KEYBOARD);
+ } else {
+ LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
+ lv->message(_("Unknown function."));
+ lv->restartCursor();
+ return;
+ }
+ }
+
+ if (func.action == LFUN_SELF_INSERT) {
+ if (encoded_last_key != 0) {
+ docstring const arg(1, encoded_last_key);
+ lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
+ FuncRequest::KEYBOARD));
+ LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
+ }
+ } else {
+ lyx::dispatch(func);
+ if (!lv)
+ return;
+ }
+}
+
+
+void GuiApplication::dispatchDelayed(FuncRequest const & func)
+{
+ d->func_request_queue_.push(func);
+ QTimer::singleShot(0, this, SLOT(processFuncRequestQueue()));