@@ -5,12 +5,19 @@ if exists('g:autoloaded_dispatch_x11')
55endif
66let g: autoloaded_dispatch_x11 = 1
77
8+ function ! s: windowid ()
9+ if executable (' xprop' )
10+ return matchstr (system (" xprop -root _NET_ACTIVE_WINDOW" ), ' 0x\x\+' )
11+ endif
12+ endf
13+
814function ! dispatch#x11#handle (request) abort
915 if $DISPLAY !~# ' ^:'
1016 return 0
1117 endif
18+ let windowid = s: windowid ()
1219 if get (a: request , ' background' ) &&
13- \ (! v: windowid || ! executable (' wmctrl' ))
20+ \ (empty ( windowid) || ! executable (' wmctrl' ))
1421 return 0
1522 endif
1623 if exists (' g:dispatch_terminal_exec' )
@@ -23,16 +30,17 @@ function! dispatch#x11#handle(request) abort
2330 return 0
2431 endif
2532 if a: request .action == # ' start'
26- return dispatch#x11#spawn (terminal , dispatch#prepare_start (a: request ), a: request )
33+ return dispatch#x11#spawn (terminal , dispatch#prepare_start (a: request ), a: request, windowid )
2734 else
2835 return 0
2936 endif
3037endfunction
3138
32- function ! dispatch#x11#spawn (terminal , command , request) abort
39+ function ! dispatch#x11#spawn (terminal , command , request, windowid ) abort
3340 let command = dispatch#set_title (a: request ) . ' ; ' . a: command
3441 if a: request .background
35- let command = ' wmctrl -i -a ' .v: windowid . ' ;' . command
42+ let command = ' wmctrl -i -a ' . a: windowid . ' ;' . command
43+ echom command
3644 endif
3745 call system (a: terminal . ' ' . dispatch#shellescape (&shell , &shellcmdflag , command ). ' &' )
3846 return 1
0 commit comments