forked from FuriLabs/external-displays
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·63 lines (48 loc) · 1.62 KB
/
Copy pathmain.py
File metadata and controls
executable file
·63 lines (48 loc) · 1.62 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
63
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2025 Furi Labs
#
# Authors:
# Bardia Moshiri <bardia@furilabs.com>
# Jesús Higueras <jesus@furilabs.com>
import gi
import os
# We set DISPLAY to make xdotool and xrandr work for display management, but always show the app in Wayland Phosh
os.environ['GDK_BACKEND'] = 'wayland'
import sys
import time
import subprocess
from asyncio import run, sleep
from gi.repository import GLib, Gio
from external_displays import ExternalDisplays
def check_dependencies():
try:
subprocess.run(["which", "xdotool"], check=True, stdout=subprocess.PIPE)
except subprocess.CalledProcessError:
print("Error: xdotool is not installed")
sys.exit(1)
async def pump_gtk_events():
main_context = GLib.MainContext.default()
if len(sys.argv) > 1:
os.environ['DISPLAY'] = sys.argv[1]
print(f"Overriding DISPLAY with: {sys.argv[1]}")
elif 'DISPLAY' not in os.environ:
os.environ['DISPLAY'] = ':1'
print("DISPLAY not set, defaulting to :1")
check_dependencies()
app = ExternalDisplays(application_id="io.furios.ExternalDisplays")
app.connect('shutdown', lambda _: exit(0))
Gio.Application.set_default(app)
app.register()
app.activate()
frame_time = 1 / (240)
while True:
start_time = time.time()
while main_context.pending():
main_context.iteration(False)
elapsed = time.time() - start_time
remaining = max(0, frame_time - elapsed)
if remaining > 0:
await sleep(remaining)
if __name__ == "__main__":
run(pump_gtk_events())