The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

KeyBindings.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/KeyBindings.vala.
Switch keyboard focus with tab key in name and description tab
1 /* 2 Copyright (C) 2012 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 public enum Key { 18 NONE = 0, 19 UP = 65362, 20 RIGHT = 65363, 21 DOWN = 65364, 22 LEFT = 65361, 23 PG_UP = 65365, 24 PG_DOWN = 65366, 25 ENTER = 65293, 26 BACK_SPACE = 65288, 27 SHIFT_LEFT = 65505, 28 SHIFT_RIGHT = 65506, 29 CTRL_LEFT = 65507, 30 CTRL_RIGHT = 65508, 31 CAPS_LOCK = 65509, 32 ALT_LEFT = 65513, 33 ALT_RIGHT = 65514, 34 ALT_GR = 65027, 35 LOGO_LEFT = 65515, 36 LOGO_RIGHT = 65516, 37 CONTEXT_MENU = 65383, 38 TAB = 65289, 39 DEL = 65535, 40 NUM_PLUS = 65451, 41 NUM_MINUS = 65453, 42 END = 65367, 43 HOME = 65360 44 } 45 46 bool is_arrow_key (uint keyval) { 47 return keyval == Key.UP || 48 keyval == Key.DOWN || 49 keyval == Key.LEFT || 50 keyval == Key.RIGHT; 51 } 52 53 bool is_modifier_key (uint i) { 54 return Key.UP == i || 55 Key.RIGHT == i || 56 Key.DOWN == i || 57 Key.LEFT == i || 58 Key.PG_UP == i || 59 Key.PG_DOWN == i || 60 Key.ENTER == i || 61 Key.BACK_SPACE == i || 62 Key.SHIFT_LEFT == i || 63 Key.SHIFT_RIGHT == i || 64 Key.CTRL_LEFT == i || 65 Key.CTRL_RIGHT == i || 66 Key.ALT_LEFT == i || 67 Key.ALT_RIGHT == i || 68 Key.ALT_GR == i || 69 Key.LOGO_LEFT == i || 70 Key.LOGO_RIGHT == i || 71 Key.TAB == i || 72 Key.CAPS_LOCK == i || 73 Key.LOGO_RIGHT == i || 74 Key.ENTER == i || 75 Key.DEL == i; 76 } 77 78 /** Modifier flags */ 79 public static const uint NONE = 0; 80 public static const uint CTRL = 1 << 0; 81 public static const uint ALT = 1 << 1; 82 public static const uint SHIFT = 1 << 2; 83 public static const uint LOGO = 1 << 3; 84 85 public class KeyBindings { 86 87 static bool modifier_ctrl = false; 88 static bool modifier_alt = false; 89 static bool modifier_shift = false; 90 static bool modifier_logo = false; 91 92 public static uint modifier = 0; 93 94 public static bool require_modifier; 95 96 public static uint get_modifiers () { 97 return modifier; 98 } 99 100 public static void reset () { 101 modifier = NONE; 102 modifier_ctrl = false; 103 modifier_alt = false; 104 modifier_shift = false; 105 modifier_logo = false; 106 } 107 108 public static void set_require_modifier (bool t) { 109 require_modifier = t; 110 } 111 112 public static uint get_mod_from_key (uint keyval) { 113 uint mod = NONE; 114 mod |= (keyval == Key.CTRL_RIGHT || keyval == Key.CTRL_LEFT) ? CTRL : 0; 115 mod |= (keyval == Key.SHIFT_RIGHT || keyval == Key.SHIFT_LEFT) ? SHIFT : 0; 116 mod |= (keyval == Key.ALT_LEFT || keyval == Key.ALT_GR) ? ALT : 0; 117 mod |= (keyval == Key.LOGO_LEFT || keyval == Key.LOGO_RIGHT) ? LOGO : 0; 118 return mod; 119 } 120 121 public static void remove_modifier_from_keyval (uint keyval) { 122 uint mod = 0xFFFFFF ^ get_mod_from_key (keyval); 123 set_modifier (modifier & mod); 124 } 125 126 public static void add_modifier_from_keyval (uint keyval) { 127 uint mod = get_mod_from_key (keyval); 128 set_modifier (modifier | mod); 129 } 130 131 public static void set_modifier (uint mod) { 132 modifier = mod; 133 134 modifier_ctrl = ((modifier & CTRL) > 0); 135 modifier_alt = ((modifier & ALT) > 0); 136 modifier_shift = ((modifier & SHIFT) > 0); 137 modifier_logo = ((modifier & LOGO) > 0); 138 } 139 140 public static bool has_alt () { 141 return modifier_alt; 142 } 143 144 public static bool has_shift () { 145 return modifier_shift; 146 } 147 148 public static bool has_ctrl () { 149 return modifier_ctrl; 150 } 151 152 public static bool has_logo () { 153 return modifier_logo; 154 } 155 } 156 157 } 158