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

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

Issue 2925353002: Implement sync of keyboard layout between Ozone and Wayland clients (Closed)
Patch Set: Fix -Wall build failure 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)
sadrul 2017/06/14 03:16:53 Do you need this? Are there other platforms where
jclinton 2017/06/14 15:49:04 This was already reviewed and it is necessary. See
sadrul 2017/06/15 06:45:21 Link please?
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(USE_OZONE) && defined(OS_CHROMEOS)
sadrul 2017/06/14 03:16:53 Do you need either of the define checks?
jclinton 2017/06/14 15:49:04 This was already reviewed and it is necessary. See
sadrul 2017/06/15 06:57:27 I am requesting more information here to understan
reveman 2017/06/15 11:44:15 We're not making the assumption that exo will only
sadrul 2017/06/15 13:18:11 The linux_chromium_chromeos_rel_ng still runs non-
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(USE_OZONE) && defined(OS_CHROMEOS)
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 SendNamedLayout(keyboard->GetCurrentKeyboardLayoutName());
sadrul 2017/06/14 03:16:53 Looks like you don't actually need the null-check
jclinton 2017/06/14 15:49:04 This was already reviewed and it is necessary; nul
sadrul 2017/06/15 13:18:11 If |keyboard| can be null, won't this line cause a
jclinton 2017/06/15 15:46:46 Done.
2751 std::unique_ptr<char, base::FreeDeleter> keymap_string( 2761 #else
2752 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); 2762 SendLayout(nullptr);
2753 DCHECK(keymap_string.get()); 2763 #endif
2754 size_t keymap_size = strlen(keymap_string.get()) + 1;
2755 base::SharedMemory shared_keymap;
2756 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size);
2757 DCHECK(rv);
2758 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size);
2759 wl_keyboard_send_keymap(keyboard_resource_,
2760 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
2761 shared_keymap.handle().GetHandle(), keymap_size);
2762 } 2764 }
2765 #if defined(USE_OZONE) && defined(OS_CHROMEOS)
2766 ~WaylandKeyboardDelegate() override {
2767 chromeos::input_method::ImeKeyboard* keyboard =
2768 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
2769 if (keyboard)
2770 keyboard->RemoveObserver(this);
2771 }
2772 #endif
2763 2773
2764 // Overridden from KeyboardDelegate: 2774 // Overridden from KeyboardDelegate:
2765 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; } 2775 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; }
2766 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override { 2776 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override {
2767 wl_resource* surface_resource = GetSurfaceResource(surface); 2777 wl_resource* surface_resource = GetSurfaceResource(surface);
2768 // We can accept events for this surface if the client is the same as the 2778 // We can accept events for this surface if the client is the same as the
2769 // keyboard. 2779 // keyboard.
2770 return surface_resource && 2780 return surface_resource &&
2771 wl_resource_get_client(surface_resource) == client(); 2781 wl_resource_get_client(surface_resource) == client();
2772 } 2782 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 wl_keyboard_send_modifiers( 2819 wl_keyboard_send_modifiers(
2810 keyboard_resource_, next_serial(), 2820 keyboard_resource_, next_serial(),
2811 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED), 2821 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED),
2812 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED), 2822 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED),
2813 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED), 2823 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED),
2814 xkb_state_serialize_layout(xkb_state_.get(), 2824 xkb_state_serialize_layout(xkb_state_.get(),
2815 XKB_STATE_LAYOUT_EFFECTIVE)); 2825 XKB_STATE_LAYOUT_EFFECTIVE));
2816 wl_client_flush(client()); 2826 wl_client_flush(client());
2817 } 2827 }
2818 2828
2829 #if defined(USE_OZONE) && defined(OS_CHROMEOS)
2830 // Overridden from input_method::ImeKeyboard::Observer:
2831 void OnCapsLockChanged(bool enabled) override {}
2832 void OnLayoutChanging(const std::string& layout_name) override {
2833 SendNamedLayout(layout_name);
2834 }
2835 #endif
2836
2819 private: 2837 private:
2820 // Returns the corresponding key given a dom code. 2838 // Returns the corresponding key given a dom code.
2821 uint32_t DomCodeToKey(ui::DomCode code) const { 2839 uint32_t DomCodeToKey(ui::DomCode code) const {
2822 // This assumes KeycodeConverter has been built with evdev/xkb codes. 2840 // This assumes KeycodeConverter has been built with evdev/xkb codes.
2823 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>( 2841 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>(
2824 ui::KeycodeConverter::DomCodeToNativeKeycode(code)); 2842 ui::KeycodeConverter::DomCodeToNativeKeycode(code));
2825 2843
2826 // Keycodes are offset by 8 in Xkb. 2844 // Keycodes are offset by 8 in Xkb.
2827 DCHECK_GE(xkb_keycode, 8u); 2845 DCHECK_GE(xkb_keycode, 8u);
2828 return xkb_keycode - 8; 2846 return xkb_keycode - 8;
(...skipping 17 matching lines...) Expand all
2846 uint32_t xkb_modifiers = 0; 2864 uint32_t xkb_modifiers = 0;
2847 for (auto modifier : modifiers) { 2865 for (auto modifier : modifiers) {
2848 if (modifier_flags & modifier.flag) { 2866 if (modifier_flags & modifier.flag) {
2849 xkb_modifiers |= 2867 xkb_modifiers |=
2850 1 << xkb_keymap_mod_get_index(xkb_keymap_.get(), modifier.xkb_name); 2868 1 << xkb_keymap_mod_get_index(xkb_keymap_.get(), modifier.xkb_name);
2851 } 2869 }
2852 } 2870 }
2853 return xkb_modifiers; 2871 return xkb_modifiers;
2854 } 2872 }
2855 2873
2874
2875 #if defined(USE_OZONE) && defined(OS_CHROMEOS)
2876 // Send the named keyboard layout to the client.
2877 void SendNamedLayout(const std::string& layout_name) {
2878 std::string layout_id, layout_variant;
2879 ui::XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id,
2880 &layout_variant);
2881 xkb_rule_names names = {.rules = nullptr,
2882 .model = "pc101",
2883 .layout = layout_id.c_str(),
2884 .variant = layout_variant.c_str(),
2885 .options = ""};
2886 SendLayout(&names);
2887 }
2888 #endif
2889
2890 // Send the keyboard layout named by XKB rules to the client.
2891 void SendLayout(const xkb_rule_names* names) {
2892 xkb_keymap_.reset(xkb_keymap_new_from_names(xkb_context_.get(), names,
2893 XKB_KEYMAP_COMPILE_NO_FLAGS));
2894 xkb_state_.reset(xkb_state_new(xkb_keymap_.get()));
2895 std::unique_ptr<char, base::FreeDeleter> keymap_string(
2896 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1));
2897 DCHECK(keymap_string.get());
2898 size_t keymap_size = strlen(keymap_string.get()) + 1;
2899 base::SharedMemory shared_keymap;
2900 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size);
2901 DCHECK(rv);
2902 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size);
2903 wl_keyboard_send_keymap(keyboard_resource_,
2904 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
2905 shared_keymap.handle().GetHandle(), keymap_size);
2906 }
2907
2856 // The client who own this keyboard instance. 2908 // The client who own this keyboard instance.
2857 wl_client* client() const { 2909 wl_client* client() const {
2858 return wl_resource_get_client(keyboard_resource_); 2910 return wl_resource_get_client(keyboard_resource_);
2859 } 2911 }
2860 2912
2861 // Returns the next serial to use for keyboard events. 2913 // Returns the next serial to use for keyboard events.
2862 uint32_t next_serial() const { 2914 uint32_t next_serial() const {
2863 return wl_display_next_serial(wl_client_get_display(client())); 2915 return wl_display_next_serial(wl_client_get_display(client()));
2864 } 2916 }
2865 2917
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 DCHECK(event_loop); 4100 DCHECK(event_loop);
4049 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 4101 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
4050 } 4102 }
4051 4103
4052 void Server::Flush() { 4104 void Server::Flush() {
4053 wl_display_flush_clients(wl_display_.get()); 4105 wl_display_flush_clients(wl_display_.get());
4054 } 4106 }
4055 4107
4056 } // namespace wayland 4108 } // namespace wayland
4057 } // namespace exo 4109 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698