File indexing completed on 2024-11-10 04:56:51
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2009 Lucas Murray <lmurray@undefinedfire.com> 0006 SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "kwinscreenedgeconfigform.h" 0012 #include "ui_main.h" 0013 0014 namespace KWin 0015 { 0016 0017 KWinScreenEdgesConfigForm::KWinScreenEdgesConfigForm(QWidget *parent) 0018 : KWinScreenEdge(parent) 0019 , ui(std::make_unique<Ui::KWinScreenEdgesConfigUI>()) 0020 { 0021 ui->setupUi(this); 0022 0023 connect(ui->kcfg_ElectricBorderDelay, qOverload<int>(&QSpinBox::valueChanged), this, &KWinScreenEdgesConfigForm::sanitizeCooldown); 0024 0025 // Visual feedback of action group conflicts 0026 connect(ui->kcfg_ElectricBorders, qOverload<int>(&QComboBox::currentIndexChanged), this, &KWinScreenEdgesConfigForm::groupChanged); 0027 connect(ui->kcfg_ElectricBorderMaximize, &QCheckBox::stateChanged, this, &KWinScreenEdgesConfigForm::groupChanged); 0028 connect(ui->kcfg_ElectricBorderTiling, &QCheckBox::stateChanged, this, &KWinScreenEdgesConfigForm::groupChanged); 0029 0030 connect(ui->remainActiveOnFullscreen, &QCheckBox::stateChanged, this, &KWinScreenEdgesConfigForm::onChanged); 0031 connect(ui->electricBorderCornerRatioSpin, qOverload<int>(&QSpinBox::valueChanged), this, &KWinScreenEdgesConfigForm::onChanged); 0032 connect(ui->electricBorderCornerRatioSpin, qOverload<int>(&QSpinBox::valueChanged), this, &KWinScreenEdgesConfigForm::updateDefaultIndicators); 0033 } 0034 0035 KWinScreenEdgesConfigForm::~KWinScreenEdgesConfigForm() = default; 0036 0037 void KWinScreenEdgesConfigForm::setElectricBorderCornerRatio(double value) 0038 { 0039 m_referenceCornerRatio = value; 0040 ui->electricBorderCornerRatioSpin->setValue(m_referenceCornerRatio * 100.); 0041 } 0042 0043 void KWinScreenEdgesConfigForm::setDefaultElectricBorderCornerRatio(double value) 0044 { 0045 m_defaultCornerRatio = value; 0046 updateDefaultIndicators(); 0047 } 0048 0049 void KWinScreenEdgesConfigForm::setRemainActiveOnFullscreen(bool remainActive) 0050 { 0051 m_remainActiveOnFullscreen = remainActive; 0052 ui->remainActiveOnFullscreen->setChecked(remainActive); 0053 updateDefaultIndicators(); 0054 } 0055 0056 double KWinScreenEdgesConfigForm::electricBorderCornerRatio() const 0057 { 0058 return ui->electricBorderCornerRatioSpin->value() / 100.; 0059 } 0060 0061 void KWinScreenEdgesConfigForm::setElectricBorderCornerRatioEnabled(bool enable) 0062 { 0063 ui->electricBorderCornerRatioSpin->setEnabled(enable); 0064 } 0065 0066 void KWinScreenEdgesConfigForm::reload() 0067 { 0068 ui->electricBorderCornerRatioSpin->setValue(m_referenceCornerRatio * 100.); 0069 KWinScreenEdge::reload(); 0070 } 0071 0072 void KWinScreenEdgesConfigForm::setDefaults() 0073 { 0074 ui->electricBorderCornerRatioSpin->setValue(m_defaultCornerRatio * 100.); 0075 ui->remainActiveOnFullscreen->setChecked(false); 0076 KWinScreenEdge::setDefaults(); 0077 } 0078 0079 void KWinScreenEdgesConfigForm::setDefaultsIndicatorsVisible(bool visible) 0080 { 0081 if (m_defaultIndicatorVisible != visible) { 0082 m_defaultIndicatorVisible = visible; 0083 updateDefaultIndicators(); 0084 } 0085 } 0086 0087 bool KWinScreenEdgesConfigForm::remainActiveOnFullscreen() const 0088 { 0089 return ui->remainActiveOnFullscreen->isChecked(); 0090 } 0091 0092 Monitor *KWinScreenEdgesConfigForm::monitor() const 0093 { 0094 return ui->monitor; 0095 } 0096 0097 bool KWinScreenEdgesConfigForm::isSaveNeeded() const 0098 { 0099 return m_referenceCornerRatio != electricBorderCornerRatio() || m_remainActiveOnFullscreen != remainActiveOnFullscreen(); 0100 } 0101 0102 bool KWinScreenEdgesConfigForm::isDefault() const 0103 { 0104 return m_defaultCornerRatio == electricBorderCornerRatio() && m_remainActiveOnFullscreen == false; 0105 } 0106 0107 void KWinScreenEdgesConfigForm::sanitizeCooldown() 0108 { 0109 ui->kcfg_ElectricBorderCooldown->setMinimum(ui->kcfg_ElectricBorderDelay->value() + 50); 0110 } 0111 0112 void KWinScreenEdgesConfigForm::groupChanged() 0113 { 0114 // Monitor conflicts 0115 bool hide = false; 0116 if (ui->kcfg_ElectricBorders->currentIndex() == 2) { 0117 hide = true; 0118 } 0119 monitorHideEdge(ElectricTop, hide); 0120 monitorHideEdge(ElectricRight, hide); 0121 monitorHideEdge(ElectricBottom, hide); 0122 monitorHideEdge(ElectricLeft, hide); 0123 } 0124 0125 void KWinScreenEdgesConfigForm::updateDefaultIndicators() 0126 { 0127 ui->electricBorderCornerRatioSpin->setProperty("_kde_highlight_neutral", m_defaultIndicatorVisible && (electricBorderCornerRatio() != m_defaultCornerRatio)); 0128 ui->electricBorderCornerRatioSpin->update(); 0129 ui->remainActiveOnFullscreen->setProperty("_kde_highlight_neutral", m_defaultIndicatorVisible && remainActiveOnFullscreen() == true); 0130 ui->remainActiveOnFullscreen->update(); 0131 } 0132 0133 } // namespace 0134 0135 #include "moc_kwinscreenedgeconfigform.cpp"