~ruther/nixos-config

ref: b97d300d59eb377964e56a1b09075292a465ea16 nixos-config/modules/desktop/qtile/config/screens.py -rw-r--r-- 3.1 KiB
b97d300d — Frantisek Bohacek chore: update 1 year, 12 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import time
import subprocess
from libqtile.lazy import lazy
from libqtile.config import Click, Drag, Group, KeyChord, EzKey, EzKeyChord, Match, Screen, ScratchPad, DropDown, Key
import screeninfo
import utils
import bars
from functions import focus_window_by_class, warp_cursor_to_focused_window, go_to_screen, go_to_group
from nixenvironment import setupLocation, configLocation, sequenceDetectorExec
from libqtile.log_utils import logger

def init_screens():
    wallpaper = f'{setupLocation}/wall.png'

    screens_info = screeninfo.get_monitors()
    screens_count = len(screens_info)
    screens = [None] * screens_count

    logger.warning(f'setting up {screens_count} screens')

    for i in range(0, screens_count):
        screen_info = screens_info[i]
        systray = False
        if screens_count <= 2 and i == 0:
            systray = True
            print(f'Putting systray on {i}')
        elif i == 1:
            systray  = True
            print(f'Putting systray on {i}')

        top_bar = bars.create_top_bar(systray = systray)

        screens[i] = Screen(top=top_bar, bottom=bars.create_bottom_bar(), wallpaper=f'{setupLocation}/wall.png', width=screen_info.width, height=screen_info.height)

    return screens

def init_navigation_keys(keys, screens):
    if len(screens) >= 4:
        monitor_navigation_keys = ['q', 'w', 'e', 'r']
    else:
        monitor_navigation_keys = ['w', 'e', 'r']

    for i, key in enumerate(monitor_navigation_keys):
        keys.extend([
            EzKey(f'M-{key}', go_to_screen(i), desc = f'Move focus to screen {i}'),
            EzKey(f'M-S-{key}', lazy.window.toscreen(i), desc = f'Move window to screen {i}'),
        ])

# Monitors changing connected displays and the lid.
# Calls autorandr to change the outputs, and QTile
# restart
async def observe_monitors():
    from pydbus import SystemBus
    from gi.repository import GLib
    from libqtile.utils import add_signal_receiver
    from dbus_next.message import Message
    import pyudev

    @utils.debounce(0.2)
    def call_autorandr():
        # Autorandr restarts QTile automatically
        subprocess.call(['autorandr', '--change', '--default', 'horizontal'])
        # time.sleep(0.3)
        # subprocess.call(['qtile', 'cmd-obj', '-o', 'cmd', '-f', 'restart'])

    def on_upower_event(message: Message):
        args = message.body
        properties = args[1]
        logger.info(message.body)
        if 'LidIsClosed' in properties:
            call_autorandr()

    def on_drm_event(action=None, device=None):
        if action == "change":
            call_autorandr()

    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by(subsystem = 'drm')
    monitor.enable_receiving()

    logger.warning("Adding signal receiver")
    subscribe = await add_signal_receiver(
        on_upower_event,
        session_bus = False,
        signal_name = "PropertiesChanged",
        path = '/org/freedesktop/UPower',
        dbus_interface = 'org.freedesktop.DBus.Properties',
    )
    logger.warning(f"Add signal receiver: {subscribe}")

    observer = pyudev.MonitorObserver(monitor, on_drm_event)
    observer.start()
Do not follow this link