mirror of
https://github.com/kbumsik/VirtScreen.git
synced 2025-03-09 15:40:18 +00:00
QML: auto positioning window
This commit is contained in:
parent
9fe8e36d22
commit
0975e4e8ac
2 changed files with 55 additions and 5 deletions
23
main.qml
23
main.qml
|
@ -2,6 +2,7 @@ import QtQuick 2.10
|
||||||
import QtQuick.Controls 2.3
|
import QtQuick.Controls 2.3
|
||||||
// import QtQuick.Controls.Material 2.3
|
// import QtQuick.Controls.Material 2.3
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
import QtQuick.Window 2.2
|
||||||
|
|
||||||
import Qt.labs.platform 1.0 as Labs
|
import Qt.labs.platform 1.0 as Labs
|
||||||
|
|
||||||
|
@ -10,7 +11,8 @@ import VirtScreen.Backend 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: window
|
id: window
|
||||||
visible: true
|
visible: false
|
||||||
|
flags: Qt.FramelessWindowHint
|
||||||
title: "Basic layouts"
|
title: "Basic layouts"
|
||||||
|
|
||||||
// Material.theme: Material.Light
|
// Material.theme: Material.Light
|
||||||
|
@ -20,6 +22,14 @@ ApplicationWindow {
|
||||||
width: 380
|
width: 380
|
||||||
height: 600
|
height: 600
|
||||||
|
|
||||||
|
// hide screen when loosing focus
|
||||||
|
onActiveFocusItemChanged: {
|
||||||
|
if (!activeFocusItem) {
|
||||||
|
this.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// virtscreen.py hackend.
|
||||||
Backend {
|
Backend {
|
||||||
id: backend
|
id: backend
|
||||||
}
|
}
|
||||||
|
@ -235,6 +245,17 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivated: {
|
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.show()
|
||||||
window.raise()
|
window.raise()
|
||||||
window.requestActivate()
|
window.requestActivate()
|
||||||
|
|
|
@ -6,7 +6,7 @@ from enum import Enum
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
from PyQt5.QtCore import QObject, QUrl, Qt
|
from PyQt5.QtCore import QObject, QUrl, Qt
|
||||||
from PyQt5.QtCore import pyqtProperty, pyqtSlot, pyqtSignal
|
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 PyQt5.QtQml import qmlRegisterType, QQmlApplicationEngine
|
||||||
|
|
||||||
from twisted.internet import protocol, error
|
from twisted.internet import protocol, error
|
||||||
|
@ -243,6 +243,11 @@ class Backend(QObject):
|
||||||
self._vncPort = 5900
|
self._vncPort = 5900
|
||||||
self._vncPassword = ""
|
self._vncPassword = ""
|
||||||
self._vncState = VNCState.OFF
|
self._vncState = VNCState.OFF
|
||||||
|
# Primary screen and mouse posistion
|
||||||
|
self._cursor_x: int
|
||||||
|
self._cursor_y: int
|
||||||
|
self._primaryDisplayWidth: int
|
||||||
|
self._primaryDisplayHeight: int
|
||||||
# objects
|
# objects
|
||||||
self.xrandr = XRandR()
|
self.xrandr = XRandR()
|
||||||
|
|
||||||
|
@ -306,6 +311,30 @@ class Backend(QObject):
|
||||||
self._vncState = state
|
self._vncState = state
|
||||||
self.vncStateChanged.emit(self._vncState.value)
|
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
|
# Qt Slots
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def createVirtScreen(self):
|
def createVirtScreen(self):
|
||||||
|
@ -417,7 +446,7 @@ if __name__ == '__main__':
|
||||||
engine = QQmlApplicationEngine()
|
engine = QQmlApplicationEngine()
|
||||||
engine.load(QUrl('main.qml'))
|
engine.load(QUrl('main.qml'))
|
||||||
if not engine.rootObjects():
|
if not engine.rootObjects():
|
||||||
print("Failed to load qml")
|
QMessageBox.critical(None, "VirtScreen", "Failed to load qml")
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue