X11: Set the WINDOWID environment variable

Fixes #232
This commit is contained in:
Kovid Goyal 2017-12-16 08:57:52 +05:30
parent 3cce9b1c38
commit 51ac78f74d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 18 additions and 4 deletions

View File

@ -45,6 +45,8 @@ version 0.6.0 [future]
- Add an option to control the underline style for URL highlighting on hover
- X11: Set the WINDOWID environment variable
version 0.5.1 [2017-12-01]
---------------------------

View File

@ -20,11 +20,12 @@ class Child:
child_fd = pid = None
forked = False
def __init__(self, argv, cwd, opts, stdin=None):
def __init__(self, argv, cwd, opts, stdin=None, env=None):
self.argv = argv
self.cwd = os.path.abspath(os.path.expandvars(os.path.expanduser(cwd or os.getcwd())))
self.opts = opts
self.stdin = stdin
self.env = env or {}
def fork(self):
if self.forked:
@ -37,6 +38,7 @@ class Child:
if stdin is not None:
stdin_read_fd, stdin_write_fd = os.pipe()
remove_cloexec(stdin_read_fd)
env = self.env
pid = os.fork()
if pid == 0: # child
try:
@ -54,6 +56,7 @@ class Child:
os.closerange(3, 200)
# Establish the controlling terminal (see man 7 credentials)
os.close(os.open(os.ttyname(1), os.O_RDWR))
os.environ.update(env)
os.environ['TERM'] = self.opts.term
os.environ['COLORTERM'] = 'truecolor'
if os.path.isdir(terminfo_dir):

View File

@ -9,11 +9,13 @@ from functools import partial
from .borders import Borders
from .child import Child
from .config import build_ansi_color_table
from .constants import WindowGeometry, appname, get_boss, shell_path
from .constants import (
WindowGeometry, appname, get_boss, is_macos, is_wayland, shell_path
)
from .fast_data_types import (
DECAWM, Screen, add_tab, glfw_post_empty_event, remove_tab, remove_window,
set_active_tab, set_active_window, set_tab_bar_render_data, swap_tabs,
swap_windows, viewport_for_window
swap_windows, viewport_for_window, x11_window_id
)
from .layout import Rect, all_layouts
from .utils import color_as_int
@ -113,7 +115,14 @@ class Tab: # {{{
cmd = [shell_path]
else:
cmd = self.args.args or [shell_path]
ans = Child(cmd, self.cwd, self.opts, stdin)
env = {}
if not is_macos and not is_wayland:
try:
env['WINDOWID'] = str(x11_window_id(self.os_window_id))
except Exception:
import traceback
traceback.print_exc()
ans = Child(cmd, self.cwd, self.opts, stdin, env)
ans.fork()
return ans