You are not logged in.

#1 2013-02-12 01:03:32

MIH1406
Member
From: Riyadh, Saudi Arabia
Registered: 2013-01-03
Posts: 13
Website

How to enable Shift+Alt as keyboard layout switcher?

Hi,

I am trying to change the keyboard layout using "Keyboard->Shortcuts->Typing" but this seems to be unable to specify only the "Shift+Alt" buttons because it requires an extra button from the keyboard such as a letter or a number, eg "Shift+Alt+K"

Is there a way to specify only "Shift+Alt" combination?


Edit: I am using GNOME Shell.

Last edited by MIH1406 (2013-02-12 01:20:35)

Offline

#2 2013-02-12 01:16:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: How to enable Shift+Alt as keyboard layout switcher?

You should probably specify what WM/DE you are using otherwise no one could help at all.

Though I highly doubt this would be possible anyways - at least not through X.  Shift and Alt are modifiers, they must modify some non-modifier key before X11 generates an event.

Xev does detect these key presses, but one could not bind these with standard XGrabKey calls which is what every WM I know of uses for key bindings.

Last edited by Trilby (2013-02-12 01:20:47)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2013-02-12 01:41:58

Lord Bo
Member
Registered: 2012-11-11
Posts: 168

Re: How to enable Shift+Alt as keyboard layout switcher?

Trilby wrote:

Though I highly doubt this would be possible anyways - at least not through X.  Shift and Alt are modifiers, they must modify some non-modifier key before X11 generates an event.

From "http://tronche.com/gui/x/xlib/events/ke … inter.html":
The X server reports KeyPress or KeyRelease events to clients wanting information about keys that logically change state. Note that these events are generated for all keys, even those mapped to modifier bits.
So I think it is possible to get those events. And how could Xev detect them, if X11 would not generate them? I tried to bind some command to Alt + Shift_L with xbindkeys. It didn't work. My guess is, that it just ignores pure modifier keycombos. Of course, this doesen't help MIH1406. A working workaround would be to remap one of the modifiers with udev to something other - if you could spare one of those keys.

Last edited by Lord Bo (2013-02-12 01:44:14)

Offline

#4 2013-02-12 01:47:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: How to enable Shift+Alt as keyboard layout switcher?

Yes, X11 does generate events for these keys, but like I said, no WM I know of catches every single keypress event - it would be ridiculous to do so, and this would likely cause substantial interferance with any client programs and would be a huge resource hog.

WMs use the XGrabKey function to select which global key events they want to receive.  Xev works because it is only catching its own events - note that xev only reports keypresses when the xev window has input focus.

It would be very easy to write a little program that displayed a small window that when it had focus one could press Alt+Shift to do something like this - but that program wouldn't catch Alt+Shift presses globally.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2013-02-12 02:17:41

Lord Bo
Member
Registered: 2012-11-11
Posts: 168

Re: How to enable Shift+Alt as keyboard layout switcher?

Trilby wrote:

It would be very easy to write a little program that displayed a small window that when it had focus one could press Alt+Shift to do something like this - but that program wouldn't catch Alt+Shift presses globally.

If you grap for the specific keys in the root window, you can do it! I modified the idea given here to work for Ctrl + Alt_L:
keypress.cc

#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xutil.h>


using namespace std;


int main()
{
    Display*    dpy     = XOpenDisplay(0);
    Window      root    = DefaultRootWindow(dpy);
    XEvent      ev;

    unsigned int    modifiers       = ControlMask;
    int             keycode         = XKeysymToKeycode(dpy, XK_Alt_L);
    Window          grab_window     =  root;
    Bool            owner_events    = False;
    int             pointer_mode    = GrabModeAsync;
    int             keyboard_mode   = GrabModeAsync;

    XGrabKey(dpy, keycode, modifiers, grab_window, owner_events, pointer_mode,
             keyboard_mode);

    XSelectInput(dpy, root, KeyPressMask );
    while(true)
    {
        bool shouldQuit = false;
        XNextEvent(dpy, &ev);
        switch(ev.type)
        {
            case KeyPress:
                cout << "Hot key pressed!" << endl;
                XUngrabKey(dpy,keycode,modifiers,grab_window);
                shouldQuit = true;

            default:
                break;
        }

        if(shouldQuit)
            break;
    }

    XCloseDisplay(dpy);
    return 0;
}

Compile with:

g++ keypress.cc -lX11

I hope you get the idea.

edit: Use "ShiftMask" instead of "ControlMask" to modify it for your needs.

Last edited by Lord Bo (2013-02-12 02:19:35)

Offline

#6 2013-02-12 02:27:24

YavkatA
Member
Registered: 2011-07-30
Posts: 12

Re: How to enable Shift+Alt as keyboard layout switcher?

The key for switching layouts is stored in GSettings.

gsettings set org.gnome.settings-daemon.peripherals.keyboard input-sources-switcher alt-shift

Will switch it to Alt + Shift for you

Offline

#7 2013-02-12 02:37:06

MIH1406
Member
From: Riyadh, Saudi Arabia
Registered: 2013-01-03
Posts: 13
Website

Re: How to enable Shift+Alt as keyboard layout switcher?

YavkatA wrote:

The key for switching layouts is stored in GSettings.

gsettings set org.gnome.settings-daemon.peripherals.keyboard input-sources-switcher alt-shift

Will switch it to Alt + Shift for you

That worked for me. Thank you!!

Offline

Board footer

Powered by FluxBB