diff --git a/main.qml b/main.qml index ed51ae0..e4c3485 100644 --- a/main.qml +++ b/main.qml @@ -2,6 +2,7 @@ import QtQuick 2.10 import QtQuick.Controls 2.3 // import QtQuick.Controls.Material 2.3 import QtQuick.Layouts 1.3 +import QtQuick.Window 2.2 import Qt.labs.platform 1.0 as Labs @@ -10,7 +11,8 @@ import VirtScreen.Backend 1.0 ApplicationWindow { id: window - visible: true + visible: false + flags: Qt.FramelessWindowHint title: "Basic layouts" // Material.theme: Material.Light @@ -20,6 +22,14 @@ ApplicationWindow { width: 380 height: 600 + // hide screen when loosing focus + onActiveFocusItemChanged: { + if (!activeFocusItem) { + this.hide(); + } + } + + // virtscreen.py hackend. Backend { id: backend } @@ -235,6 +245,17 @@ ApplicationWindow { } onActivated: { + if (window.visible) { + window.hide(); + return; + } + // Move window to the corner of the primary display + var width = backend.primaryDisplayWidth; + var height = backend.primaryDisplayHeight; + var x_mid = width / 2; + var y_mid = height / 2; + window.x = (backend.cursor_x > x_mid)? width - window.width : 0; + window.y = (backend.cursor_y > y_mid)? height - window.height : 0; window.show() window.raise() window.requestActivate() diff --git a/virtscreen.py b/virtscreen.py index 7385c00..fde4bbd 100755 --- a/virtscreen.py +++ b/virtscreen.py @@ -6,7 +6,7 @@ from enum import Enum from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QObject, QUrl, Qt from PyQt5.QtCore import pyqtProperty, pyqtSlot, pyqtSignal -from PyQt5.QtGui import QIcon +from PyQt5.QtGui import QIcon, QCursor from PyQt5.QtQml import qmlRegisterType, QQmlApplicationEngine from twisted.internet import protocol, error @@ -243,6 +243,11 @@ class Backend(QObject): self._vncPort = 5900 self._vncPassword = "" self._vncState = VNCState.OFF + # Primary screen and mouse posistion + self._cursor_x: int + self._cursor_y: int + self._primaryDisplayWidth: int + self._primaryDisplayHeight: int # objects self.xrandr = XRandR() @@ -305,7 +310,31 @@ class Backend(QObject): def vncState(self, state): self._vncState = state self.vncStateChanged.emit(self._vncState.value) - + + @pyqtProperty(int) + def cursor_x(self): + cursor = QCursor().pos() + self._cursor_x = cursor.x() + return self._cursor_x + + @pyqtProperty(int) + def cursor_y(self): + 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): @@ -417,7 +446,7 @@ if __name__ == '__main__': engine = QQmlApplicationEngine() engine.load(QUrl('main.qml')) if not engine.rootObjects(): - print("Failed to load qml") - exit(1) + QMessageBox.critical(None, "VirtScreen", "Failed to load qml") + sys.exit(1) sys.exit(app.exec_()) reactor.run()