1
0
Fork 0
mirror of https://github.com/kbumsik/VirtScreen.git synced 2025-03-09 15:40:18 +00:00

Added: Open ARandR or Gnome display settings

This commit is contained in:
Bumsik Kim 2018-05-11 22:19:37 -04:00
parent 3c31266c5c
commit b0baf026c5
No known key found for this signature in database
GPG key ID: E31041C8EC5B01C6
2 changed files with 99 additions and 22 deletions

View file

@ -26,10 +26,32 @@ ApplicationWindow {
height: 550 height: 550
// hide screen when loosing focus // hide screen when loosing focus
property bool autoClose: true
property bool ignoreCloseOnce: false
onAutoCloseChanged: {
// When setting auto close disabled and then enabled again, we need to
// ignore focus change once. Otherwise the window always is closed one time
// even when the mouse is clicked in the window.
if (!autoClose) {
ignoreCloseOnce = true;
}
}
onActiveFocusItemChanged: { onActiveFocusItemChanged: {
if ((!activeFocusItem) && (!sysTrayIcon.clicked)) { if (autoClose && !ignoreCloseOnce && !activeFocusItem && !sysTrayIcon.clicked) {
this.hide(); this.hide();
} }
if (ignoreCloseOnce && autoClose) {
ignoreCloseOnce = false;
}
}
// One-shot signal connect
function connectOnce (signal, slot) {
var f = function() {
slot.apply(this, arguments);
signal.disconnect(f);
}
signal.connect(f);
} }
// virtscreen.py backend. // virtscreen.py backend.
@ -262,20 +284,16 @@ ApplicationWindow {
if (!backend.virtScreenCreated) { if (!backend.virtScreenCreated) {
backend.createVirtScreen(); backend.createVirtScreen();
} else { } else {
function autoOff() { // If auto start enabled, stop VNC first then
console.log("autoOff called here", backend.vncState);
if (backend.vncState == Backend.OFF) {
console.log("Yes. Delete it");
backend.deleteVirtScreen();
backend.vncAutoStart = true;
}
}
if (backend.vncAutoStart && (backend.vncState != Backend.OFF)) { if (backend.vncAutoStart && (backend.vncState != Backend.OFF)) {
backend.vncAutoStart = false; backend.vncAutoStart = false;
backend.onVncStateChanged.connect(autoOff); connectOnce(backend.onVncStateChanged, function() {
backend.onVncStateChanged.connect(function() { console.log("autoOff called here", backend.vncState);
backend.onVncStateChanged.disconnect(autoOff); if (backend.vncState == Backend.OFF) {
console.log("Yes. Delete it");
backend.deleteVirtScreen();
backend.vncAutoStart = true;
}
}); });
backend.stopVNC(); backend.stopVNC();
} else { } else {
@ -291,6 +309,43 @@ ApplicationWindow {
}); });
} }
} }
Button {
id: displaySettingButton
text: "Open Display Setting"
anchors.left: parent.left
anchors.right: parent.right
// Material.accent: Material.Teal
// Material.theme: Material.Dark
enabled: backend.virtScreenCreated ? true : false
onClicked: {
busyDialog.open();
window.autoClose = false;
if (backend.vncState != Backend.OFF) {
console.log("vnc is running");
var restoreVNC = true;
if (backend.vncAutoStart) {
backend.vncAutoStart = false;
var restoreAutoStart = true;
}
}
connectOnce(backend.onDisplaySettingClosed, function() {
window.autoClose = true;
busyDialog.close();
if (restoreAutoStart) {
backend.vncAutoStart = true;
}
if (restoreVNC) {
backend.startVNC();
}
});
backend.stopVNC();
backend.openDisplaySetting();
}
}
} }
ColumnLayout { ColumnLayout {

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys, os, subprocess, signal, re, atexit, time, json import sys, os, subprocess, signal, re, atexit, time, json, shutil
from enum import Enum from enum import Enum
from typing import List, Dict from typing import List, Dict
@ -51,16 +51,18 @@ class SubprocessWrapper:
# Display properties # Display properties
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class DisplayProperty(QObject): class DisplayProperty(QObject):
_name: str
_primary: bool
_connected: bool
_active: bool
_width: int
_height: int
_x_offset: int
_y_offset: int
def __init__(self, parent=None): def __init__(self, parent=None):
super(DisplayProperty, self).__init__(parent) super(DisplayProperty, self).__init__(parent)
self._name: str
self._primary: bool
self._connected: bool
self._active: bool
self._width: int
self._height: int
self._x_offset: int
self._y_offset: int
def __str__(self): def __str__(self):
ret = f"{self.name}" ret = f"{self.name}"
if self.connected: if self.connected:
@ -353,6 +355,7 @@ class Backend(QObject):
_primary: DisplayProperty() _primary: DisplayProperty()
_cursor_x: int _cursor_x: int
_cursor_y: int _cursor_y: int
vncServer: ProcessProtocol
# Signals # Signals
onVirtScreenCreatedChanged = pyqtSignal(bool) onVirtScreenCreatedChanged = pyqtSignal(bool)
@ -360,6 +363,7 @@ class Backend(QObject):
onVncStateChanged = pyqtSignal(VNCState) onVncStateChanged = pyqtSignal(VNCState)
onVncAutoStartChanged = pyqtSignal(bool) onVncAutoStartChanged = pyqtSignal(bool)
onIPAddressesChanged = pyqtSignal() onIPAddressesChanged = pyqtSignal()
onDisplaySettingClosed = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
super(Backend, self).__init__(parent) super(Backend, self).__init__(parent)
@ -549,6 +553,24 @@ class Backend(QObject):
# auto stop on exit # auto stop on exit
atexit.register(self.stopVNC, force=True) atexit.register(self.stopVNC, force=True)
@pyqtSlot()
def openDisplaySetting(self):
# define callbacks
def _onConnected():
print("External Display Setting opened.")
def _onReceived(data):
pass
def _onEnded(exitCode):
print("External Display Setting closed.")
self.onDisplaySettingClosed.emit()
program_list = ["gnome-control-center display", "arandr"]
program = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, None)
for arg in program_list:
if not shutil.which(arg.split()[0]):
continue
program.run(arg)
break
@pyqtSlot() @pyqtSlot()
def stopVNC(self, force=False): def stopVNC(self, force=False):
if force: if force: