Turn Xkb into a QObject

Reduced dependencies on other classes and allows to emit signal directly
instead of emitting a signal on another class.
This commit is contained in:
Martin Flöser 2017-08-13 20:43:28 +02:00
parent fcfe48ea6b
commit 08ae17e265
3 changed files with 11 additions and 8 deletions

View file

@ -47,6 +47,7 @@ KeyboardInputRedirection::KeyboardInputRedirection(InputRedirection *parent)
, m_input(parent) , m_input(parent)
, m_xkb(new Xkb(parent)) , m_xkb(new Xkb(parent))
{ {
connect(m_xkb.data(), &Xkb::ledsChanged, this, &KeyboardInputRedirection::ledsChanged);
} }
KeyboardInputRedirection::~KeyboardInputRedirection() = default; KeyboardInputRedirection::~KeyboardInputRedirection() = default;

View file

@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
#include "xkb.h" #include "xkb.h"
#include "keyboard_input.h"
#include "utils.h" #include "utils.h"
#include "wayland_server.h" #include "wayland_server.h"
// frameworks // frameworks
@ -66,8 +65,8 @@ static void xkbLogHandler(xkb_context *context, xkb_log_level priority, const ch
} }
} }
Xkb::Xkb(InputRedirection *input) Xkb::Xkb(QObject *parent)
: m_input(input) : QObject(parent)
, m_context(xkb_context_new(static_cast<xkb_context_flags>(0))) , m_context(xkb_context_new(static_cast<xkb_context_flags>(0)))
, m_keymap(NULL) , m_keymap(NULL)
, m_state(NULL) , m_state(NULL)
@ -237,7 +236,7 @@ void Xkb::createKeymapFile()
} }
const uint size = qstrlen(keymapString.data()) + 1; const uint size = qstrlen(keymapString.data()) + 1;
QTemporaryFile *tmp = new QTemporaryFile(m_input); QTemporaryFile *tmp = new QTemporaryFile(this);
if (!tmp->open()) { if (!tmp->open()) {
delete tmp; delete tmp;
return; return;
@ -327,7 +326,7 @@ void Xkb::updateModifiers()
} }
if (m_leds != leds) { if (m_leds != leds) {
m_leds = leds; m_leds = leds;
emit m_input->keyboard()->ledsChanged(m_leds); emit ledsChanged(m_leds);
} }
m_currentLayout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE); m_currentLayout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE);

9
xkb.h
View file

@ -41,10 +41,11 @@ typedef uint32_t xkb_layout_index_t;
namespace KWin namespace KWin
{ {
class KWIN_EXPORT Xkb class KWIN_EXPORT Xkb : public QObject
{ {
Q_OBJECT
public: public:
Xkb(InputRedirection *input); Xkb(QObject *parent = nullptr);
~Xkb(); ~Xkb();
void setConfig(KSharedConfigPtr config) { void setConfig(KSharedConfigPtr config) {
m_config = config; m_config = config;
@ -98,6 +99,9 @@ public:
**/ **/
void forwardModifiers(); void forwardModifiers();
Q_SIGNALS:
void ledsChanged(const LEDs &leds);
private: private:
xkb_keymap *loadKeymapFromConfig(); xkb_keymap *loadKeymapFromConfig();
xkb_keymap *loadDefaultKeymap(); xkb_keymap *loadDefaultKeymap();
@ -106,7 +110,6 @@ private:
void updateModifiers(); void updateModifiers();
void updateConsumedModifiers(uint32_t key); void updateConsumedModifiers(uint32_t key);
QString layoutName(xkb_layout_index_t layout) const; QString layoutName(xkb_layout_index_t layout) const;
InputRedirection *m_input;
xkb_context *m_context; xkb_context *m_context;
xkb_keymap *m_keymap; xkb_keymap *m_keymap;
xkb_state *m_state; xkb_state *m_state;