سؤال

I am very fond of xmonad, but one thing would be great:

If I open a file by gvim -p --remote-tab-silent my-file and it gets opened in vim which is always on workspace 1, I want to switch automatically to workspace 1.

I just discovered the viewShift-trick, but this only changes the workspace if a new gvim is spawned, and as such solves my problem just in part.

Edit:

Thanks to Daniel Wagner's comment I was able to do some research:

I found a little program to set and unset urgency hints: seturgency. And with xwininifo I can get gvim's window id. After some trial and error I xprop showed me that the hint flag was actually set.

GVIMWINID=`xwininfo -tree -root | grep GVIM | cut -d ' ' -f6`
seturgent $GVIMWINID 1
xprop -id $GVIMWINID | grep urgency

now i added

import XMonad.Hooks.UrgencyHook
..
 myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
[..
, ((mod4Mask             , xK_x      ), focusUrgent)
..]
..
main = do¬                                                                       
        xmproc <- spawnPipe "/usr/bin/xmobar"¬                                   
        xmonad $ withUrgencyHook NoUrgencyHook $ defaultConfig {..}

to my .xmonad.hs, and xmonad --recompile && xmonad --restart was without errors but no hitting mod4 + x did nothing, though xprop did report the urgency hint is set.

هل كانت مفيدة؟

المحلول

Thanks to the comments by Daniel Wagner and Joachim Breitner I could solve the problem, at least in parts.

  • Automatically switching to gvim if it is not opened yet simply works with adding to `myManageHooks

    myManageHook = composeAll [.., className =? "Gvim"--> viewShift "^ vim",..]
    
  • if gvim is already open the situation is a bit more tricky, I've made a shell script to get the window id of gvim and see if there were arguments passed.

    #! /usr/bin/zsh
    
    GVIMWINID=`xwininfo -tree -root |grep GVIM | cut -d ' ' -f6`
    
    if [[ -n $GVIMWINID ]]; then
        #echo gvim is running
        #echo $GVIMWINID
        if [[ -n $@ ]]; then
            #echo there are args
            gvim -p --remote-tab-silent $@
        else
            #echo no args
            gvim --remote-send ":tabnew<cr>"
        fi
    else
        #echo gvim is not yet running
        #echo $GVIMWINID
        gvim -p $@
    fi
    seturgent $GVIMWINID 1
    

now if I spawn a new gv the window has its urgency hint set and I am able to switch to it. But I wanted to switch automatically to the window - so at least if I spawn gvim by keyboard I want to switch automatically. So I added to myKeys in xmonad.hs

myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
[.., ((mod4Mask, xK_F1),
        spawn "gv" >>
        spawn "notify-send -t 500 -i /usr/share/pixmaps/vim-32.xpm gVim" >>
        focusUrgent),..]

Where the spawn "notify-send .." line acts as a timebuffer as spawning+setting urgency hint seems to take some time and focusUrgent is called too early.

The only unsolved thing is if I call my gv-script from the terminal to be switched to gvim's workspace.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top