[xmonad] Re: two beginner's questions on XMonad config
Riccardo Murri
riccardo.murri at gmail.com
Thu Dec 11 19:53:15 EST 2008
Riccardo Murri <riccardo.murri at ...> writes:
> 1) Since I have no modifier keys left on my laptop, and I'm an Emacs
> user (which takes away many C- and M- keybindings), I'd like to bind
> most XMonad actions with "C-z" as a prefix (using EZConfig).
>
> Is there a way to bind a key so that "C-z C-z" sends a C-z to the
> currently focused window? (Ratpoison has a similar feature for C-t)
>
I did some googling and found out that:
1) the quickest solution is to use "xdotool"
[http://www.semicomplete.com/projects/xdotool/], which can (among
other nifty things), send a fake keypress to the currently focused
window::
("C-z C-z", spawn "xdotool key ctrl+z")
2) According to:
http://www.handhelds.org/moin/moin.cgi/GeneratingSyntheticX11Events
there are two Xlib programmatic solution, one using the XTest
extension (recommended), and one using XSendEvent(). As far as I
understand, there are no bindings for XTest in the Graphics.X11
module, so one has to code using sendEvent...
With the following code, I have been able to send a Ctrl+Z to urxvt
and "xev" windows directly from XMonad::
-- send Ctrl+Z to focused window
sendCtrlZ = sendKey controlMask xK_z
sendKey modmask keysym = withDisplay $ \d -> do
keycode <- io $ keysymToKeycode d keysym
root <- asks theRoot
let subw = none -- FIXME: should this be the subwindow which the pointer is in?
withFocused $ \w -> do
io $ allocaXEvent $ \ev -> do
setEventType ev keyPress
setKeyEvent ev w root subw modmask keycode True
sendEvent d w False noEventMask ev
io $ allocaXEvent $ \ev -> do
setEventType ev keyRelease
setKeyEvent ev w root subw modmask keycode True
sendEvent d w False noEventMask ev
return ()
Thanks to all those who replied with suggestions to my original post!
Cheers,
Riccardo
More information about the xmonad
mailing list