keyboard: Replace Keypad object with a "digits" JSON OSK keymap
Drop some code, in favor of a numeric keypad that is driven through the same JSON-based maps. This is also a first use of the "height" key property in the JSON files, for the Enter key. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3162>
This commit is contained in:
parent
3f6f2f2376
commit
32ada34e1d
@ -12,6 +12,7 @@
|
|||||||
<file>ch+fr.json</file>
|
<file>ch+fr.json</file>
|
||||||
<file>cz.json</file>
|
<file>cz.json</file>
|
||||||
<file>de.json</file>
|
<file>de.json</file>
|
||||||
|
<file>digits.json</file>
|
||||||
<file>dk.json</file>
|
<file>dk.json</file>
|
||||||
<file>ee.json</file>
|
<file>ee.json</file>
|
||||||
<file>epo.json</file>
|
<file>epo.json</file>
|
||||||
|
83
data/osk-layouts/digits.json
Normal file
83
data/osk-layouts/digits.json
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
{
|
||||||
|
"levels": [
|
||||||
|
{
|
||||||
|
"level": "",
|
||||||
|
"mode": "default",
|
||||||
|
"rows": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"7"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"9"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"action": "delete",
|
||||||
|
"iconName": "edit-clear-symbolic"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"4"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"5"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"6"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"iconName": "keyboard-enter-symbolic",
|
||||||
|
"keyval": "0xff0d",
|
||||||
|
"height": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"strings": [
|
||||||
|
"3"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"width": 3,
|
||||||
|
"strings": [
|
||||||
|
"0"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"action": "hide",
|
||||||
|
"iconName": "keyboard-hide-symbolic"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "Digits"
|
||||||
|
}
|
@ -1084,63 +1084,6 @@ const EmojiSelection = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const Keypad = GObject.registerClass({
|
|
||||||
Signals: {
|
|
||||||
'keyval': {param_types: [GObject.TYPE_UINT]},
|
|
||||||
},
|
|
||||||
}, class Keypad extends AspectContainer {
|
|
||||||
_init() {
|
|
||||||
let keys = [
|
|
||||||
{label: '1', keyval: Clutter.KEY_1, left: 0, top: 0},
|
|
||||||
{label: '2', keyval: Clutter.KEY_2, left: 1, top: 0},
|
|
||||||
{label: '3', keyval: Clutter.KEY_3, left: 2, top: 0},
|
|
||||||
{label: '4', keyval: Clutter.KEY_4, left: 0, top: 1},
|
|
||||||
{label: '5', keyval: Clutter.KEY_5, left: 1, top: 1},
|
|
||||||
{label: '6', keyval: Clutter.KEY_6, left: 2, top: 1},
|
|
||||||
{label: '7', keyval: Clutter.KEY_7, left: 0, top: 2},
|
|
||||||
{label: '8', keyval: Clutter.KEY_8, left: 1, top: 2},
|
|
||||||
{label: '9', keyval: Clutter.KEY_9, left: 2, top: 2},
|
|
||||||
{label: '0', keyval: Clutter.KEY_0, left: 1, top: 3},
|
|
||||||
{keyval: Clutter.KEY_BackSpace, icon: 'edit-clear-symbolic', left: 3, top: 0},
|
|
||||||
{keyval: Clutter.KEY_Return, extraClassName: 'enter-key', icon: 'keyboard-enter-symbolic', left: 3, top: 1, height: 2},
|
|
||||||
];
|
|
||||||
|
|
||||||
super._init({
|
|
||||||
layout_manager: new Clutter.BinLayout(),
|
|
||||||
x_expand: true,
|
|
||||||
y_expand: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const gridLayout = new Clutter.GridLayout({
|
|
||||||
orientation: Clutter.Orientation.HORIZONTAL,
|
|
||||||
column_homogeneous: true,
|
|
||||||
row_homogeneous: true,
|
|
||||||
});
|
|
||||||
this._box = new St.Widget({layout_manager: gridLayout, x_expand: true, y_expand: true});
|
|
||||||
this.add_child(this._box);
|
|
||||||
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
|
||||||
let cur = keys[i];
|
|
||||||
let key = new Key({
|
|
||||||
label: cur.label,
|
|
||||||
iconName: cur.icon,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (keys[i].extraClassName)
|
|
||||||
key.keyButton.add_style_class_name(cur.extraClassName);
|
|
||||||
|
|
||||||
let w, h;
|
|
||||||
w = cur.width || 1;
|
|
||||||
h = cur.height || 1;
|
|
||||||
gridLayout.attach(key, cur.left, cur.top, w, h);
|
|
||||||
|
|
||||||
key.connect('released', () => {
|
|
||||||
this.emit('keyval', cur.keyval);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export class KeyboardManager extends Signals.EventEmitter {
|
export class KeyboardManager extends Signals.EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -1390,15 +1333,6 @@ export const Keyboard = GObject.registerClass({
|
|||||||
this._emojiSelection.hide();
|
this._emojiSelection.hide();
|
||||||
this._aspectContainer.add_child(this._emojiSelection);
|
this._aspectContainer.add_child(this._emojiSelection);
|
||||||
|
|
||||||
this._keypad = new Keypad();
|
|
||||||
this._keypad.connectObject('keyval', (_keypad, keyval) => {
|
|
||||||
this._keyboardController.keyvalPress(keyval);
|
|
||||||
this._keyboardController.keyvalRelease(keyval);
|
|
||||||
}, this);
|
|
||||||
this._aspectContainer.add_child(this._keypad);
|
|
||||||
this._keypad.hide();
|
|
||||||
this._keypadVisible = false;
|
|
||||||
|
|
||||||
this._updateKeys();
|
this._updateKeys();
|
||||||
|
|
||||||
this._keyboardController.connectObject(
|
this._keyboardController.connectObject(
|
||||||
@ -1460,7 +1394,7 @@ export const Keyboard = GObject.registerClass({
|
|||||||
if (purpose === Clutter.InputContentPurpose.DIGITS ||
|
if (purpose === Clutter.InputContentPurpose.DIGITS ||
|
||||||
purpose === Clutter.InputContentPurpose.NUMBER ||
|
purpose === Clutter.InputContentPurpose.NUMBER ||
|
||||||
purpose === Clutter.InputContentPurpose.PHONE) {
|
purpose === Clutter.InputContentPurpose.PHONE) {
|
||||||
this._onKeypadVisible(null, true);
|
keyboardModel = new KeyboardModel('digits');
|
||||||
} else {
|
} else {
|
||||||
let groups = [groupName];
|
let groups = [groupName];
|
||||||
if (groupName.includes('+'))
|
if (groupName.includes('+'))
|
||||||
@ -1480,8 +1414,6 @@ export const Keyboard = GObject.registerClass({
|
|||||||
|
|
||||||
if (!keyboardModel)
|
if (!keyboardModel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this._onKeypadVisible(null, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let levels = keyboardModel.getLevels();
|
let levels = keyboardModel.getLevels();
|
||||||
@ -1753,7 +1685,7 @@ export const Keyboard = GObject.registerClass({
|
|||||||
|
|
||||||
_updateCurrentPageVisible() {
|
_updateCurrentPageVisible() {
|
||||||
if (this._currentPage)
|
if (this._currentPage)
|
||||||
this._currentPage.visible = !this._emojiActive && !this._keypadVisible;
|
this._currentPage.visible = !this._emojiActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setEmojiActive(active) {
|
_setEmojiActive(active) {
|
||||||
@ -1825,15 +1757,6 @@ export const Keyboard = GObject.registerClass({
|
|||||||
this._onGroupChanged();
|
this._onGroupChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onKeypadVisible(controller, visible) {
|
|
||||||
if (visible === this._keypadVisible)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this._keypadVisible = visible;
|
|
||||||
this._keypad.visible = this._keypadVisible;
|
|
||||||
this._updateCurrentPageVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
_onEmojiKeyVisible(controller, visible) {
|
_onEmojiKeyVisible(controller, visible) {
|
||||||
if (visible === this._emojiKeyVisible)
|
if (visible === this._emojiKeyVisible)
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user