Changeset View
Changeset View
Standalone View
Standalone View
globalshortcuts.cpp
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | |||||
102 | { | 102 | { | ||
103 | for (auto it = shortcuts.begin(); it != shortcuts.end(); ++it) { | 103 | for (auto it = shortcuts.begin(); it != shortcuts.end(); ++it) { | ||
104 | qDeleteAll((*it)); | 104 | qDeleteAll((*it)); | ||
105 | } | 105 | } | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | GlobalShortcutsManager::~GlobalShortcutsManager() | 108 | GlobalShortcutsManager::~GlobalShortcutsManager() | ||
109 | { | 109 | { | ||
110 | clearShortcuts(m_shortcuts); | | |||
111 | clearShortcuts(m_pointerShortcuts); | 110 | clearShortcuts(m_pointerShortcuts); | ||
112 | clearShortcuts(m_axisShortcuts); | 111 | clearShortcuts(m_axisShortcuts); | ||
113 | } | 112 | } | ||
114 | 113 | | |||
115 | void GlobalShortcutsManager::init() | 114 | void GlobalShortcutsManager::init() | ||
116 | { | 115 | { | ||
117 | if (kwinApp()->shouldUseWaylandForCompositing()) { | 116 | if (kwinApp()->shouldUseWaylandForCompositing()) { | ||
118 | qputenv("KGLOBALACCELD_PLATFORM", QByteArrayLiteral("org.kde.kwin")); | 117 | qputenv("KGLOBALACCELD_PLATFORM", QByteArrayLiteral("org.kde.kwin")); | ||
Show All 24 Lines | 135 | while (it2 != list.end()) { | |||
143 | } | 142 | } | ||
144 | ++it2; | 143 | ++it2; | ||
145 | } | 144 | } | ||
146 | } | 145 | } | ||
147 | } | 146 | } | ||
148 | 147 | | |||
149 | void GlobalShortcutsManager::objectDeleted(QObject *object) | 148 | void GlobalShortcutsManager::objectDeleted(QObject *object) | ||
150 | { | 149 | { | ||
151 | handleDestroyedAction(object, m_shortcuts); | | |||
152 | handleDestroyedAction(object, m_pointerShortcuts); | 150 | handleDestroyedAction(object, m_pointerShortcuts); | ||
153 | handleDestroyedAction(object, m_axisShortcuts); | 151 | handleDestroyedAction(object, m_axisShortcuts); | ||
154 | } | 152 | } | ||
155 | 153 | | |||
156 | template <typename T, typename R> | 154 | template <typename T, typename R> | ||
157 | void addShortcut(T &shortcuts, QAction *action, Qt::KeyboardModifiers modifiers, R value) | 155 | void addShortcut(T &shortcuts, QAction *action, Qt::KeyboardModifiers modifiers, R value) | ||
158 | { | 156 | { | ||
159 | GlobalShortcut *cut = new InternalGlobalShortcut(modifiers, value, action); | 157 | GlobalShortcut *cut = new InternalGlobalShortcut(modifiers, value, action); | ||
160 | auto it = shortcuts.find(modifiers); | 158 | auto it = shortcuts.find(modifiers); | ||
161 | if (it != shortcuts.end()) { | 159 | if (it != shortcuts.end()) { | ||
162 | // TODO: check if shortcut already exists | 160 | // TODO: check if shortcut already exists | ||
163 | (*it).insert(value, cut); | 161 | (*it).insert(value, cut); | ||
164 | } else { | 162 | } else { | ||
165 | QHash<R, GlobalShortcut*> s; | 163 | QHash<R, GlobalShortcut*> s; | ||
166 | s.insert(value, cut); | 164 | s.insert(value, cut); | ||
167 | shortcuts.insert(modifiers, s); | 165 | shortcuts.insert(modifiers, s); | ||
168 | } | 166 | } | ||
169 | } | 167 | } | ||
170 | 168 | | |||
171 | void GlobalShortcutsManager::registerShortcut(QAction *action, const QKeySequence &shortcut) | | |||
172 | { | | |||
173 | QKeySequence s = getShortcutForAction(KWIN_NAME, action->objectName(), shortcut); | | |||
romangg: `getShortcutForAction` was only called here, so you could remove this function aswell? | |||||
174 | if (s.isEmpty()) { | | |||
175 | // TODO: insert into a list of empty shortcuts to react on changes | | |||
176 | return; | | |||
177 | } | | |||
178 | int keys = s[0]; | | |||
179 | Qt::KeyboardModifiers mods = Qt::NoModifier; | | |||
180 | if (keys & Qt::ShiftModifier) { | | |||
181 | mods |= Qt::ShiftModifier; | | |||
182 | } | | |||
183 | if (keys & Qt::ControlModifier) { | | |||
184 | mods |= Qt::ControlModifier; | | |||
185 | } | | |||
186 | if (keys & Qt::AltModifier) { | | |||
187 | mods |= Qt::AltModifier; | | |||
188 | } | | |||
189 | if (keys & Qt::MetaModifier) { | | |||
190 | mods |= Qt::MetaModifier; | | |||
191 | } | | |||
192 | int keysym = 0; | | |||
193 | if (!KKeyServer::keyQtToSymX(keys, &keysym)) { | | |||
194 | return; | | |||
195 | } | | |||
196 | addShortcut(m_shortcuts, action, mods, static_cast<uint32_t>(keysym)); | | |||
197 | connect(action, &QAction::destroyed, this, &GlobalShortcutsManager::objectDeleted); | | |||
198 | } | | |||
199 | | ||||
200 | void GlobalShortcutsManager::registerPointerShortcut(QAction *action, Qt::KeyboardModifiers modifiers, Qt::MouseButtons pointerButtons) | 169 | void GlobalShortcutsManager::registerPointerShortcut(QAction *action, Qt::KeyboardModifiers modifiers, Qt::MouseButtons pointerButtons) | ||
201 | { | 170 | { | ||
202 | addShortcut(m_pointerShortcuts, action, modifiers, pointerButtons); | 171 | addShortcut(m_pointerShortcuts, action, modifiers, pointerButtons); | ||
203 | connect(action, &QAction::destroyed, this, &GlobalShortcutsManager::objectDeleted); | 172 | connect(action, &QAction::destroyed, this, &GlobalShortcutsManager::objectDeleted); | ||
204 | } | 173 | } | ||
205 | 174 | | |||
206 | void GlobalShortcutsManager::registerAxisShortcut(QAction *action, Qt::KeyboardModifiers modifiers, PointerAxisDirection axis) | 175 | void GlobalShortcutsManager::registerAxisShortcut(QAction *action, Qt::KeyboardModifiers modifiers, PointerAxisDirection axis) | ||
207 | { | 176 | { | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 230 | } else if (keyQt == Qt::Key_Backtab) { | |||
269 | if (check(mods | Qt::ShiftModifier, keyQt)) { | 238 | if (check(mods | Qt::ShiftModifier, keyQt)) { | ||
270 | return true; | 239 | return true; | ||
271 | } | 240 | } | ||
272 | if (check(mods | Qt::ShiftModifier, Qt::Key_Tab)) { | 241 | if (check(mods | Qt::ShiftModifier, Qt::Key_Tab)) { | ||
273 | return true; | 242 | return true; | ||
274 | } | 243 | } | ||
275 | } | 244 | } | ||
276 | } | 245 | } | ||
277 | if (processShortcut(mods, key, m_shortcuts)) { | | |||
278 | return true; | | |||
279 | } | | |||
280 | return false; | 246 | return false; | ||
281 | } | 247 | } | ||
282 | 248 | | |||
283 | bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Qt::MouseButtons pointerButtons) | 249 | bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Qt::MouseButtons pointerButtons) | ||
284 | { | 250 | { | ||
285 | return processShortcut(mods, pointerButtons, m_pointerShortcuts); | 251 | return processShortcut(mods, pointerButtons, m_pointerShortcuts); | ||
286 | } | 252 | } | ||
287 | 253 | | |||
288 | bool GlobalShortcutsManager::processAxis(Qt::KeyboardModifiers mods, PointerAxisDirection axis) | 254 | bool GlobalShortcutsManager::processAxis(Qt::KeyboardModifiers mods, PointerAxisDirection axis) | ||
289 | { | 255 | { | ||
290 | return processShortcut(mods, axis, m_axisShortcuts); | 256 | return processShortcut(mods, axis, m_axisShortcuts); | ||
291 | } | 257 | } | ||
292 | 258 | | |||
293 | } // namespace | 259 | } // namespace |
getShortcutForAction was only called here, so you could remove this function aswell?