24 #include <X11/Xatom.h>
27 #include "liblocale.h"
28 #include "keyboard_x11.h"
29 #include "xkb_layout_ids.h"
31 static BOOL parse_xkb_rule_names(
char* xkb_rule,
unsigned long num_bytes,
char** layout,
49 for (
size_t i = 0, index = 0; i < num_bytes; i++, index++)
51 char* ptr = xkb_rule + i;
62 char* delimiter = strchr(ptr,
',');
81 static DWORD kbd_layout_id_from_x_property(Display* display, Window root,
char* property_name)
88 unsigned long items = 0;
89 unsigned long unread_items = 0;
92 Atom
property = XInternAtom(display, property_name, False);
96 if (XGetWindowProperty(display, root, property, 0, 1024, False, XA_STRING, &type, &item_size,
97 &items, &unread_items, (
unsigned char**)&rule) != Success)
100 if (type != XA_STRING || item_size != 8 || unread_items != 0)
106 parse_xkb_rule_names(rule, items, &layout, &variant);
108 DEBUG_KBD(
"%s layout: %s, variant: %s", property_name, layout, variant);
109 layout_id = find_keyboard_layout_in_xorg_rules(layout, variant);
116 int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
118 Display* display = XOpenDisplay(NULL);
123 Window root = DefaultRootWindow(display);
128 DWORD
id = kbd_layout_id_from_x_property(display, root,
"_XKB_RULES_NAMES_BACKUP");
131 id = kbd_layout_id_from_x_property(display, root,
"_XKB_RULES_NAMES");
134 *keyboardLayoutId = id;
136 XCloseDisplay(display);