forked from YggdrasiI/NeoLayoutViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckModifier.c
More file actions
58 lines (50 loc) · 1.33 KB
/
Copy pathcheckModifier.c
File metadata and controls
58 lines (50 loc) · 1.33 KB
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
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
/*
Code ideas from
http://stackoverflow.com/questions/2968336/qt-password-field
*/
#ifdef Q_OS_WIN32
#include <windows.h>
#else
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#endif
char keymap[32];
bool keyPressed(int keycode, char* keymap){
return ( keymap[keycode/8] & (1 << keycode%8) ) > 0;
}
/*
Input: Display, Array of keycodes, length of both arrays
Output: Array of ints. (no bools because sizeof(bool,vala) != sizeof(bool, stdbool.h)
*/
void checkModifier(Display* display, int* keycodes, int nkeycodes, int* pressed){
XQueryKeymap(display, keymap);
int i;
for (i=0; i<nkeycodes; i++) {
pressed[i] = keyPressed(keycodes[i], keymap)?1:0;
//printf("%i Pressed? %i\n", keycodes[i], (pressed[i]) );
}
}
bool checkCapsLock(Display* d) {
// platform dependent method of determining if CAPS LOCK is on
/*#ifdef Q_OS_WIN32 // MS Windows version
return GetKeyState(VK_CAPITAL) == 1;
#else // X11 version (Linux/Unix/Mac OS X/etc...)*/
//Display* d = XOpenDisplay((char*)0);
bool caps_state = false;
if (d) {
unsigned n;
XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
//printf("Indicator State: %u\n",n);
caps_state = (n & 0x01) == 1;
}
return caps_state;
//#endif
}