OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" | 5 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <xkbcommon/xkbcommon-names.h> | 8 #include <xkbcommon/xkbcommon-names.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 {ui::EF_ALTGR_DOWN, "Mod5"}, | 820 {ui::EF_ALTGR_DOWN, "Mod5"}, |
821 {ui::EF_MOD3_DOWN, "Mod3"}, | 821 {ui::EF_MOD3_DOWN, "Mod3"}, |
822 {ui::EF_CAPS_LOCK_ON, XKB_MOD_NAME_CAPS}}; | 822 {ui::EF_CAPS_LOCK_ON, XKB_MOD_NAME_CAPS}}; |
823 xkb_flag_map_.clear(); | 823 xkb_flag_map_.clear(); |
824 xkb_flag_map_.resize(arraysize(flags)); | 824 xkb_flag_map_.resize(arraysize(flags)); |
825 for (size_t i = 0; i < arraysize(flags); ++i) { | 825 for (size_t i = 0; i < arraysize(flags); ++i) { |
826 xkb_mod_index_t index = xkb_keymap_mod_get_index(keymap, flags[i].xkb_name); | 826 xkb_mod_index_t index = xkb_keymap_mod_get_index(keymap, flags[i].xkb_name); |
827 if (index == XKB_MOD_INVALID) { | 827 if (index == XKB_MOD_INVALID) { |
828 DVLOG(3) << "XKB keyboard layout does not contain " << flags[i].xkb_name; | 828 DVLOG(3) << "XKB keyboard layout does not contain " << flags[i].xkb_name; |
829 } else { | 829 } else { |
| 830 if (flags[i].ui_flag == ui::EF_SHIFT_DOWN) |
| 831 xkb_mod_indexes_.shift = index; |
| 832 else if (flags[i].ui_flag == ui::EF_CONTROL_DOWN) |
| 833 xkb_mod_indexes_.control = index; |
| 834 else if (flags[i].ui_flag == ui::EF_ALT_DOWN) |
| 835 xkb_mod_indexes_.alt = index; |
| 836 |
830 xkb_mod_mask_t flag = static_cast<xkb_mod_mask_t>(1) << index; | 837 xkb_mod_mask_t flag = static_cast<xkb_mod_mask_t>(1) << index; |
831 XkbFlagMapEntry e = {flags[i].ui_flag, flag}; | 838 XkbFlagMapEntry e = {flags[i].ui_flag, flag}; |
832 xkb_flag_map_.push_back(e); | 839 xkb_flag_map_.push_back(e); |
833 } | 840 } |
834 } | 841 } |
835 | 842 |
836 // Update num lock mask. | 843 // Update num lock mask. |
837 num_lock_mod_mask_ = 0; | 844 num_lock_mod_mask_ = 0; |
838 xkb_mod_index_t num_mod_index = | 845 xkb_mod_index_t num_mod_index = |
839 xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); | 846 xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 if (close_index == std::string::npos) | 975 if (close_index == std::string::npos) |
969 close_index = layout_name.size(); | 976 close_index = layout_name.size(); |
970 *layout_variant = layout_name.substr(parentheses_index + 1, | 977 *layout_variant = layout_name.substr(parentheses_index + 1, |
971 close_index - parentheses_index - 1); | 978 close_index - parentheses_index - 1); |
972 } else if (dash_index != std::string::npos) { | 979 } else if (dash_index != std::string::npos) { |
973 *layout_id = layout_name.substr(0, dash_index); | 980 *layout_id = layout_name.substr(0, dash_index); |
974 *layout_variant = layout_name.substr(dash_index + 1); | 981 *layout_variant = layout_name.substr(dash_index + 1); |
975 } | 982 } |
976 } | 983 } |
977 | 984 |
| 985 int XkbKeyboardLayoutEngine::UpdateModifiers(uint32_t depressed_mods, |
| 986 uint32_t latched_mods, |
| 987 uint32_t locked_mods, |
| 988 uint32_t group) { |
| 989 xkb_state_update_mask(xkb_state_.get(), depressed_mods, latched_mods, |
| 990 locked_mods, 0, 0, group); |
| 991 |
| 992 int modifiers = 0; |
| 993 auto component = static_cast<xkb_state_component>(XKB_STATE_MODS_DEPRESSED | |
| 994 XKB_STATE_MODS_LATCHED); |
| 995 if (xkb_state_mod_index_is_active(xkb_state_.get(), xkb_mod_indexes_.control, |
| 996 component)) |
| 997 modifiers |= EF_CONTROL_DOWN; |
| 998 if (xkb_state_mod_index_is_active(xkb_state_.get(), xkb_mod_indexes_.alt, |
| 999 component)) |
| 1000 modifiers |= EF_ALT_DOWN; |
| 1001 if (xkb_state_mod_index_is_active(xkb_state_.get(), xkb_mod_indexes_.shift, |
| 1002 component)) |
| 1003 modifiers |= EF_SHIFT_DOWN; |
| 1004 |
| 1005 return modifiers; |
| 1006 } |
| 1007 |
978 } // namespace ui | 1008 } // namespace ui |
OLD | NEW |