Skip to content

Commit

Permalink
vim-compat: fix: Allow window to be raised under linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
raghur committed Oct 2, 2018
1 parent 204916e commit 306d83c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
8 changes: 2 additions & 6 deletions plugin/ghost.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ function! s:startGhost(tid)
endfunction

function! s:loadGhost()
if !has("nvim")
if executable("xdotool")
let g:ghost_nvim_window_id = system("xdotool getactivewindow")
return
endif

if !has('timers')
return
endif

if executable("xdotool")
let g:ghost_nvim_window_id = system("xdotool getactivewindow")
return
endif

if exists("g:ghost_autostart") && g:ghost_autostart
let timer = timer_start(500, function("s:startGhost"))
endif
Expand Down
37 changes: 21 additions & 16 deletions rplugin/python3/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,27 @@ def _handle_on_message(self, req, websocket):
self.nvim.command("echo '%s'" % ex)

def _raise_window(self):
if self.linux_window_id:
subprocess.call(["xdotool", "windowactivate", self.linux_window_id])
logger.debug("activated window: %s", self.linux_window_id)
elif self.winapp:
logger.debug("WINDOWS: trying to raise window")
# dragons - this is the only thing that works.
try:
self.winapp.windows()[0].set_focus()
self.winapp.windows()[0].ShowInTaskbar()
except Exception as e:
logger.warning("Error during _raise_window, %s", e)
elif self.darwinapp:
logger.debug("Darwin: trying to raise window")
subprocess.call(["osascript", "-e",
'tell application "' + self.darwinapp +
'" to activate'])
try:
if self.linux_window_id:
subprocess.call(["xdotool", "windowactivate", self.linux_window_id])
logger.debug("activated window: %s", self.linux_window_id)
elif self.winapp:
logger.debug("WINDOWS: trying to raise window")
# dragons - this is the only thing that works.
try:
self.winapp.windows()[0].set_focus()
self.winapp.windows()[0].ShowInTaskbar()
except Exception as e:
logger.warning("Error during _raise_window, %s", e)
elif self.darwinapp:
logger.debug("Darwin: trying to raise window")
subprocess.call(["osascript", "-e",
'tell application "' + self.darwinapp +
'" to activate'])
except Exception as e:
# with vim yarp etc - letting an exception escape messes
# with other plugins. so catch everything
logger.debug("error while activating window - %s" % e)

def on_message(self, req, websocket):
self.nvim.async_call(self._handle_on_message, req, websocket)
Expand Down

0 comments on commit 306d83c

Please sign in to comment.