Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions autoload/dispatch/x11.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ if exists('g:autoloaded_dispatch_x11')
endif
let g:autoloaded_dispatch_x11 = 1

function! s:windowid()
if executable('xprop')
return matchstr(system("xprop -root _NET_ACTIVE_WINDOW"), '0x\x\+')
endif
endf

function! dispatch#x11#handle(request) abort
if $DISPLAY !~# '^:'
return 0
endif
let windowid = s:windowid()
if get(a:request, 'background') &&
\ (!v:windowid || !executable('wmctrl'))
\ (empty(windowid) || !executable('wmctrl'))
return 0
endif
if exists('g:dispatch_terminal_exec')
Expand All @@ -23,16 +30,17 @@ function! dispatch#x11#handle(request) abort
return 0
endif
if a:request.action ==# 'start'
return dispatch#x11#spawn(terminal, dispatch#prepare_start(a:request), a:request)
return dispatch#x11#spawn(terminal, dispatch#prepare_start(a:request), a:request, windowid)
else
return 0
endif
endfunction

function! dispatch#x11#spawn(terminal, command, request) abort
function! dispatch#x11#spawn(terminal, command, request, windowid) abort
let command = dispatch#set_title(a:request) . '; ' . a:command
if a:request.background
let command = 'wmctrl -i -a '.v:windowid . ';' . command
let command = 'wmctrl -i -a '. a:windowid . ';' . command
echom command
endif
call system(a:terminal . ' ' . dispatch#shellescape(&shell, &shellcmdflag, command). ' &')
return 1
Expand Down