From 7f3448a25eff90c5cf772532101ee13e549b49a2 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Thu, 31 May 2018 02:48:07 -0400 Subject: [PATCH] Selectable x11vnc options in QML --- virtscreen/assets/AppWindow.qml | 11 +++++ virtscreen/assets/DisplayPage.qml | 4 +- virtscreen/assets/VncOptionsDialog.qml | 62 ++++++++++++++++++++++++++ virtscreen/assets/VncPage.qml | 13 +++++- virtscreen/assets/config.default.json | 5 +++ virtscreen/assets/data.json | 7 +++ virtscreen/assets/main.qml | 25 +++++++++-- virtscreen/virtscreen.py | 6 +-- 8 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 virtscreen/assets/VncOptionsDialog.qml diff --git a/virtscreen/assets/AppWindow.qml b/virtscreen/assets/AppWindow.qml index 697b018..2bf9e6a 100644 --- a/virtscreen/assets/AppWindow.qml +++ b/virtscreen/assets/AppWindow.qml @@ -277,6 +277,17 @@ ApplicationWindow { } } + Loader { + id: vncOptionsLoader + active: false + source: "VncOptionsDialog.qml" + onLoaded: { + item.onClosed.connect(function() { + vncOptionsLoader.active = false; + }); + } + } + SwipeView { anchors.top: tabBar.bottom anchors.bottom: parent.bottom diff --git a/virtscreen/assets/DisplayPage.qml b/virtscreen/assets/DisplayPage.qml index 3e3f1dd..b71ac0b 100644 --- a/virtscreen/assets/DisplayPage.qml +++ b/virtscreen/assets/DisplayPage.qml @@ -109,7 +109,7 @@ ColumnLayout { window.autoClose = false; if (backend.vncState != Backend.OFF) { console.log("vnc is running"); - backend.stopVNC(); + stopVNC(); var restoreVNC = true; if (autostart) { autostart = false; @@ -123,7 +123,7 @@ ColumnLayout { autostart = true; } if (restoreVNC) { - backend.startVNC(settings.vnc.port); + startVNC(); } }); backend.openDisplaySetting(settings.displaySettingApp); diff --git a/virtscreen/assets/VncOptionsDialog.qml b/virtscreen/assets/VncOptionsDialog.qml new file mode 100644 index 0000000..da1a036 --- /dev/null +++ b/virtscreen/assets/VncOptionsDialog.qml @@ -0,0 +1,62 @@ +import QtQuick 2.10 +import QtQuick.Controls 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Layouts 1.3 + +Dialog { + id: preferenceDialog + title: "VNC Options" + focus: true + modal: true + visible: true + standardButtons: Dialog.Ok + x: (window.width - width) / 2 + y: (window.width - height) / 2 + width: popupWidth + height: 300 + + Component.onCompleted: { + var request = new XMLHttpRequest(); + request.open('GET', 'data.json'); + request.onreadystatechange = function(event) { + if (request.readyState == XMLHttpRequest.DONE) { + var data = JSON.parse(request.responseText).x11vncOptions; + // merge data and settings + for (var key in data) { + Object.assign(data[key], settings.x11vncOptions[key]); + } + var repeater = vncOptionsRepeater; + repeater.model = Object.keys(data).map(function(k){return data[k]}); + } + }; + request.send(); + } + + ColumnLayout { + anchors.fill: parent + + Repeater { + id: vncOptionsRepeater + RowLayout { + enabled: modelData.available + Label { + Layout.fillWidth: true + text: modelData.description + ' (' + modelData.value + ')' + } + Switch { + checked: modelData.available ? modelData.enabled : false + onCheckedChanged: { + settings.x11vncOptions[modelData.value].enabled = checked; + } + } + } + } + + RowLayout { + // Empty layout + Layout.fillHeight: true + } + } + onAccepted: {} + onRejected: {} +} diff --git a/virtscreen/assets/VncPage.qml b/virtscreen/assets/VncPage.qml index 6f22ee9..0d4b627 100644 --- a/virtscreen/assets/VncPage.qml +++ b/virtscreen/assets/VncPage.qml @@ -45,6 +45,17 @@ ColumnLayout { onClicked: passwordDialog.open() } } + RowLayout { + Layout.alignment: Qt.AlignRight + Button { + text: "Advanced" + font.capitalization: Font.MixedCase + onClicked: vncOptionsLoader.active = true; + background.opacity : 0 + onHoveredChanged: hovered ? background.opacity = 0.4 + :background.opacity = 0; + } + } } } RowLayout { @@ -64,7 +75,7 @@ ColumnLayout { autostart = checked; if ((checked == true) && (backend.vncState == Backend.OFF) && backend.virtScreenCreated) { - backend.startVNC(settings.vnc.port); + startVNC(); } } } diff --git a/virtscreen/assets/config.default.json b/virtscreen/assets/config.default.json index da6b35a..a60a8ef 100644 --- a/virtscreen/assets/config.default.json +++ b/virtscreen/assets/config.default.json @@ -24,6 +24,11 @@ "available": null, "enabled": true, "arg": null + }, + "-repeat": { + "available": null, + "enabled": true, + "arg": null } }, "presets": [] diff --git a/virtscreen/assets/data.json b/virtscreen/assets/data.json index 64cfe17..4fa0d1b 100644 --- a/virtscreen/assets/data.json +++ b/virtscreen/assets/data.json @@ -2,12 +2,19 @@ "version": "0.2", "x11vncOptions": { "-ncache": { + "value": "-ncache", "description": "Client side caching", "long_description": "Enables cache" }, "-multiptr": { + "value": "-multiptr", "description": "Show mouse pointer", "long_description": "This also enables input per-client." + }, + "-repeat": { + "value": "-repeat", + "description": "Keyboard auto repeating", + "long_description": "Enables X server key auto repeat" } }, "displaySettingApps": { diff --git a/virtscreen/assets/main.qml b/virtscreen/assets/main.qml index ffc6588..039966d 100644 --- a/virtscreen/assets/main.qml +++ b/virtscreen/assets/main.qml @@ -10,9 +10,28 @@ Item { property var settings: JSON.parse(backend.settings) property bool autostart: settings.vnc.autostart + function startVNC () { + var options = ''; + var data = settings.x11vncOptions; + for (var key in data) { + if(data[key].available && data[key].enabled) { + options += key + ' '; + if(data[key].arg !== null) { + options += data[key].arg.toString() + ' '; + } + } + } + console.log('options: ', options); + backend.startVNC(settings.vnc.port, options); + } + + function stopVNC () { + backend.stopVNC(); + } + function switchVNC () { if ((backend.vncState == Backend.OFF) && backend.virtScreenCreated) { - backend.startVNC(settings.vnc.port); + startVNC(); } } @@ -180,7 +199,7 @@ Item { autostart = true; } }); - backend.stopVNC(); + stopVNC(); } else { backend.deleteVirtScreen(); } @@ -194,7 +213,7 @@ Item { backend.vncState == Backend.OFF ? "Start VNC Server" : "Stop VNC Server" enabled: autostart ? false : backend.virtScreenCreated ? true : false - onTriggered: backend.vncState == Backend.OFF ? backend.startVNC(settings.vnc.port) : backend.stopVNC() + onTriggered: backend.vncState == Backend.OFF ? startVNC() : stopVNC() } MenuItem { separator: true diff --git a/virtscreen/virtscreen.py b/virtscreen/virtscreen.py index 1b56571..7c21242 100755 --- a/virtscreen/virtscreen.py +++ b/virtscreen/virtscreen.py @@ -579,8 +579,8 @@ class Backend(QObject): else: self.onError.emit("Failed deleting the password file") - @pyqtSlot(int) - def startVNC(self, port): + @pyqtSlot(int, str) + def startVNC(self, port, options=''): # Check if a virtual screen created if not self.virtScreenCreated: self.onError.emit("Virtual Screen not crated.") @@ -621,7 +621,7 @@ class Backend(QObject): self.vncServer = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, logfile) virt = self.xrandr.get_virtual_screen() clip = f"{virt.width}x{virt.height}+{virt.x_offset}+{virt.y_offset}" - arg = f"x11vnc -multiptr -repeat -rfbport {port} -clip {clip}" + arg = f"x11vnc -rfbport {port} -clip {clip} {options}" if self.vncUsePassword: arg += f" -rfbauth {X11VNC_PASSWORD_PATH}" self.vncServer.run(arg)