summaryrefslogtreecommitdiff
path: root/libxklavier/xklavier_evt_xkb.c
blob: eb23aa1ed4cf466dbdcc99463b003c867296e793 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <time.h>

#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xlibint.h>

#include "xklavier_private.h"
#include "xklavier_private_xkb.h"

/**
 * XKB event handler
 */
gint
xkl_xkb_process_x_event(XEvent * xev)
{
#ifdef XKB_HEADERS_PRESENT
	gint i;
	guint bit;
	guint inds;
	XkbEvent *kev = (XkbEvent *) xev;

	if (xev->type != xkl_xkb_event_type)
		return 0;

	if (!(xkl_listener_type &
	      (XKLL_MANAGE_WINDOW_STATES | XKLL_TRACK_KEYBOARD_STATE)))
		return 0;

	xkl_debug(150, "Xkb event detected\n");

	switch (kev->any.xkb_type) {
    /**
     * Group is changed!
     */
	case XkbStateNotify:
#define GROUP_CHANGE_MASK \
    ( XkbGroupStateMask | XkbGroupBaseMask | XkbGroupLatchMask | XkbGroupLockMask )

		xkl_debug(150,
			  "XkbStateNotify detected, changes: %X/(mask %X), new group %d\n",
			  kev->state.changed, GROUP_CHANGE_MASK,
			  kev->state.locked_group);

		if (kev->state.changed & GROUP_CHANGE_MASK)
			xkl_process_state_modification(GROUP_CHANGED,
						       kev->state.
						       locked_group, 0,
						       FALSE);
		else {		/* ...not interested... */

			xkl_debug(200,
				  "This type of state notification is not regarding groups\n");
			if (kev->state.locked_group !=
			    xkl_current_state.group)
				xkl_debug(0,
					  "ATTENTION! Currently cached group %d is not equal to the current group from the event: %d\n!",
					  xkl_current_state.group,
					  kev->state.locked_group);
		}

		break;

    /**
     * Indicators are changed!
     */
	case XkbIndicatorStateNotify:

		xkl_debug(150, "XkbIndicatorStateNotify\n");

		inds = xkl_current_state.indicators;

		ForPhysIndicators(i,
				  bit) if (kev->indicators.changed & bit) {
			if (kev->indicators.state & bit)
				inds |= bit;
			else
				inds &= ~bit;
		}

		xkl_process_state_modification(INDICATORS_CHANGED,
					       0, inds, TRUE);
		break;

    /**
     * The configuration is changed!
     */
	case XkbIndicatorMapNotify:
	case XkbControlsNotify:
	case XkbNamesNotify:
#if 0
		/* not really fair - but still better than flooding... */
		XklDebug(200,
			 "warning: configuration event %s is not actually processed\n",
			 _XklXkbGetXkbEventName(kev->any.xkb_type));
		break;
#endif
	case XkbNewKeyboardNotify:
		xkl_debug(150, "%s\n",
			  xkl_xkb_event_get_name(kev->any.xkb_type));
		xkl_reset_all_info("XKB event: XkbNewKeyboardNotify");
		break;

    /**
     * ...Not interested...
     */
	default:
		xkl_debug(150, "Unknown XKB event %d [%s]\n",
			  kev->any.xkb_type,
			  xkl_xkb_event_get_name(kev->any.xkb_type));
		return 0;
	}
	return 1;
#else
	return 0;
#endif
}

void
xkl_xkb_indicators_set(const XklState * window_state)
{
#ifdef XKB_HEADERS_PRESENT
	int i;
	unsigned bit;

	ForPhysIndicators(i,
			  bit) if (xkl_xkb_desc->names->indicators[i] !=
				   None) {
		gboolean status;
		status = xkl_indicator_set(i,
					   (window_state->
					    indicators & bit) != 0);
		xkl_debug(150, "Set indicator \"%s\"/%d to %d: %d\n",
			  xkl_indicator_names[i],
			  xkl_xkb_desc->names->indicators[i],
			  window_state->indicators & bit, status);
	}
#endif
}