Exemplo n.º 1
0
SkOSWindow::NextXEventResult SkOSWindow::nextXEvent() {
    XEvent evt;
    Display* dsp = fUnixWindow.fDisplay;

    if (!MyXNextEventWithDelay(dsp, &evt)) {
        return kContinue_NextXEventResult;
    }

    switch (evt.type) {
        case Expose:
            if (0 == evt.xexpose.count) {
                return kPaintRequest_NextXEventResult;
            }
            break;
        case ConfigureNotify:
            this->resize(evt.xconfigure.width, evt.xconfigure.height);
            break;
        case ButtonPress:
            if (evt.xbutton.button == Button1)
                this->handleClick(evt.xbutton.x, evt.xbutton.y,
                            SkView::Click::kDown_State, NULL, getModi(evt));
            break;
        case ButtonRelease:
            if (evt.xbutton.button == Button1)
                this->handleClick(evt.xbutton.x, evt.xbutton.y,
                              SkView::Click::kUp_State, NULL, getModi(evt));
            break;
        case MotionNotify:
            this->handleClick(evt.xmotion.x, evt.xmotion.y,
                           SkView::Click::kMoved_State, NULL, getModi(evt));
            break;
        case KeyPress: {
            int shiftLevel = (evt.xkey.state & ShiftMask) ? 1 : 0;
            KeySym keysym = XkbKeycodeToKeysym(dsp, evt.xkey.keycode,
                                               0, shiftLevel);
            if (keysym == XK_Escape) {
                return kQuitRequest_NextXEventResult;
            }
            this->handleKey(XKeyToSkKey(keysym));
            long uni = keysym2ucs(keysym);
            if (uni != -1) {
                this->handleChar((SkUnichar) uni);
            }
            break;
        }
        case KeyRelease:
            this->handleKeyUp(XKeyToSkKey(XkbKeycodeToKeysym(dsp, evt.xkey.keycode, 0, 0)));
            break;
        case ClientMessage:
            if ((Atom)evt.xclient.data.l[0] == wm_delete_window_message) {
                return kQuitRequest_NextXEventResult;
            }
            // fallthrough
        default:
            // Do nothing for other events
            break;
    }
    return kContinue_NextXEventResult;
}
Exemplo n.º 2
0
void SkOSWindow::loop() {
    Display* dsp = fUnixWindow.fDisplay;
    if (NULL == dsp) {
        return;
    }
    XSelectInput(dsp, fUnixWindow.fWin, EVENT_MASK);

    bool loop = true;
    XEvent evt;
    while (loop) {
        XNextEvent(dsp, &evt);
        switch (evt.type) {
            case Expose:
                if (evt.xexpose.count == 0)
                    this->inval(NULL);
                break;
            case ConfigureNotify:
                this->resize(evt.xconfigure.width, evt.xconfigure.height);
                break;
            case ButtonPress:
                if (evt.xbutton.button == Button1)
                    this->handleClick(evt.xbutton.x, evt.xbutton.y, SkView::Click::kDown_State);
                break;
            case ButtonRelease:
                if (evt.xbutton.button == Button1)
                    this->handleClick(evt.xbutton.x, evt.xbutton.y, SkView::Click::kUp_State);
                break;
            case MotionNotify:
                this->handleClick(evt.xmotion.x, evt.xmotion.y, SkView::Click::kMoved_State);
                break;
            case KeyPress: {
                KeySym keysym = XkbKeycodeToKeysym(dsp, evt.xkey.keycode, 0, 0);
                //SkDebugf("pressed key %i!\n\tKeySym:%i\n", evt.xkey.keycode, XKeycodeToKeysym(dsp, evt.xkey.keycode, 0));
                if (keysym == XK_Escape) {
                    loop = false;
                    break;
                }
                this->handleKey(XKeyToSkKey(keysym));
                long uni = keysym2ucs(keysym);
                if (uni != -1) {
                    this->handleChar((SkUnichar) uni);
                }
                break;
            }
            case KeyRelease:
                //SkDebugf("released key %i\n", evt.xkey.keycode);
                this->handleKeyUp(XKeyToSkKey(XkbKeycodeToKeysym(dsp, evt.xkey.keycode, 0, 0)));
                break;
            case ClientMessage:
                if (SkEvent::ProcessEvent()) {
                    this->post_linuxevent();
                }
                break;
            default:
                // Do nothing for other events
                break;
        }
    }
}
Exemplo n.º 3
0
void grab_keys(int mk, int uk, int dk,
	       int mm, int um, int dm,
	       int step) {
  Display* disp = GDK_DISPLAY();

  // ungrab any previous keys
  XUngrabKey(disp, AnyKey, AnyModifier, GDK_ROOT_WINDOW());

  volMuteKey = mk;
  volUpKey = uk;
  volDownKey = dk;
  volMuteMods = mm;
  volUpMods = um;
  volDownMods = dm;
  volStep = step;

  if (mk < 0 &&
      uk < 0 &&
      dk < 0)
    return;
  
  xErr = 0;
  errBuf = g_malloc(errBufSize*sizeof(gchar));
  printBuf = errBuf + snprintf(errBuf,errBufSize,_("Could not bind the following hotkeys:\n"));
  errBufSize -= (printBuf - errBuf);

  if (muteSymStr) g_free(muteSymStr);
  if (upSymStr)   g_free(upSymStr);
  if (downSymStr) g_free(downSymStr);
  muteSymStr = gtk_accelerator_name(XkbKeycodeToKeysym(GDK_DISPLAY(), volMuteKey, 0, 0),volMuteMods);
  upSymStr = gtk_accelerator_name(XkbKeycodeToKeysym(GDK_DISPLAY(),volUpKey,0, 0),volUpMods);
  downSymStr = gtk_accelerator_name(XkbKeycodeToKeysym(GDK_DISPLAY(), volDownKey, 0, 0),volDownMods);

  XErrorHandler old_hdlr = XSetErrorHandler(errhdl);
  if (volMuteKey > 0) {
    muteSerial = NextRequest(disp);
    XGrabKey(disp,volMuteKey,volMuteMods,GDK_ROOT_WINDOW(),1,GrabModeAsync,GrabModeAsync);
  }

  if (volUpKey > 0) {
    upSerial = NextRequest(disp);
    XGrabKey(disp,volUpKey,volUpMods,GDK_ROOT_WINDOW(),1,GrabModeAsync,GrabModeAsync);
  }

  if (volDownKey > 0) {
    downSerial = NextRequest(disp);
    XGrabKey(disp,volDownKey,volDownMods,GDK_ROOT_WINDOW(),1,GrabModeAsync,GrabModeAsync);
  }

  XFlush(disp);
  XSync(disp, False);
  (void) XSetErrorHandler(old_hdlr);
  
  if (xErr) 
    g_idle_add(idle_report_error, NULL);
  else
    g_free(errBuf);
}
Exemplo n.º 4
0
static char *next_state(const cmdp_token *token) {
    cmdp_state _next_state = token->next_state;

    if (token->next_state == __CALL) {
        const char *modifiers = get_string("modifiers");
        int keycode = atoi(get_string("key"));
        int level = 0;
        if (modifiers != NULL &&
            strstr(modifiers, "Shift") != NULL) {
            /* When shift is included, we really need to use the second-level
             * symbol (upper-case). The lower-case symbol could be on a
             * different key than the upper-case one (unlikely for letters, but
             * more likely for special characters). */
            level = 1;

            /* Try to use the keysym on the first level (lower-case). In case
             * this doesn’t make it ambiguous (think of a keyboard layout
             * having '1' on two different keys, but '!' only on keycode 10),
             * we’ll stick with the keysym of the first level.
             *
             * This reduces a lot of confusion for users who switch keyboard
             * layouts from qwerty to qwertz or other slight variations of
             * qwerty (yes, that happens quite often). */
            KeySym sym = XkbKeycodeToKeysym(dpy, keycode, 0, 0);
            if (!keysym_used_on_other_key(sym, keycode))
                level = 0;
        }
        KeySym sym = XkbKeycodeToKeysym(dpy, keycode, 0, level);
        char *str = XKeysymToString(sym);
        const char *release = get_string("release");
        char *res;
        char *modrep = (modifiers == NULL ? sstrdup("") : sstrdup(modifiers));
        char *comma;
        while ((comma = strchr(modrep, ',')) != NULL) {
            *comma = '+';
        }
        sasprintf(&res, "bindsym %s%s%s %s%s\n", (modifiers == NULL ? "" : modrep), (modifiers == NULL ? "" : "+"), str, (release == NULL ? "" : release), get_string("command"));
        clear_stack();
        return res;
    }

    state = _next_state;

    /* See if we are jumping back to a state in which we were in previously
     * (statelist contains INITIAL) and just move statelist_idx accordingly. */
    for (int i = 0; i < statelist_idx; i++) {
        if (statelist[i] != _next_state)
            continue;
        statelist_idx = i+1;
        return NULL;
    }

    /* Otherwise, the state is new and we add it to the list */
    statelist[statelist_idx++] = _next_state;
    return NULL;
}
Exemplo n.º 5
0
void
xu_key_ungrab(Window win, u_int mask, KeySym keysym)
{
	KeyCode	 code;
	u_int	 i;

	code = XKeysymToKeycode(X_Dpy, keysym);
	if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) &&
	    (XkbKeycodeToKeysym(X_Dpy, code, 0, 1) == keysym))
		mask |= ShiftMask;

	for (i = 0; i < nitems(ign_mods); i++)
		XUngrabKey(X_Dpy, code, (mask | ign_mods[i]), win);
}
Exemplo n.º 6
0
KeySym
XKeycodeToKeysym(Display *dpy,
#if NeedWidePrototypes
		 unsigned int kc,
#else
		 KeyCode kc,
#endif
		 int col)
{
    XkbDescRec	*xkb;

    if (_XkbUnavailable(dpy))
	return _XKeycodeToKeysym(dpy, kc, col);

    _XkbCheckPendingRefresh(dpy,dpy->xkb_info);

    xkb = dpy->xkb_info->desc;
    if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code))
	return NoSymbol;

    if (col>3) {
	int lastSym,tmp,nGrp;

	lastSym= 3;
	nGrp= XkbKeyNumGroups(xkb,kc);
	if ((nGrp>0)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup1Index))>2)) {
	    if (col<=(lastSym+tmp-2))
		return XkbKeycodeToKeysym(dpy,kc,XkbGroup1Index,col-lastSym+2);
	    lastSym+= tmp-2;
	}
	if ((nGrp>1)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup2Index))>2)) {
	    if (col<=(lastSym+tmp-2))
		return XkbKeycodeToKeysym(dpy,kc,XkbGroup2Index,col-lastSym+2);
	    lastSym+= tmp-2;
	}
	if (nGrp>2) {
	    tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup3Index);
	    if (col<=lastSym+tmp)
		return XkbKeycodeToKeysym(dpy,kc,XkbGroup3Index,col-lastSym);
	    lastSym+= tmp;
	}
	if (nGrp>3) {
	    tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup4Index);
	    if (col<=lastSym+tmp)
		return XkbKeycodeToKeysym(dpy,kc,XkbGroup4Index,col-lastSym);
	}
	return NoSymbol;
    }
    return XkbKeycodeToKeysym(dpy,kc,(col>>1),(col&1));
}
Exemplo n.º 7
0
void PressKey(wchar key, _XDisplay *dpy = NULL) {
    bool local = false;
    if (!dpy) {
        if (!(dpy = XOpenDisplay(NULL)))
            return;
        local = true;
    }
    wchar k = key;
    if (key > 0x00ff)
        key = key | 0x01000000;

    bool shift = false;
    KeyCode code = XKeysymToKeycode(dpy, key);
    if (code != 0) {
        if (XkbKeycodeToKeysym(dpy, code, 0, 0) != key) {
            if (XkbKeycodeToKeysym(dpy, code, 1, 0) == key)
                shift = true;
            else
                code = 0;
        }
    } else {
        int firstKeycode, maxKeycode;
        int keysymsPerKeycode;

        XDisplayKeycodes(dpy, &firstKeycode, &maxKeycode);
        KeySym *keysyms = XGetKeyboardMapping(dpy, firstKeycode, maxKeycode - firstKeycode + 1, &keysymsPerKeycode);
        int indx = (maxKeycode - firstKeycode - 1)*keysymsPerKeycode;
        keysyms[indx] = key;
        XChangeKeyboardMapping(dpy, firstKeycode, keysymsPerKeycode, keysyms, maxKeycode-firstKeycode);
        XSync(dpy, False);
        code = maxKeycode-1;
        if (XkbKeycodeToKeysym(dpy, code, 0, 0) != key) {
            if (XkbKeycodeToKeysym(dpy, code, 1, 0) == key)
                shift = true;
        }
    }
    if (code != 0) {
        if (shift)
            XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, XK_Shift_L), True, CurrentTime);
        XTestFakeKeyEvent(dpy, code, True,  CurrentTime);
        XTestFakeKeyEvent(dpy, code, False, CurrentTime);
        if (shift)
            XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, XK_Shift_L), False, CurrentTime);
    }
    if (local) {
        XFlush(dpy);
        XCloseDisplay(dpy);
    }
}
Exemplo n.º 8
0
void
xu_key_grab(Window win, unsigned int mask, KeySym keysym)
{
	KeyCode		 code;
	unsigned int	 i;

	code = XKeysymToKeycode(X_Dpy, keysym);
	if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) &&
	    (XkbKeycodeToKeysym(X_Dpy, code, 0, 1) == keysym))
		mask |= ShiftMask;

	for (i = 0; i < nitems(ign_mods); i++)
		XGrabKey(X_Dpy, code, (mask | ign_mods[i]), win,
		    True, GrabModeAsync, GrabModeAsync);
}
void
handle_key (XCape_t* self, int key_event)
{
    if ( key_event == KeyPress ) {
        g_debug ("Key Pressed!\n");
        key_press_cnt++;
    } else {
        g_debug ("Key Released!\n");
        if ( (key_press_cnt == 1) && (super_press) ) {
        /*if ( (key_press_cnt == 1) ) {*/
            if ( is_grabbed () ) {
               return ;
            }
            KeySym key_sym;

            key_sym = XkbKeycodeToKeysym (self->ctrl_conn, self->key, 0, 0);
            gchar* key_str = g_strdup_printf ("%lu", (gulong)key_sym);
            if ( key_str ) {
                gchar* cmd = g_hash_table_lookup (key_table, key_str);
                if ( cmd ) {
                    if ( system (cmd) == -1 ) {
                        g_debug ("system exec error!");
                    }
                }
                g_free ( key_str);
            }
        }
        key_press_cnt = 0;
        super_press = False;
    }
}
Exemplo n.º 10
0
static int handle_special_keys(WindowInfo* info, XEvent* event, int down) {
	int keySym;

	if (!s_keyb_ext) 
		return 0;

	keySym = XkbKeycodeToKeysym(s_display, event->xkey.keycode, 0, 1);

	switch (keySym)
	{
		case XK_KP_0:
		case XK_KP_1:
		case XK_KP_2:
		case XK_KP_3:
		case XK_KP_4:
		case XK_KP_5:
		case XK_KP_6:
		case XK_KP_7:
		case XK_KP_8:
		case XK_KP_9:
		case XK_KP_Separator:
		case XK_KP_Decimal:
		case XK_KP_Equal:
		case XK_KP_Enter:
		{
			if (info->key_callback) {
				info->key_callback(info->rust_data, keySym, down);
				return 1;
			}
		}
	}

	return 0;
}
Exemplo n.º 11
0
void
TkpSetKeycodeAndState(
    Tk_Window tkwin,
    KeySym keySym,
    XEvent *eventPtr)
{
    Display *display = Tk_Display(tkwin);
    int state;
    KeyCode keycode;

    if (keySym == NoSymbol) {
	keycode = 0;
    } else {
	keycode = XKeysymToKeycode(display, keySym);
	if (keycode != 0) {
	    for (state = 0; state < 4; state++) {
		if (XkbKeycodeToKeysym(display, keycode, 0, state) == keySym){
		    if (state & 1) {
			eventPtr->xkey.state |= ShiftMask;
		    }
		    if (state & 2) {
			TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

			eventPtr->xkey.state |= dispPtr->modeModMask;
		    }
		    break;
		}
	    }
	}
    }
    eventPtr->xkey.keycode = keycode;
}
Exemplo n.º 12
0
void XWindow::OnKeyRelease(WindowEventKey *e)
{
    XkbStateRec s;
    Status st = XkbGetState(e->Handle()->display, XkbUseCoreKbd, &s);
    if (st != XkbOD_Success)
        throw new XException("Error getting xkb keyboard state", __FILE__, __LINE__, __func__);

    int shift = (s.mods & ShiftMask) != 0 ? 1 : 0;
    if (shift == 0) shift =  (s.mods & Mod5Mask) != 0 ? 2 : 0;
    //int lock = (s.mods & LockMask) != 0 ? 1 : 0;
    //int ctrl = (s.mods & ControlMask) != 0 ? 1 : 0;
    //int mod1 = (s.mods & Mod1Mask) != 0 ? 1 : 0;
    //int mod2 = (s.mods & Mod2Mask) != 0 ? 1 : 0;
    //int mod3 = (s.mods & Mod3Mask) != 0 ? 1 : 0;
    //int mod4 = (s.mods & Mod4Mask) != 0 ? 1 : 0;
    //int mod5 = (s.mods & Mod5Mask) != 0 ? 1 : 0;
    KeySym keySym = XkbKeycodeToKeysym(e->Handle()->display, e->Handle()->keycode, 0, shift);

    char cadena[10];
    int overflow = 0;
    int nbytes = XkbTranslateKeySym(e->Handle()->display, &keySym, s.mods, cadena, 10, &overflow);
    Text keyText = nbytes > 0 ? cadena : "";

    ControlEventKey kr(*e, KeyCompositionSymbol(keySym, keyText));

    // Key redirection until the focused control catches it
    bool redirected = false;
    for (int i=0; i<controls->Count() && !redirected; i++)
        redirected = (*controls)[i]->OnKeyRelease(&kr);

    DelegationOnKeyRelease().Execute(e);
}
Exemplo n.º 13
0
void keypress(XEvent *e) {
	int t;
	KeySym key = XkbKeycodeToKeysym(dpy,e->xkey.keycode,0,0);
	if (key == XK_q) running = False;
	else if (key == XK_Up || key == XK_equal || key == XK_k) {
		t = ww; wx -= ((ww*=1.1) - t)/2; t = wh; wy -= ((wh*=1.1) - t)/2;
	}
	else if (key == XK_Down || key == XK_minus || key == XK_j) {
		t = ww; wx += (t - (ww/=1.1))/2; t = wh; wy += (t - (wh/=1.1))/2;
	}
	else if (key == XK_Right || key == XK_l) {
		wx-=5; wy+=5; ww+=10; wh-=10;
	}
	else if (key == XK_Left || key == XK_h) {
		wx+=5; wy-=5; ww-=10; wh+=10;
	}
	else if (key == XK_r) {
		ww = iw; wh = ih; 
		wx = ( sw > ww ? (sw-ww)/2 : 0); wy = ( sh > wh ? (sh-wh)/2 : 0);
	}
	else if (key == XK_s || (key == XK_f && (fullscreen=!fullscreen))) {
		scale = ( sw/(float)iw > sh/(float)ih ? sh/(float)ih : sw/(float)iw );
		ww = iw * scale + 0.5; wh = ih * scale + 0.5;
		wx = (sw-ww)/2; wy = (sh-wh)/2;
	}
	else {
		return;
	}
	if (fullscreen) XMoveResizeWindow(dpy,win,0,0,sw,sh);
	else XMoveResizeWindow(dpy,win,wx,wy,ww,wh);
	XFlush(dpy);
	draw();
}
Exemplo n.º 14
0
void init_modifier_keys() {
    int i, k = 0;
    int min_keycode, max_keycode, keysyms_per_keycode = 0;

    std::list<KeySym> Mod1MaskSyms, Mod2MaskSyms, Mod3MaskSyms,
		      Mod4MaskSyms, Mod5MaskSyms;

    gXNumLockMask = 0;
    XModifierKeymap *map = XGetModifierMapping(XimServer::gDpy);
    XDisplayKeycodes(XimServer::gDpy, &min_keycode, &max_keycode);
    KeySym *sym = XGetKeyboardMapping(XimServer::gDpy,
                    static_cast<KeyCode>(min_keycode),
                    (max_keycode - min_keycode + 1), &keysyms_per_keycode);
    for (i = 0; i < 8; i++) {
	int j;
	for (j = 0; j < map->max_keypermod; j++) {
	    if (map->modifiermap[k]) {
		KeySym ks;
		int index = 0;
		do {
		    ks = XkbKeycodeToKeysym(XimServer::gDpy,
				    map->modifiermap[k], 0, index);
		    index++;
		} while (!ks && index < keysyms_per_keycode);

		switch (i) {
		case ShiftMapIndex: break;
		case LockMapIndex: break;
		case ControlMapIndex: break;
		case Mod1MapIndex: Mod1MaskSyms.push_back(ks); break;
		case Mod2MapIndex: Mod2MaskSyms.push_back(ks); break;
		case Mod3MapIndex: Mod3MaskSyms.push_back(ks); break;
		case Mod4MapIndex: Mod4MaskSyms.push_back(ks); break;
		case Mod5MapIndex: Mod5MaskSyms.push_back(ks); break;
		default: break;
		}
		// Check NumLock key
		if (ks == XK_Num_Lock)
		    gXNumLockMask |= (1 << i);
	    }
	    k++;
	}
    }
    XFreeModifiermap(map);
    XFree(sym);

    gMod1Mask = check_modifier(Mod1MaskSyms);
    gMod2Mask = check_modifier(Mod2MaskSyms);
    gMod3Mask = check_modifier(Mod3MaskSyms);
    gMod4Mask = check_modifier(Mod4MaskSyms);
    gMod5Mask = check_modifier(Mod5MaskSyms);

    if (uim_scm_c_bool(uim_scm_callf("require-dynlib", "s", "xkb")))
	uim_scm_callf("%xkb-set-display", "p", XimServer::gDpy);

#if UIM_XIM_USE_JAPANESE_KANA_KEYBOARD_HACK
    // Init at here to sync with proper update timing although not a modifier.
    uim_x_kana_input_hack_init(XimServer::gDpy);
#endif
}
Exemplo n.º 15
0
static void sorter(const char *cmd) {
	int i, j, n, nn = show->cur, grid, pn = -1;
	grid = (int) ceil(sqrt(show->nslides));
	cairo_surface_t *t = cairo_image_surface_create(0, show->w, show->h);
	cairo_t *ctx = cairo_create(t);
	cairo_scale(ctx, MARGIN/(float)grid, MARGIN/(float)grid);
	cairo_translate(ctx,
			(show->w * (1-MARGIN))/2.0,
			(show->w * (1-MARGIN))/2.0);
	grab_mouse();
	XEvent ev;
	XDefineCursor(dpy, wshow, None);
	while (True) {
		if (nn != pn) {
			pn = nn;
			cairo_set_source_rgba(ctx, 0, 0, 0, 1);
			cairo_paint(ctx);
			for (j = 0; j < grid; j++) for (i = 0; i < grid; i++) {
				if ( (n=j * grid + i) >= show->nslides ) break;
				cairo_set_source_surface(ctx, show->slide[n],
					(show->w * i)/MARGIN, (show->h * j)/MARGIN);
				cairo_paint_with_alpha(ctx,(n == nn ? 1.0 : 0.5));
			}
			cairo_set_source_surface(show->target[0].ctx, t, 0, 0);
			cairo_paint(show->target[0].ctx);
			XFlush(dpy);
		}
		XMaskEvent(dpy,PointerMotionMask|ButtonPressMask|KeyPressMask,&ev);
		if (ev.type == KeyPress) {
			switch (XkbKeycodeToKeysym(dpy, ev.xkey.keycode, 0, 0)) {
				case 'h': case XK_Right: nn++; break;
				case 'j': case XK_Down: nn += grid; break;
				case 'k': case XK_Up: nn -= grid; break;
				case 'l': case XK_Left: nn--; break;
				case XK_space: case XK_Return: goto full_break_change; break;
				default: goto full_break_no_change;
			}
			if (nn < 0) nn = 0;
			else if (nn >= show->nslides) nn = show->nslides - 1;
		}
		else if (ev.type == ButtonPress) {
			if (ev.xbutton.button == 1) break;
			else if (ev.xbutton.button == 2) goto full_break_no_change;
			else if (ev.xbutton.button == 3) goto full_break_no_change;
		}
		else if (ev.type == MotionNotify) {
			nn = (ev.xbutton.y * grid / show->h) * grid +
					(ev.xbutton.x * grid / show->w);
		}
	}
	full_break_change:
	show->cur = nn;
	full_break_no_change:
	XUngrabKeyboard(dpy, CurrentTime);
	XUngrabPointer(dpy, CurrentTime);
	cairo_destroy(ctx);
	cairo_surface_destroy(t);
	XDefineCursor(dpy, wshow, invisible_cursor);
	draw(None);
}
Exemplo n.º 16
0
/*
 * Fetch one entry from the device's keymap if supported.
 * this does a fake mapping based on the orginal DFB code
 */
static DFBResult
driver_get_keymap_entry( CoreInputDevice           *device,
                         void                      *driver_data,
                         DFBInputDeviceKeymapEntry *entry )
{
     int           i;
     X11InputData *data = driver_data;
     DFBX11       *x11  = data->x11;

     XLockDisplay( x11->display );

     for (i=0; i<4; i++) {
          KeySym xSymbol = XkbKeycodeToKeysym( x11->display, entry->code, 0, i );

          if (i == 0)
               entry->identifier = xsymbol_to_id( xSymbol );

          entry->symbols[i] = xsymbol_to_symbol( xSymbol );
     }

     XUnlockDisplay( x11->display );

     /* is CapsLock effective? */
     if (entry->identifier >= DIKI_A && entry->identifier <= DIKI_Z)
          entry->locks |= DILS_CAPS;

     /* is NumLock effective? */
     if (entry->identifier >= DIKI_KP_DECIMAL && entry->identifier <= DIKI_KP_9)
          entry->locks |= DILS_NUM;

     return DFB_OK;
}
Exemplo n.º 17
0
void intercept(XPointer user_data, XRecordInterceptData *data) {
	XCape_t *self = (XCape_t*) user_data;
	static Bool mouse_pressed = False;
	KeyMap_t *km;

	if (data->category == XRecordFromServer) {
		int key_event = data->data[0];
		KeyCode key_code = data->data[1];

		if (self->debug)
			fprintf(stdout, "Intercepted key event %d, key code %d\n",
					key_event, key_code);

		for (km = self->map; km != NULL; km = km->next) {
			if ((km->UseKeyCode == False
					&& XkbKeycodeToKeysym(self->ctrl_conn, key_code, 0, 0)
							== km->ks)
					|| (km->UseKeyCode == True && key_code == km->kc)) {
				handle_key(self, km, mouse_pressed, key_event);
			} else if (km->pressed && key_event == KeyPress) {
				km->used = True;
			}
		}

	}
}
Exemplo n.º 18
0
uint32_t EventHandler::_getKey( XEvent& event )
{
    int index = 0;
    if( event.xkey.state & ShiftMask )
        index = 1;

    const KeySym key = XkbKeycodeToKeysym( event.xany.display,
                                           event.xkey.keycode, 0, index );
    switch( key )
    {
        case XK_Escape:    return KC_ESCAPE;
        case XK_BackSpace: return KC_BACKSPACE;
        case XK_Return:    return KC_RETURN;
        case XK_Tab:       return KC_TAB;
        case XK_Home:      return KC_HOME;
        case XK_Left:      return KC_LEFT;
        case XK_Up:        return KC_UP;
        case XK_Right:     return KC_RIGHT;
        case XK_Down:      return KC_DOWN;
        case XK_Page_Up:   return KC_PAGE_UP;
        case XK_Page_Down: return KC_PAGE_DOWN;
        case XK_End:       return KC_END;
        case XK_F1:        return KC_F1;
        case XK_F2:        return KC_F2;
        case XK_F3:        return KC_F3;
        case XK_F4:        return KC_F4;
        case XK_F5:        return KC_F5;
        case XK_F6:        return KC_F6;
        case XK_F7:        return KC_F7;
        case XK_F8:        return KC_F8;
        case XK_F9:        return KC_F9;
        case XK_F10:       return KC_F10;
        case XK_F11:       return KC_F11;
        case XK_F12:       return KC_F12;
        case XK_F13:       return KC_F13;
        case XK_F14:       return KC_F14;
        case XK_F15:       return KC_F15;
        case XK_F16:       return KC_F16;
        case XK_F17:       return KC_F17;
        case XK_F18:       return KC_F18;
        case XK_F19:       return KC_F19;
        case XK_F20:       return KC_F20;
        case XK_Shift_L:   return KC_SHIFT_L;
        case XK_Shift_R:   return KC_SHIFT_R;
        case XK_Control_L: return KC_CONTROL_L;
        case XK_Control_R: return KC_CONTROL_R;
        case XK_Alt_L:     return KC_ALT_L;
        case XK_Alt_R:     return KC_ALT_R;

        default:
            if( (key >= XK_space && key <= XK_asciitilde ) ||
                (key >= XK_nobreakspace && key <= XK_ydiaeresis))
            {
                return key;
            }
            LBWARN << "Unrecognized X11 key code " << key << std::endl;
            return KC_VOID;
    }
}
Exemplo n.º 19
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") + ">" );
}
Exemplo n.º 20
0
unsigned long wrapXkbKeycodeToKeysym(Display *pDisplay, unsigned char cCode,
                                     unsigned int cGroup, unsigned int cIndex)
{
    KeySym cSym = XkbKeycodeToKeysym(pDisplay, cCode, cGroup, cIndex);
    if (cSym != NoSymbol)
        return cSym;
    return XKeycodeToKeysym(pDisplay, cCode, cGroup * 2 + cIndex % 2);
}
Exemplo n.º 21
0
static void handle_key(XGenericEventCookie *cookie)
{
	XIDeviceEvent *ev = (XIDeviceEvent *)cookie->data;
	qboolean down = cookie->evtype == XI_KeyPress;
	int keycode = ev->detail;
	unsigned time = Sys_XTimeToSysTime(ev->time);

	// Ignore shift_level for game key press
	KeySym keysym = XkbKeycodeToKeysym(x11display.dpy, keycode, 0, 0);
	int key = XLateKey( keysym );

	// Set or clear 1 in the shift_level bitmask
	if ( keysym == XK_Shift_L || keysym == XK_Shift_R )
		shift_level ^=  (-down ^ shift_level) & 1;

	// Set or clear 2 in the shift_level bitmask
	else if( keysym == XK_ISO_Level3_Shift )
		shift_level ^=  (-down ^ shift_level) & 2;

	Key_Event(key, down, time);

	if( down )
	{
		// Use shift_level for chat and console input
		qwchar wc = keysym2ucs(XkbKeycodeToKeysym(x11display.dpy, keycode, 0, shift_level));
		if( wc == -1 && key > K_NUMLOCK && key <= KP_EQUAL )
			wc = ( qwchar )key;

		// Convert ctrl-c / ctrl-v combinations to the expected events
		if( Key_IsDown(K_LCTRL) || Key_IsDown(K_RCTRL) )
		{
			if( key == 'v' )
			{
				key = CTRLV;
				wc = CTRLV;
			}
			else if( key == 'c' )
			{
				key = CTRLC;
				wc = CTRLC;
			}
		}
		Key_CharEvent( key, wc );
	}
}
Exemplo n.º 22
0
Arquivo: prefs.c Projeto: Cw1X/pnmixer
static void set_label_for_keycode(GtkWidget* label,gint code, GdkModifierType mods) {
  int keysym;
  gchar *key_text;
  if (code < 0) return;
  keysym = XkbKeycodeToKeysym(GDK_DISPLAY(), code, 0, 0);
  key_text = gtk_accelerator_name (keysym, mods);
  gtk_label_set_text(GTK_LABEL(label),key_text);
  g_free(key_text);
}
Exemplo n.º 23
0
void keypress(XEvent *e) {
    unsigned int i;
    XKeyEvent *ev = &e->xkey;
    KeySym keysym = XkbKeycodeToKeysym(dpy,(KeyCode)ev->keycode,0,0);
    for (i = 0; i < sizeof(keys)/sizeof(keys[0]); i++)
        if ( (keysym == keys[i].keysym) &&
                keys[i].func && keys[i].mod  == ((ev->state&~Mod2Mask)&~LockMask) )
            keys[i].func(keys[i].arg);
}
Exemplo n.º 24
0
KeySym
keycode_to_keysym(Display *dpy, KeyCode kc, int group, int level)
{
#if defined (WANT_XKB) && defined (HAVE_X11_XKBLIB_H) && defined (HAVE_XKBKEYCODETOKEYSYM)
  if (use_xkb)
    return XkbKeycodeToKeysym (dpy, kc, group, level);
#endif
  (void) group;
  return XKeycodeToKeysym (dpy, kc, level);
}
Exemplo n.º 25
0
unsigned int X11Extras::getGroup1KeySym(unsigned int virtualkey)
{
    unsigned int result = 0;
    Display *display = this->display();

    unsigned int temp = XKeysymToKeycode(display, virtualkey);
    result = XkbKeycodeToKeysym(display, temp, 0, 0);

    return result;
}
void kXneurApp::addUserAction::keyPressEvent(QKeyEvent *event)
{
    QString key;
    QString md_key;
    key = QString("%1").arg(XKeysymToString(XkbKeycodeToKeysym(kXneurApp::xNeurConfig::dpy, event->nativeScanCode(),0,0)));
    md_key = modif(event->modifiers());
    if(key.endsWith("_L") ||  key.endsWith("_R") )
        key.remove(key.length()-2,2);
    ui->lblHotKey->setText(QString("%1%2").arg(md_key).arg(key));
}
Exemplo n.º 27
0
Arquivo: xlib.c Projeto: iffsid/Slider
void keypress(XEvent *ev) {
	int i;
	XKeyEvent *e = &ev->xkey;
	KeySym sym = XkbKeycodeToKeysym(dpy, e->keycode, 0, 0);
	for (i = 0; i < conf.nkeys; i++) {
		if( (sym==conf.key[i].keysym) && (conf.key[i].arg) &&
				conf.key[i].mod == ((e->state&~Mod2Mask)&~LockMask) ) {
			command(conf.key[i].arg);
		}
	}
}
Exemplo n.º 28
0
void keypress(XEvent *e)
{
	unsigned int i;
	KeySym keysym;
	XKeyEvent *ke;
	ke = &e->xkey;
	keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ke->keycode, 0, 0);

	for (i = 0; i < LENGTH(keys); i++) {
		if (keysym == keys[i].keysym && keys[i].mod == ke->state && keys[i].func)
			keys[i].func(&(keys[i].arg));
	}
}
Exemplo n.º 29
0
Arquivo: event.c Projeto: xorg62/wmfs
static void
event_keypress(XEvent *e)
{
     XKeyPressedEvent *ev = &e->xkey;
     KeySym keysym = XkbKeycodeToKeysym(EVDPY(e), (KeyCode)ev->keycode, 0, 0);
     struct keybind *k;

     screen_update_sel();
     status_flush_surface();

     SLIST_FOREACH(k, &W->h.keybind, next)
          if(k->keysym == keysym && KEYPRESS_MASK(k->mod) == KEYPRESS_MASK(ev->state))
               if(k->func)
                    k->func(k->cmd);
}
Exemplo n.º 30
0
void wait_key(void)
{
    XEvent event;

    while(1)
    {
        XNextEvent(dpy, &event);

        if(event.type == KeyPress)
        {
            if(XkbKeycodeToKeysym(dpy, event.xkey.keycode, 0, 0) == opt_key)
                mainwindow_toggle(0);
        }
    }
}