⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config-parser.c.svn-base

📁 螢幕小鍵盤,可在Windows/linux上或其他嵌入式系統如手機上使用
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
          if (!util_file_readable(buf))            snprintf(buf, 512, "%s/.matchbox/%s", getenv("HOME"), &val[6]);          img = mb_kbd_image_new (state->keyboard, buf);        }      else        img = mb_kbd_image_new (state->keyboard, &val[6]);      if (!img)        {          fprintf(stderr, "matchbox-keyboard: Failed to load '%s'\n", &val[6]);          state->error = True;          return;        }      mb_kbd_key_set_image_face(state->current_key, keystate, img);    }  else    {      mb_kbd_key_set_glyph_face(state->current_key, keystate,                                 attr_get_val("display", attr));    }  if ((val = attr_get_val("action", attr)) != NULL)    {      /*             action="utf8char"     // optional, action defulats to this                 action="modifier:Shift|Alt|ctrl|mod1|mod2|mod3|caps"             action="changer:lows|caps|numbers|symbols|Chinese"             action="xkeysym:XK_BLAH"             action="control:">    // return etc - not needed use lookup       */      if (!strncmp(val, "changer:", 8))        {          MBKeyboardLayoutType found_type;          found_type = config_str_to_layouttype(&val[8]);          if (found_type)            {              mb_kbd_key_set_changer_action(state->current_key,                                            keystate,                                            found_type);            }          else            {              set_error(state, "Unknown changer");              return;            }        }      else if (!strncmp(val, "modifier:", 9))        {          MBKeyboardKeyModType found_type;          DBG("checking '%s'", &val[9]);          found_type = config_str_to_modtype(&val[9]);          if (found_type)            {              mb_kbd_key_set_modifer_action(state->current_key,                                            keystate,                                            found_type);            }          else            {              set_error(state, "Unknown modifier");              return;            }                  }      else if (!strncmp(val, "xkeysym:", 8))        {          DBG("Checking %s\n", &val[8]);          found_keysym = XStringToKeysym(&val[8]);          if (found_keysym)            {              mb_kbd_key_set_keysym_action(state->current_key,                                            keystate,                                           found_keysym);            }          else             {              /* Should this error really be terminal */              set_error(state, "Unknown keysym");              return;            }        }      else        {          /* Its just 'regular' key  */          if (strlen(val) > 1          /* match backspace, return etc */              && ((found_keysym  = config_str_to_keysym(val)) != 0))            {              mb_kbd_key_set_keysym_action(state->current_key,                                            keystate,                                           found_keysym);            }          else            {              /* XXX We should actually check its a single UTF8 Char here */              mb_kbd_key_set_char_action(state->current_key,                                          keystate, val);            }        }    }  else /* fallback to reusing whats displayed  */    {      /* display could be an image in which case we should throw an error        * or summin.      */      mb_kbd_key_set_char_action(state->current_key,                                  keystate,                                  attr_get_val("display", attr));    }}static voidconfig_handle_layout_tag(MBKeyboardConfigState *state, const char **attr){  const char            *val;  Bool                  realsize = False;  MBKeyboardLayoutType  type = 0;  if ((val = attr_get_val("realsize", attr)) != NULL)    {      if (strcaseeq("true", val))        realsize = True;    }  if ((val = attr_get_val("type", attr)) != NULL)    {      if ((type = config_str_to_layouttype(val)) == 0)        {          set_error (state, "Unkown layout type");          return;        }    }  if ((val = attr_get_val("id", attr)) == NULL)    {      set_error(state, "Attribute 'id' is required");      return;    }  state->current_layout = mb_kbd_layout_new(state->keyboard, val);  mb_kbd_layout_set_realsize(state->current_layout, realsize);  if (type != 0)    mb_kbd_layout_set_type(state->current_layout, type);  mb_kbd_add_layout(state->keyboard, state->current_layout);}static voidconfig_handle_row_tag(MBKeyboardConfigState *state, const char **attr){  state->current_row = mb_kbd_row_new(state->keyboard);  mb_kbd_layout_append_row(state->current_layout, state->current_row);}static voidconfig_handle_key_tag(MBKeyboardConfigState *state, const char **attr){  const char *val;  DBG("got key");  state->current_key = mb_kbd_key_new(state->keyboard);  if ((val = attr_get_val("obey-caps", attr)) != NULL)    {      if (strcaseeq(val, "true"))	mb_kbd_key_set_obey_caps(state->current_key, True);    }  if ((val = attr_get_val("extended", attr)) != NULL)    {      if (strcaseeq(val, "true"))	mb_kbd_key_set_extended(state->current_key, True);    }  if ((val = attr_get_val("width", attr)) != NULL)    {      if (atoi(val) > 0)	mb_kbd_key_set_req_uwidth(state->current_key, atoi(val));    }  if (mb_kbd_layout_realsize(state->current_layout))    {      int        x = 0;      int        y = 0;      int        w = 0;      int        h = 0;      if ((val = attr_get_val("fill", attr)) != NULL)        {          if (strcaseeq(val, "true"))    	mb_kbd_key_set_fill(state->current_key, True);        }          if ((val = attr_get_val("real_x", attr)) != NULL)        {          if (atoi(val) > 0)            x = atoi(val);        }          if ((val = attr_get_val("real_y", attr)) != NULL)        {          if (atoi(val) > 0)            y = atoi(val);        }          if ((val = attr_get_val("real_w", attr)) != NULL)        {          if (atoi(val) > 0)            w = atoi(val);        }          if ((val = attr_get_val("real_h", attr)) != NULL)        {          if (atoi(val) > 0)            h = atoi(val);        }          mb_kbd_key_set_geometry (state->current_key, x, y, w, h);    }  mb_kbd_row_append_key(state->current_row, state->current_key);}static voidconfig_handle_layout_background(MBKeyboardConfigState *state,                                const char **attr){  const char *val;  char  buf[512];  if ((val = attr_get_val("image", attr)) == NULL)    {      set_error(state, "Backgroud Attribute 'image' is required");      return;    }  if (val[0] != '/')    {      snprintf(buf, 512, "%s/%s", PKGDATADIR, val);      if (!util_file_readable(buf))        snprintf(buf, 512, "%s/.matchbox/%s", getenv("HOME"), val);      mb_kbd_layout_set_background(state->current_layout, buf);    }  else    {      mb_kbd_layout_set_background(state->current_layout, val);    }  if (mb_kbd_layout_realsize(state->current_layout))    {      if ((val = attr_get_val("width", attr)) != NULL)        {          if (atoi(val) > 0)            mb_kbd_layout_set_width(state->current_layout, atoi(val));        }      if ((val = attr_get_val("height", attr)) != NULL)        {          if (atoi(val) > 0)            mb_kbd_layout_set_height(state->current_layout, atoi(val));        }    }}static voidconfig_handle_layout_changerground(MBKeyboardConfigState *state,                                   const char **attr){  const char *val;  char  buf[512];  /* only realsize mode support the changer background image */  if (!mb_kbd_layout_realsize(state->current_layout))    return;  if ((val = attr_get_val("image", attr)) == NULL)    {      set_error(state, "Changerground Attribute 'image' is required");      return;    }  if (val[0] != '/')    {      snprintf(buf, 512, "%s/%s", PKGDATADIR, val);      if (!util_file_readable(buf))        snprintf(buf, 512, "%s/.matchbox/%s", getenv("HOME"), val);      mb_kbd_layout_set_changerground(state->current_layout, buf);    }  else    {      mb_kbd_layout_set_changerground(state->current_layout, val);    }  if ((val = attr_get_val("width", attr)) != NULL)    {      if (atoi(val) > 0)        mb_kbd_layout_set_changerground_w(state->current_layout, atoi(val));    }  if ((val = attr_get_val("height", attr)) != NULL)    {      if (atoi(val) > 0)        mb_kbd_layout_set_changerground_h(state->current_layout, atoi(val));    }  if ((val = attr_get_val("real_x", attr)) != NULL)    {      if (atoi(val) > 0)        mb_kbd_layout_set_changerground_x(state->current_layout, atoi(val));    }  if ((val = attr_get_val("real_y", attr)) != NULL)    {      if (atoi(val) > 0)        mb_kbd_layout_set_changerground_y(state->current_layout, atoi(val));    }}static void config_xml_start_cb(void *data, const char *tag, const char **attr){  MBKeyboardConfigState *state = (MBKeyboardConfigState *)data;  if (streq(tag, "layout"))    {      config_handle_layout_tag(state, attr);    }  else if (streq(tag, "row"))    {      config_handle_row_tag(state, attr);    }  else if (streq(tag, "key"))    {      config_handle_key_tag(state, attr);    }  else  if (streq(tag, "space"))    {      config_handle_key_tag(state, attr);      mb_kbd_key_set_blank(state->current_key, True);    }  else  if (streq(tag, "normalimage")	   || streq(tag, "pushimage"))    {      config_handle_key_background_tag(state, tag, attr);    }  else if (streq(tag, "normal") 	   || streq(tag, "default")	   || streq(tag, "shifted")	   || streq(tag, "mod1")	   || streq(tag, "mod2")	   || streq(tag, "mod3"))    {      config_handle_key_subtag(state, tag, attr);    }  else if (streq(tag, "background"))    {      config_handle_layout_background(state, attr);    }  else if (streq(tag, "changerground"))    {      config_handle_layout_changerground(state, attr);    }  if (state->error)    {      fprintf(stderr, "matchbox-keyboard:%s:%d: %s\n", state->keyboard->config_file,                                               state->error_lineno, state->error_msg);      util_fatal_error("Error parsing\n");    }}intmb_kbd_config_load(MBKeyboard *kbd, char *variant){  char                  *data;  XML_Parser             p;  MBKeyboardConfigState *state;  if ((data = config_load_file(kbd, variant)) == NULL)    util_fatal_error("Couldn't find a keyboard config file\n");  p = XML_ParserCreate(NULL);  if (!p)     util_fatal_error("Couldn't allocate memory for XML parser\n");  if (variant && !strstr(kbd->config_file, variant))    fprintf(stderr, 	    "matchbox-keyboard: *Warning* Unable to locate variant: %s\n"	    "                   falling back to %s\n",	    variant, kbd->config_file);  state = util_malloc0(sizeof(MBKeyboardConfigState));  state->keyboard = kbd;  state->parser = p;  XML_SetElementHandler(p, config_xml_start_cb, NULL);  /* XML_SetCharacterDataHandler(p, chars); */  XML_SetUserData(p, (void *)state);  if (! XML_Parse(p, data, strlen(data), 1)) {    fprintf(stderr, 	    "matchbox-keyboard:%s:%d: XML Parse error:%s\n",	    kbd->config_file,	    XML_GetCurrentLineNumber(p),	    XML_ErrorString(XML_GetErrorCode(p)));    util_fatal_error("XML Parse failed.\n");  }  return 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -