Skip to content

Commit

Permalink
Reactivated keyboard plugin
Browse files Browse the repository at this point in the history
Using upstream plugin and own UI
  • Loading branch information
R1tschY committed Aug 19, 2020
1 parent 7d8a328 commit 59f2739
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 325 deletions.
3 changes: 1 addition & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add_static_plugins_lib(
RemoteControl
RemoteCommands
RunCommand
# Battery
RemoteKeyboard
RemoteSystemVolume
# Presenter
)
Expand All @@ -34,7 +34,6 @@ add_static_plugins_lib(
Contacts
Clipboard
MprisRemote
RemoteKeyboard
SendNotifications
Share
Telepathy
Expand Down
2 changes: 1 addition & 1 deletion app/qml/pages/DevicePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Page {
device: _device
title: i18n("Open keyboard")
icon: "image://theme/icon-m-keyboard"
pluginId: "sailfishconnect_remotekeyboard"
pluginId: "kdeconnect_remotekeyboard"
onClicked: openPage(Qt.resolvedUrl("KeyboardPage.qml"))
}
PluginAction {
Expand Down
4 changes: 2 additions & 2 deletions app/qml/pages/DevicePluginsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Page {
readonly property var _pluginIcons: {
"kdeconnect_ping": "image://theme/icon-m-accept",
"kdeconnect_remotecontrol": "image://theme/icon-m-gesture",
"kdeconnect_remotekeyboard": "image://theme/icon-m-keyboard",
"kdeconnect_remotecommands": "image://theme/icon-m-wizard",
"kdeconnect_runcommand": "image://theme/icon-m-wizard",
"kdeconnect_remotesystemvolume": "image://theme/icon-m-speaker",
Expand All @@ -36,8 +37,7 @@ Page {
"sailfishconnect_share": "image://theme/icon-m-share",
"sailfishconnect_telepathy": "image://theme/icon-m-sms",
"sailfishconnect_sendnotifications": "image://theme/icon-m-notifications",
"sailfishconnect_mprisremote": "image://theme/icon-m-media",
"sailfishconnect_remotekeyboard": "image://theme/icon-m-keyboard"
"sailfishconnect_mprisremote": "image://theme/icon-m-media"
}

readonly property var _pluginConfigs: {
Expand Down
144 changes: 69 additions & 75 deletions app/qml/pages/KeyboardPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,42 @@ Page {
id: page
allowedOrientations: Orientation.All
property QtObject device
property QtObject plugin: device.plugin("SailfishConnect::RemoteKeyboardPlugin")
property QtObject plugin: device.getRemoteKeyboardApi()
property QtObject modifiers: QtObject {
// Three state modifier: None, One Key, Permanent
property int shift: 0
property int ctrl: 0
property int alt: 0
}
property bool chars: false
property bool chars: false // special chars view

property var _specialKeysMap: {
"backspace": 1,
"tab": 2,
"left": 4,
"up": 5,
"right": 6,
"down": 7,
"pgup": 8,
"pgdn": 9,
"home": 10,
"end": 11,
"enter": 12,
"del": 13,
"esc": 14,
"F1": 21,
"F2": 22,
"F3": 23,
"F4": 24,
"F5": 25,
"F6": 26,
"F7": 27,
"F8": 28,
"F9": 29,
"F10": 30,
"F11": 31,
"F12": 32
}

function displayCorrectChar(data) {
if (page.chars && typeof data["symView"] !== "undefined") {
Expand All @@ -47,6 +76,28 @@ Page {
}
}

function sendKey(label) {
var key = _specialKeysMap[label] || 0
if (key !== 0) {
label = ""
}

if (page.chars) {
plugin.sendKeyPress(label, key, false, modifiers.ctrl, modifiers.alt)
} else {
plugin.sendKeyPress(label, key, modifiers.shift, modifiers.ctrl, modifiers.alt)
if (modifiers.shift === 1) {
modifiers.shift = 0
}
}
if (modifiers.ctrl === 1) {
modifiers.ctrl = 0
}
if (modifiers.alt === 1) {
modifiers.alt = 0
}
}

SilicaFlickable {
anchors.fill: parent

Expand Down Expand Up @@ -75,22 +126,7 @@ Page {
height: page.height / 7
label: displayCorrectChar(modelData)

onClicked: {
if (page.chars) {
plugin.sendKeyPress(label, false, modifiers.ctrl, modifiers.alt)
} else {
plugin.sendKeyPress(label, modifiers.shift, modifiers.ctrl, modifiers.alt)
if (modifiers.shift === 1) {
modifiers.shift = 0
}
}
if (modifiers.ctrl === 1) {
modifiers.ctrl = 0
}
if (modifiers.alt === 1) {
modifiers.alt = 0
}
}
onClicked: page.sendKey(label)
}
}
}
Expand All @@ -104,22 +140,7 @@ Page {
height: page.height / 7
label: displayCorrectChar(modelData)

onClicked: {
if (page.chars) {
plugin.sendKeyPress(label, false, modifiers.ctrl, modifiers.alt)
} else {
plugin.sendKeyPress(label, modifiers.shift, modifiers.ctrl, modifiers.alt)
if (modifiers.shift === 1) {
modifiers.shift = 0
}
}
if (modifiers.ctrl === 1) {
modifiers.ctrl = 0
}
if (modifiers.alt === 1) {
modifiers.alt = 0
}
}
onClicked: page.sendKey(label)
}
}
}
Expand All @@ -133,22 +154,7 @@ Page {
height: page.height / 7
label: displayCorrectChar(modelData)

onClicked: {
if (page.chars) {
plugin.sendKeyPress(label, false, modifiers.ctrl, modifiers.alt)
} else {
plugin.sendKeyPress(label, modifiers.shift, modifiers.ctrl, modifiers.alt)
if (modifiers.shift === 1) {
modifiers.shift = 0
}
}
if (modifiers.ctrl === 1) {
modifiers.ctrl = 0
}
if (modifiers.alt === 1) {
modifiers.alt = 0
}
}
onClicked: page.sendKey(label)
}
}
}
Expand Down Expand Up @@ -200,26 +206,12 @@ Page {
if (modelData["caption"] === "shift") {
modifiers.shift = (modifiers.shift + 1) % 3
if (page.chars && modifiers.shift === 1) modifiers.shift = 2
return
} else if (modelData["caption"] === "backspace") {
plugin.sendKeyPress("backspace")
} else if (modelData["symView"] === "up") {
plugin.sendKeyPress("up", false, modifiers.ctrl, modifiers.alt)
plugin.sendKeyPress("", page._specialKeysMap["backspace"], false, modifiers.ctrl, modifiers.alt)
} else if (chars && modelData["symView"] === "up") {
plugin.sendKeyPress("", page._specialKeysMap["up"], false, modifiers.ctrl, modifiers.alt)
} else {
if (page.chars) {
plugin.sendKeyPress(label, false, modifiers.ctrl, modifiers.alt)
} else {
plugin.sendKeyPress(label, modifiers.shift, modifiers.ctrl, modifiers.alt)
if (modifiers.shift === 1) {
modifiers.shift = 0
}
}
if (modifiers.ctrl === 1) {
modifiers.ctrl = 0
}
if (modifiers.alt === 1) {
modifiers.alt = 0
}
page.sendKey(label)
}
}
}
Expand Down Expand Up @@ -262,13 +254,15 @@ Page {
} else if (label === "ctrl") {
modifiers.ctrl = (modifiers.ctrl + 1) % 3
} else if (label === "enter") {
plugin.sendKeyPress("enter", modifiers.shift, modifiers.ctrl, modifiers.alt)
} else if (modelData["symView"] === "left") {
plugin.sendKeyPress("left", false, modifiers.ctrl, modifiers.alt)
} else if (modelData["symView"] === "down") {
plugin.sendKeyPress("down", false, modifiers.ctrl, modifiers.alt)
} else if (modelData["symView"] === "right") {
plugin.sendKeyPress("right", false, modifiers.ctrl, modifiers.alt)
plugin.sendKeyPress("", page._specialKeysMap["enter"], modifiers.shift, modifiers.ctrl, modifiers.alt)
} else if (chars && modelData["symView"] === "left") {
plugin.sendKeyPress("", page._specialKeysMap["left"], false, modifiers.ctrl, modifiers.alt)
} else if (chars && modelData["symView"] === "down") {
plugin.sendKeyPress("", page._specialKeysMap["down"], false, modifiers.ctrl, modifiers.alt)
} else if (chars && modelData["symView"] === "right") {
plugin.sendKeyPress("", page._specialKeysMap["right"], false, modifiers.ctrl, modifiers.alt)
} else {
page.sendKey(label)
}
}
}
Expand Down
61 changes: 52 additions & 9 deletions app/qml/pages/TouchpadPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,45 @@ Page {
property int lastX: 0xDEAD
property int lastY: 0xDEAD
property bool moved: false
property bool holding: false

PageHeader {
id: header
title: i18n("Touchpad")
}

state: "normal"
states: [
State {
name: "holding"
when: holding
PropertyChanges {
target: hintLabel
text: i18n("Holding ...")
}
},
State {
name: "moving"
when: moved
PropertyChanges {
target: hintLabel
text: i18n("Moving ...")
}
},
State {
name: "normal"
PropertyChanges {
target: hintLabel
text: i18n(
"Move finger on screen\n" +
"Tap for click\n" +
"Hold shortly for Drag'n'Drop")
}
}
]

InfoLabel {
id: hintLabel
text: i18n(
"Move finger on screen\n" +
"Tap for click\n" +
"Hold shortly for Drag'n'Drop")
anchors.verticalCenter: touchpad.verticalCenter
}

Expand Down Expand Up @@ -95,22 +122,38 @@ Page {
}

onClicked: {
if (!moved && plugin !== null) {
plugin.sendCommand("singleclick", true)
console.log("onClicked")
if (plugin !== null) {
if (!holding) {
plugin.sendCommand("singleclick", true)
} else {
plugin.sendCommand("singlerelease", true)
holding = false
}
}
holding = false
moved = false
}

onDoubleClicked: {
if (!moved && plugin !== null) {
plugin.sendCommand("doubleclick", true)
console.log("onDoubleClicked")
if (plugin !== null) {
if (!holding) {
plugin.sendCommand("doubleclick", true)
} else {
plugin.sendCommand("singlerelease", true)
holding = false
}
}
holding = false
moved = false
}

onPressAndHold: {
if (!moved && plugin !== null) {
console.log("onPressAndHold")
if (plugin !== null) {
plugin.sendCommand("singlehold", true)
holding = true
}
moved = false
}
Expand Down
20 changes: 19 additions & 1 deletion app/src/dbus/kdeconnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ class RemoteControlApi : public RemoteControlDbusInterface {
}
};

class RemoteKeyboardApi : public RemoteKeyboardDbusInterface {
Q_OBJECT
public:
using RemoteKeyboardDbusInterface::RemoteKeyboardDbusInterface;

Q_SCRIPTABLE void sendKeyPress(
const QString& key, int specialKey = 0, bool shift = false, bool ctrl = false,
bool alt = false, bool sendAck = true)
{
return checkForDbusError(
RemoteKeyboardDbusInterface::sendKeyPress(key, specialKey, shift, ctrl, alt, sendAck));
}
};

class RemoteCommandsApi : public RemoteCommandsDbusInterface {
Q_OBJECT
public:
Expand Down Expand Up @@ -166,6 +180,10 @@ class DeviceApi : public DeviceDbusInterface {
return new RemoteSystemVolumeApi(id());
}

Q_SCRIPTABLE RemoteKeyboardApi* getRemoteKeyboardApi() {
return new RemoteKeyboardApi(id());
}

Q_SCRIPTABLE ShareApi* getShareApi() {
return new ShareApi(id());
}
Expand Down Expand Up @@ -207,4 +225,4 @@ class DaemonApi : public DaemonDbusInterface {
}
};

} // namespace SailfishConnect
} // namespace SailfishConnect
4 changes: 4 additions & 0 deletions app/src/helper/keyboardlayoutprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,16 @@ void KeyboardLayoutProvider::setFeedback(const bool &feedback)

void KeyboardLayoutProvider::pressFeedback()
{
#ifndef BUILD_FOR_HARBOUR
QFeedbackHapticsEffect::playThemeEffect(QFeedbackEffect::PressStrong);
#endif
}

void KeyboardLayoutProvider::releaseFeedback()
{
#ifndef BUILD_FOR_HARBOUR
QFeedbackHapticsEffect::playThemeEffect(QFeedbackEffect::ReleaseStrong);
#endif
}

void KeyboardLayoutProvider::loadNames()
Expand Down
Loading

0 comments on commit 59f2739

Please sign in to comment.