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

📄 gdkkeyboard-fb.c

📁 linux下电话本所依赖的一些图形库
💻 C
📖 第 1 页 / 共 3 页
字号:
  {'w', 0},  {'x', 0},  {'y', 0},  {'z', 0},  {'{', 0},  {'|', 0},  {'}', 0},  {'~', 0},  {GDK_BackSpace, 0},  /* 0x80 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  /* 0x90 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  /* 0xA0 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  /* 0xB0 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  /* 0xC0 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  /* 0xD0 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  /* 0xE0 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  /* 0xF0 */  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},  {0, 0},};static gbooleaniscode (char *code, char *str, int str_max){  int i;  for (i = 0; code[i] && (i < str_max); i++)    {      if (code[i] != str[i])	return FALSE;    }  return (code[i] == 0);}static gbooleanxlate_io (GIOChannel *gioc,	  GIOCondition cond,	  gpointer data){  GdkFBKeyboard *keyb = (GdkFBKeyboard *)data;  guchar buf[128];  guint keycode;  guint modifier;  gboolean handled;  int i, n, j;  int left;    n = read (keyb->fd, buf, sizeof(buf));  if (n <= 0)    g_error ("Nothing from keyboard!");  for (i = 0; i < n; )    {      handled = FALSE;      modifier = 0;      if ((buf[i] == 27) && (i+1 != n)) /* Escape */	{	  /* Esc is not the last char in buffer, interpret as code sequence */	  if (buf[i+1] == '[')	    {	      i += 2;	      left = n-i;	      if (left <= 0)		return TRUE;	      for (j=0;j<G_N_ELEMENTS (xlate_codes);j++)		{		  if (iscode (xlate_codes[j].str, &buf[i], left))		    {		      /* Ctrl-Alt Return can't be pressed in the XLATE driver,		       * use Shift F1 instead */		      if ((xlate_codes[j].code == GDK_F1) &&			  (xlate_codes[j].modifier & GDK_SHIFT_MASK))			gdk_fb_redraw_all ();		      if ((xlate_codes[j].code == GDK_F2) &&			  (xlate_codes[j].modifier & GDK_SHIFT_MASK))			{			  static gint deg = 0;			  deg = (deg + 1) % 4;			    			  gdk_fb_set_rotation (deg);			}		      if ((xlate_codes[j].code == GDK_F8) &&			  (xlate_codes[j].modifier & GDK_SHIFT_MASK))			exit (1);		      		      gdk_fb_handle_key (xlate_codes[j].code,					 xlate_codes[j].code,					 xlate_codes[j].modifier,					 0,					 NULL,					 0,					 FALSE);		      gdk_fb_handle_key (xlate_codes[j].code,					 xlate_codes[j].code,					 xlate_codes[j].modifier,					 0,					 NULL,					 0,					 TRUE);		      i += strlen (xlate_codes[j].str);		      handled = TRUE;		      break;		    }		}	    }	  else	    {	      /* Alt-key */	      modifier |= GDK_MOD1_MASK;	      i++;	    }	}      if (!handled)	{	  char dummy[2];	  gint len;	  	  keycode = xlate_chars[buf[i]].code;	  if (keycode == 0)	    keycode = buf[i];	  modifier |= xlate_chars[buf[i]].modifier;	  	  dummy[0] = keycode;	  dummy[1] = 0;	  len = ((keycode < 255) && isprint (keycode)) ? 1 : 0;	  gdk_fb_handle_key (keycode,			     keycode,			     modifier,			     0,			     (len)?g_strdup(dummy) : NULL,			     len,			     FALSE);	  gdk_fb_handle_key (keycode,			     keycode,			     modifier,			     0,			     (len)?g_strdup(dummy) : NULL,			     len,			     TRUE);	  i++;	}    }  return TRUE;}static gbooleanwrite_string (gint         fd,	      const gchar *str){  gsize to_write = strlen (str);  while (to_write > 0)    {      gssize count = write (fd, str, to_write);      if (count < 0)	{	  if (errno != EINTR)	    return FALSE;	}      else	{	  to_write -= count;	  str += count;	}    }  return TRUE;}static gbooleanxlate_open (GdkFBKeyboard *kb){  const char cursoroff_str[] = "\033[?1;0;0c";  struct termios ts;    tcgetattr (gdk_display->tty_fd, &ts);  ts.c_cc[VTIME] = 0;  ts.c_cc[VMIN] = 1;  ts.c_lflag &= ~(ICANON|ECHO|ISIG);  ts.c_iflag = 0;  tcsetattr (gdk_display->tty_fd, TCSAFLUSH, &ts);  tcsetpgrp (gdk_display->tty_fd, getpgrp());  write_string (gdk_display->tty_fd, cursoroff_str);    ioctl (gdk_display->tty_fd, KDSKBMODE, K_XLATE);  kb->fd = gdk_display->tty_fd;  kb->io = g_io_channel_unix_new (kb->fd);  kb->io_tag = g_io_add_watch (kb->io,			       G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,			       xlate_io,			       kb);    return TRUE;}static voidxlate_close (GdkFBKeyboard *kb){  struct termios ts;  const char cursoron_str[] = "\033c\033[3g\033]R";  write_string (gdk_display->tty_fd, cursoron_str);  tcgetattr (gdk_display->tty_fd, &ts);  ts.c_lflag |= (ICANON|ECHO|ISIG);  tcsetattr (gdk_display->tty_fd, TCSAFLUSH, &ts);    g_source_remove (kb->io_tag);  g_io_channel_unref (kb->io);  kb->fd = -1;  /* don't close kb->fd, it is the tty from gdk_display */}static guintxlate_lookup (GdkFBKeyboard       *kb,	      const GdkKeymapKey  *key){  if (key->group != 0)    return 0;  if (key->level != 0)    return 0;  return key->keycode;}static gbooleanxlate_translate (GdkFBKeyboard       *kb,		 guint                hardware_keycode,		 GdkModifierType      state,		 gint                 group,		 guint               *keyval,		 gint                *effective_group,		 gint                *level,		 GdkModifierType     *consumed_modifiers){  if (keyval)    *keyval = hardware_keycode;  if (effective_group)    *effective_group = 0;  if (level)    *level = 0;  if (consumed_modifiers)    *consumed_modifiers = 0;  return TRUE;}static gbooleanxlate_get_for_keyval (GdkFBKeyboard       *kb,		      guint                keyval,		      GdkKeymapKey       **keys,		      gint                *n_keys){  *n_keys = 1;  *keys = g_new (GdkKeymapKey, 1);  (*keys)->keycode = keyval;  (*keys)->group = 0;  (*keys)->level = 0;  return TRUE;}static gbooleanxlate_get_for_keycode (GdkFBKeyboard       *kb,		       guint                hardware_keycode,		       GdkKeymapKey       **keys,		       guint              **keyvals,		       gint                *n_entries){  if (keys)    {      *keys = g_new (GdkKeymapKey, 1);      (*keys)->keycode = hardware_keycode;      (*keys)->level = 0;      (*keys)->group = 0;    }  if (keyvals)    {      *keyvals = g_new (guint, 1);      **keyvals = hardware_keycode;    }  if (n_entries)    *n_entries = 1;  return TRUE;}/* Raw keyboard support */static const guint trans_table[256][3] = {  /* 0x00 */  {0, 0, 0},  {GDK_Escape, 0, 0},  {'1', '!', 0},  {'2', '@', 0},  {'3', '#', 0},  {'4', '$', 0},  {'5', '%', 0},  {'6', '^', 0},  {'7', '&', 0},  {'8', '*', 0},  {'9', '(', 0},  {'0', ')', 0},  {'-', '_', 0},  {'=', '+', 0},  {GDK_BackSpace, 0, 0},  {GDK_Tab, 0, 0},  /* 0x10 */  {'q', 'Q', 0},  {'w', 'W', 0},  {'e', 'E', 0},  {'r', 'R', 0},  {'t', 'T', 0},  {'y', 'Y', 0},  {'u', 'U', 0},  {'i', 'I', 0},  {'o', 'O', 0},  {'p', 'P', 0},  {'[', '{', 0},  {']', '}', 0},  {GDK_Return, 0, 0},  {GDK_Control_L, 0, 0}, /* mod */  {'a', 'A', 0},  {'s', 'S', 0},	/* 0x20 */  {'d', 'D', 0},  {'f', 'F', 0},  {'g', 'G', 0},  {'h', 'H', 0},  {'j', 'J', 0},  {'k', 'K', 0},  {'l', 'L', 0},  {';', ':', 0},  {'\'', '"', 0},  {'`', '~', 0},  {GDK_Shift_L, 0, 0}, /* mod */  {'\\', 0, 0},  {'z', 0, 0},  {'x', 0, 0},  {'c', 0, 0},  {'v', 'V', 0},	/* 0x30 */  {'b', 'B', 0},  {'n', 'N', 0},  {'m', 'M', 0},  {',', 0, 0},  {'.', 0, 0},  {'/', 0, 0},  {GDK_Shift_R, 0, 0}, /* mod */  {GDK_KP_Multiply, 0, 0},  {0, 0, 0},  {GDK_space, 0, 0},  {0, 0, 0},  {GDK_F1, 0, 0},  {GDK_F2, 0, 0},  {GDK_F3, 0, 0},  {GDK_F4, 0, 0},  {GDK_F5, 0, 0},	/* 0x40 */  {GDK_F6, 0, 0},  {GDK_F7, 0, 0},  {GDK_F8, 0, 0},  {GDK_F9, 0, 0},  {GDK_F10, 0, 0},  {0, 0, 0},  {0, 0, 0},  {'7', 0, 0},  {'8', 0, 0},  {'9', 0, 0},  {'-', 0, 0},  {'4', 0, 0},  {'5', 0, 0},  {'6', 0, 0},  {'+', 0, 0},  {'1', 0, 0},	/* 0x50 */  {'2', 0, 0},  {'3', 0, 0},  {'0', 0, 0},  {'.', 0, 0},  {0, 0, 0},  {0, 0, 0},  {0, 0, 0},  {GDK_F11, 0, 0},  {GDK_F12, 0, 0},  {0, 0, 0},  {0, 0, 0},  {0, 0, 0},  {0, 0, 0},  {0, 0, 0},  {0, 0, 0},  {0, 0, 0},	/* 0x60 */  {GDK_Return, 0, 0},  {0, 0, 0},  {0, 0, 0},  {0, 0, 0},

⌨️ 快捷键说明

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