~ruther/nixos-config

ref: 5b1602c8f5563556f28c67d066d1aee7b46e55e7 nixos-config/modules/desktop/qtile/config/functions.py -rw-r--r-- 2.8 KiB
5b1602c8 — Frantisek Bohacek chore: update 1 year, 3 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
import libqtile
from libqtile.lazy import lazy
from libqtile.core.manager import Qtile
from libqtile.backend.base import Window
from libqtile.config import Click, Drag, Group, KeyChord, EzKey, EzKeyChord, Match, Screen, ScratchPad, DropDown, Key

# #####################################
# Utility functions
@lazy.function
def focus_window_by_class(qtile: Qtile, wmclass: str):
    match = Match(wm_class=wmclass)
    windows = [w for w in qtile.windows_map.values() if isinstance(w, Window) and match.compare(w)]
    if len(windows) == 0:
        return

    window = windows[0]
    group = window.group
    group.toscreen()
    group.focus(window)

@lazy.function
def warp_cursor_to_focused_window(qtile: Qtile):
    current_window = qtile.current_window
    win_size = current_window.get_size()
    win_pos = current_window.get_position()

    x = win_pos[0] + win_size[0] // 2
    y = win_pos[1] + win_size[1] // 2

    qtile.core.warp_pointer(x, y)

@lazy.function
def go_to_screen(qtile: Qtile, index: int):
    current_screen = qtile.current_screen
    screen = qtile.screens[index]

    if current_screen == screen:
        x = screen.x + screen.width // 2
        y = screen.y + screen.height // 2
        qtile.core.warp_pointer(x, y)

    qtile.to_screen(index)
    qtile.current_group.focus(qtile.current_group.current_window)
    qtile.current_window.focus()

@lazy.function
def go_to_group(qtile: Qtile, group_name: str, switch_monitor: bool = False):
    found = False
    current_group = qtile.current_group
    if group_name == current_group.name:
        warp_cursor_to_focused_window()
        return

    current_screen = qtile.current_screen
    target_screen = current_screen

    for screen in qtile.screens:
        if screen.group.name == group_name:
            target_screen = screen
            if switch_monitor:
                qtile.focus_screen(screen.index)
            found = True
            break

    current_bar = current_screen.top
    target_bar = target_screen.top

    if found and current_bar != target_bar and isinstance(target_bar, libqtile.bar.Bar) and isinstance(current_bar, libqtile.bar.Bar):
        # found on other monitor, so switch bars
        target_bar_show = target_bar.is_show()
        current_bar_show = current_bar.is_show()

        current_bar.show(target_bar_show)
        target_bar.show(current_bar_show)

    qtile.groups_map[group_name].toscreen()

    for window in current_group.windows:
        if window.fullscreen:
            window.toggle_fullscreen()
            # time.sleep(0.1)
            window.toggle_fullscreen()

    if not switch_monitor or not found:
        window: Window
        for window in qtile.groups_map[group_name].windows:
            if window.fullscreen:
                window.toggle_fullscreen()
                # time.sleep(0.1)
                window.toggle_fullscreen()
Do not follow this link