mirror of
https://github.com/kbumsik/VirtScreen.git
synced 2025-03-09 15:40:18 +00:00
Auto-detect possible x11vnc options
This commit is contained in:
parent
1ac430cdc0
commit
0353e60f28
3 changed files with 92 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": 0.1,
|
"version": "0.2",
|
||||||
|
"x11vncVersion": "0.9.15",
|
||||||
"theme_color": 8,
|
"theme_color": 8,
|
||||||
"virt": {
|
"virt": {
|
||||||
"device": "VIRTUAL1",
|
"device": "VIRTUAL1",
|
||||||
|
@ -12,5 +13,18 @@
|
||||||
"port": 5900,
|
"port": 5900,
|
||||||
"autostart": false
|
"autostart": false
|
||||||
},
|
},
|
||||||
|
"displaySettingApp": "arandr",
|
||||||
|
"x11vncOptions": {
|
||||||
|
"-ncache": {
|
||||||
|
"available": null,
|
||||||
|
"enabled": false,
|
||||||
|
"arg": 10
|
||||||
|
},
|
||||||
|
"-multiptr": {
|
||||||
|
"available": null,
|
||||||
|
"enabled": true,
|
||||||
|
"arg": null
|
||||||
|
}
|
||||||
|
},
|
||||||
"presets": []
|
"presets": []
|
||||||
}
|
}
|
30
virtscreen/data/data.json
Normal file
30
virtscreen/data/data.json
Normal 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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,6 +45,7 @@ X11VNC_PASSWORD_PATH = HOME_PATH + "/x11vnc_passwd"
|
||||||
CONFIG_PATH = HOME_PATH + "/config.json"
|
CONFIG_PATH = HOME_PATH + "/config.json"
|
||||||
# Path in the program path
|
# Path in the program path
|
||||||
DEFAULT_CONFIG_PATH = BASE_PATH + "/data/config.default.json"
|
DEFAULT_CONFIG_PATH = BASE_PATH + "/data/config.default.json"
|
||||||
|
DATA_PATH = BASE_PATH + "/data/data.json"
|
||||||
ICON_PATH = BASE_PATH + "/icon/icon.png"
|
ICON_PATH = BASE_PATH + "/icon/icon.png"
|
||||||
QML_PATH = BASE_PATH + "/qml"
|
QML_PATH = BASE_PATH + "/qml"
|
||||||
MAIN_QML_PATH = QML_PATH + "/main.qml"
|
MAIN_QML_PATH = QML_PATH + "/main.qml"
|
||||||
|
@ -405,14 +406,53 @@ class Backend(QObject):
|
||||||
# Primary screen and mouse posistion
|
# Primary screen and mouse posistion
|
||||||
self._primaryProp: DisplayProperty
|
self._primaryProp: DisplayProperty
|
||||||
self.vncServer: ProcessProtocol
|
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
|
# Qt properties
|
||||||
@pyqtProperty(str, constant=True)
|
@pyqtProperty(str, constant=True)
|
||||||
def settings(self):
|
def settings(self):
|
||||||
try:
|
|
||||||
with open(CONFIG_PATH, "r") as f:
|
|
||||||
return f.read()
|
|
||||||
except FileNotFoundError:
|
|
||||||
with open(DEFAULT_CONFIG_PATH, "r") as f:
|
with open(DEFAULT_CONFIG_PATH, "r") as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
|
@ -666,7 +706,7 @@ def main():
|
||||||
os.makedirs(HOME_PATH)
|
os.makedirs(HOME_PATH)
|
||||||
except:
|
except:
|
||||||
QMessageBox.critical(None, "VirtScreen",
|
QMessageBox.critical(None, "VirtScreen",
|
||||||
"Cannot create ~/.virtscreen")
|
"Cannot create ~/.config/virtscreen")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Replace Twisted reactor with qt5reactor
|
# Replace Twisted reactor with qt5reactor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue