mirror of
https://github.com/kbumsik/VirtScreen.git
synced 2025-03-09 15:40:18 +00:00
UI:Separated display button and vnc button
This commit is contained in:
parent
03d7ae02bb
commit
726e71c126
1 changed files with 68 additions and 33 deletions
101
virtscreen.py
101
virtscreen.py
|
@ -85,7 +85,11 @@ class XRandR:
|
||||||
def _signal_handler(self, signum=None, frame=None) -> None:
|
def _signal_handler(self, signum=None, frame=None) -> None:
|
||||||
self.delete_virtual_screen()
|
self.delete_virtual_screen()
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
def get_virtual_screen(self) -> DisplayProperty:
|
||||||
|
self._update_virtual_screen()
|
||||||
|
return self.virt
|
||||||
|
|
||||||
def set_virtual_screen(self, width, height, portrait=False, hidpi=False):
|
def set_virtual_screen(self, width, height, portrait=False, hidpi=False):
|
||||||
self.virt.width = width
|
self.virt.width = width
|
||||||
self.virt.height = height
|
self.virt.height = height
|
||||||
|
@ -101,7 +105,8 @@ class XRandR:
|
||||||
self._add_screen_mode()
|
self._add_screen_mode()
|
||||||
self._check_call(f"xrandr --output {self.virt.name} --mode {self.mode_name}")
|
self._check_call(f"xrandr --output {self.virt.name} --mode {self.mode_name}")
|
||||||
self._check_call("sleep 5")
|
self._check_call("sleep 5")
|
||||||
self._check_call(f"xrandr --output {self.virt.name} {position} {self.primary.name}")
|
# self._check_call(f"xrandr --output {self.virt.name} {position} {self.primary.name}")
|
||||||
|
self._check_call(f"xrandr --output {self.virt.name} --auto")
|
||||||
self._update_primary_screen()
|
self._update_primary_screen()
|
||||||
self._update_virtual_screen()
|
self._update_virtual_screen()
|
||||||
|
|
||||||
|
@ -187,6 +192,7 @@ class Window(QDialog):
|
||||||
self.createTrayIcon()
|
self.createTrayIcon()
|
||||||
self.xrandr = XRandR()
|
self.xrandr = XRandR()
|
||||||
# Additional attributes
|
# Additional attributes
|
||||||
|
self.isDisplayCreated = False
|
||||||
self.isVNCRunning = False
|
self.isVNCRunning = False
|
||||||
# Update UI
|
# Update UI
|
||||||
self.update_ip_address()
|
self.update_ip_address()
|
||||||
|
@ -197,7 +203,8 @@ class Window(QDialog):
|
||||||
self.setLayout(mainLayout)
|
self.setLayout(mainLayout)
|
||||||
# Events
|
# Events
|
||||||
self.trayIcon.activated.connect(self.iconActivated)
|
self.trayIcon.activated.connect(self.iconActivated)
|
||||||
self.startVNCButton.pressed.connect(self.startPressed)
|
self.createDisplayButton.pressed.connect(self.createDisplayPressed)
|
||||||
|
self.startVNCButton.pressed.connect(self.startVNCPressed)
|
||||||
self.VNCMessageListWidget.model().rowsInserted.connect(
|
self.VNCMessageListWidget.model().rowsInserted.connect(
|
||||||
self.VNCMessageListWidget.scrollToBottom)
|
self.VNCMessageListWidget.scrollToBottom)
|
||||||
# Show
|
# Show
|
||||||
|
@ -230,13 +237,39 @@ class Window(QDialog):
|
||||||
event.ignore()
|
event.ignore()
|
||||||
else:
|
else:
|
||||||
QApplication.instance().quit()
|
QApplication.instance().quit()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def startPressed(self):
|
def createDisplayPressed(self):
|
||||||
if self.isVNCRunning:
|
if not self.isDisplayCreated:
|
||||||
self.VNCServer.kill()
|
# Create virtual screen
|
||||||
|
self.createDisplayButton.setEnabled(False)
|
||||||
|
width = self.displayWidthSpinBox.value()
|
||||||
|
height = self.displayHeightSpinBox.value()
|
||||||
|
portrait = self.displayPortraitCheckBox.isChecked()
|
||||||
|
hidpi = self.displayHIDPICheckBox.isChecked()
|
||||||
|
position = self.displayPositionComboBox.currentData()
|
||||||
|
self.xrandr.set_virtual_screen(width, height, portrait, hidpi)
|
||||||
|
self.xrandr.create_virtual_screen(position)
|
||||||
|
self.createDisplayButton.setText("Disable the virtual display")
|
||||||
|
self.isDisplayCreated = True
|
||||||
|
self.createDisplayButton.setEnabled(True)
|
||||||
|
self.startVNCButton.setEnabled(True)
|
||||||
else:
|
else:
|
||||||
|
# Delete the screen
|
||||||
|
self.createDisplayButton.setEnabled(False)
|
||||||
|
self.xrandr.delete_virtual_screen()
|
||||||
|
self.isDisplayCreated = False
|
||||||
|
self.createDisplayButton.setText("Create a Virtual Display")
|
||||||
|
self.createDisplayButton.setEnabled(True)
|
||||||
|
self.startVNCButton.setEnabled(False)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def startVNCPressed(self):
|
||||||
|
if not self.isVNCRunning:
|
||||||
|
self.createDisplayButton.setEnabled(False)
|
||||||
self.startVNC()
|
self.startVNC()
|
||||||
|
else:
|
||||||
|
self.VNCServer.kill()
|
||||||
|
|
||||||
@pyqtSlot('QSystemTrayIcon::ActivationReason')
|
@pyqtSlot('QSystemTrayIcon::ActivationReason')
|
||||||
def iconActivated(self, reason):
|
def iconActivated(self, reason):
|
||||||
|
@ -261,7 +294,7 @@ class Window(QDialog):
|
||||||
def createDisplayGroupBox(self):
|
def createDisplayGroupBox(self):
|
||||||
self.displayGroupBox = QGroupBox("Virtual Display Settings")
|
self.displayGroupBox = QGroupBox("Virtual Display Settings")
|
||||||
|
|
||||||
# First row
|
# Position Row
|
||||||
positionLabel = QLabel("Position:")
|
positionLabel = QLabel("Position:")
|
||||||
|
|
||||||
self.displayPositionComboBox = QComboBox()
|
self.displayPositionComboBox = QComboBox()
|
||||||
|
@ -274,7 +307,7 @@ class Window(QDialog):
|
||||||
self.displayPortraitCheckBox = QCheckBox("Portrait Mode")
|
self.displayPortraitCheckBox = QCheckBox("Portrait Mode")
|
||||||
self.displayPortraitCheckBox.setChecked(False)
|
self.displayPortraitCheckBox.setChecked(False)
|
||||||
|
|
||||||
# Second row
|
# Resolution Row
|
||||||
resolutionLabel = QLabel("Resolution:")
|
resolutionLabel = QLabel("Resolution:")
|
||||||
|
|
||||||
self.displayWidthSpinBox = QSpinBox()
|
self.displayWidthSpinBox = QSpinBox()
|
||||||
|
@ -292,23 +325,32 @@ class Window(QDialog):
|
||||||
self.displayHIDPICheckBox = QCheckBox("HiDPI (2x resolution)")
|
self.displayHIDPICheckBox = QCheckBox("HiDPI (2x resolution)")
|
||||||
self.displayHIDPICheckBox.setChecked(False)
|
self.displayHIDPICheckBox.setChecked(False)
|
||||||
|
|
||||||
# Putting them togather
|
# Start button
|
||||||
layout = QGridLayout()
|
self.createDisplayButton = QPushButton("Create a Virtual Display")
|
||||||
|
self.createDisplayButton.setDefault(True)
|
||||||
|
|
||||||
|
# Putting them together
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
|
# Grid layout for screen settings
|
||||||
|
gridLayout = QGridLayout()
|
||||||
# Display Position row
|
# Display Position row
|
||||||
layout.addWidget(positionLabel, 0, 0)
|
gridLayout.addWidget(positionLabel, 0, 0)
|
||||||
layout.addWidget(self.displayPositionComboBox, 0, 1, 1, 2)
|
gridLayout.addWidget(self.displayPositionComboBox, 0, 1, 1, 2)
|
||||||
layout.addWidget(self.displayPortraitCheckBox, 0, 6, 1, 2, Qt.AlignLeft)
|
gridLayout.addWidget(self.displayPortraitCheckBox, 0, 6, 1, 2, Qt.AlignLeft)
|
||||||
# Resolution row
|
# Resolution row
|
||||||
layout.addWidget(resolutionLabel, 1, 0)
|
gridLayout.addWidget(resolutionLabel, 1, 0)
|
||||||
layout.addWidget(self.displayWidthSpinBox, 1, 1, 1, 2)
|
gridLayout.addWidget(self.displayWidthSpinBox, 1, 1, 1, 2)
|
||||||
layout.addWidget(xLabel, 1, 3, Qt.AlignHCenter)
|
gridLayout.addWidget(xLabel, 1, 3, Qt.AlignHCenter)
|
||||||
layout.addWidget(self.displayHeightSpinBox, 1, 4, 1, 2)
|
gridLayout.addWidget(self.displayHeightSpinBox, 1, 4, 1, 2)
|
||||||
layout.addWidget(self.displayHIDPICheckBox, 1, 6, 1, 2, Qt.AlignLeft)
|
gridLayout.addWidget(self.displayHIDPICheckBox, 1, 6, 1, 2, Qt.AlignLeft)
|
||||||
# Set strectch
|
# Set strectch
|
||||||
layout.setColumnStretch(1, 0)
|
gridLayout.setColumnStretch(1, 0)
|
||||||
layout.setColumnStretch(3, 0)
|
gridLayout.setColumnStretch(3, 0)
|
||||||
# layout.setRowStretch(4, 1)
|
# layout.setRowStretch(4, 1)
|
||||||
|
|
||||||
|
layout.addLayout(gridLayout)
|
||||||
|
layout.addWidget(self.createDisplayButton)
|
||||||
self.displayGroupBox.setLayout(layout)
|
self.displayGroupBox.setLayout(layout)
|
||||||
|
|
||||||
def createVNCGroupBox(self):
|
def createVNCGroupBox(self):
|
||||||
|
@ -316,7 +358,7 @@ class Window(QDialog):
|
||||||
|
|
||||||
portLabel = QLabel("Port:")
|
portLabel = QLabel("Port:")
|
||||||
self.VNCPortSpinBox = QSpinBox()
|
self.VNCPortSpinBox = QSpinBox()
|
||||||
self.VNCPortSpinBox.setRange(5900, 6000)
|
self.VNCPortSpinBox.setRange(1, 65535)
|
||||||
self.VNCPortSpinBox.setValue(5900)
|
self.VNCPortSpinBox.setValue(5900)
|
||||||
|
|
||||||
IPLabel = QLabel("Connect a VNC client to one of:")
|
IPLabel = QLabel("Connect a VNC client to one of:")
|
||||||
|
@ -324,6 +366,7 @@ class Window(QDialog):
|
||||||
|
|
||||||
self.startVNCButton = QPushButton("Start VNC Server")
|
self.startVNCButton = QPushButton("Start VNC Server")
|
||||||
self.startVNCButton.setDefault(False)
|
self.startVNCButton.setDefault(False)
|
||||||
|
self.startVNCButton.setEnabled(False)
|
||||||
|
|
||||||
messageLabel = QLabel("Server Messages")
|
messageLabel = QLabel("Server Messages")
|
||||||
self.VNCMessageListWidget = QListWidget()
|
self.VNCMessageListWidget = QListWidget()
|
||||||
|
@ -388,35 +431,27 @@ class Window(QDialog):
|
||||||
self.VNCMessageListWidget.addItem(line)
|
self.VNCMessageListWidget.addItem(line)
|
||||||
def _onEnded(exitCode):
|
def _onEnded(exitCode):
|
||||||
self.startVNCButton.setEnabled(False)
|
self.startVNCButton.setEnabled(False)
|
||||||
self.xrandr.delete_virtual_screen()
|
|
||||||
self.isVNCRunning = False
|
self.isVNCRunning = False
|
||||||
self.VNCMessageListWidget.setEnabled(False)
|
self.VNCMessageListWidget.setEnabled(False)
|
||||||
self.startVNCButton.setText("Start VNC Server")
|
self.startVNCButton.setText("Start VNC Server")
|
||||||
self.startVNCButton.setEnabled(True)
|
self.startVNCButton.setEnabled(True)
|
||||||
|
self.createDisplayButton.setEnabled(True)
|
||||||
# Setting UI before starting
|
# Setting UI before starting
|
||||||
self.VNCMessageListWidget.clear()
|
self.VNCMessageListWidget.clear()
|
||||||
self.startVNCButton.setEnabled(False)
|
self.startVNCButton.setEnabled(False)
|
||||||
self.startVNCButton.setText("Running...")
|
self.startVNCButton.setText("Running...")
|
||||||
# Create virtual screen
|
|
||||||
width = self.displayWidthSpinBox.value()
|
|
||||||
height = self.displayHeightSpinBox.value()
|
|
||||||
portrait = self.displayPortraitCheckBox.isChecked()
|
|
||||||
hidpi = self.displayHIDPICheckBox.isChecked()
|
|
||||||
position = self.displayPositionComboBox.currentData()
|
|
||||||
self.xrandr.set_virtual_screen(width, height, portrait, hidpi)
|
|
||||||
self.xrandr.create_virtual_screen(position)
|
|
||||||
# Run VNC server
|
# Run VNC server
|
||||||
self.isVNCRunning = True
|
self.isVNCRunning = True
|
||||||
self.VNCServer = ProcessProtocol(_onReceived, _onReceived, _onEnded)
|
self.VNCServer = ProcessProtocol(_onReceived, _onReceived, _onEnded)
|
||||||
port = self.VNCPortSpinBox.value()
|
port = self.VNCPortSpinBox.value()
|
||||||
virt = self.xrandr.virt
|
virt = self.xrandr.get_virtual_screen()
|
||||||
clip = f"{virt.width}x{virt.height}+{virt.x_offset}+{virt.y_offset}"
|
clip = f"{virt.width}x{virt.height}+{virt.x_offset}+{virt.y_offset}"
|
||||||
arg = f"x11vnc -multiptr -repeat -rfbport {port} -clip {clip}"
|
arg = f"x11vnc -multiptr -repeat -rfbport {port} -clip {clip}"
|
||||||
self.VNCServer.run(arg)
|
self.VNCServer.run(arg)
|
||||||
# Change UI
|
# Change UI
|
||||||
self.VNCMessageListWidget.setEnabled(True)
|
self.VNCMessageListWidget.setEnabled(True)
|
||||||
self.startVNCButton.setEnabled(True)
|
self.startVNCButton.setEnabled(True)
|
||||||
self.startVNCButton.setText("Stop")
|
self.startVNCButton.setText("Stop Sharing")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Main Code
|
# Main Code
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue