Looking for "runOrKill" function

My `additionalKeys` section of xmonad.hs has this key binding: ((mod3Mask, xK_d), raiseMaybe (runInTerm "-title calendar -hold -geometry 105x12+0+25" "task calendar") (title =? "calendar")) I would like to replace the raiseMaybe by something like runOrKill. This means, it should run the terminal with title "calendar" if it's not yet running. Otherwise it should kill the terminal. How can I do that? Is it possible at all?

On Wed, Sep 24, 2014 at 11:57 AM, Sepp Tannhuber
My `additionalKeys` section of xmonad.hs has this key binding: ((mod3Mask, xK_d), raiseMaybe (runInTerm "-title calendar -hold -geometry 105x12+0+25" "task calendar") (title =? "calendar"))
I would like to replace the raiseMaybe by something like runOrKill. This means, it should run the terminal with title "calendar" if it's not yet running. Otherwise it should kill the terminal. How can I do that? Is it possible at all?
raiseAndDo (runInTerm "-title calendar -hold -geometry 105x12+0+25" "task calendar") (title =? "calendar")) killWindow Although I wonder if you'd be better served by making it a NamedScratchpad instead. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

That's it. Thank you. The reason why I don't use scratchpads is simple: I don't know how to do it. I liked the scratchpad in ion3 and tried to implement a scratchpad with xmonad several times, without success. If anybody can tell me step by step for the given calendar example, I would give it another try. But the raiseAndDo does what I want. So it would be just for fun and learning haskell.

On Wed, Sep 24, 2014 at 1:38 PM, Sepp Tannhuber
The reason why I don't use scratchpads is simple: I don't know how to do it. I liked the scratchpad in ion3 and tried to implement a scratchpad with xmonad several times, without success. If anybody can tell me step by step for the given calendar example, I would give it another try. But the raiseAndDo does what I want. So it would be just for fun and learning haskell.
Something along the lines of http://lpaste.net/111558 should do it. Note that you can't use a geometry directly with this setup; it might be possible to revise it so that you can keep using a -geometry instead of doing it in the ManageHook, and you'll want to doublecheck the terminal. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On Wed, Sep 24, 2014 at 1:53 PM, Brandon Allbery
Something along the lines of http://lpaste.net/111558 should do it. Note that you can't use a geometry directly with this setup; it might be possible to revise it so that you can keep using a -geometry instead of doing it in the ManageHook, and you'll want to doublecheck the terminal.
Also, if what you're looking for is an example of scratchpads in action, http://lpaste.net/100571 is a bit out of date (and includes a bit of experimental stuff) but shows a working scratchpad setup. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I found http://splash-of-open-sauce.blogspot.de/2011/02/xmonadhs-haskell-xmonad-conf... which looks similar to my config: --- BEGIN --- scratchpads = [ NS "calendar" "urxvt -name calendar -e task calendar" (title =? "calendar") ] where name = stringProperty "WM_NAME" main = do dzenLeftBar <- spawnPipe myXmonadBar dzenRightBar <- spawnPipe myStatusBar dzenTrayerBar <- spawnPipe myTrayerBar xmonad $ ewmh $ withUrgencyHook NoUrgencyHook defaultConfig { focusFollowsMouse = True , modMask = mod3Mask , workspaces = myWorkspaces , manageHook = namedScratchpadManageHook scratchpads <+> manageDocks <+> myManageHook {- ... -} , ((mod3Mask, xK_d), namedScratchpadAction scratchpads "calendar") --- END --- The result is: --- BEGIN --- Error detected while loading xmonad configuration file: /home/sepp/.xmonad/xmonad.hs xmonad.hs:195:54: Couldn't match type `ManageHook -> NamedScratchpad' with `NamedScratchpad' Expected type: NamedScratchpads Actual type: [ManageHook -> NamedScratchpad] In the first argument of `namedScratchpadManageHook', namely `scratchpads' In the first argument of `(<+>)', namely `namedScratchpadManageHook scratchpads' In the first argument of `(<+>)', namely `namedScratchpadManageHook scratchpads <+> manageDocks' xmonad.hs:216:62: Couldn't match type `ManageHook -> NamedScratchpad' with `NamedScratchpad' Expected type: NamedScratchpads Actual type: [ManageHook -> NamedScratchpad] In the first argument of `namedScratchpadAction', namely `scratchpads' In the expression: namedScratchpadAction scratchpads "calendar" In the expression: ((mod3Mask, xK_d), namedScratchpadAction scratchpads "calendar") Please check the file for errors. --- END ---

On Wed, Sep 24, 2014 at 4:40 PM, Sepp Tannhuber
scratchpads = [ NS "calendar" "urxvt -name calendar -e task calendar" (title =? "calendar") ] where name = stringProperty "WM_NAME"
(1) the "where name = ..." isn't doing anything here (2) You're missing the target rectangle for the scratchpad (whether to make a tiled window, a standard floating window, or a custom floating window). That's the source of the type error. Compare to my earlier pastebinned example: myScratchpads = [NS "calendar" "xterm -title calendar -hold -e task calendar" (title =? "calendar") -- I don't know screen or font size so this is a very rough guess at the RationalRect (customFloating $ W.RationalRect 0 (1/10) (4/10) (3/10)) ] You're missing the customFloating part, or a replacement for it (nonFloating, defaultFloating) that tells it what to do with the window when it's created. (That's the "ManageHook" it's complaining about.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

OK, I changed that into: scratchpads = [ NS "calendar" "urxvt -name calendar -e task calendar" (title =? "calendar") (customFloating $ W.RationalRect 0 (1/10) (4/10) (3/10)) ] Now it compiles without an error. But when I type <Mod-d>, a window pops up and disappears. I changed the »task calendar« command into »htop«. Then a terminal with htop is opened. But it's not floated.

On Wed, Sep 24, 2014 at 6:37 PM, Sepp Tannhuber
OK, I changed that into: scratchpads = [ NS "calendar" "urxvt -name calendar -e task calendar" (title =? "calendar") (customFloating $ W.RationalRect 0 (1/10) (4/10) (3/10)) ]
Now it compiles without an error. But when I type <Mod-d>, a window pops up and disappears. I changed the »task calendar« command into »htop«. Then a terminal with htop is opened. But it's not floated.
Yes. The problem is the program runs and immediately exits, so the terminal exits. The xterm one uses -hold to make the terminal stick around after the program exits, so you have a persistent calendar window. It looks like urxvt also supports -hold, so add that after `-name calendar`. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Of course, I forgot the hold option. :-) The other problem still remains. :-( I posted my whole xmonad.hs to http://lpaste.net/111588. I also tried to change the order in line 196 because I thought something might overwrite the floating settings. But this is obviously not the case.

On Thu, Sep 25, 2014 at 2:08 AM, Sepp Tannhuber
Of course, I forgot the hold option. :-) The other problem still remains. :-(
Which? The htop part? The title string you pass to the terminal must exactly match the title string in the window test (title =? "whatever"). There are ways to change this if needed, but unless it can identify the window precisely when it appears, it will not be able to float or position it. (X11 does not provide any way to match running a command to a window opening; indeed, there is no mapping at all between processes and windows (consider remote TCP connections and ssh X11 forwarding; also, some command-line browsers use this to draw graphics in terminal windows, and Acrobat Reader uses this to open windows inside a browser. This is also used by desk applets that can "swallow" arbitrary windows). -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (2)
-
Brandon Allbery
-
Sepp Tannhuber