XMonad: SpawnOn workspace that had focus when spawn key was pressed - linux

I would like to have my programs spawn on the screen that was in focus when its keybinding was pressed not on the screen thats currently in focus when it finishes loading.
Why:
My current setup is Arch Linux + XMonad and I have it running on 6 monitors. I have been using XMonad for about a year now and my only issue with it is for programs that take a little while to open. For example the very first time I start chromium it takes 3 odd seconds to load. I press my key binding for chrome and then go to a different screen to do something else. But when chrome loads it loads on the screen im currently focused on not on the screen that was focused at the time the spawn key binding was pressed.
My haskell skills are well... non existent. I have programmed in Lisp before and spend a lot of time in C, python and JavaScript so im sure I can pick it up if need be (so please be clear when it comes to haskell samples in answers).
Thanks in advance.

I found the answer to my own question.
First you must add to your imports:
import XMonad.Actions.SpawnOn
Then under your main function have something like:
main = do
xmonad $ defaultConfig
{
manageHook = myManageHooks <+> manageSpawn <+> manageDocks <+> manageHook defaultConfig
, startupHook = myStartupHook
, ETC.....
The key here was the addition of the manageSpawn in the manageHook line.
Then replace your spawns with spawnHere:
, ((modMask, xK_w), spawn "chromium")
Becomes:
, ((modMask, xK_w), spawnHere "chromium")

Related

Window Close Hook in Xmonad

There's the manageHook which is called every time a new window is recognized by Xmonad.
Is there something similar for a window closing hook?
No, one does not exist.
However, you can use handleEventHook listening for DestroyWindowEvent events. (Note, by default, two DestroyWindowEvent hooks are produced, one will have ev_window == ev_event, the other will have ev_event = the parent.)

xmonad submap not working

I'm new to xmonad and haskell. I try to create a xmonad config on my own, this is the current state: https://gist.github.com/sbechtel/7900440
My problem is the submap on line 45 for different search prompts. It compiles without problems but doesn't do anything. I belief it was working but now it isn't working anymore so my guess is some kind of side effect because I didn't change anything on that line?
Kind regards,
Sebastian
It looks correct on first sight to me. Beware though that there is no prompt for the search engine selection. To test it, you have to to press mod1 + s, then g for example. Only then google pops up.

Xmonad extension to cycle recent windows

I find it a bit awkward in xmonad to switch back and forth between two windows. Is there an extension (or a part of core xmonad) which allows this?
For example, I want to switch between firefox and emacs often, and they might not be in the same workspace. I currently do this using gotoMenu by typing M-g firefox<cr> and M-g emacs<cr> but this is awkward, especially if there's more than one instance of either app. Ideally I'd like a single shortcut to perform an action like give-focus-to-most-recently-used-unfocussed-window, which I could just press over and over to switch back and forth.
XMonad.Actions.GroupNavigation seems to be a perfect fit. To let the module track your window history, make sure that logHook invokes historyHook. For example:
import XMonad.Actions.GroupNavigation
...
main = xmonad $ defaultConfig {
...
, logHook = myLogHook xmobars >> historyHook
}
Then create a key binding for the following expression, which will toggle between the current and most recent window.
("M-x", nextMatch History (return True))

XMonad classic alt tab

Is it possible for XMonad to behave like many window managers with regard to switching active window using Alt-Tab keys? After some looking I've tried:
((mod1Mask, xK_Tab), cycleRecentWindows [xK_Alt_L] xK_Tab xK_Tab)
from XMonad.Actions.CycleWindows module. This configuration "almost" works. One issue is that I must execute the sequence slowly (just under 1 second I think). Other WMs I have do not suffer from this kind of input lag. The other issue is that it shuffles windows around, I would love to have alt-tab just switch focus to previous window.
I am using GroupNavigation for similar thing
Following example does cycle through windows on all workspaces:
import XMonad.Actions.GroupNavigation
...
((modm , xK_Tab), nextMatch Backward (return True))
...
You can use standalone application: https://github.com/sagb/alttab .
It pulls selected window to the top instead of shuffle and has special xmonad readme.
Just use:
…
-- Move focus to the next window.
, ((mod1Mask, xK_Tab), windows W.focusDown)
-- Move focus to the previous window.
, ((mod1Mask .|. shiftMask, xK_Tab), windows W.focusUp )
…
To cycle throw windows in the same desktop as indicated by Neil Forrester

Could someone explain gtk2hs drag and drop to me, the listDND.hs demo just isn't doing it for me?

As the title says, I just don't get DND (or rather I understand the concept and I understand the order of callbacks, I just don't understand how to setup DND for actual usage.) I'd like to say that I've done DND stuff before in C, but considering I never really got that working...
So I'm trying (and mostly succeeding, save DND) to write a text editor (using gtksourceview, because it has built in code highlighting.) Reasons are below if you want them. Anyways, there's not really a good DND demo or tutorial available for gtk2hs (listDND.hs just doesn't translate well in my head.)
So what I'm asking is for code that demonstrates simple DND on a window widget (for example.) Ideally, it should accept drops from other windows (such as Thunar) and print out the information in string form. I think I can take it from there...
Reasons:
I'm running a fairly light weight setup, dwm and a few gtk+2 programs. I really don't want to have to pull in gtk+3 to get the current gedit from the repos (Arch Linux.) Currently, I'm using geany for all of my text editing needs, however, geany is a bit heavy for editing config files. Further, geany doesn't care for my terminal of choice (st;) so I don't even get the benefit of using it as an IDE. Meaning I'd like a lightweight text editor with syntax highlighting. I could configure emacs or vim or something, but that seems to me to be more of a hack then a proper solution. Thus my project was born. It's mostly working (aside from DND, all that's left is proper multi-tab support.)
Admittedly, I could probably work this out if I wrote it in C, but there isn't that much state in a text editor so Haskell's been working fine with almost no need for mutable variables.
Following the tutorial I linked and the gtk2hs documentation, I have written the following minimal application that receives text. I will add it to the gtk2hs demos directory shortly.
import Control.Monad.IO.Class
import Graphics.UI.Gtk
main = do
initGUI
w <- windowNew
l <- labelNew $ Just "drag here lol"
onDestroy w mainQuit
containerAdd w l
dragDestSet w [DestDefaultMotion, DestDefaultDrop] [ActionCopy]
dragDestAddTextTargets w
w `on` dragDataReceived $ \dc pos id ts -> do
s <- selectionDataGetText
liftIO . putStrLn $ case s of
Nothing -> "didn't understand the drop"
Just s -> "understood, here it is: <" ++ s ++ ">"
widgetShowAll w
mainGUI
I have no idea whether thunar offers text as one of its selection formats, but if not, the formats it does offer are surely documented somewhere.

Resources