Gnome 3: Activate Overlay and More by Mouse Button

I would like to activate the “Gnome 3/Shell Overlay” with the click of an otherwise-unused mouse button. As I posted earlier, Gnome 3 does not currently have any ability to assign actions/functions to mouse buttons. But there is a way to make it work using xdotool and xbindkeys. Thanks to AlphaLux (see comment below) I was able to replace my earlier easystroke solution with xbindkeys.

There’s also a program called easystroke that employs mouse gestures for executing shortcuts. The only reason I know this is because someone smarter than myself described the solution on the Ubuntu Forums. So, to “stinkeye” of the magical land of “Woop Woop”, I bequeath a laurel . . . and hearty handshake for answering this question about keyboard and mouse shortcuts in Gnome 3. Though I am including two solutions below, I recommend the xbindkeys solution.

First, descriptions of what  xdotool, xbindkeys and easystroke do:

  • xdotool
    This tool is invisible. You will not directly use it. But it will give you the ability to compose a commandline instruction for telling your computer that a button or group of buttons have been pressed. There is more to it than that, but for our purposes that’s all that matters.
  • xbindkeys
    This tool allows you to use bind keyboard and mouse keys to shell commands.
  • easystroke
    This tool allows you to use “mouse gestures” to submit commands to your computer. Mouse gestures are akin to the “touch gestures” that are an important part of newer touch interface computer systems like Apple’s iOS and even OSX via their ever-growing touchpads as well as Android, Windows Phone 7, etc. etc. The instructions below will be using this program to merely press a mouse button. I won’t be talking about gestures today.

Making a Mouse Button Make Things Happen with xbindkeys

As described above my only motivation for this functionality is to summon the Gnome Shell Overview. The directions below will describe how to do that. Feel free to substitute your own functionality as you see fit. Hopefully the instructions will be written in a clear enough way as to make that easy to do.

  1. AssignKeyboard Input to the Desired Functionality
    System Settings > Keyboard > Shortcuts
    In my case I set Show the activities overview to the Menu key, because I use the Super/Windows key for Third- and Fourth-level switching.
  2. Install xdotool and xbindkeys 
    You’ll have to figure out the best/easiest way to do this for your flavor of Linux. If you are running Ubuntu you can install them via the Software Center or:

    sudo apt-get install xbindkeys xdotool
  3. Determine Mouse Button Identity with xev
    Open a terminal and enter this command

    xev

    Xev will create a small, empty window. Hover your mouse over this window and click the various buttons on your mouse. After you click xev will tell you the identity of that button. Now that you know their identities we can use xbindkeys to associate them with shell commands.

  4. Configure xbindkeys
    Open a terminal and enter this command:

    gedit ~/.xbindkeysrc

    and press Enter. This will open the xbindkeys configuration file in Gedit. It should be a blank file. Add the following to the document and save.

    # Gnome Shell Mouse Button 8 to Overview
    "xdotool key Menu"
    release + b:8

    The above configuration sets the mouse button 8 to activate the Gnome Shell Overview. The first line is a comment to help you remember what this setting does. The second line defines the shell command to be enacted within double quotes. The third line defines the button action, in this case upon the release of the mouse button 8 the command will be executed.

  5. Set xbindkeys to autostart on login
    From the Gnome Shell Overview > Applications list, look for “Startup Applications” and start it. After the application window appears click the Addbutton. You can title the entry whatever you want, but “xbindkeys” is nice and concise. Most importantly though, enter the following into the Command input:

    xbindkeys &

    Once correctly entered, click OK and then Close. Now xbindkeys will automatically start upon logging in.

Making a Mouse Button Make Things Happen with easystroke

  1. Install xdotool and easystroke
    You’ll have to figure out the best/easiest way to do this for your flavor of Linux. If you are running Ubuntu you can install them via the Software Center or:

    sudo apt-get install easystroke xdotool
  2. Easystroke Preferences
    Start Easystroke. Go to the Preferences tab. Under the Behavior section, click the Gesture Button button. Move your cursor to the empty gray space in the resulting window and click the mouse button that you would like to associate to activating the Gnome Shell Activities Overlay (or whatever you are trying to do at the click of a mouse button). Once you click you should see a change in the settings at the bottom of the small window. In my case I have a Logitech laser mouse and I am using “Button 8”. Also under the Appearance section check the option “Autostart Easystroke”.
  3. Create New Easystroke Action
    Go to the Actions tab. Click the Add Action button. Name the action “Overlay via Mouse”. The Type should be “Command” and the Detailswill be:

    xdotool key Menu
  4. Associate Mouse Button to Easystroke Action
    In Easystroke highlight your new “Action” by clicking on it. Click the Record Stroke button. Move your cursor to the small resulting window and click the desired mouse button. Click the Yes button to confirm your mouse button input. Click the Hide button when you are finished.

Again, unless you specifically want to use mouse gestures, I think xbindkeys is a better, more responsive solution than easystroke. You should be able to test this fancy new functionality immediately. If not, try logging out and logging back in. Enjoy.

10 thoughts on “Gnome 3: Activate Overlay and More by Mouse Button”

  1. That’s a quick and easy way of doing it. The only problem is that easystroke is trying to detect a gesture so if I slip when pushing my mouse button or hold it down for too long it’ll try to detect a gesture, fail, and not open the shell overlay on button release. Well written article though, very easy to follow.

    1. Thanks and yeah, it’s not a perfect solution. But it works pretty well. I am pretty impressed with easystroke but don’t think I’ll ever use gestures. It’s been working pretty well for me. But you’re right. You gotta make sure you aren’t moving the mouse when you click the desired button. Still better than nothing!

  2. This may be a better solution for the time being, as it avoids the gestures quirk you mentioned. I used this idea: http://billauer.co.il/blog/2011/11/mouse-buttons-binding-copy-paste/

    Essentially, you install xbindkeys and xautomation packages. Then I added these lines to my ~/.xbindkeysrc
    # Gnome Shell Mouse Button 8 to Overview
    “xte ‘keydown Alt_L’ ‘key F1’ ‘keyup Alt_L'”
    release + b:8

    Then just added xbindkeys to the autostart applications folder in Gnome 3, and I don’t have to think about it again. I might have tried to make it not dependent on the original Gnome Shell binding, but I have no intention of changing it. If your desire differs, just create an obscure keybinding and map it the same way. Cheers.

  3. I also tried xbindkeys but couldn’t get it working for me. I have found btnx works under Gnome Shell though so have stuck with that.

  4. Thanks for that!

    I wanted to set a mouse button to open a new window on the same desktop. The same as if you right click on an icon an then choose “New Window”. But I couldn’t find the command for that.

    Is there a way to find what the Gnome Shell command is for such things?

  5. @Powederking I am guessing that you want “New Window” to happen across various applications? If so, I would simply associate Control_L + N with a mouse button as described above. In Nautilus and in web browsers this would create a new window and in other apps it would create a new document.

  6. I would suggest an easier approach. Instead of issueing events why not do a call into the gnome shell using gdbus. This calls the overlay natively. (Note: here .toggle() run, but you can do .show()” as well

    Edit ~/.xbindkeysrc

    “gdbus call –session –dest org.gnome.Shell –object-path /org/gnome/Shell –method org.gnome.Shell.Eval ‘Main.overview.toggle();'”
    release + b:8

  7. @goodwill Wow, that might be “more native” to Gnome Shell’s way of doing things but I have no idea what any of what you wrote there means. (Well, I can discern how it works, but I could never compose it.) The solution I provide above I think makes a lot more sense to people that have no knowledge of how the Shell works.

    Very impressive though! Thanks for sharing.

  8. Great and useful post, thank you! I’m using fedora 18.
    I’m having problems setting a mouse button to do any xte or xdotool command. When I use xev to see what the mouse button triggers I get this:

    FocusOut event, serial 31, synthetic NO, window 0x2200001,
    mode NotifyGrab, detail NotifyAncestor

    FocusOut event, serial 31, synthetic NO, window 0x2200001,
    mode NotifyUngrab, detail NotifyPointer

    FocusIn event, serial 31, synthetic NO, window 0x2200001,
    mode NotifyUngrab, detail NotifyAncestor

    KeymapNotify event, serial 31, synthetic NO, window 0x0,
    keys: 4294967199 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
    32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    KeyPress event, serial 31, synthetic NO, window 0x2200001,
    root 0x9f, subw 0x0, time 573916, (45,4), root:(46,95),
    state 0x50, keycode 40 (keysym 0x64, d), same_screen YES,
    XLookupString gives 1 bytes: (64) “d”
    XmbLookupString gives 1 bytes: (64) “d”
    XFilterEvent returns: False

    KeyRelease event, serial 31, synthetic NO, window 0x2200001,
    root 0x9f, subw 0x0, time 573950, (45,4), root:(46,95),
    state 0x50, keycode 40 (keysym 0x64, d), same_screen YES,
    XLookupString gives 1 bytes: (64) “d”
    XFilterEvent returns: False

    KeyRelease event, serial 31, synthetic NO, window 0x2200001,
    root 0x9f, subw 0x0, time 573982, (45,4), root:(46,95),
    state 0x50, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

    As for this, I get a combination like Mod2+Mod4+ d for the mouse button press. But when I put this in to the .xbindkeysrc like for example:

    #Mozilla
    “firefox”
    m:0x50 + c:40
    Mod2+Mod4+d

    It doesn’t work with the mouse button and I just keep getting a “d” everytime I press the button. Nevertheless if I press the keyboard key Super_R + d it does open firefox. But if I press the key Super_L + d it doesn’t. I managed to notice that pressing Super_L + d + d (pressing d repeteadly twice) opens firefox.

    Somehow this mouse button is linked to my Super_L physical key. when I press Super_L by itself, it show’s the activities overview (the same as alt+F1 in the keyboard shortcuts, or going with the mouse pointer to the upper left corner activities menu). I did try the keyboard layout distribution map, to see which keys highlight when I press one on my physical keyboard. I noticed that when I press the right Super key, control, alt, etc, the appropriate key highlights on the map. Nonetheless when I press the left Super key it doesn’t highlight any keys on the layout map.

    I do have xmodmap but haven’t done anything strange with it. This is the output I get when running xmodmap and seems to be fine.

    xmodmap: up to 4 keys per modifier, (keycodes in parentheses):

    shift Shift_L (0×32), Shift_R (0x3e)
    lock Caps_Lock (0×42)
    control Control_L (0×25), Control_R (0×69)
    mod1 Alt_L (0×40), Alt_R (0x6c), Meta_L (0xcd)
    mod2 Num_Lock (0x4d)
    mod3
    mod4 Super_L (0×85), Super_R (0×86), Super_L (0xce), Hyper_L (0xcf)
    mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)

    If you could help me with this, it would be great.
    Thanks in advance for your help.

Leave a Reply

Your email address will not be published. Required fields are marked *