1
0
Fork 0
mirror of https://github.com/kbumsik/VirtScreen.git synced 2025-02-14 12:21:50 +00:00

Auto-detect possible x11vnc options

This commit is contained in:
Bumsik Kim 2018-05-29 23:42:32 -04:00
parent 1ac430cdc0
commit 0353e60f28
No known key found for this signature in database
GPG key ID: E31041C8EC5B01C6
3 changed files with 92 additions and 8 deletions

View file

@ -1,5 +1,6 @@
{
"version": 0.1,
"version": "0.2",
"x11vncVersion": "0.9.15",
"theme_color": 8,
"virt": {
"device": "VIRTUAL1",
@ -12,5 +13,18 @@
"port": 5900,
"autostart": false
},
"displaySettingApp": "arandr",
"x11vncOptions": {
"-ncache": {
"available": null,
"enabled": false,
"arg": 10
},
"-multiptr": {
"available": null,
"enabled": true,
"arg": null
}
},
"presets": []
}

30
virtscreen/data/data.json Normal file
View file

@ -0,0 +1,30 @@
{
"version": "0.2",
"x11vncOptions": {
"-ncache": {
"description": "Cache",
"long_description": "Enables cache"
},
"-multiptr": {
"description": "Show mouse pointer",
"long_description": "This also enables input per-client."
}
},
"displaySettingApps": {
"gnome": {
"name": "GNOME",
"args": "gnome-control-center display",
"XDG_CURRENT_DESKTOP": ["gnome", "unity"]
},
"kde": {
"name": "KDE",
"args": "kcmshell5 kcm_kscreen",
"XDG_CURRENT_DESKTOP": ["kde"]
},
"arandr": {
"name": "ARandR",
"args": "arandr",
"XDG_CURRENT_DESKTOP": []
}
}
}

View file

@ -45,6 +45,7 @@ X11VNC_PASSWORD_PATH = HOME_PATH + "/x11vnc_passwd"
CONFIG_PATH = HOME_PATH + "/config.json"
# Path in the program path
DEFAULT_CONFIG_PATH = BASE_PATH + "/data/config.default.json"
DATA_PATH = BASE_PATH + "/data/data.json"
ICON_PATH = BASE_PATH + "/icon/icon.png"
QML_PATH = BASE_PATH + "/qml"
MAIN_QML_PATH = QML_PATH + "/main.qml"
@ -405,16 +406,55 @@ class Backend(QObject):
# Primary screen and mouse posistion
self._primaryProp: DisplayProperty
self.vncServer: ProcessProtocol
# Check config file
# and initialize if needed
need_init = False
if not os.path.exists(CONFIG_PATH):
shutil.copy(DEFAULT_CONFIG_PATH, CONFIG_PATH)
need_init = True
# Version check
file_match = True
with open(CONFIG_PATH, 'r') as f_config, open(DATA_PATH, 'r') as f_data:
config = json.load(f_config)
data = json.load(f_data)
if config['version'] != data['version']:
file_match = False
# Override config with default when version doesn't match
if not file_match:
shutil.copy(DEFAULT_CONFIG_PATH, CONFIG_PATH)
need_init = True
# initialize config file
if need_init:
# 1. Available x11vnc options
# Get available x11vnc options from x11vnc first
p = SubprocessWrapper()
arg = 'x11vnc -opts'
ret = p.run(arg)
options = tuple(m.group(1) for m in re.finditer("\s*(-\w+)\s+", ret))
# Set/unset available x11vnc options flags in config
with open(CONFIG_PATH, 'r') as f, open(DATA_PATH, 'r') as f_data:
config = json.load(f)
data = json.load(f_data)
for key, value in config["x11vncOptions"].items():
if key in options:
value["available"] = True
else:
value["available"] = False
# 2. 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']:
if de in desktop_environ:
config["displaySettingApp"] = key
# Save the new config
with open(CONFIG_PATH, 'w') as f:
f.write(json.dumps(config, indent=4, sort_keys=True))
# Qt properties
@pyqtProperty(str, constant=True)
def settings(self):
try:
with open(CONFIG_PATH, "r") as f:
return f.read()
except FileNotFoundError:
with open(DEFAULT_CONFIG_PATH, "r") as f:
return f.read()
with open(DEFAULT_CONFIG_PATH, "r") as f:
return f.read()
@settings.setter
def settings(self, json_str):
@ -666,7 +706,7 @@ def main():
os.makedirs(HOME_PATH)
except:
QMessageBox.critical(None, "VirtScreen",
"Cannot create ~/.virtscreen")
"Cannot create ~/.config/virtscreen")
sys.exit(1)
# Replace Twisted reactor with qt5reactor