Changeset View
Changeset View
Standalone View
Standalone View
keyboard_layout_switching.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
55 | Policy *Policy::create(Xkb *xkb, KeyboardLayout *layout, const QString &policy) | 55 | Policy *Policy::create(Xkb *xkb, KeyboardLayout *layout, const QString &policy) | ||
56 | { | 56 | { | ||
57 | if (policy.toLower() == QStringLiteral("desktop")) { | 57 | if (policy.toLower() == QStringLiteral("desktop")) { | ||
58 | return new VirtualDesktopPolicy(xkb, layout); | 58 | return new VirtualDesktopPolicy(xkb, layout); | ||
59 | } | 59 | } | ||
60 | if (policy.toLower() == QStringLiteral("window")) { | 60 | if (policy.toLower() == QStringLiteral("window")) { | ||
61 | return new WindowPolicy(xkb, layout); | 61 | return new WindowPolicy(xkb, layout); | ||
62 | } | 62 | } | ||
63 | if (policy.toLower() == QStringLiteral("winclass")) { | ||||
64 | return new ApplicationPolicy(xkb, layout); | ||||
65 | } | ||||
63 | return new GlobalPolicy(xkb, layout); | 66 | return new GlobalPolicy(xkb, layout); | ||
64 | } | 67 | } | ||
65 | 68 | | |||
66 | GlobalPolicy::GlobalPolicy(Xkb *xkb, KeyboardLayout *layout) | 69 | GlobalPolicy::GlobalPolicy(Xkb *xkb, KeyboardLayout *layout) | ||
67 | : Policy(xkb, layout) | 70 | : Policy(xkb, layout) | ||
68 | { | 71 | { | ||
69 | } | 72 | } | ||
70 | 73 | | |||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 161 | { | |||
177 | } else { | 180 | } else { | ||
178 | if (it.value() == l) { | 181 | if (it.value() == l) { | ||
179 | return; | 182 | return; | ||
180 | } | 183 | } | ||
181 | it.value() = l; | 184 | it.value() = l; | ||
182 | } | 185 | } | ||
183 | } | 186 | } | ||
184 | 187 | | |||
188 | ApplicationPolicy::ApplicationPolicy(KWin::Xkb* xkb, KWin::KeyboardLayout* layout) | ||||
189 | : Policy(xkb, layout) | ||||
190 | { | ||||
191 | connect(workspace(), &Workspace::clientActivated, this, &ApplicationPolicy::clientActivated); | ||||
192 | } | ||||
193 | | ||||
194 | ApplicationPolicy::~ApplicationPolicy() | ||||
195 | { | ||||
196 | } | ||||
197 | | ||||
198 | void ApplicationPolicy::clientActivated(AbstractClient *c) | ||||
199 | { | ||||
200 | if (!c) { | ||||
201 | return; | ||||
202 | } | ||||
203 | // ignore some special types | ||||
204 | if (c->isDesktop() || c->isDock()) { | ||||
205 | return; | ||||
206 | } | ||||
207 | quint32 layout = 0; | ||||
208 | for (auto it = m_layouts.constBegin(); it != m_layouts.constEnd(); it++) { | ||||
209 | if (AbstractClient::belongToSameApplication(c, it.key())) { | ||||
210 | layout = it.value(); | ||||
211 | break; | ||||
212 | } | ||||
213 | } | ||||
214 | setLayout(layout); | ||||
215 | } | ||||
216 | | ||||
217 | void ApplicationPolicy::clearCache() | ||||
218 | { | ||||
219 | m_layouts.clear(); | ||||
220 | } | ||||
221 | | ||||
222 | void ApplicationPolicy::layoutChanged() | ||||
223 | { | ||||
224 | auto c = workspace()->activeClient(); | ||||
225 | if (!c) { | ||||
226 | return; | ||||
227 | } | ||||
228 | // ignore some special types | ||||
229 | if (c->isDesktop() || c->isDock()) { | ||||
230 | return; | ||||
231 | } | ||||
232 | | ||||
233 | auto it = m_layouts.find(c); | ||||
234 | const auto l = layout(); | ||||
235 | if (it == m_layouts.constEnd()) { | ||||
236 | m_layouts.insert(c, l); | ||||
237 | connect(c, &AbstractClient::windowClosed, this, | ||||
238 | [this, c] { | ||||
239 | m_layouts.remove(c); | ||||
240 | } | ||||
241 | ); | ||||
242 | } else { | ||||
243 | if (it.value() == l) { | ||||
244 | return; | ||||
245 | } | ||||
246 | it.value() = l; | ||||
247 | } | ||||
248 | // update all layouts for the application | ||||
249 | for (it = m_layouts.begin(); it != m_layouts.end(); it++) { | ||||
250 | if (!AbstractClient::belongToSameApplication(it.key(), c)) { | ||||
251 | continue; | ||||
252 | } | ||||
253 | it.value() = l; | ||||
254 | } | ||||
255 | } | ||||
256 | | ||||
185 | } | 257 | } | ||
186 | } | 258 | } |