Skip to content

Commit fd4410f

Browse files
SevereOverfl0wtpope
authored andcommitted
Use xprop for x11 window switching
Some popular terminals, e.g. gnome-terminal do not set $WINDOWID. Additionally, the Neovim TUI does not yet support $WINDOWID. Fix #277
1 parent 40aec75 commit fd4410f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

autoload/dispatch/x11.vim

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ if exists('g:autoloaded_dispatch_x11')
55
endif
66
let 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+
814
function! 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
3037
endfunction
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

Comments
 (0)