Trying to code jump-or-execute

I'm a former sawfish user, and I used to have this really awesome keyboard shortcut called "jump-or-exec". I would press for example Super+F, and if Firefox was not running, it would be executed, and if it was already running, then it would be given focus. I had similar shortcuts for emacs, terminals, etc. I'm a bit of a haskell newb -- I can tell that I can simply use 'spawn' to launch a process, and if I had a list of current windows I would know how to iterate through them and find out whether one currently exists, but I don't know how to get such a list. Ideally I'd like to be able to match against window title or class. Is there a way to do this with xmonad?

On Wed, Jan 30, 2008 at 06:05:01PM -0500, Joseph Garvin wrote:
I'm a former sawfish user, and I used to have this really awesome keyboard shortcut called "jump-or-exec". I would press for example Super+F, and if Firefox was not running, it would be executed, and if it was already running, then it would be given focus. I had similar shortcuts for emacs, terminals, etc.
I'm a bit of a haskell newb -- I can tell that I can simply use 'spawn' to launch a process, and if I had a list of current windows I would know how to iterate through them and find out whether one currently exists, but I don't know how to get such a list. Ideally I'd like to be able to match against window title or class. Is there a way to do this with xmonad?
You can use XMonad.StackSet.allWindows to get a list of all windows. Then you've just got to match against the desired properties -- XMonad.ManageHook has some examples you can emulate. Finally, use XMonad.StackSet.focusWindow to bring focus to the identified window. Cheers, Spencer Janssen

The extension XMonad.Prompt.Window allows you to enter a window name (with completion), then teleports you to that window. So this extension already does what you need: get a list of windows, find the right one. Kai Joseph Garvin wrote:
I'm a former sawfish user, and I used to have this really awesome keyboard shortcut called "jump-or-exec". I would press for example Super+F, and if Firefox was not running, it would be executed, and if it was already running, then it would be given focus. I had similar shortcuts for emacs, terminals, etc.
I'm a bit of a haskell newb -- I can tell that I can simply use 'spawn' to launch a process, and if I had a list of current windows I would know how to iterate through them and find out whether one currently exists, but I don't know how to get such a list. Ideally I'd like to be able to match against window title or class. Is there a way to do this with xmonad? ------------------------------------------------------------------------
_______________________________________________ xmonad mailing list xmonad@haskell.org http://www.haskell.org/mailman/listinfo/xmonad

2008/1/30 Joseph Garvin
I'm a former sawfish user, and I used to have this really awesome keyboard shortcut called "jump-or-exec". I would press for example Super+F, and if Firefox was not running, it would be executed, and if it was already running, then it would be given focus. I had similar shortcuts for emacs, terminals, etc.
I'm a bit of a haskell newb -- I can tell that I can simply use 'spawn' to launch a process, and if I had a list of current windows I would know how to iterate through them and find out whether one currently exists, but I don't know how to get such a list. Ideally I'd like to be able to match against window title or class. Is there a way to do this with xmonad?
A bit of a followup: With Spencer's help, I just 'darcs sent' a patch which adds a module - XMonad.Actions.WindowGo - to XMonadContrib. What would interest you is the 'runOrRaise' function in it (I come from a Ratpoison/StumpWM background, not Sawfish), which does basically what you want. I right now have in my xmonad.hs's keybindings the line:
, ((modm, xK_a ), runOrRaise "firefox" (className =? "Firefox-bin"))
This does as you would expect, it matches any window with a class of Firefox-bin, jumping to it; or failing that, it executes through spawn "firefox". In my limited testing, it seems to work fine. (The module also has two other functions in case you don't want to do anything on failure, or you want to do something else besides spawn.) I hope it works well for you too! -- gwern

gwern0:
2008/1/30 Joseph Garvin
: I'm a former sawfish user, and I used to have this really awesome keyboard shortcut called "jump-or-exec". I would press for example Super+F, and if Firefox was not running, it would be executed, and if it was already running, then it would be given focus. I had similar shortcuts for emacs, terminals, etc.
I'm a bit of a haskell newb -- I can tell that I can simply use 'spawn' to launch a process, and if I had a list of current windows I would know how to iterate through them and find out whether one currently exists, but I don't know how to get such a list. Ideally I'd like to be able to match against window title or class. Is there a way to do this with xmonad?
A bit of a followup: With Spencer's help, I just 'darcs sent' a patch which adds a module - XMonad.Actions.WindowGo - to XMonadContrib. What would interest you is the 'runOrRaise' function in it (I come from a Ratpoison/StumpWM background, not Sawfish), which does basically what you want.
I right now have in my xmonad.hs's keybindings the line:
, ((modm, xK_a ), runOrRaise "firefox" (className =? "Firefox-bin"))
This does as you would expect, it matches any window with a class of Firefox-bin, jumping to it; or failing that, it executes through spawn "firefox".
In my limited testing, it seems to work fine. (The module also has two other functions in case you don't want to do anything on failure, or you want to do something else besides spawn.) I hope it works well for you too!
Awesome :) Let's keep the new ideas rolling. Anyone else got some dream extension/UI ideas? -- Don

Don Stewart schrieb:
Let's keep the new ideas rolling.
Anyone else got some dream extension/UI ideas?
I'd like some of the extensions in contrib to be more generic. e.g.
instead of the Tall layout + ThreeColumns + Accordion I'd like to have
a generic parameterized layout that is able to do all three. A
parameter to specify which column is the master would also be nice (I
just hacked ThreeColumns to put the master column into the middle,
which is trivial, but a more generic solution would be better).
The same goes for the Combo layouts. There's just CombineTwo which is
not (really) usable with ThreeColumns, so there could be 'Combine n'.
...
Another thing I'd like to see is a kind of gmrun/dmenu on steroids. It
should interactively display (a subset of) the current matches and
allow me to start XMonad commands, ssh sessions as well as programs
and also to find currently active windows, all in the same transient
window. However specifying useful semantics for such a monster might
be hard.
Former sawfish users might remember "waffle" which did some of these
tasks. I'm also dimly aware of an application for MacOSX which
implements a similar idea.
...
I'd also like to have a title just for the master window(s), but it
appears that is already under way.
Kind regards
Friedel
--
Friedrich Delgado Friedrichs

On Mon, Feb 04, 2008 at 07:38:14PM +0100, Friedrich Delgado Friedrichs wrote:
The same goes for the Combo layouts. There's just CombineTwo which is not (really) usable with ThreeColumns, so there could be 'Combine n'.
How would combineThree ThreeColumns l1 l2 l3 differ from l1 *|** (l2 *|* l3) ? I guess one answer is that it may differ in how it sizes things when there are only two windows. Support for something like combineN is going to wait until there's support for hierarchical stacks in xmonad (which may never happen). combineTwo is a horrible hack as it is, and it's far more elegant than combineThree would be, if it's forced to use the same approach (which duplicates the information that xmonad stores about the windows present in the workspace and tries to reconstruct what changes were made each time doLayout is called). -- David Roundy Department of Physics Oregon State University

Sorry, I'm pretty new to xmonad and quite a bit confused: David Roundy schrieb:
How would combineThree ThreeColumns l1 l2 l3 differ from
l1 *|** (l2 *|* l3) ?
I guess one answer is that it may differ in how it sizes things when there are only two windows.
Uhm... I just tried to find a useful application of what you proposed
there and failed.
Maybe it helps if I try to be more concrete:
My current "dream" is to have a ThreeColumn layout, with the master
pane in the middle, which is automatically tabbed according to the
window group.
I don't understand enough of xmonad, its implementation and the
modules in xmonad-contrib yet to figure out how to do that now or in
the future.
--
Friedrich Delgado Friedrichs

Another thing I'd like to see is a kind of gmrun/dmenu on steroids. It should interactively display (a subset of) the current matches and allow me to start XMonad commands, ssh sessions as well as programs and also to find currently active windows, all in the same transient window. However specifying useful semantics for such a monster might be hard. check out the Prompt stuff in contrib; I think there are some modules in
* On Monday, February 04 2008, Friedrich Delgado Friedrichs wrote: there that do exactly what you want.
participants (8)
-
Adam Vogt
-
David Roundy
-
Don Stewart
-
Friedrich Delgado Friedrichs
-
Gwern Branwen
-
Joseph Garvin
-
Kai Grossjohann
-
Spencer Janssen