示例#1
0
/* find_unknown_key_assignment
 *  In some cases, X11 doesn't report any KeySym for a key - so the earliest
 *  time we can map it to an Allegro key is when it is first pressed.
 */
static int find_unknown_key_assignment(int i)
{
    int j;

    for (j = 1; j < ALLEGRO_KEY_MAX; j++) {
        if (!used[j]) {
            const char *str;
            keycode_to_scancode[i] = j;
            str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
            if (str)
                key_names[j] = str;
            else {
                key_names[j] = _al_keyboard_common_names[j];
            }
            used[j] = 1;
            break;
        }
    }

    if (j == ALLEGRO_KEY_MAX) {
        ALLEGRO_ERROR("You have more keys reported by X than Allegro's "
                      "maximum of %i keys. Please send a bug report.\n", ALLEGRO_KEY_MAX);
        keycode_to_scancode[i] = 0;
    }

    char str[1024];
    sprintf(str, "Key %i missing:", i);
    for (j = 0; j < sym_per_key; j++) {
        char *sym_str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode) + j]);
        sprintf(str + strlen(str), " %s", sym_str ? sym_str : "NULL");
    }
    ALLEGRO_DEBUG("%s assigned to %i.\n", str, keycode_to_scancode[i]);

    return keycode_to_scancode[i];
}
示例#2
0
文件: parse.c 项目: bbidulock/adwm
void
addchain(Key *k)
{
	Key **kp;

	XPRINTF("Adding chain: %s ...\n", showchain(k));
	for (kp = &scr->keylist; *kp; kp = &(*kp)->cnext)
		if ((*kp)->mod == k->mod && (*kp)->keysym == k->keysym)
			break;
	if (*kp) {
		XPRINTF("Overlapping key definition %s\n", XKeysymToString(k->keysym));
		if ((*kp)->chain && k->chain)
			mergechain(*kp, k);
		else {
			XPRINTF("Overriding previous key definition: %s!\n", showchain(k));
			k->cnext = (*kp)->cnext;
			(*kp)->cnext = NULL;
			freechain(*kp);
			*kp = k;
		}
		XPRINTF("... added chain: %s\n", showchain(*kp));
	} else {
		XPRINTF("Adding new key %s\n", XKeysymToString(k->keysym));
		k->cnext = scr->keylist;
		scr->keylist = k;
		XPRINTF("... added chain: %s\n", showchain(k));
	}
}
示例#3
0
void event_callback(XPointer priv, XRecordInterceptData *hook)
{
  /* FIXME: we need use XQueryPointer to get the first location */
  static int cur_x = 0;
  static int cur_y = 0;

  if (hook->category != XRecordFromServer) {
    XRecordFreeData (hook);
    return;
  }

  XRecordDatum *data = (XRecordDatum*) hook->data;

  int event_type = data->type;

  BYTE btncode, keycode;
  btncode = keycode = data->event.u.u.detail;

  int rootx = data->event.u.keyButtonPointer.rootX;
  int rooty = data->event.u.keyButtonPointer.rootY;
  int time = hook->server_time;

  switch (event_type) {
  case KeyPress:
    /* if escape is pressed, stop the loop and clean up, then exit */
    if (keycode == 9) stop = 1;

    /* Note: you should not use data_disp to do normal X operations !!!*/
    printf ("KeyPress: \t%s\n", XKeysymToString(XKeycodeToKeysym(ctrl_disp, keycode, 0)));
    break;
  case KeyRelease:
    printf ("KeyRelease: \t%s\n", XKeysymToString(XKeycodeToKeysym(ctrl_disp, keycode, 0)));
    break;
  case ButtonPress:
    /* printf ("ButtonPress: /t%d, rootX=%d, rootY=%d", btncode, cur_x, cur_y); */
    break;
  case ButtonRelease:
    /* printf ("ButtonRelease: /t%d, rootX=%d, rootY=%d", btncode, cur_x, cur_y); */
    break;
  case MotionNotify:
    /* printf ("MouseMove: /trootX=%d, rootY=%d",rootx, rooty); */
    cur_x = rootx;
    cur_y = rooty;
    break;
  case CreateNotify:
    break;
  case DestroyNotify:
    break;
  case NoExpose:
    break;
  case Expose:
    break;
  default:
    break;
  }

  printf (", time=%d\n", time);

  XRecordFreeData (hook);
}
示例#4
0
/* find_unknown_key_assignment
 *  In some cases, X11 doesn't report any KeySym for a key - so the earliest
 *  time we can map it to an Allegro key is when it is first pressed.
 */
static int find_unknown_key_assignment (int i)
{
   int j;

   for (j = 1; j < KEY_MAX; j++) {
      if (!used[j]) {
	 AL_CONST char *str;
	 _xwin.keycode_to_scancode[i] = j;
	 str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
	 if (str)
	    key_names[j] = str;
	 else
	    key_names[j] = _keyboard_common_names[j];
	 used[j] = 1;
	 break;
      }
   }

   if (j == KEY_MAX) {
      TRACE(PREFIX_E "You have more keys reported by X than Allegro's "
	    "maximum of %i keys. Please send a bug report.\n", KEY_MAX);
      _xwin.keycode_to_scancode[i] = 0;
   }

   TRACE(PREFIX_I "Key %i missing:", i);
   for (j = 0; j < sym_per_key; j++) {
      char *sym_str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode) + j]);
      TRACE(" %s", sym_str ? sym_str : "NULL");
   }
   TRACE(" - assigned to %i.\n", _xwin.keycode_to_scancode[i]);

   return _xwin.keycode_to_scancode[i];
}
示例#5
0
文件: key.c 项目: morenko/sven
void ungrab_key (int key_code)
{
	GdkWindow *root=gdk_get_default_root_window();
	
	gdk_error_trap_push ();
	XUngrabKey (GDK_DISPLAY (), key_code, AnyModifier,
			(GDK_WINDOW_XID (root) ? GDK_WINDOW_XID (root) : DefaultRootWindow (GDK_DISPLAY())));
	XUngrabKey (GDK_DISPLAY (), AnyKey, AnyModifier, (GDK_WINDOW_XID (root) ? GDK_WINDOW_XID (root) : DefaultRootWindow (GDK_DISPLAY())));


	gdk_flush ();
	if (gdk_error_trap_pop ()) 
	{
		gchar *error;
		gchar *key;

		key=g_strdup_printf ("%s",(XKeysymToString (XKeycodeToKeysym (GDK_DISPLAY (), key_code, 0)) != NULL)? 
		XKeysymToString (XKeycodeToKeysym (GDK_DISPLAY (),key_code, 0)):
		g_strdup_printf ("%d",key_code));
		
		error = g_strdup_printf
			(_("It seems that another application already has"
			   " access to the multimedia keys.\n"
			   "Key %s couldn't be bound.\n"
			   "Is another daemon already running ?\n"),
			 key);
		show_error(error);
		printf("[Sven][ERROR]:%s",error);
		g_free (key);
		g_free (error);
	}
}
示例#6
0
int main(int argc, char **argv)
{
    Display *display;
    XEvent xevent;
    Window window;

    if( (display = XOpenDisplay(NULL)) == NULL )
        return -1;


    window = DefaultRootWindow(display);
    XAllowEvents(display, AsyncBoth, CurrentTime);

    XGrabPointer(display, 
                 window,
                 1, 
                 PointerMotionMask | ButtonPressMask | ButtonReleaseMask , 
                 GrabModeAsync,
                 GrabModeAsync, 
                 None,
                 None,
                 CurrentTime);

    XGrabKeyboard(display, window, false, GrabModeAsync, GrabModeAsync, CurrentTime);

    while(1) {
        XNextEvent(display, &xevent);
        int mykey;
        switch (xevent.type) {
            case MotionNotify:
                printf("Mouse move      : [%d, %d]\n", xevent.xmotion.x_root, xevent.xmotion.y_root);
                break;
            case ButtonPress:
                printf("Button pressed  : %s, %d\n", key_name[xevent.xbutton.button - 1], xevent.xbutton.button);
                break;
            case ButtonRelease:
                printf("Button released : %s, %d\n", key_name[xevent.xbutton.button - 1], xevent.xbutton.button);
                break;
            case KeyPress:
                mykey = XKeycodeToKeysym(display, xevent.xkey.keycode, 0);
                printf("KeyPress : %s, %d\n", XKeysymToString(mykey), mykey);
                
                if (xevent.xkey.keycode == 27 || xevent.xkey.keycode == 9) {
                    return 0;
                }
                break;
            case KeyRelease:
                mykey = XKeycodeToKeysym(display, xevent.xkey.keycode, 0);
                printf("KeyRelease : %s, %d\n", XKeysymToString(mykey), mykey);
                break;
        }
    }

    return 0;
}
示例#7
0
文件: handle.c 项目: aosm/X11apps
static void 
print_opcode(union op *op)
{
    int i;

    printf ("        ");
    switch (op->generic.type) {
      case doKeycode:
	if (op->keycode.target_keycode)
	    printf ("keycode 0x%lx =", (long) op->keycode.target_keycode);
	else
	    printf ("keycode any =");
	for (i = 0; i < op->keycode.count; i++) {
	    char *name = XKeysymToString (op->keycode.keysyms[i]);

	    printf (" %s", name ? name : "BADKEYSYM");
	}
	printf ("\n");
	break;
      case doAddModifier:
	printf ("add %s =", modifier_table[op->addmodifier.modifier].name);
	for (i = 0; i < op->addmodifier.count; i++) {
	    char *name = XKeysymToString (op->addmodifier.keysyms[i]);
	    printf (" %s", name ? name : "BADKEYSYM");
	}
	printf ("\n");
	break;
      case doRemoveModifier:
	printf ("remove %s = ",
		modifier_table[op->removemodifier.modifier].name);
	for (i = 0; i < op->removemodifier.count; i++) {
	    printf (" 0x%lx", (long) op->removemodifier.keycodes[i]);
	}
	printf ("\n");
	break;
      case doClearModifier:
	printf ("clear %s\n", modifier_table[op->clearmodifier.modifier].name);
	break;
      case doPointer:
	printf ("pointer = ");
	if (op->pointer.count == 0)
	    printf(" default");
	else for (i=0; i < op->pointer.count; i++)
	    printf(" %d", op->pointer.button_codes[i]);
	printf ("\n");
	break;
      default:
	printf ("! unknown opcode %d\n", op->generic.type);
	break;
    }				/* end switch */
    return;
}
示例#8
0
int Keys_callback(int widget_desc, void *data, const char **unused)
{
    unsigned	bufsize = (num_keydefs * 64);
    char	*buf = calloc(bufsize, 1), *end = buf, *str;
    const char	*help;
    int		i, len, maxkeylen = 0;

    UNUSED_PARAM(widget_desc); UNUSED_PARAM(data); UNUSED_PARAM(unused);

    for (i = 0; i < num_keydefs; i++) {
	if ((str = XKeysymToString((KeySym)keydefs[i].keysym)) != NULL
	    && (len = strlen(str)) > maxkeylen) {
	    maxkeylen = len;
	}
    }
    for (i = 0; i < num_keydefs; i++) {
	if (!(str = XKeysymToString((KeySym)keydefs[i].keysym))
	    || !(help = Get_keyHelpString(keydefs[i].key)))
	    continue;

	if ((end - buf) + (maxkeylen + strlen(help) + 4) >= bufsize) {
	    bufsize += 4096;
	    xpprintf("realloc: %d\n", bufsize);
	    if (!(buf = realloc(buf, bufsize))) {
		error("No memory for key list");
		return 0;
	    }
	}
	sprintf(end, "%-*s  %s\n", maxkeylen, str, help);
	end += strlen(end);
    }
    keys_viewer =
	Widget_create_viewer(buf,
			     end - buf,
			     2*DisplayWidth(dpy, DefaultScreen(dpy))/3,
			     4*DisplayHeight(dpy, DefaultScreen(dpy))/5,
			     2,
			     "XPilot - key reference", "XPilot:keys",
			     motdFont);
    if (keys_viewer == NO_WIDGET) {
	warn("Can't create key viewer");
	return 0;
    }
#if 0
    else if (keys_viewer != NO_WIDGET)
	Widget_map(keys_viewer);
#endif
    return 0;
}
示例#9
0
static char *make_menu_label(ui_menu_entry_t *e)
{
    const char *key_string, *tmp = "";
    char *retstr, *trans, *dots = "";

    /* Check wether NO_TRANS prefix is there, if yes don't translate it */
    if (strncmp(e->string, NO_TRANS, strlen(NO_TRANS)) == 0) {
        trans = lib_stralloc(e->string + strlen(NO_TRANS));
    } else {
        trans = lib_stralloc(_(e->string));
    }

    if (e->type == UI_MENU_TYPE_DOTS || e->type == UI_MENU_TYPE_TICKDOTS) {
       dots = "...";
    }

    if (e->hotkey_keysym == KEYSYM_NONE) {
        retstr = util_concat(trans, dots, NULL);
        lib_free(trans);
        return retstr;
    }

    if (e->hotkey_modifier & UI_HOTMOD_CONTROL) {
        tmp = "C-";
    }
    if (e->hotkey_modifier & UI_HOTMOD_META) {
        tmp = "M-";
    }
    if (e->hotkey_modifier & UI_HOTMOD_ALT) {
        tmp = "A-";
    }
    if (e->hotkey_modifier & UI_HOTMOD_SHIFT) {
        tmp = "S-";
    }

    key_string = strchr(XKeysymToString(e->hotkey_keysym), '_');
    if (key_string == NULL) {
        key_string = XKeysymToString(e->hotkey_keysym);
    } else {
        key_string++;
    }

    retstr = util_concat(trans, dots, "    (", tmp, key_string, ")", NULL);

    lib_free(trans);

    return retstr;
}
示例#10
0
文件: menu.c 项目: thequux/pcb
static int
DumpKeys2 ()
{
  int i;
  char ch[2];
  printf ("in dumpkeys! %d\n", acc_num);
  qsort (acc_table, acc_num, sizeof (acc_table_t), acc_sort);
  ch[1] = 0;
  for (i = 0; i < acc_num; i++)
    {
      char mod[16];
      int vi;
      char *tabs = "";

      sprintf (mod, "%s%s%s",
	       acc_table[i].mods & M_Alt ? "Alt-" : "",
	       acc_table[i].mods & M_Ctrl ? "Ctrl-" : "",
	       acc_table[i].mods & M_Shift ? "Shift-" : "");
      ch[0] = toupper ((int)  acc_table[i].key_char);
      printf ("%16s%s\t", mod,
	      acc_table[i].key_char ? ch : XKeysymToString (acc_table[i].
							    u.a.key));

      for (vi = 1; vi < acc_table[i].u.a.node->c; vi++)
	if (resource_type (acc_table[i].u.a.node->v[vi]) == 10)
	  {
	    printf ("%s%s", tabs, acc_table[i].u.a.node->v[vi].value);
	    tabs = "\n\t\t\t  ";
	  }

      printf ("\n");
    }
  exit (0);
}
示例#11
0
  std::string key2string(XKeyEvent* kb)
  {
#define KEYSTRING_SIZE 10
    char keystring[KEYSTRING_SIZE];
    KeySym keysym_return;
    int len=0;

    if(inputContext) {
      len=Xutf8LookupString(inputContext, kb,keystring,KEYSTRING_SIZE,
                            &keysym_return,NULL);
    }
    if(len<1) {
      len=XLookupString(kb,keystring,2,&keysym_return,NULL);
    }

    if ( (keysym_return & 0xff00)== 0xff00 ) {
      //non alphanumeric key: use keysym
      return std::string(XKeysymToString(keysym_return));
    }

    if (len==0) {
      //modifier key:use keysym
      //triggerKeyboardEvent(XKeysymToString(keysym_return), kb->keycode, 1);
    } else if(len<KEYSTRING_SIZE) {
      keystring[len]=0;
    } else {
      keystring[KEYSTRING_SIZE-1]=0;
    }

    return std::string(keystring);
  }
示例#12
0
void sendkey(void *s,int press_and_release,int toggled){
	symbol_x11 *sym=(symbol_x11 *)s;
	KeyCode modifier;
	KeySym modifier_sym;
	assert(dpy);

	kbio.lastsent=sym->keycode;

	ungrabkeys();
	XFlush(dpy);

	uk_log("send keysym 0x%x keycode %i %s modifier=%i",
			(unsigned int)sym->ks,
			(int)sym->keycode,
			XKeysymToString(sym->ks),
			sym->modifier);

	XTestFakeKeyEvent(dpy,sym->keycode,1,CurrentTime); 
	XFlush(dpy);
	XTestFakeKeyEvent(dpy,sym->keycode,0,CurrentTime+100); 
	XFlush(dpy);

	XFlush(dpy);

	grabkeys();
}
示例#13
0
void _get_unique_keycodes(KeySym *keymap,int min,int max,int keysyms_per_keycode,int pass){
	// We really shouldn't skip all modifiers after 3
	int num=0;

	if(symbol_mode==DUMP){
		uk_log("Opening %s\n",symbol_file);
		sym_file=fopen(symbol_file,"w+");
		if(!sym_file){
		}
		assert(sym_file);
		fprintf(sym_file,"# x11\n");
		fprintf(sym_file,"#\n");
		fprintf(sym_file,"# line starting with  # is a comment\n");
		fprintf(sym_file,"# Only edit below this line!\n");
	}

	for(int modifier=0;modifier<keysyms_per_keycode && modifier < MOD_MAX;modifier++){
		// We don't need caps lock since shift will do the same
//		if(modifier == 1 ) continue;
		for(int kcode=min;kcode<=max;kcode++){
			KeySym ks=keymap[(kcode-min)*keysyms_per_keycode+modifier];
			if( ks != NoSymbol ){
				char *s=XKeysymToString(ks);
				// TODO: perhaps skipping XF86 and SUN is too a harsh design decision
				if(!_already_used(s) && strncmp("XF86",s,4) && strncmp("SUN",s,3)  
						&& strncmp("KP_",s,3)){

					if(pass==0 && _is_modifier(kcode)) _add_unique(s,ks,modifier,kcode);
					if(pass==1 && !_is_modifier(kcode)) _add_unique(s,ks,modifier,kcode);
				}
			}
		}
	}
}
static pa_hook_result_t sink_input_send_event_hook_cb(
        pa_core *c,
        pa_sink_input_send_event_hook_data *data,
        struct userdata *u) {

    KeySym sym;
    KeyCode code;
    Display *display;

    pa_assert(c);
    pa_assert(data);
    pa_assert(u);

    if (pa_streq(data->event, PA_STREAM_EVENT_REQUEST_CORK))
        sym = XF86XK_AudioPause;
    else if (pa_streq(data->event, PA_STREAM_EVENT_REQUEST_UNCORK))
        sym = XF86XK_AudioPlay;
    else
        return PA_HOOK_OK;

    pa_log_debug("Triggering X11 keysym: %s", XKeysymToString(sym));

    display = pa_x11_wrapper_get_display(u->x11_wrapper);
    code = XKeysymToKeycode(display, sym);

    XTestFakeKeyEvent(display, code, True, CurrentTime);
    XSync(display, False);

    XTestFakeKeyEvent(display, code, False, CurrentTime);
    XSync(display, False);

    return PA_HOOK_OK;
}
示例#15
0
void xevent_get_key_info (struct _xevent *p)
{
	XKeyEvent *e = (XKeyEvent *) &p->event;
	KeySym ks;
	KeyCode kc = 0;
	Bool kc_set = False;
	char *ksname;

	int nbytes;
	char str[256+1];
	nbytes = XLookupString (e, str, 256, &ks, NULL);
    if (ks == NoSymbol)
		ksname = "NoSymbol";
    else 
	{
		if (!(ksname = XKeysymToString (ks)))
			ksname = "(no name)";
		kc = XKeysymToKeycode(main_window->display, ks);
		kc_set = True;
    }
	
	log_message(DEBUG, "Key Info: ");
    log_message(DEBUG, "    root 0x%lx, subw 0x%lx, time %lu, (%d,%d), root:(%d,%d),",
	    e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root);
    log_message(DEBUG, "    state 0x%x, keycode %u (keysym 0x%lx, name \"%s\"),",
	    e->state, e->keycode, (unsigned long) ks, ksname);
    if (kc_set && e->keycode != kc)
		log_message(DEBUG, "    XKeysymToKeycode returns keycode: %u",kc);
	
	str[nbytes] = NULLSYM;
	log_message(DEBUG, "    XLookupString gives %d bytes: \"%s\" (is latin \"%c\")", nbytes, str, 
		main_window->xkeymap->get_cur_ascii_char(main_window->xkeymap, p->event));
}
示例#16
0
文件: cfg.c 项目: Devil084/pcsxr
void GetAnalogDescription(char *buf, int joynum, int analognum, int dir)
{
	switch (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].JoyEvType) {
		case BUTTON:
			sprintf(buf, _("Joystick: Button %d"), g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Button);
			break;
			
		case AXIS:
			sprintf(buf, _("Joystick: Axis %d%c"), abs(g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Axis) - 1,
					g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Axis > 0 ? '+' : '-');
			break;
			
		case HAT:
			sprintf(buf, _("Joystick: Hat %d %s"), (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Hat >> 8),
					hatname[g.cfg.PadDef[joynum].AnalogDef[analognum][dir].J.Hat & 0x0F]);
			break;
			
		case NONE:
		default:
			buf[0] = '\0';
			break;
	}
	
	if (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].Key != 0) {
		if (buf[0] != '\0') {
			strcat(buf, " / ");
		}
		char keyboardBuf[64] = {0};
		
		snprintf(keyboardBuf, 63, _("Keyboard: %s"), XKeysymToString(g.cfg.PadDef[joynum].AnalogDef[analognum][dir].Key));
		strcat(buf, keyboardBuf);
	}
}
static void
key_event (x_global_t *xg, XKeyEvent *event)
{
    cairo_5c_surface_t	*c5s = get_window_surface (xg, event->window);
    cairo_5c_gui_t	*gui;
    
    if (!c5s)
	return;
    gui = c5s->u.window.gui;
    if (gui->send_events)
    {
	char	*type = event->type == KeyPress ? "down" : "up";
	char	buffer[128];
	int	n, i;
	KeySym	sym;

	n = XLookupString (event, buffer, sizeof (buffer), &sym, NULL);
	fprintf (gui->send_events, "%d key-%s %s ",
		 (int) event->time, type, XKeysymToString (sym));
	for (i = 0; i < n; i++)
	    fprintf (gui->send_events, "%02x", buffer[i]);
        fprintf (gui->send_events, "\n");
	fflush (gui->send_events);
    }
}
示例#18
0
文件: kstoucs.c 项目: GNUHurdTR/hurd
unsigned int
KeySymToUcs4 (int keysym)
{
#ifdef XKB_DEBUG
  char *XKeysymToString(int keysym);
  printf ("KeySymToUcs4: %s (%d) -> ", XKeysymToString (keysym), keysym);
unsigned int doit (int keysym)
{
#endif

  /* Control characters not covered by keysym map. */
  if (keysym > 0 && keysym < 32)
    return keysym;

  /* 'Unicode keysym' */
  if ((keysym & 0xff000000) == 0x01000000)
    return (keysym & 0x00ffffff);

  #define NUM_KEYSYMS (sizeof kstoucs_map / sizeof(struct ksmap))
  return find_ucs(keysym, &kstoucs_map[0], &kstoucs_map[NUM_KEYSYMS - 1]);
#ifdef XKB_DEBUG
}
  unsigned int ret = doit (keysym);
  printf ("%d\n", ret);
  return ret;
#endif
}
void setItemShortcut(DbusmenuMenuitem *item, int jmodifiers, int x11keycode) {
  char* xname = XKeysymToString((KeySym)x11keycode);
  if (xname == NULL) {
    // _logmsg(LOG_LEVEL_ERROR, "XKeysymToString returns null for x11keycode=%d", x11keycode);
    return;
  }
  // _logmsg(LOG_LEVEL_INFO, "XKeysymToString returns %s for x11keycode=%d", xname, x11keycode);

  GVariantBuilder builder;
  g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
  if ((jmodifiers & SHIFT_MASK) != 0)
    g_variant_builder_add(&builder, "s",  DBUSMENU_MENUITEM_SHORTCUT_SHIFT);
  if ((jmodifiers & CTRL_MASK) != 0)
    g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_CONTROL);
  if ((jmodifiers & ALT_MASK) != 0)
    g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_ALT);
  if ((jmodifiers & META_MASK) != 0)
    g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_SUPER);

  g_variant_builder_add(&builder, "s", xname);

  GVariant *insideArr = g_variant_builder_end(&builder);
  g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
  g_variant_builder_add_value(&builder, insideArr);

  GVariant *outsideArr = g_variant_builder_end(&builder);
  dbusmenu_menuitem_property_set_variant(item, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsideArr);
}
示例#20
0
void
update_key_ring (XPointer priv, XRecordInterceptData *data)
{
  static int meta = 0;
  static int ctrl = 0;
  static int shift = 0;
  xEvent *event;
  KeySym ks;
  char *display_string;
  char *ksname;
  if (data->category==XRecordFromServer) {
    event=(xEvent *)data->data;
    /* display_keystack(keystack); */
    switch (event->u.u.type) {
      case KeyPress:
	ks = XKeycodeToKeysym(d0, event->u.u.detail, 0);
	ksname = XKeysymToString (ks); /* TBD: Might have to handle no symbol keys */
	if (! process_modifiers(ks, &meta, &ctrl, &shift, 1)) {
	  display_string = create_emacs_keyname(ksname, meta, ctrl, shift);
	  push(keystack, display_string);
	  display_keystrokes(osd, keystack);
	}
	break;
      case KeyRelease:
	ks = XKeycodeToKeysym(d0, event->u.u.detail, 0);
	process_modifiers(ks, &meta, &ctrl, &shift, 0);
	break;
    }
  }
}
示例#21
0
static void
mapping_busy_key(int timeout)
{
    int i;
    unsigned char keymap[32];
    static unsigned int masktable[8] = {
        0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
    };

    XQueryKeymap (dpy, (char *) keymap);

    fprintf (stderr,
             "%s:  please release the following keys within %d seconds:\n",
             ProgramName, timeout);
    for (i = 0; i < 256; i++) {
        if (keymap[i >> 3] & masktable[i & 7]) {
            KeySym ks = XKeycodeToKeysym (dpy, (KeyCode) i, 0);
            char *cp = XKeysymToString (ks);
            fprintf (stderr, "    %s (keysym 0x%x, keycode %d)\n",
                     cp ? cp : "UNNAMED", (unsigned int)ks, i);
        }
    }
    sleep (timeout);
    return;
}
示例#22
0
char *keyBindingToString(CompDisplay * d, CompKeyBinding * key)
{
	char *binding;

	binding = modifiersToString(d, key->modifiers);

	if (key->keycode != 0) {
		KeySym *keysym;
		char *keyname;
		int keysymsPerKeycode = 0;

		/* convert keycode to keysym */
		keysym = XGetKeyboardMapping(d->display,
					     key->keycode, 1,
					     &keysymsPerKeycode);

		keyname = XKeysymToString(keysym[0]);

		XFree(keysym);

		if (keyname) {
			binding = stringAppend(binding, keyname);
		} else {
			char keyCodeStr[256];

			snprintf(keyCodeStr, 256, "0x%x", key->keycode);
			binding = stringAppend(binding, keyCodeStr);
		}
	}

	return binding;
}
std::string keypress_str()
{
    if (e.type == KeyPress)
            return XKeysymToString(XKeycodeToKeysym(dpy,e.xkey.keycode,0));
    return "0";

}
示例#24
0
static char *xkey_get_key_name(int key)
{
  static char buf[32];
  KeySym ksym;
  char *prefix, *name;

  if ((key & 0xff00) == 0x100) {
    key &= 0xff;
    ksym = (KeySym)((XK_Home & 0xff00) | key); 
    name = XKeysymToString(ksym);
    if (!name)
      name = "Unknown key";
    strcpy(buf, name);
    return buf;
  }
  
  if (key & 0xff00) {
    key &= 0xff;
    prefix = "meta-";
  }
  else {
    prefix = "";
  }

  if (key < 32) {
    sprintf(buf, "%sctrl-%c", prefix, key+'A'-1);	
  }
  else {
    sprintf(buf, "%s%c", prefix, key);
  }

  return buf;
}
示例#25
0
文件: input.c 项目: ivoarch/ratpoison
/* Return the name of the keysym. caller must free returned pointer */
char *
keysym_to_string (KeySym keysym, unsigned int modifier)
{
  struct sbuf *name;
  char *tmp;

  name = sbuf_new (0);

  if (modifier & RP_SHIFT_MASK) sbuf_concat (name, "S-");
  if (modifier & RP_CONTROL_MASK) sbuf_concat (name, "C-");
  if (modifier & RP_META_MASK) sbuf_concat (name, "M-");
  if (modifier & RP_ALT_MASK) sbuf_concat (name, "A-");
  if (modifier & RP_HYPER_MASK) sbuf_concat (name, "H-");
  if (modifier & RP_SUPER_MASK) sbuf_concat (name, "s-");

  /* On solaris machines (perhaps other machines as well) this call
     can return NULL. In this case use the "NULL" string. */
  tmp = XKeysymToString (keysym);
  if (tmp == NULL)
    tmp = "NULL";

  sbuf_concat (name, tmp);

  return sbuf_free_struct (name);
}
示例#26
0
文件: input.c 项目: xtaran/ratpoison
/* Return the name of the keysym. caller must free returned pointer */
char *
keysym_to_string (KeySym keysym, unsigned int modifier)
{
  static char *null_string = "NULL"; /* A NULL string. */
  struct sbuf *name;
  char *tmp;

  name = sbuf_new (0);

  if (modifier & RP_SHIFT_MASK) sbuf_concat (name, "S-");
  if (modifier & RP_CONTROL_MASK) sbuf_concat (name, "C-");
  if (modifier & RP_META_MASK) sbuf_concat (name, "M-");
  if (modifier & RP_ALT_MASK) sbuf_concat (name, "A-");
  if (modifier & RP_HYPER_MASK) sbuf_concat (name, "H-");
  if (modifier & RP_SUPER_MASK) sbuf_concat (name, "s-");

  /* On solaris machines (perhaps other machines as well) this call
     can return NULL. In this case use the "NULL" string. */
  tmp = XKeysymToString (keysym);
  if (tmp == NULL)
    tmp = null_string;

  sbuf_concat (name, tmp);

  /* Eat the nut and throw away the shells. */
  tmp = sbuf_get (name);
  free (name);

  return tmp;
}
示例#27
0
文件: gravity.c 项目: tomby42/prg-xws
/*
 * Hlavní cyklus zpracování událostí
 */
static void event_loop(void)
{
    XEvent event;
    char buf[10];
    KeySym keysym;

    while(1) {
        XNextEvent(display, &event);
        switch(event.type) {
        case Expose:
            expose(&event.xexpose);
            break;
        case ButtonPress:
            debug("Button %u pressed\n", event.xbutton.button);
            return;
            break;
        case KeyPress:
            XLookupString(&event.xkey, buf, 10, &keysym, NULL);
            debug("Key \"%s\" pressed\n", XKeysymToString(keysym));
            return;
            break;
        case MappingNotify:
            /* Naèíst zmìnìné mapování kláves */
            if(event.xmapping.request == MappingKeyboard)
                XRefreshKeyboardMapping(&event.xmapping);
            break;
        default:
            /* Zbylé nezajímavé události */
            break;
        }
    }
}
示例#28
0
static void
on_evdev_key_pressed (guint32  time_,
                      guint32  key,
                      guint32  state,
                      gpointer data)
{
  Rebinder *rebinder = data;
  Binding *binding;

  if (!state)
    {
      fakekey_release (rebinder->fake);
      return;
    }

  /* don't look at events with keycodes < 255, they go through X */
  if (key <= 255)
    return;

  /* Custom bindings (from rebinder.conf) */
  binding = find_binding_by_keycode (rebinder, key);

  /* Try to find the keycode in the static binding pool */
  if (binding == NULL)
    binding = find_evdev_binding_by_keycode (key);

  if (binding == NULL)
    return;

  MEX_NOTE (EVDEV, "Sending keysym 0x%08x (%s)", (int) binding->keysym,
            XKeysymToString (binding->keysym));

  fakekey_press_keysym (rebinder->fake, binding->keysym,  0);
}
示例#29
0
void
print_key (Display * d, Keys_t * key)
{
  char str[STR_KEY_LEN];

  if (verbose)
    {
      if (key->type == SYM)
	{
	  modifier_to_string (key->modifier, str);

	  printf ("\"%s\"\n    %s%s%s%s\n",
		  key->command != NULL ? key->command : ( key->function != 0 ? "(Scheme function)" : "NoCommand" ),
		  key->event_type == PRESS ? "" : "Release + ",
		  str, str[0] ? " + " : "", XKeysymToString (key->key.sym));
	}
      else if (key->type == BUTTON)
	{
	  printf ("\"%s\"\n    %sm:0x%x + b:%d   (mouse)\n",
		  key->command != NULL ? key->command : ( key->function != 0 ? "(Scheme function)" : "NoCommand" ),
		  key->event_type == PRESS ? "" : "Release + ",
		  key->modifier, key->key.button);
	}
      else
	{
	  printf ("\"%s\"\n    %sm:0x%x + c:%d\n",
		  key->command != NULL ? key->command : ( key->function != 0 ? "(Scheme function)" : "NoCommand" ),
		  key->event_type == PRESS ? "" : "Release + ",
		  key->modifier, key->key.code);
	  if (d != NULL)
	    {
	      modifier_to_string (key->modifier, str);
	      printf ("    %s%s%s%s\n",
		      str,
		      str[0] ? " + " : "",
		      key->event_type == PRESS ? "" : "Release + ",
		      (XKeysymToString
		       (XKeycodeToKeysym (d, key->key.code, 0)) !=
		       NULL) ? XKeysymToString (XKeycodeToKeysym (d,
								  key->key.
								  code,
								  0)) :
		      "NoSymbol");
	    }
	}
    }
}
示例#30
0
void ModifiersModule::updateWidgets()
{
	if( m_pchkMacKeyboard->isChecked() ) {
		// If keys are swapped around to reflect MacOS norms:
		if( m_pchkMacSwap->isChecked() ) {
			m_plblCtrl->setText( i18n("Command") ); // Ctrl in Alt's place
			m_plblAlt->setText( i18n("Option") );   // Alt in Win's place
			m_plblWin->setText( i18n("Control") );  // Win in Ctrl's place
		} else {
			m_plblCtrl->setText( i18n("Control") ); // Ctrl labeled Control
			m_plblAlt->setText( i18n("Option") );  // Alt labeled Command
			m_plblWin->setText( i18n("Command") );   // Win labeled Option
		}
		m_pchkMacSwap->setEnabled( true );
	} else {
		m_plblCtrl->setText( i18n(TQACCEL_OBJECT_NAME_STRING, "Ctrl") );
		m_plblAlt->setText( i18n(TQACCEL_OBJECT_NAME_STRING, "Alt") );
		m_plblWin->setText( i18n("Win") );
		m_pchkMacSwap->setEnabled( false );
	}

	XModifierKeymap* xmk = XGetModifierMapping( tqt_xdisplay() );

	for( int iKey = m_plstXMods->columns()-1; iKey < xmk->max_keypermod; iKey++ )
		m_plstXMods->addColumn( i18n("Key %1").arg(iKey+1) );

	//int iModWinDef = -1;
	for( int iMod = 0; iMod < 8; iMod++ ) {
		// Find the default modifier index for the Win key.
		/*if( iMod > Mod2Index ) {
			uint symX = XkbKeycodeToKeysym( tqt_xdisplay(), xmk->modifiermap[xmk->max_keypermod * iMod], 0, 0 );
			if( symX == XK_Super_L || symX == XK_Super_R )
				iModWinDef = iMod;
			else if( iModWinDef == -1 && (symX == XK_Meta_L || symX == XK_Meta_R) )
				iModWinDef = iMod;
		}*/

		// Insert items into X modifier map list
		for( int iKey = 0; iKey < xmk->max_keypermod; iKey++ ) {
			uint symX = XkbKeycodeToKeysym( tqt_xdisplay(), xmk->modifiermap[xmk->max_keypermod * iMod + iKey], 0, 0 );
			m_plstXMods->itemAtIndex( iMod )->setText( 1 + iKey, XKeysymToString( symX ) );
		}
	}

	XFreeModifiermap( xmk );

	int i;
	switch( KKeyNative::modX(KKey::WIN) ) {
		case Mod2Mask: i = 2; break;
		case Mod3Mask: i = 3; break;
		case Mod4Mask: i = 4; break;
		case Mod5Mask: i = 5; break;
		default:       i = 0;
	}
	if( i != 0 )
		m_plblWinModX->setText( "mod" + TQString::number(i) );
	else
		m_plblWinModX->setText( "<" + i18n("None") + ">" );
}