void init_key(void) { if(!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "error: can not open display %s", XDisplayName(NULL)); exit(1); } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); opt_key = conf_get_key(); modmask = conf_get_mod(); int i, j; XModifierKeymap *modmap = XGetModifierMapping(dpy); for(i = 0; i < 8; i++) { for(j = 0; j < modmap->max_keypermod; j++) { if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) numlockmask = (1 << i); } } XFreeModifiermap(modmap); }
/* if the target key has not been found, the method will return NULL */ int conf_get_value_by_key(char *value, char *file_path, char* target_key) { char *conf_opt; char key[TOKEN_NAME_MAX_LEN]; char *buffer; CONFIG *config; int i; int file_size; Assert(value != NULL); file_size = file_get_size(file_path); buffer = (char *)MEMALLOCHEAP(file_size); file_read(file_path, buffer, file_size); config = conf_build(buffer, LINE_SEPARATOR); for(i=0; i<config->conf_opt_size; i++) { conf_opt = config->conf_opt_infor[i].conf_value; Assert(STRLEN(conf_opt) != 0); MEMSET(key, TOKEN_NAME_MAX_LEN); conf_get_key(key, conf_opt); if(match(key, target_key)) { conf_get_value(value, conf_opt); break; } } conf_destroy(config); trim(value, ' '); MEMFREEHEAP(buffer); return TRUE; }