Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: components/exo/wayland/server.cc

Issue 2925353002: Implement sync of keyboard layout between Ozone and Wayland clients (Closed)
Patch Set: Address reveman comments round 2 Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/wayland/server.h" 5 #include "components/exo/wayland/server.h"
6 6
7 #include <alpha-compositing-unstable-v1-server-protocol.h> 7 #include <alpha-compositing-unstable-v1-server-protocol.h>
8 #include <gaming-input-unstable-v1-server-protocol.h> 8 #include <gaming-input-unstable-v1-server-protocol.h>
9 #include <gaming-input-unstable-v2-server-protocol.h> 9 #include <gaming-input-unstable-v2-server-protocol.h>
10 #include <grp.h> 10 #include <grp.h>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 #include "ui/gfx/buffer_format_util.h" 78 #include "ui/gfx/buffer_format_util.h"
79 #include "ui/gfx/buffer_types.h" 79 #include "ui/gfx/buffer_types.h"
80 #include "ui/views/widget/widget.h" 80 #include "ui/views/widget/widget.h"
81 #include "ui/views/widget/widget_observer.h" 81 #include "ui/views/widget/widget_observer.h"
82 #include "ui/wm/core/coordinate_conversion.h" 82 #include "ui/wm/core/coordinate_conversion.h"
83 83
84 #if defined(USE_OZONE) 84 #if defined(USE_OZONE)
85 #include <drm_fourcc.h> 85 #include <drm_fourcc.h>
86 #include <linux-dmabuf-unstable-v1-server-protocol.h> 86 #include <linux-dmabuf-unstable-v1-server-protocol.h>
87 #include <wayland-drm-server-protocol.h> 87 #include <wayland-drm-server-protocol.h>
88 #if defined(OS_CHROMEOS)
89 #include "ui/base/ime/chromeos/ime_keyboard.h"
90 #include "ui/base/ime/chromeos/input_method_manager.h"
91 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
92 #endif
88 #endif 93 #endif
89 94
90 #if BUILDFLAG(USE_XKBCOMMON) 95 #if BUILDFLAG(USE_XKBCOMMON)
91 #include <xkbcommon/xkbcommon.h> 96 #include <xkbcommon/xkbcommon.h>
92 #include "ui/events/keycodes/scoped_xkb.h" // nogncheck 97 #include "ui/events/keycodes/scoped_xkb.h" // nogncheck
93 #endif 98 #endif
94 99
95 DECLARE_UI_CLASS_PROPERTY_TYPE(wl_resource*); 100 DECLARE_UI_CLASS_PROPERTY_TYPE(wl_resource*);
96 101
97 namespace exo { 102 namespace exo {
(...skipping 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 const struct wl_pointer_interface pointer_implementation = {pointer_set_cursor, 2735 const struct wl_pointer_interface pointer_implementation = {pointer_set_cursor,
2731 pointer_release}; 2736 pointer_release};
2732 2737
2733 #if BUILDFLAG(USE_XKBCOMMON) 2738 #if BUILDFLAG(USE_XKBCOMMON)
2734 2739
2735 //////////////////////////////////////////////////////////////////////////////// 2740 ////////////////////////////////////////////////////////////////////////////////
2736 // wl_keyboard_interface: 2741 // wl_keyboard_interface:
2737 2742
2738 // Keyboard delegate class that accepts events for surfaces owned by the same 2743 // Keyboard delegate class that accepts events for surfaces owned by the same
2739 // client as a keyboard resource. 2744 // client as a keyboard resource.
2740 class WaylandKeyboardDelegate : public KeyboardDelegate { 2745 class WaylandKeyboardDelegate
2746 : public KeyboardDelegate
2747 #if defined(OS_CHROMEOS)
reveman 2017/06/09 21:15:18 #if defined(USE_OZONE) && defined(OS_CHROMEOS) as
jclinton 2017/06/09 22:17:59 Done.
2748 , public chromeos::input_method::ImeKeyboard::Observer
2749 #endif
2750 {
2741 public: 2751 public:
2742 explicit WaylandKeyboardDelegate(wl_resource* keyboard_resource) 2752 explicit WaylandKeyboardDelegate(wl_resource* keyboard_resource)
2743 : keyboard_resource_(keyboard_resource), 2753 : keyboard_resource_(keyboard_resource),
2744 xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)), 2754 xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)) {
2745 // TODO(reveman): Keep keymap synchronized with the keymap used by 2755 #if defined(OS_CHROMEOS)
reveman 2017/06/09 21:15:18 #if defined(USE_OZONE) && defined(OS_CHROMEOS)
jclinton 2017/06/09 22:17:58 Done.
2746 // chromium and the host OS. 2756 chromeos::input_method::ImeKeyboard* keyboard =
2747 xkb_keymap_(xkb_keymap_new_from_names(xkb_context_.get(), 2757 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
2748 nullptr, 2758 if (keyboard)
2749 XKB_KEYMAP_COMPILE_NO_FLAGS)), 2759 keyboard->AddObserver(this);
2750 xkb_state_(xkb_state_new(xkb_keymap_.get())) { 2760 std::string layout_id, layout_variant;
2751 std::unique_ptr<char, base::FreeDeleter> keymap_string( 2761 std::string layout_name = keyboard->GetCurrentKeyboardLayoutName();
2752 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); 2762 ui::XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id,
2753 DCHECK(keymap_string.get()); 2763 &layout_variant);
2754 size_t keymap_size = strlen(keymap_string.get()) + 1; 2764 xkb_rule_names names = {.rules = NULL,
2755 base::SharedMemory shared_keymap; 2765 .model = "pc101",
2756 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size); 2766 .layout = layout_id.c_str(),
2757 DCHECK(rv); 2767 .variant = layout_variant.c_str(),
2758 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size); 2768 .options = ""};
reveman 2017/06/09 21:15:18 Please avoid duplication of above code. Maybe add
jclinton 2017/06/09 22:17:58 Done.
2759 wl_keyboard_send_keymap(keyboard_resource_, 2769 SendLayout(names);
2760 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, 2770 }
2761 shared_keymap.handle().GetHandle(), keymap_size); 2771 ~WaylandKeyboardDelegate() override {
2772 chromeos::input_method::ImeKeyboard* keyboard =
2773 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
2774 if (keyboard)
2775 keyboard->RemoveObserver(this);
2776 #else
reveman 2017/06/09 21:15:18 ifdef that spans multiple functions like this is c
jclinton 2017/06/09 22:17:58 Done.
2777 SendLayout(nullptr);
2778 #endif
2762 } 2779 }
2763 2780
2764 // Overridden from KeyboardDelegate: 2781 // Overridden from KeyboardDelegate:
2765 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; } 2782 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; }
2766 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override { 2783 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override {
2767 wl_resource* surface_resource = GetSurfaceResource(surface); 2784 wl_resource* surface_resource = GetSurfaceResource(surface);
2768 // We can accept events for this surface if the client is the same as the 2785 // We can accept events for this surface if the client is the same as the
2769 // keyboard. 2786 // keyboard.
2770 return surface_resource && 2787 return surface_resource &&
2771 wl_resource_get_client(surface_resource) == client(); 2788 wl_resource_get_client(surface_resource) == client();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 wl_keyboard_send_modifiers( 2826 wl_keyboard_send_modifiers(
2810 keyboard_resource_, next_serial(), 2827 keyboard_resource_, next_serial(),
2811 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED), 2828 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED),
2812 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED), 2829 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED),
2813 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED), 2830 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED),
2814 xkb_state_serialize_layout(xkb_state_.get(), 2831 xkb_state_serialize_layout(xkb_state_.get(),
2815 XKB_STATE_LAYOUT_EFFECTIVE)); 2832 XKB_STATE_LAYOUT_EFFECTIVE));
2816 wl_client_flush(client()); 2833 wl_client_flush(client());
2817 } 2834 }
2818 2835
2836 #if defined(OS_CHROMEOS)
reveman 2017/06/09 21:15:18 #if defined(USE_OZONE) && defined(OS_CHROMEOS)
jclinton 2017/06/09 22:17:58 Done.
2837 // Overridden from input_method::ImeKeyboard::Observer:
2838 void OnCapsLockChanged(bool enabled) override {}
2839 void OnLayoutChanged(const std::string& layout_name) override {
2840 std::string layout_id, layout_variant;
2841 ui::XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id,
2842 &layout_variant);
2843 xkb_rule_names names = {.rules = NULL,
2844 .model = "pc101",
2845 .layout = layout_id.c_str(),
2846 .variant = layout_variant.c_str(),
2847 .options = ""};
2848 SendLayout(names);
2849 }
2850 #endif
2851
2819 private: 2852 private:
2820 // Returns the corresponding key given a dom code. 2853 // Returns the corresponding key given a dom code.
2821 uint32_t DomCodeToKey(ui::DomCode code) const { 2854 uint32_t DomCodeToKey(ui::DomCode code) const {
2822 // This assumes KeycodeConverter has been built with evdev/xkb codes. 2855 // This assumes KeycodeConverter has been built with evdev/xkb codes.
2823 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>( 2856 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>(
2824 ui::KeycodeConverter::DomCodeToNativeKeycode(code)); 2857 ui::KeycodeConverter::DomCodeToNativeKeycode(code));
2825 2858
2826 // Keycodes are offset by 8 in Xkb. 2859 // Keycodes are offset by 8 in Xkb.
2827 DCHECK_GE(xkb_keycode, 8u); 2860 DCHECK_GE(xkb_keycode, 8u);
2828 return xkb_keycode - 8; 2861 return xkb_keycode - 8;
(...skipping 17 matching lines...) Expand all
2846 uint32_t xkb_modifiers = 0; 2879 uint32_t xkb_modifiers = 0;
2847 for (auto modifier : modifiers) { 2880 for (auto modifier : modifiers) {
2848 if (modifier_flags & modifier.flag) { 2881 if (modifier_flags & modifier.flag) {
2849 xkb_modifiers |= 2882 xkb_modifiers |=
2850 1 << xkb_keymap_mod_get_index(xkb_keymap_.get(), modifier.xkb_name); 2883 1 << xkb_keymap_mod_get_index(xkb_keymap_.get(), modifier.xkb_name);
2851 } 2884 }
2852 } 2885 }
2853 return xkb_modifiers; 2886 return xkb_modifiers;
2854 } 2887 }
2855 2888
2889 // Send the current keyboard layout to the Wayland client
reveman 2017/06/09 21:15:18 End sentence with "." and remove Wayland, "to the
jclinton 2017/06/09 22:17:58 Done.
2890 void SendLayout(const struct xkb_rule_names& names) {
reveman 2017/06/09 21:15:18 "struct" is not needed in c++ code. and "const xkb
jclinton 2017/06/09 22:17:58 Done.
2891 xkb_keymap_.reset(xkb_keymap_new_from_names(xkb_context_.get(), &names,
2892 XKB_KEYMAP_COMPILE_NO_FLAGS));
2893 xkb_state_.reset(xkb_state_new(xkb_keymap_.get()));
2894 std::unique_ptr<char, base::FreeDeleter> keymap_string(
2895 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1));
2896 DCHECK(keymap_string.get());
2897 size_t keymap_size = strlen(keymap_string.get()) + 1;
2898 base::SharedMemory shared_keymap;
2899 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size);
2900 DCHECK(rv);
2901 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size);
2902 wl_keyboard_send_keymap(keyboard_resource_,
2903 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
2904 shared_keymap.handle().GetHandle(), keymap_size);
2905 }
2906
2856 // The client who own this keyboard instance. 2907 // The client who own this keyboard instance.
2857 wl_client* client() const { 2908 wl_client* client() const {
2858 return wl_resource_get_client(keyboard_resource_); 2909 return wl_resource_get_client(keyboard_resource_);
2859 } 2910 }
2860 2911
2861 // Returns the next serial to use for keyboard events. 2912 // Returns the next serial to use for keyboard events.
2862 uint32_t next_serial() const { 2913 uint32_t next_serial() const {
2863 return wl_display_next_serial(wl_client_get_display(client())); 2914 return wl_display_next_serial(wl_client_get_display(client()));
2864 } 2915 }
2865 2916
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 DCHECK(event_loop); 4099 DCHECK(event_loop);
4049 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 4100 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
4050 } 4101 }
4051 4102
4052 void Server::Flush() { 4103 void Server::Flush() {
4053 wl_display_flush_clients(wl_display_.get()); 4104 wl_display_flush_clients(wl_display_.get());
4054 } 4105 }
4055 4106
4056 } // namespace wayland 4107 } // namespace wayland
4057 } // namespace exo 4108 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698