Skip to content

Commit

Permalink
#6: Added support for custom x11vnc arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kbumsik committed Jun 10, 2018
1 parent 7941f19 commit 8c65910
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 44 deletions.
3 changes: 1 addition & 2 deletions virtscreen/assets/AppWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ ApplicationWindow {
TextField {
id: passwordFIeld
focus: true
anchors.left: parent.left
anchors.right: parent.right
Layout.fillWidth: true
placeholderText: "New Password";
echoMode: TextInput.Password;
}
Expand Down
48 changes: 34 additions & 14 deletions virtscreen/assets/VncOptionsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Dialog {
x: (window.width - width) / 2
y: (window.width - height) / 2
width: popupWidth
height: 300
height: 350

Component.onCompleted: {
var request = new XMLHttpRequest();
Expand All @@ -33,24 +33,44 @@ Dialog {

ColumnLayout {
anchors.fill: parent

Repeater {
id: vncOptionsRepeater
RowLayout {
enabled: modelData.available
Label {
Layout.fillWidth: true
text: modelData.description + ' (' + modelData.value + ')'
RowLayout {
TextField {
id: vncCustomArgsTextField
enabled: vncCustomArgsCheckbox.checked
Layout.fillWidth: true
placeholderText: "Custom x11vnc arguments"
onTextEdited: {
settings.customX11vncArgs.value = text;
}
text: vncCustomArgsCheckbox.checked ? settings.customX11vncArgs.value : ""
}
CheckBox {
id: vncCustomArgsCheckbox
checked: settings.customX11vncArgs.enabled
onToggled: {
settings.customX11vncArgs.enabled = checked;
}
Switch {
checked: modelData.available ? modelData.enabled : false
onCheckedChanged: {
settings.x11vncOptions[modelData.value].enabled = checked;
}
}
ColumnLayout {
enabled: !vncCustomArgsCheckbox.checked
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
Expand Down
6 changes: 5 additions & 1 deletion virtscreen/assets/config.default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.0",
"version": "0.3.0",
"x11vncVersion": "0.9.15",
"theme_color": 8,
"virt": {
Expand Down Expand Up @@ -31,5 +31,9 @@
"arg": null
}
},
"customX11vncArgs": {
"enabled": false,
"value": ""
},
"presets": []
}
2 changes: 1 addition & 1 deletion virtscreen/assets/data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.0",
"version": "0.3.0",
"x11vncOptions": {
"-ncache": {
"value": "-ncache",
Expand Down
22 changes: 8 additions & 14 deletions virtscreen/assets/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,20 @@ Item {
property var settings: JSON.parse(backend.settings)
property bool autostart: settings.vnc.autostart

function saveSettings () {
settings.vnc.autostart = autostart;
backend.settings = JSON.stringify(settings, null, 4);
}

function createVirtScreen () {
backend.createVirtScreen(settings.virt.device, settings.virt.width,
settings.virt.height, settings.virt.portrait,
settings.virt.hidpi);
}

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);
saveSettings();
backend.startVNC(settings.vnc.port);
}

function stopVNC () {
Expand Down Expand Up @@ -234,8 +229,7 @@ Item {
id: quitAction
text: qsTr("&Quit")
onTriggered: {
settings.vnc.autostart = autostart;
backend.settings = JSON.stringify(settings, null, 4);
saveSettings();
backend.quitProgram();
}
}
Expand Down
29 changes: 17 additions & 12 deletions virtscreen/virtscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def __init__(self, parent=None):
value["available"] = True
else:
value["available"] = False
# 2. Default Display settings app for a Desktop Environment
# Default Display settings app for a Desktop Environment
desktop_environ = os.environ['XDG_CURRENT_DESKTOP'].lower()
for key, value in data['displaySettingApps'].items():
for de in value['XDG_CURRENT_DESKTOP']:
Expand Down Expand Up @@ -569,8 +569,8 @@ def deleteVNCPassword(self):
else:
self.onError.emit("Failed deleting the password file")

@pyqtSlot(int, str)
def startVNC(self, port, options=''):
@pyqtSlot(int)
def startVNC(self, port):
# Check if a virtual screen created
if not self.virtScreenCreated:
self.onError.emit("Virtual Screen not crated.")
Expand Down Expand Up @@ -606,7 +606,19 @@ def _onEnded(exitCode):
self.vncState = self.VNCState.OFF
print("VNC Exited.")
atexit.unregister(self.stopVNC)

# load settings
with open(CONFIG_PATH, 'r') as f:
config = json.load(f)
options = ''
if config['customX11vncArgs']['enabled']:
options = config['customX11vncArgs']['value']
else:
for key, value in config['x11vncOptions'].items():
if value['available'] and value['enabled']:
options += key + ' '
if value['arg'] is not None:
options += str(value['arg']) + ' '
# Sart x11vnc, turn settings object into VNC arguments format
logfile = open(X11VNC_LOG_PATH, "wb")
self.vncServer = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, logfile)
try:
Expand Down Expand Up @@ -856,13 +868,6 @@ def main_cli(args: argparse.Namespace):
for key, value in tmp_args.items():
if value:
position = key
# Turn settings object into VNC arguments format
vnc_option = ''
for key, value in config['x11vncOptions'].items():
if value['available'] and value['enabled']:
vnc_option += key + ' '
if value['arg'] is not None:
vnc_option += str(value['arg']) + ' '
# Create virtscreen and Start VNC
def handle_error(msg):
print('Error: ', msg)
Expand All @@ -876,7 +881,7 @@ def handle_vnc_changed(state):
sys.exit(0)
backend.onVncStateChanged.connect(handle_vnc_changed)
from twisted.internet import reactor # pylint: disable=E0401
backend.startVNC(config['vnc']['port'], vnc_option)
backend.startVNC(config['vnc']['port'])
reactor.run()

if __name__ == '__main__':
Expand Down

0 comments on commit 8c65910

Please sign in to comment.