1 /*************************************************************************** 2 * Copyright (c) 2013 Nikita Mikhaylov <nslqqq@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the 16 * Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 ***************************************************************************/ 19 20 #include "KeyboardModel.h" 21 #include "KeyboardModel_p.h" 22 #include "XcbKeyboardBackend.h" 23 24 namespace SDDM { 25 /**********************************************/ 26 /* KeyboardModel */ 27 /**********************************************/ 28 KeyboardModel()29 KeyboardModel::KeyboardModel() : d(new KeyboardModelPrivate) { 30 m_backend = new XcbKeyboardBackend(d); 31 m_backend->init(); 32 m_backend->connectEventsDispatcher(this); 33 } 34 ~KeyboardModel()35 KeyboardModel::~KeyboardModel() { 36 m_backend->disconnect(); 37 delete m_backend; 38 39 for (QObject *layout: d->layouts) { 40 delete layout; 41 } 42 delete d; 43 } 44 numLockState() const45 bool KeyboardModel::numLockState() const { 46 return d->numlock.enabled; 47 } 48 setNumLockState(bool state)49 void KeyboardModel::setNumLockState(bool state) { 50 if (d->numlock.enabled != state) { 51 d->numlock.enabled = state; 52 m_backend->sendChanges(); 53 54 emit numLockStateChanged(); 55 } 56 } 57 capsLockState() const58 bool KeyboardModel::capsLockState() const { 59 return d->capslock.enabled; 60 } 61 setCapsLockState(bool state)62 void KeyboardModel::setCapsLockState(bool state) { 63 if (d->capslock.enabled != state) { 64 d->capslock.enabled = state; 65 m_backend->sendChanges(); 66 67 emit capsLockStateChanged(); 68 } 69 } 70 layouts() const71 QList<QObject*> KeyboardModel::layouts() const { 72 return d->layouts; 73 } 74 currentLayout() const75 int KeyboardModel::currentLayout() const { 76 return d->layout_id; 77 } 78 setCurrentLayout(int id)79 void KeyboardModel::setCurrentLayout(int id) { 80 if (d->layout_id != id) { 81 d->layout_id = id; 82 m_backend->sendChanges(); 83 84 emit currentLayoutChanged(); 85 } 86 } 87 enabled() const88 bool KeyboardModel::enabled() const { 89 return d->enabled; 90 } 91 dispatchEvents()92 void KeyboardModel::dispatchEvents() { 93 // Save old states 94 bool num_old = d->numlock.enabled, caps_old = d->capslock.enabled; 95 int layout_old = d->layout_id; 96 QList<QObject*> layouts_old = d->layouts; 97 98 // Process events 99 m_backend->dispatchEvents(); 100 101 // Send updates 102 if (caps_old != d->capslock.enabled) 103 emit capsLockStateChanged(); 104 105 if (num_old != d->numlock.enabled) 106 emit numLockStateChanged(); 107 108 if (layout_old != d->layout_id) 109 emit currentLayoutChanged(); 110 111 if (layouts_old != d->layouts) 112 emit layoutsChanged(); 113 } 114 } 115 116 #include "moc_KeyboardModel.cpp" 117