Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 #include "ui/base/ime/chromeos/ime_keyboard.h" | |
|
reveman
2017/06/09 16:50:13
think we need another ifdef for this file. ozone c
jclinton
2017/06/09 20:24:22
Done.
| |
| 89 #include "ui/base/ime/chromeos/input_method_manager.h" | |
|
reveman
2017/06/09 16:50:13
ditto
jclinton
2017/06/09 20:24:22
Done.
| |
| 90 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" | |
| 88 #endif | 91 #endif |
| 89 | 92 |
| 90 #if BUILDFLAG(USE_XKBCOMMON) | 93 #if BUILDFLAG(USE_XKBCOMMON) |
| 91 #include <xkbcommon/xkbcommon.h> | 94 #include <xkbcommon/xkbcommon.h> |
| 92 #include "ui/events/keycodes/scoped_xkb.h" // nogncheck | 95 #include "ui/events/keycodes/scoped_xkb.h" // nogncheck |
| 93 #endif | 96 #endif |
| 94 | 97 |
| 95 DECLARE_UI_CLASS_PROPERTY_TYPE(wl_resource*); | 98 DECLARE_UI_CLASS_PROPERTY_TYPE(wl_resource*); |
| 96 | 99 |
| 97 namespace exo { | 100 namespace exo { |
| (...skipping 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 #if defined(USE_OZONE) | |
| 2746 , public chromeos::input_method::ImeKeyboard::Observer | |
|
reveman
2017/06/09 16:50:12
ozone can be used without chromeos
jclinton
2017/06/09 20:24:22
Done.
| |
| 2747 #endif | |
| 2748 { | |
| 2741 public: | 2749 public: |
| 2742 explicit WaylandKeyboardDelegate(wl_resource* keyboard_resource) | 2750 explicit WaylandKeyboardDelegate(wl_resource* keyboard_resource) |
| 2743 : keyboard_resource_(keyboard_resource), | 2751 : keyboard_resource_(keyboard_resource), |
| 2744 xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)), | 2752 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(), | 2753 xkb_keymap_(xkb_keymap_new_from_names(xkb_context_.get(), |
| 2748 nullptr, | 2754 nullptr, |
| 2749 XKB_KEYMAP_COMPILE_NO_FLAGS)), | 2755 XKB_KEYMAP_COMPILE_NO_FLAGS)), |
| 2750 xkb_state_(xkb_state_new(xkb_keymap_.get())) { | 2756 xkb_state_(xkb_state_new(xkb_keymap_.get())) { |
| 2751 std::unique_ptr<char, base::FreeDeleter> keymap_string( | 2757 std::unique_ptr<char, base::FreeDeleter> keymap_string( |
| 2752 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); | 2758 xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); |
| 2753 DCHECK(keymap_string.get()); | 2759 DCHECK(keymap_string.get()); |
| 2754 size_t keymap_size = strlen(keymap_string.get()) + 1; | 2760 size_t keymap_size = strlen(keymap_string.get()) + 1; |
| 2755 base::SharedMemory shared_keymap; | 2761 base::SharedMemory shared_keymap; |
| 2756 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size); | 2762 bool rv = shared_keymap.CreateAndMapAnonymous(keymap_size); |
| 2757 DCHECK(rv); | 2763 DCHECK(rv); |
| 2758 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size); | 2764 memcpy(shared_keymap.memory(), keymap_string.get(), keymap_size); |
| 2759 wl_keyboard_send_keymap(keyboard_resource_, | 2765 wl_keyboard_send_keymap(keyboard_resource_, |
| 2760 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, | 2766 WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 2761 shared_keymap.handle().GetHandle(), keymap_size); | 2767 shared_keymap.handle().GetHandle(), keymap_size); |
| 2768 #if defined(USE_OZONE) | |
| 2769 chromeos::input_method::ImeKeyboard* keyboard = | |
| 2770 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); | |
| 2771 if (keyboard) { | |
| 2772 keyboard->AddObserver(this); | |
| 2773 keyboard->ReapplyCurrentKeyboardLayout(); | |
|
reveman
2017/06/09 16:50:13
See my SendLayout() comment below. Can we call tha
jclinton
2017/06/09 20:24:22
Done.
| |
| 2774 } | |
| 2775 } | |
| 2776 ~WaylandKeyboardDelegate() override { | |
| 2777 chromeos::input_method::ImeKeyboard* keyboard = | |
| 2778 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); | |
| 2779 if (keyboard) | |
| 2780 keyboard->RemoveObserver(this); | |
| 2781 #endif | |
| 2762 } | 2782 } |
| 2763 | 2783 |
| 2764 // Overridden from KeyboardDelegate: | 2784 // Overridden from KeyboardDelegate: |
| 2765 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; } | 2785 void OnKeyboardDestroying(Keyboard* keyboard) override { delete this; } |
| 2766 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override { | 2786 bool CanAcceptKeyboardEventsForSurface(Surface* surface) const override { |
| 2767 wl_resource* surface_resource = GetSurfaceResource(surface); | 2787 wl_resource* surface_resource = GetSurfaceResource(surface); |
| 2768 // We can accept events for this surface if the client is the same as the | 2788 // We can accept events for this surface if the client is the same as the |
| 2769 // keyboard. | 2789 // keyboard. |
| 2770 return surface_resource && | 2790 return surface_resource && |
| 2771 wl_resource_get_client(surface_resource) == client(); | 2791 wl_resource_get_client(surface_resource) == client(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2809 wl_keyboard_send_modifiers( | 2829 wl_keyboard_send_modifiers( |
| 2810 keyboard_resource_, next_serial(), | 2830 keyboard_resource_, next_serial(), |
| 2811 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED), | 2831 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED), |
| 2812 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED), | 2832 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED), |
| 2813 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED), | 2833 xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED), |
| 2814 xkb_state_serialize_layout(xkb_state_.get(), | 2834 xkb_state_serialize_layout(xkb_state_.get(), |
| 2815 XKB_STATE_LAYOUT_EFFECTIVE)); | 2835 XKB_STATE_LAYOUT_EFFECTIVE)); |
| 2816 wl_client_flush(client()); | 2836 wl_client_flush(client()); |
| 2817 } | 2837 } |
| 2818 | 2838 |
| 2839 #if defined(USE_OZONE) | |
| 2840 // Overridden from input_method::ImeKeyboard::Observer: | |
| 2841 void OnCapsLockChanged(bool enabled) override {} | |
| 2842 void OnLayoutChanged(const std::string& layout_name) override { | |
|
reveman
2017/06/09 16:50:13
This duplicates a lot of code in the ctor. Please
jclinton
2017/06/09 20:24:22
Done.
| |
| 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 16:50:12
remove ";"
jclinton
2017/06/09 20:24:22
Done.
| |
| 2867 #endif | |
| 2868 | |
| 2819 private: | 2869 private: |
| 2820 // Returns the corresponding key given a dom code. | 2870 // Returns the corresponding key given a dom code. |
| 2821 uint32_t DomCodeToKey(ui::DomCode code) const { | 2871 uint32_t DomCodeToKey(ui::DomCode code) const { |
| 2822 // This assumes KeycodeConverter has been built with evdev/xkb codes. | 2872 // This assumes KeycodeConverter has been built with evdev/xkb codes. |
| 2823 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>( | 2873 xkb_keycode_t xkb_keycode = static_cast<xkb_keycode_t>( |
| 2824 ui::KeycodeConverter::DomCodeToNativeKeycode(code)); | 2874 ui::KeycodeConverter::DomCodeToNativeKeycode(code)); |
| 2825 | 2875 |
| 2826 // Keycodes are offset by 8 in Xkb. | 2876 // Keycodes are offset by 8 in Xkb. |
| 2827 DCHECK_GE(xkb_keycode, 8u); | 2877 DCHECK_GE(xkb_keycode, 8u); |
| 2828 return xkb_keycode - 8; | 2878 return xkb_keycode - 8; |
| (...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4048 DCHECK(event_loop); | 4098 DCHECK(event_loop); |
| 4049 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 4099 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 4050 } | 4100 } |
| 4051 | 4101 |
| 4052 void Server::Flush() { | 4102 void Server::Flush() { |
| 4053 wl_display_flush_clients(wl_display_.get()); | 4103 wl_display_flush_clients(wl_display_.get()); |
| 4054 } | 4104 } |
| 4055 | 4105 |
| 4056 } // namespace wayland | 4106 } // namespace wayland |
| 4057 } // namespace exo | 4107 } // namespace exo |
| OLD | NEW |