Skip to content

Commit

Permalink
Add Wayland Support
Browse files Browse the repository at this point in the history
  • Loading branch information
rafatosta committed Jan 14, 2025
1 parent fe7019e commit d1db96a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
10 changes: 7 additions & 3 deletions zapzap/config/SetupManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
class SetupManager:
"""Gerencia as configurações de ambiente para o aplicativo."""

_abs_path = QFileInfo(__file__).absolutePath()
_is_flatpak = _abs_path.startswith('/app/')
_is_flatpak = QFileInfo(__file__).absolutePath().startswith('/app/')
_qt_platform = "xcb" # Valor padrão

@staticmethod
def apply():
"""
Aplica configurações específicas de ambiente dependendo do ambiente de execução.
Configura a plataforma gráfica e escalonamento de tela.
"""
if not SetupManager._is_flatpak:
SetupManager._qt_platform = "wayland" if SettingsManager.get(
"system/wayland", False) else "xcb"

environ['QT_QPA_PLATFORM'] = SetupManager._qt_platform

environ['QT_QPA_PLATFORM'] = "xcb"
environ['QT_SCALE_FACTOR'] = str(int(SettingsManager.get(
"system/scale", 100))/100)
environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1'
Expand Down
11 changes: 11 additions & 0 deletions zapzap/controllers/PageGeneral.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from PyQt6.QtWidgets import QWidget, QApplication, QStyle
from zapzap.config.SetupManager import SetupManager
from zapzap.services.AutostartManager import AutostartManager
from zapzap.services.DictionariesManager import DictionariesManager
from zapzap.services.DownloadManager import DownloadManager
Expand Down Expand Up @@ -28,6 +29,10 @@ def _configure_ui(self):
self.style().standardIcon(QStyle.StandardPixmap.SP_DirIcon))
self.btn_default_path_spell.setIcon(self.style().standardIcon(
QStyle.StandardPixmap.SP_DialogResetButton))

if SetupManager._is_flatpak:
self.btn_wayland.setDisabled(True)
self.btn_wayland.setToolTip("Use Flatseal to change this mode of execution.")

def _load_settings(self):
"""
Expand Down Expand Up @@ -61,6 +66,9 @@ def _load_settings(self):
self.btn_start_system.setChecked(
SettingsManager.get("system/start_system", False))

self.btn_wayland.setChecked(
SettingsManager.get("system/wayland", False))

def _configure_signals(self):
"""
Conecta os sinais dos widgets aos respectivos manipuladores:
Expand All @@ -81,6 +89,9 @@ def _configure_signals(self):
lambda: SettingsManager.set("system/start_background", self.btn_start_background.isChecked()))
self.btn_start_system.clicked.connect(self._handle_autostart)

self.btn_wayland.clicked.connect(
lambda: SettingsManager.set("system/wayland", self.btn_wayland.isChecked()))

def _handle_spellcheck(self, lang: str):
"""
Manipula a mudança de idioma para o corretor ortográfico.
Expand Down
14 changes: 14 additions & 0 deletions zapzap/ui/ui_page_general.ui
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="btn_wayland">
<property name="text">
<string>Wayland window system</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
9 changes: 9 additions & 0 deletions zapzap/views/ui_page_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def setupUi(self, PageGeneral):
self.btn_start_system = QtWidgets.QCheckBox(parent=self.groupBox_2)
self.btn_start_system.setObjectName("btn_start_system")
self.verticalLayout.addWidget(self.btn_start_system)
self.line = QtWidgets.QFrame(parent=self.groupBox_2)
self.line.setFrameShape(QtWidgets.QFrame.Shape.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
self.line.setObjectName("line")
self.verticalLayout.addWidget(self.line)
self.btn_wayland = QtWidgets.QCheckBox(parent=self.groupBox_2)
self.btn_wayland.setObjectName("btn_wayland")
self.verticalLayout.addWidget(self.btn_wayland)
self.verticalLayout_2.addWidget(self.groupBox_2)
self.horizontalLayout.addWidget(self.frame)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
Expand All @@ -117,6 +125,7 @@ def retranslateUi(self, PageGeneral):
self.btn_quit_in_close.setText(_translate("PageGeneral", "Closer when closing the window"))
self.btn_start_background.setText(_translate("PageGeneral", "Start minimized"))
self.btn_start_system.setText(_translate("PageGeneral", "Start with the system"))
self.btn_wayland.setText(_translate("PageGeneral", "Wayland window system"))


if __name__ == "__main__":
Expand Down

0 comments on commit d1db96a

Please sign in to comment.