get named indicators
This commit is contained in:
parent
17ad17dd42
commit
2fbf1e9ca4
@ -174,33 +174,34 @@ void SetKeyboard(char *layout) {
|
||||
}
|
||||
|
||||
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock) {
|
||||
// TOOD: refactor, use native API.
|
||||
// https://stackoverflow.com/questions/8427817/how-to-get-a-num-lock-state-using-c-c/8429021
|
||||
Display *display = getXDisplay();
|
||||
XKeyboardState x;
|
||||
XGetKeyboardControl(display, &x);
|
||||
|
||||
// set caps lock
|
||||
//printf("CapsLock is %s\n", (x.led_mask & 1) ? "On" : "Off");
|
||||
if(caps_lock != -1 && x.led_mask & 1 != caps_lock) {
|
||||
XKey(0xffe5, 1);
|
||||
XKey(0xffe5, 0);
|
||||
}
|
||||
Bool state;
|
||||
Atom atom;
|
||||
|
||||
// set num lock
|
||||
//printf("NumLock is %s\n", (x.led_mask & 2) ? "On" : "Off");
|
||||
if(num_lock != -1 && x.led_mask & 2 != num_lock) {
|
||||
XKey(0xff7f, 1);
|
||||
XKey(0xff7f, 0);
|
||||
atom = XInternAtom(display, "Num Lock", 0);
|
||||
XkbGetNamedIndicator(display, atom, NULL, &state, NULL, NULL);
|
||||
//printf("Num Lock is %s\n", state ? "on" : "off");
|
||||
if(num_lock != -1 && state != num_lock) {
|
||||
XKey(XK_Num_Lock, 1);
|
||||
XKey(XK_Num_Lock, 0);
|
||||
}
|
||||
|
||||
// set caps lock
|
||||
atom = XInternAtom(display, "Caps Lock", 0);
|
||||
XkbGetNamedIndicator(display, atom, NULL, &state, NULL, NULL);
|
||||
//printf("Caps Lock is %s\n", state ? "on" : "off");
|
||||
if(caps_lock != -1 && state != caps_lock) {
|
||||
XKey(XK_Caps_Lock, 1);
|
||||
XKey(XK_Caps_Lock, 0);
|
||||
}
|
||||
|
||||
/* NOT SUPPORTED
|
||||
// set scroll lock
|
||||
//printf("ScrollLock is %s\n", (x.led_mask & 4) ? "On" : "Off");
|
||||
if(scroll_lock != -1 && x.led_mask & 4 != scroll_lock) {
|
||||
XKey(0xff14, 1);
|
||||
XKey(0xff14, 0);
|
||||
atom = XInternAtom(display, "Scroll Lock", 0);
|
||||
XkbGetNamedIndicator(display, atom, NULL, &state, NULL, NULL);
|
||||
//printf("Scroll Lock is %s\n", state ? "on" : "off");
|
||||
if(scroll_lock != -1 && state != scroll_lock) {
|
||||
XKey(XK_Scroll_Lock, 1);
|
||||
XKey(XK_Scroll_Lock, 0);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
#define XDISPLAY_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/extensions/XTest.h>
|
||||
#include <libclipboard.h>
|
||||
|
Reference in New Issue
Block a user