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

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

Issue 2925353002: Implement sync of keyboard layout between Ozone and Wayland clients (Closed)
Patch Set: 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #include "components/exo/shell_surface.h" 62 #include "components/exo/shell_surface.h"
63 #include "components/exo/sub_surface.h" 63 #include "components/exo/sub_surface.h"
64 #include "components/exo/surface.h" 64 #include "components/exo/surface.h"
65 #include "components/exo/touch.h" 65 #include "components/exo/touch.h"
66 #include "components/exo/touch_delegate.h" 66 #include "components/exo/touch_delegate.h"
67 #include "components/exo/touch_stylus_delegate.h" 67 #include "components/exo/touch_stylus_delegate.h"
68 #include "components/exo/wm_helper.h" 68 #include "components/exo/wm_helper.h"
69 #include "third_party/skia/include/core/SkRegion.h" 69 #include "third_party/skia/include/core/SkRegion.h"
70 #include "ui/base/class_property.h" 70 #include "ui/base/class_property.h"
71 #include "ui/base/hit_test.h" 71 #include "ui/base/hit_test.h"
72 #include "ui/base/ime/chromeos/ime_keyboard.h"
reveman 2017/06/09 14:53:18 we don't assume that this code is only built on ch
jclinton 2017/06/09 16:36:03 Done.
73 #include "ui/base/ime/chromeos/input_method_manager.h"
72 #include "ui/base/ui_features.h" 74 #include "ui/base/ui_features.h"
73 #include "ui/compositor/compositor_vsync_manager.h" 75 #include "ui/compositor/compositor_vsync_manager.h"
74 #include "ui/display/display_observer.h" 76 #include "ui/display/display_observer.h"
75 #include "ui/display/manager/managed_display_info.h" 77 #include "ui/display/manager/managed_display_info.h"
76 #include "ui/display/screen.h" 78 #include "ui/display/screen.h"
77 #include "ui/events/keycodes/dom/keycode_converter.h" 79 #include "ui/events/keycodes/dom/keycode_converter.h"
80 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
reveman 2017/06/09 14:53:18 move this to #if defined(USE_OZONE) below
jclinton 2017/06/09 16:36:03 Done.
78 #include "ui/gfx/buffer_format_util.h" 81 #include "ui/gfx/buffer_format_util.h"
79 #include "ui/gfx/buffer_types.h" 82 #include "ui/gfx/buffer_types.h"
80 #include "ui/views/widget/widget.h" 83 #include "ui/views/widget/widget.h"
81 #include "ui/views/widget/widget_observer.h" 84 #include "ui/views/widget/widget_observer.h"
82 #include "ui/wm/core/coordinate_conversion.h" 85 #include "ui/wm/core/coordinate_conversion.h"
83 86
84 #if defined(USE_OZONE) 87 #if defined(USE_OZONE)
85 #include <drm_fourcc.h> 88 #include <drm_fourcc.h>
86 #include <linux-dmabuf-unstable-v1-server-protocol.h> 89 #include <linux-dmabuf-unstable-v1-server-protocol.h>
87 #include <wayland-drm-server-protocol.h> 90 #include <wayland-drm-server-protocol.h>
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 const struct wl_pointer_interface pointer_implementation = {pointer_set_cursor, 2733 const struct wl_pointer_interface pointer_implementation = {pointer_set_cursor,
2731 pointer_release}; 2734 pointer_release};
2732 2735
2733 #if BUILDFLAG(USE_XKBCOMMON) 2736 #if BUILDFLAG(USE_XKBCOMMON)
2734 2737
2735 //////////////////////////////////////////////////////////////////////////////// 2738 ////////////////////////////////////////////////////////////////////////////////
2736 // wl_keyboard_interface: 2739 // wl_keyboard_interface:
2737 2740
2738 // Keyboard delegate class that accepts events for surfaces owned by the same 2741 // Keyboard delegate class that accepts events for surfaces owned by the same
2739 // client as a keyboard resource. 2742 // client as a keyboard resource.
2740 class WaylandKeyboardDelegate : public KeyboardDelegate { 2743 class WaylandKeyboardDelegate
2744 : public KeyboardDelegate,
2745 public chromeos::input_method::ImeKeyboard::Observer {
reveman 2017/06/09 14:53:19 I think this needs to be protected by a chromeos i
jclinton 2017/06/09 16:36:03 Done.
2741 public: 2746 public:
2742 explicit WaylandKeyboardDelegate(wl_resource* keyboard_resource) 2747 explicit WaylandKeyboardDelegate(wl_resource* keyboard_resource)
2743 : keyboard_resource_(keyboard_resource), 2748 : keyboard_resource_(keyboard_resource),
2744 xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)), 2749 xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)),
2745 // TODO(reveman): Keep keymap synchronized with the keymap used by
2746 // chromium and the host OS.
2747 xkb_keymap_(xkb_keymap_new_from_names(xkb_context_.get(), 2750 xkb_keymap_(xkb_keymap_new_from_names(xkb_context_.get(),
2748 nullptr, 2751 nullptr,
2749 XKB_KEYMAP_COMPILE_NO_FLAGS)), 2752 XKB_KEYMAP_COMPILE_NO_FLAGS)),
2750 xkb_state_(xkb_state_new(xkb_keymap_.get())) { 2753 xkb_state_(xkb_state_new(xkb_keymap_.get())) {
2751 std::unique_ptr<char, base::FreeDeleter> keymap_string( 2754 std::unique_ptr<char, base::FreeDeleter> keymap_string(
2752 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); 2755 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1));
2753 DCHECK(keymap_string.get()); 2756 DCHECK(keymap_string.get());
2754 size_t keymap_size = strlen(keymap_string.get()) + 1; 2757 size_t keymap_size = strlen(keymap_string.get()) + 1;
2755 base::SharedMemory shared_keymap; 2758 base::SharedMemory shared_keymap;
2756 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size); 2759 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size);
2757 DCHECK(rv); 2760 DCHECK(rv);
2758 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size); 2761 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size);
2759 wl_keyboard_send_keymap(keyboard_resource_, 2762 wl_keyboard_send_keymap(keyboard_resource_,
2760 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, 2763 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
2761 shared_keymap.handle().GetHandle(), keymap_size); 2764 shared_keymap.handle().GetHandle(), keymap_size);
2765 chromeos::input_method::ImeKeyboard* keyboard =
reveman 2017/06/09 14:53:18 needs a chromeos ifdef
jclinton 2017/06/09 16:36:03 Done.
2766 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
2767
reveman 2017/06/09 14:53:18 nit: no need for this blank line
jclinton 2017/06/09 16:36:03 Done.
2768 if (keyboard) {
reveman 2017/06/09 14:53:19 when is this null? can we DCHECK instead?
jclinton 2017/06/09 16:36:03 It returns null here: https://cs.chromium.org/chro
reveman 2017/06/09 16:50:12 Ack
2769 keyboard->AddObserver(this);
2770 keyboard->ReapplyCurrentKeyboardLayout();
reveman 2017/06/09 14:53:18 Does this result in another wl_keyboard_send_keyma
jclinton 2017/06/09 16:36:03 Yes, it does but we can no longer avoid it after t
reveman 2017/06/09 16:50:12 Not sure I follow. Looks like we just need to refa
2771 }
2772 }
2773
reveman 2017/06/09 14:53:18 nit: no need for this blank line
jclinton 2017/06/09 16:36:02 Done.
2774 ~WaylandKeyboardDelegate() {
reveman 2017/06/09 14:53:18 ~WaylandKeyboardDelegate() override ? as this inhe
jclinton 2017/06/09 16:36:02 Done.
2775 chromeos::input_method::ImeKeyboard* keyboard =
reveman 2017/06/09 14:53:18 this needs ifdefs
jclinton 2017/06/09 16:36:02 Done.
2776 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
2777
reveman 2017/06/09 14:53:18 nit: not need for blank line
jclinton 2017/06/09 16:36:03 Done.
2778 if (keyboard) {
reveman 2017/06/09 14:53:18 DCHECK instead if possible
jclinton 2017/06/09 16:36:03 Acknowledged.
2779 keyboard->RemoveObserver(this);
2780 }
reveman 2017/06/09 14:53:18 nit need for {}
jclinton 2017/06/09 16:36:02 Done.
2762 } 2781 }
2763 2782
2764 // Overridden from KeyboardDelegate: 2783 // Overridden from KeyboardDelegate:
2765 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; } 2784 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; }
2766 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override { 2785 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override {
2767 wl_resource* surface_resource = GetSurfaceResource(surface); 2786 wl_resource* surface_resource = GetSurfaceResource(surface);
2768 // We can accept events for this surface if the client is the same as the 2787 // We can accept events for this surface if the client is the same as the
2769 // keyboard. 2788 // keyboard.
2770 return surface_resource && 2789 return surface_resource &&
2771 wl_resource_get_client(surface_resource) == client(); 2790 wl_resource_get_client(surface_resource) == client();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 wl_keyboard_send_modifiers( 2828 wl_keyboard_send_modifiers(
2810 keyboard_resource_, next_serial(), 2829 keyboard_resource_, next_serial(),
2811 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED), 2830 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED),
2812 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED), 2831 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED),
2813 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED), 2832 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED),
2814 xkb_state_serialize_layout(xkb_state_.get(), 2833 xkb_state_serialize_layout(xkb_state_.get(),
2815 XKB_STATE_LAYOUT_EFFECTIVE)); 2834 XKB_STATE_LAYOUT_EFFECTIVE));
2816 wl_client_flush(client()); 2835 wl_client_flush(client());
2817 } 2836 }
2818 2837
2838 // input_method::ImeKeyboard::Observer: we are not interested in caps lock:
reveman 2017/06/09 14:53:18 "// Overridden from input_method::ImeKeyboard::Obs
jclinton 2017/06/09 16:36:03 Done.
2839 void OnCapsLockChanged(bool enabled) override {}
2840
reveman 2017/06/09 14:53:18 remove this blank line. all input_method::ImeKeybo
jclinton 2017/06/09 16:36:02 Done.
2841 // input_method::ImeKeyboard::Observer implementation:
reveman 2017/06/09 14:53:18 remove comment as we should have the "Overridden f
jclinton 2017/06/09 16:36:03 Done.
2842 void OnLayoutChanged(const std::string& layout_name) override {
2843 std::string layout_id;
2844 std::string layout_variant;
2845 ui::XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id,
2846 &layout_variant);
2847 xkb_rule_names names = {.rules = NULL,
2848 .model = "pc101",
2849 .layout = layout_id.c_str(),
2850 .variant = layout_variant.c_str(),
2851 .options = ""};
2852 xkb_keymap_.reset(xkb_keymap_new_from_names(xkb_context_.get(), &names,
2853 XKB_KEYMAP_COMPILE_NO_FLAGS));
2854 xkb_state_.reset(xkb_state_new(xkb_keymap_.get()));
2855 std::unique_ptr<char, base::FreeDeleter> keymap_string(
2856 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1));
2857 DCHECK(keymap_string.get());
2858 size_t keymap_size = strlen(keymap_string.get()) + 1;
2859 base::SharedMemory shared_keymap;
2860 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size);
2861 DCHECK(rv);
2862 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size);
2863 wl_keyboard_send_keymap(keyboard_resource_,
2864 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
2865 shared_keymap.handle().GetHandle(), keymap_size);
2866 };
reveman 2017/06/09 14:53:18 s/};/}/ and all this needs to be behind and ifdef
jclinton 2017/06/09 16:36:03 Done.
2867
2819 private: 2868 private:
2820 // Returns the corresponding key given a dom code. 2869 // Returns the corresponding key given a dom code.
2821 uint32_t DomCodeToKey(ui::DomCode code) const { 2870 uint32_t DomCodeToKey(ui::DomCode code) const {
2822 // This assumes KeycodeConverter has been built with evdev/xkb codes. 2871 // This assumes KeycodeConverter has been built with evdev/xkb codes.
2823 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>( 2872 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>(
2824 ui::KeycodeConverter::DomCodeToNativeKeycode(code)); 2873 ui::KeycodeConverter::DomCodeToNativeKeycode(code));
2825 2874
2826 // Keycodes are offset by 8 in Xkb. 2875 // Keycodes are offset by 8 in Xkb.
2827 DCHECK_GE(xkb_keycode, 8u); 2876 DCHECK_GE(xkb_keycode, 8u);
2828 return xkb_keycode - 8; 2877 return xkb_keycode - 8;
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 DCHECK(event_loop); 4097 DCHECK(event_loop);
4049 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 4098 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
4050 } 4099 }
4051 4100
4052 void Server::Flush() { 4101 void Server::Flush() {
4053 wl_display_flush_clients(wl_display_.get()); 4102 wl_display_flush_clients(wl_display_.get());
4054 } 4103 }
4055 4104
4056 } // namespace wayland 4105 } // namespace wayland
4057 } // namespace exo 4106 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698