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

View file

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