-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhyprland.py
More file actions
62 lines (53 loc) · 2.21 KB
/
Copy pathhyprland.py
File metadata and controls
62 lines (53 loc) · 2.21 KB
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
import socket
from threading import Thread
import os
from share.decoratos import call_registered_functions
terminator = b"\n"
def getTerminator():
return terminator
def getData(clientsocket) -> None | bytes:
received_data = b""
try:
# Receive data character by character until the terminator sequence is found
while True:
char = clientsocket.recv(1) # Receive one byte at a time
if not char: # If no more data is received, exit the loop
break
received_data += char # Append the received character to the received data
##print(received_data)
if (
received_data[-len(terminator) :] == terminator
): # Check if the terminator sequence is present
break
if (
received_data[-len(terminator) :] == terminator
): # Check if the terminator sequence is present
return received_data.rstrip(getTerminator())
except Exception as SocketError:
print("Socket Error: ", SocketError)
return None
class Hyprland(Thread):
def __init__(self):
super().__init__()
def run(self) -> None:
try:
hyprland_socket = f"{os.environ['XDG_RUNTIME_DIR']}/hypr/{os.environ['HYPRLAND_INSTANCE_SIGNATURE']}/.socket2.sock" # Adjust the socket path as needed
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(hyprland_socket)
client.send(b"getcurrentworkspace")
# response = client.recv(1024).decode('utf-8').strip()
while True:
response = getData(client)
msg = response.decode("utf-8").strip().split(">>")
if msg[0] == "activewindow":
call_registered_functions(
"hypr-activewindow", {"type": msg[0], "data": msg[1]}
)
# if msg[0] == "moveworkspacev2":
# print(msg[1])
# if msg[0] == "createworkspacev2":
# print(msg[1])
# if msg[0] == "destroyworkspacev2":
# print("dst", msg[1])
except Exception as e:
print(f"Error: {e}")