summaryrefslogtreecommitdiffstats
path: root/kkbswitch/xkeyboard.h
blob: dc2454aa82dd81c44e9fa8f6326d8bdd0982fb11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/***************************************************************************
                          xkeyboard.h  -  description
                             -------------------
    begin                : Sun Jul 8 2001
    copyright            : (C) 2001 by Leonid Zeitlin
    email                : lz@europe.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef XKEYBOARD_H
#define XKEYBOARD_H

#include "config.h"

#include <ntqobject.h>

#include <X11/Xlib.h>
#include <X11/XKBlib.h>

#ifdef HAVE_LIBXKLAVIER
  #include <libxklavier/xklavier.h>
#endif

class TQStringList;

/**This class incapsulates XKeyboard Extension interface
  *@author Leonid Zeitlin
  */
  
class XKeyboard : public TQObject {
  Q_OBJECT
private:
#ifndef HAVE_LIBXKLAVIER
  int m_event_code;
  int m_numgroups;
#endif  
  static XKeyboard *m_self;
  bool m_xkb_available;
public:
  static const int MaxNumKbdGroups = XkbNumKbdGroups;
  XKeyboard();
  ~XKeyboard();
  /** Set the current keyboard group to the given groupno */
  void setGroupNo(int groupno);
  /** Get the names of the currently configured keyboard groups */
  void getGroupNames(TQStringList &list);
  static XKeyboard* self();
  /** return the current keyboard group index */
  int getGroupNo();
  /** return if XKEYBOARD extension is available in the X server */
  bool xkbAvailable() { return m_xkb_available; }
#ifdef HAVE_LIBXKLAVIER
  int getNumKbdGroups() { return XklGetNumGroups(); };
#else  
  int getNumKbdGroups() { return m_numgroups; };
#endif  
  /** Examines an X Event passed to it and takes actions if the event is of
    * interest to XKeyboard */
  void processEvent(XEvent *ev);
private: // Private methods
#ifdef HAVE_LIBXKLAVIER
  static void XklStateCallback(XklStateChange changeType, int group,
    Bool /*restore*/, void* /*userData*/);
  static void XklConfigCallback(void */*userData*/);
  static void XklLogAppender(const char file[], const char function[],
    int level, const char format[], va_list args);
#else
  /** No descriptions */
  void retrieveNumKbdGroups();
#endif  
signals: // Signals
  /** Signals that new keyboard group is selected */
  void groupChanged(int groupno);
  /** Signals that keyboard layout has changed and thus we need to reconfigure */
  void layoutChanged();
};

#endif