Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Cache lookup table visibility in engine side.

Also factor out keyval resolution code.
  • Loading branch information...
commit 295ed5ed25f5aced06a69a6f7b95465bbd1164bb 1 parent 282509a
Daiki Ueno authored

Showing 1 changed file with 50 additions and 27 deletions. Show diff stats Hide diff stats

  1. +50 27 src/engine.vala
77 src/engine.vala
@@ -30,6 +30,7 @@ class SkkEngine : IBus.Engine {
30 30 Skk.Context context;
31 31 IBus.LookupTable lookup_table;
32 32 uint page_start;
  33 + bool lookup_table_visible;
33 34
34 35 bool show_annotation;
35 36
@@ -143,8 +144,11 @@ class SkkEngine : IBus.Engine {
143 144 var text = new IBus.Text.from_string (output);
144 145 commit_text (text);
145 146 }
146   - hide_lookup_table ();
147   - hide_auxiliary_text ();
  147 + if (lookup_table_visible) {
  148 + hide_lookup_table ();
  149 + hide_auxiliary_text ();
  150 + lookup_table_visible = false;
  151 + }
148 152 });
149 153
150 154 update_candidates ();
@@ -193,9 +197,11 @@ class SkkEngine : IBus.Engine {
193 197 } else {
194 198 update_auxiliary_text (empty_text, false);
195 199 }
196   - } else {
  200 + lookup_table_visible = true;
  201 + } else if (lookup_table_visible) {
197 202 hide_lookup_table ();
198 203 hide_auxiliary_text ();
  204 + lookup_table_visible = false;
199 205 }
200 206 }
201 207
@@ -395,6 +401,30 @@ class SkkEngine : IBus.Engine {
395 401 return false;
396 402 }
397 403
  404 + struct Entry<K,V> {
  405 + K key;
  406 + V value;
  407 + }
  408 +
  409 + static const Entry<uint,unichar>[] CODE_KEYVALS = {
  410 + { IBus.Tab, '\t' },
  411 + { IBus.Return, '\n' },
  412 + { IBus.BackSpace, '\b' }
  413 + };
  414 +
  415 + static const Entry<uint,string>[] NAME_KEYVALS = {
  416 + { IBus.Up, "Up" },
  417 + { IBus.Down, "Down" },
  418 + { IBus.Left, "Left" },
  419 + { IBus.Right, "Right" },
  420 + { IBus.Page_Up, "Page_Up" },
  421 + { IBus.KP_Page_Up, "Page_Up" },
  422 + { IBus.Page_Down, "Page_Down" },
  423 + { IBus.KP_Page_Down, "Page_Down" },
  424 + { IBus.Muhenkan, "lshift" },
  425 + { IBus.Henkan, "rshift" }
  426 + };
  427 +
398 428 public override bool process_key_event (uint keyval,
399 429 uint keycode,
400 430 uint state)
@@ -407,32 +437,25 @@ class SkkEngine : IBus.Engine {
407 437 Skk.ModifierType modifiers = (Skk.ModifierType) state;
408 438 string? name = null;
409 439 unichar code = '\0';
410   - if (keyval == IBus.Tab) {
411   - code = '\t';
412   - }
413   - else if (keyval == IBus.Return) {
414   - code = '\n';
415   - }
416   - else if (keyval == IBus.BackSpace) {
417   - code = '\b';
418   - }
419   - else if (keyval == IBus.Muhenkan) {
420   - name = "lshift";
421   - }
422   - else if (keyval == IBus.Henkan) {
423   - name = "rshift";
424   - }
425   - else if (keyval == IBus.Left) {
426   - name = "Left";
427   - }
428   - else if (keyval == IBus.Right) {
429   - name = "Right";
  440 + foreach (var entry in NAME_KEYVALS) {
  441 + if (entry.key == keyval) {
  442 + name = entry.value;
  443 + break;
  444 + }
430 445 }
431   - else if (0x20 <= keyval && keyval < 0x7F) {
432   - code = (unichar) keyval;
  446 + foreach (var entry in CODE_KEYVALS) {
  447 + if (entry.key == keyval) {
  448 + code = entry.value;
  449 + break;
  450 + }
433 451 }
434   - else {
435   - return false;
  452 + if (name == null && code == '\0') {
  453 + if (0x20 <= keyval && keyval < 0x7F) {
  454 + code = (unichar) keyval;
  455 + }
  456 + else {
  457 + return false;
  458 + }
436 459 }
437 460
438 461 var key = new Skk.KeyEvent (name, code, modifiers);

0 comments on commit 295ed5e

Please sign in to comment.
Something went wrong with that request. Please try again.