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

Backend: make use of DisplayProperty class

This commit is contained in:
Bumsik Kim 2018-05-09 19:40:07 -04:00
parent 68efb022c7
commit 6bee3d556a
No known key found for this signature in database
GPG key ID: E31041C8EC5B01C6
2 changed files with 102 additions and 55 deletions

View file

@ -6,6 +6,7 @@ import QtQuick.Window 2.2
import Qt.labs.platform 1.0 as Labs
import VirtScreen.DisplayProperty 1.0
import VirtScreen.Backend 1.0
@ -34,6 +35,10 @@ ApplicationWindow {
id: backend
}
DisplayProperty {
id: display
}
// Timer object and function
Timer {
id: timer
@ -86,16 +91,13 @@ ApplicationWindow {
Layout.fillWidth: true
Label { text: "Width"; Layout.fillWidth: true }
SpinBox {
value: backend.width
value: backend.virt.width
from: 640
to: 1920
stepSize: 1
editable: true
textFromValue: function(value, locale) {
return Number(value).toLocaleString(locale, 'f', 0) + " px";
}
onValueModified: {
backend.width = value;
backend.virt.width = value;
}
}
}
@ -104,16 +106,13 @@ ApplicationWindow {
Layout.fillWidth: true
Label { text: "Height"; Layout.fillWidth: true }
SpinBox {
value: backend.height
value: backend.virt.height
from: 360
to: 1080
stepSize : 1
editable: true
textFromValue: function(value, locale) {
return Number(value).toLocaleString(locale, 'f', 0) + " px";
}
onValueModified: {
backend.height = value;
backend.virt.height = value;
}
}
}
@ -322,8 +321,9 @@ ApplicationWindow {
}
sysTrayIcon.clicked = true;
// Move window to the corner of the primary display
var width = backend.primaryDisplayWidth;
var height = backend.primaryDisplayHeight;
var primary = backend.primary;
var width = primary.width;
var height = primary.height;
var x_mid = width / 2;
var y_mid = height / 2;
window.x = width - window.width; //(backend.cursor_x > x_mid)? width - window.width : 0;

View file

@ -50,16 +50,17 @@ class SubprocessWrapper:
#-------------------------------------------------------------------------------
# Display properties
#-------------------------------------------------------------------------------
class DisplayProperty:
def __init__(self):
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
class DisplayProperty(QObject):
def __init__(self, parent=None):
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):
ret = f"{self.name}"
if self.connected:
@ -73,6 +74,62 @@ class DisplayProperty:
else:
ret += " disconnected"
return ret
@pyqtProperty(str)
def name(self):
return self._name
@name.setter
def name(self, name):
self._name = name
@pyqtProperty(bool)
def primary(self):
return self._primary
@primary.setter
def primary(self, primary):
self._primary = primary
@pyqtProperty(bool)
def connected(self):
return self._connected
@connected.setter
def connected(self, connected):
self._connected = connected
@pyqtProperty(bool)
def active(self):
return self._active
@active.setter
def active(self, active):
self._active = active
@pyqtProperty(int)
def width(self):
return self._width
@width.setter
def width(self, width):
self._width = width
@pyqtProperty(int)
def height(self):
return self._height
@height.setter
def height(self, height):
self._height = height
@pyqtProperty(int)
def x_offset(self):
return self._x_offset
@x_offset.setter
def x_offset(self, x_offset):
self._x_offset = x_offset
@pyqtProperty(int)
def y_offset(self):
return self._y_offset
@y_offset.setter
def y_offset(self, y_offset):
self._y_offset = y_offset
#-------------------------------------------------------------------------------
# Screen adjustment class
@ -158,6 +215,10 @@ class XRandR(SubprocessWrapper):
self.delete_virtual_screen()
os._exit(0)
def get_primary_screen(self) -> DisplayProperty:
self._update_screens()
return self.primary
def get_virtual_screen(self) -> DisplayProperty:
self._update_screens()
return self.virt
@ -272,9 +333,12 @@ class Backend(QObject):
def __init__(self, parent=None):
super(Backend, self).__init__(parent)
# objects
self.xrandr = XRandR()
# Virtual screen properties
self._width = 1368
self._height = 1024
self._virt = DisplayProperty()
self.virt.width = 1368
self.virt.height = 1024
self._portrait = False
self._hidpi = False
self._virtScreenCreated = False
@ -283,27 +347,17 @@ class Backend(QObject):
self._vncPassword = ""
self._vncState = VNCState.OFF
# Primary screen and mouse posistion
self._primary: DisplayProperty() = self.xrandr.get_primary_screen()
self._cursor_x: int
self._cursor_y: int
self._primaryDisplayWidth: int
self._primaryDisplayHeight: int
# objects
self.xrandr = XRandR()
# Qt properties
@pyqtProperty(int)
def width(self):
return self._width
@width.setter
def width(self, width):
self._width = width
@pyqtProperty(int)
def height(self):
return self._height
@height.setter
def height(self, height):
self._height = height
@pyqtProperty(DisplayProperty)
def virt(self):
return self._virt
@virt.setter
def virt(self, virt):
self._virt = virt
@pyqtProperty(bool)
def portrait(self):
@ -349,6 +403,11 @@ class Backend(QObject):
self._vncState = state
self.onVncStateChanged.emit(self._vncState.value)
@pyqtProperty(DisplayProperty)
def primary(self):
self._primary = self.xrandr.get_primary_screen()
return self._primary
@pyqtProperty(int)
def cursor_x(self):
cursor = QCursor().pos()
@ -360,27 +419,14 @@ class Backend(QObject):
cursor = QCursor().pos()
self._cursor_y = cursor.y()
return self._cursor_y
@pyqtProperty(int)
def primaryDisplayWidth(self):
screen = QApplication.desktop().screenGeometry()
self._primaryDisplayWidth = screen.width()
return self._primaryDisplayWidth
@pyqtProperty(int)
def primaryDisplayHeight(self):
screen = QApplication.desktop().screenGeometry()
self._primaryDisplayHeight = screen.height()
return self._primaryDisplayHeight
# Qt Slots
@pyqtSlot()
def createVirtScreen(self):
print("Creating a Virtual Screen...")
self.xrandr.create_virtual_screen(self.width, self.height, self.portrait, self.hidpi)
self.xrandr.create_virtual_screen(self.virt.width, self.virt.height, self.portrait, self.hidpi)
self.virtScreenCreated = True
# Qt Slots
@pyqtSlot()
def deleteVirtScreen(self):
print("Deleting the Virtual Screen...")
@ -489,6 +535,7 @@ if __name__ == '__main__':
# Register the Python type. Its URI is 'People', it's v1.0 and the type
# will be called 'Person' in QML.
qmlRegisterType(DisplayProperty, 'VirtScreen.DisplayProperty', 1, 0, 'DisplayProperty')
qmlRegisterType(Backend, 'VirtScreen.Backend', 1, 0, 'Backend')
# Create a component factory and load the QML script.