File indexing completed on 2024-11-10 04:57:17
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "screenedgehandler.h" 0010 0011 #include <config-kwin.h> 0012 0013 #include "screenedge.h" 0014 #include "workspace.h" 0015 0016 #include <QAction> 0017 0018 namespace KWin 0019 { 0020 0021 ScreenEdgeHandler::ScreenEdgeHandler(QObject *parent) 0022 : QObject(parent) 0023 , m_enabled(true) 0024 , m_edge(NoEdge) 0025 , m_action(new QAction(this)) 0026 { 0027 connect(m_action, &QAction::triggered, this, &ScreenEdgeHandler::activated); 0028 } 0029 0030 ScreenEdgeHandler::~ScreenEdgeHandler() 0031 { 0032 } 0033 0034 void ScreenEdgeHandler::setEnabled(bool enabled) 0035 { 0036 if (m_enabled == enabled) { 0037 return; 0038 } 0039 disableEdge(); 0040 m_enabled = enabled; 0041 enableEdge(); 0042 Q_EMIT enabledChanged(); 0043 } 0044 0045 void ScreenEdgeHandler::setEdge(Edge edge) 0046 { 0047 if (m_edge == edge) { 0048 return; 0049 } 0050 disableEdge(); 0051 m_edge = edge; 0052 enableEdge(); 0053 Q_EMIT edgeChanged(); 0054 } 0055 0056 void ScreenEdgeHandler::enableEdge() 0057 { 0058 if (!m_enabled || m_edge == NoEdge) { 0059 return; 0060 } 0061 switch (m_mode) { 0062 case Mode::Pointer: 0063 workspace()->screenEdges()->reserve(static_cast<ElectricBorder>(m_edge), this, "borderActivated"); 0064 break; 0065 case Mode::Touch: 0066 workspace()->screenEdges()->reserveTouch(static_cast<ElectricBorder>(m_edge), m_action); 0067 break; 0068 default: 0069 Q_UNREACHABLE(); 0070 } 0071 } 0072 0073 void ScreenEdgeHandler::disableEdge() 0074 { 0075 if (!m_enabled || m_edge == NoEdge) { 0076 return; 0077 } 0078 switch (m_mode) { 0079 case Mode::Pointer: 0080 workspace()->screenEdges()->unreserve(static_cast<ElectricBorder>(m_edge), this); 0081 break; 0082 case Mode::Touch: 0083 workspace()->screenEdges()->unreserveTouch(static_cast<ElectricBorder>(m_edge), m_action); 0084 break; 0085 default: 0086 Q_UNREACHABLE(); 0087 } 0088 } 0089 0090 bool ScreenEdgeHandler::borderActivated(ElectricBorder edge) 0091 { 0092 if (edge != static_cast<ElectricBorder>(m_edge) || !m_enabled) { 0093 return false; 0094 } 0095 Q_EMIT activated(); 0096 return true; 0097 } 0098 0099 void ScreenEdgeHandler::setMode(Mode mode) 0100 { 0101 if (m_mode == mode) { 0102 return; 0103 } 0104 disableEdge(); 0105 m_mode = mode; 0106 enableEdge(); 0107 Q_EMIT modeChanged(); 0108 } 0109 0110 } // namespace 0111 0112 #include "moc_screenedgehandler.cpp"