From c3e68955e30dea275574eb04fbc764688a9eff43 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 20 Jul 2016 17:50:55 +0200 Subject: [PATCH] keyboard: Implement more of the wayland caribou adapter Have it notify properly of changes to the current input source, as well as exposing those in get_groups(). The support for virtual keyboard events has been replaced by ClutterVirtualInputDevice, which can be thought of as the equivalent to the XTEST devices in X11. https://bugzilla.gnome.org/show_bug.cgi?id=765009 --- js/ui/keyboard.js | 50 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js index de1fb21f5..4af1f1a75 100644 --- a/js/ui/keyboard.js +++ b/js/ui/keyboard.js @@ -10,6 +10,7 @@ const Meta = imports.gi.Meta; const Shell = imports.gi.Shell; const Signals = imports.signals; const St = imports.gi.St; +const InputSourceManager = imports.ui.status.keyboard; const BoxPointer = imports.ui.boxpointer; const Layout = imports.ui.layout; @@ -757,19 +758,48 @@ const ShellWaylandAdapter = new Lang.Class({ Name: 'ShellWaylandAdapter', Extends: Caribou.XAdapter, + _init: function () { + this.parent(); + let deviceManager = Clutter.DeviceManager.get_default(); + this._virtualDevice = deviceManager.create_virtual_device(Clutter.InputDeviceType.KEYBOARD_DEVICE); + + this._inputSourceManager = InputSourceManager.getInputSourceManager(); + this._sourceChangedId = this._inputSourceManager.connect('current-source-changed', + Lang.bind(this, this._onSourceChanged)); + this._sourcesModifiedId = this._inputSourceManager.connect ('sources-changed', + Lang.bind(this, this._onSourcesModified)); + }, + + _onSourcesModified: function () { + this.emit('config-changed'); + }, + + _onSourceChanged: function (inputSourceManager, oldSource) { + let source = inputSourceManager.currentSource; + this.emit('group-changed', source.index, source.id, ''); + }, + + vfunc_get_groups: function () { + let inputSources = this._inputSourceManager.inputSources; + let groups = [] + let variants = []; + + for (let i in inputSources) { + let is = inputSources[i]; + groups[is.index] = is.id; + variants[is.index] = ''; + } + + return [groups, groups.length, variants, variants.length]; + }, + vfunc_keyval_press: function(keyval) { - let focus = global.stage.get_key_focus(); - if (focus instanceof Clutter.Text) - Shell.util_text_insert_keyval(focus, keyval); - else - this.parent(keyval); + this._virtualDevice.notify_keyval(Clutter.get_current_event_time(), + keyval, Clutter.KeyState.PRESSED); }, vfunc_keyval_release: function(keyval) { - let focus = global.stage.get_key_focus(); - if (focus instanceof Clutter.Text) - return; // do nothing - else - this.parent(keyval); + this._virtualDevice.notify_keyval(Clutter.get_current_event_time(), + keyval, Clutter.KeyState.RELEASED); }, });