]> git.pld-linux.org Git - packages/ueberzug.git/blob - single_process_terminals.patch
new
[packages/ueberzug.git] / single_process_terminals.patch
1 From 160481b9922acb5f183bc5cb2af675cdc508db0c Mon Sep 17 00:00:00 2001
2 From: Jan Palus <atler@pld-linux.org>
3 Date: Wed, 13 Jan 2021 01:57:44 +0100
4 Subject: [PATCH] add support for single process terminals
5
6 some terminals (urxvt in daemon mode, mate-terminal) consist of single
7 process having multiple X windows. This in turn breaks ueberzug which
8 requires 1:1 mapping between PID and window id. If present use WINDOWID
9 environment variable set by those terminals as a direct pointer to
10 window which should be target for displayed image.
11 ---
12  ueberzug/xutil.py | 24 +++++++++++++++++++-----
13  1 file changed, 19 insertions(+), 5 deletions(-)
14
15 diff --git a/ueberzug/xutil.py b/ueberzug/xutil.py
16 index 2c6c871..6864aa4 100644
17 --- a/ueberzug/xutil.py
18 +++ b/ueberzug/xutil.py
19 @@ -1,6 +1,7 @@
20  """This module contains x11 utils"""
21  import functools
22  import asyncio
23 +import os
24  
25  import Xlib
26  import Xlib.display as Xdisplay
27 @@ -84,6 +85,16 @@ def get_pid_by_window_id(display: Xdisplay.Display, window_id: int):
28              else None)
29  
30  
31 +def get_visible_window_ids(display: Xdisplay.Display = None):
32 +    d = display or get_display()
33 +    try:
34 +        return d.screen().root.get_full_property(
35 +                    d.intern_atom('_NET_CLIENT_LIST'),
36 +                    Xlib.X.AnyPropertyType).value
37 +    finally:
38 +        if not display:
39 +            d.close()
40 +
41  def get_pid_window_id_map():
42      """Determines the pid of each mapped window.
43  
44 @@ -92,11 +103,7 @@ def get_pid_window_id_map():
45      """
46      with get_display() as display:
47          root = display.screen().root
48 -        visible_window_ids = \
49 -            (root.get_full_property(
50 -                display.intern_atom('_NET_CLIENT_LIST'),
51 -                Xlib.X.AnyPropertyType)
52 -             .value)
53 +        visible_window_ids = get_visible_window_ids(display)
54          return {**{
55              get_pid_by_window_id(display, window.id): window.id
56              for window in root.query_tree().children
57 @@ -159,6 +166,13 @@ def get_parent_window_infos():
58      Returns:
59          list of TerminalWindowInfo
60      """
61 +
62 +    window_id = os.getenv('WINDOWID')
63 +
64 +    if window_id and window_id.isnumeric() and int(window_id) in get_visible_window_ids():
65 +        pty = get_first_pty(get_parent_pids(process.get_own_pid()))
66 +        return [TerminalWindowInfo(int(window_id), pty)]
67 +
68      window_infos = []
69      client_pids = {}
70  
71 -- 
72 2.30.0
73
This page took 0.064628 seconds and 3 git commands to generate.