-
Notifications
You must be signed in to change notification settings - Fork 4
/
i3-chrome-tab-dragging.py
executable file
·80 lines (63 loc) · 2.36 KB
/
i3-chrome-tab-dragging.py
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
#!/usr/bin/env python3
# vi:expandtab tabstop=4
# This is intended to be run when i3 starts it will exit on restart; make sure
# to use "exec_always --no-startup-id" to run this
from argparse import ArgumentParser
from pynput.mouse import Listener, Button
from i3ipc import Connection, Event
# Constants
browser_classes = [
"Google-chrome",
"Google-chrome-beta",
"Google-chrome-unstable",
"Chromium",
"Chromium-browser",
"Brave-browser",
]
# Global Variables
mouse_pressed = False
current_window = None
# Called by mouse listener when the mouse is clicked
def on_click(x, y, button, pressed):
global mouse_pressed
global current_window
# we want to store the status of the left mouse button
if button == Button.left:
if args.verbose:
if current_window:
print(f"{mouse_pressed=} {button=} {pressed=} {current_window.name=}")
else:
print(f"None {mouse_pressed=} {button=} {pressed=}")
mouse_pressed = pressed
# if the button is released and we were currently dragging a window, unfloat it
if not pressed and current_window:
if args.verbose:
print(f"Disable floating for {current_window.name}")
current_window.command('floating disable')
current_window = None
# Called by i3 when a new window is created
def on_window_new(i3, e):
global current_window
# we only care about chromium windows
if e.container.window_class in browser_classes:
if args.verbose:
print(f"New Window: {e.container.name=}")
# only switch to floating mode if the user is currently dragging (=mouse button pressed)
if mouse_pressed:
if args.verbose:
print(f"Enable floating for {e.container.name}")
e.container.command("floating enable")
# store the reference to the window, so we can unfloat it later
current_window = e.container
if args.verbose:
print(f"Current Window is {current_window.name}")
def main(args):
i3 = Connection()
i3.on(Event.WINDOW_NEW, on_window_new)
with Listener(on_click=on_click):
i3.main()
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-v", "--verbose", action="count", default=0)
args = parser.parse_args()
main(args)