28
28
wserver = Flask (__name__ )
29
29
dependencies = []
30
30
stream_sources = ["static-images" , "v4l2" , "vnc-browser" ]
31
- sway_socket_path = "/tmp/sway.sock"
32
31
cmds = {"clock" : "humanbeans_clock" ,
33
32
"image_viewer" : "imv" ,
34
33
"media_player" : "mpv" ,
@@ -230,7 +229,7 @@ def create(self, uris):
230
229
item ["player" ] = "system"
231
230
item ["play_time_s" ] = self .default_play_time_s
232
231
elif uri .startswith ("iss-weather://" ):
233
- weather = Weather (self .location )
232
+ self . weather = Weather (self .location )
234
233
item ["num" ] = n
235
234
item ["uri" ] = uri
236
235
item ["player" ] = "weather"
@@ -263,12 +262,12 @@ def start_player(self):
263
262
x = threading .Thread (target = self .start_image_view , args = ())
264
263
elif item ["player" ] == "news" :
265
264
x = threading .Thread (target = self .start_news_view , args = (self .news ,))
266
- elif item ["system " ] == "system" :
265
+ elif item ["player " ] == "system" :
267
266
x = threading .Thread (target = self .start_system_view , args = ())
268
267
elif item ["player" ] == "weather" :
269
- x = threading .Thread (target = self .start_weather_view , args = ())
268
+ x = threading .Thread (target = self .start_weather_view , args = (self . weather , ))
270
269
271
- # x.start()
270
+ x .start ()
272
271
if not x .is_alive ():
273
272
logging .error ("Failed to start {}" .format (item ["player" ]))
274
273
else :
@@ -544,8 +543,11 @@ def fetch_weather(self):
544
543
encoding = "utf8" )
545
544
546
545
#data = p.communicate()[0]
547
- data = requests .get (url , timeout = 10 )
548
- data = data .content
546
+ try :
547
+ data = requests .get (url , timeout = 10 )
548
+ data = data .content
549
+ except ReadTimeout as e :
550
+ logging .error ("weather: Timeout for request" )
549
551
550
552
if not data :
551
553
logging .error ("Failed to fetch weather data" )
@@ -654,6 +656,7 @@ def __init__(self, address, port, res_x=1280, res_y=1024):
654
656
self .window_blacklist = list ()
655
657
self .screenshot_path = "/tmp"
656
658
self .screenshot_file = "screenshot.png"
659
+ self .socket_path = self .get_socket_path ()
657
660
658
661
logging .info ("Resolution: {} x {}"
659
662
.format (self .res_x , self .res_y ))
@@ -666,14 +669,30 @@ def __init__(self, address, port, res_x=1280, res_y=1024):
666
669
667
670
logging .info ("Blacklisted {} windows" .format (len (self .window_blacklist )))
668
671
672
+ self .x = threading .Thread (target = self .focus_next_window , args = ())
673
+ self .x .start ()
674
+
675
+ def get_socket_path (self ):
676
+ cmd = ['/usr/bin/sway' , '--get-socketpath' ]
677
+ p = subprocess .Popen (cmd ,
678
+ shell = False ,
679
+ stdout = subprocess .PIPE ,
680
+ stderr = subprocess .STDOUT ,
681
+ encoding = "utf8" )
682
+
683
+ path = p .communicate ()
684
+ path = path [0 ].rstrip ()
685
+ #path = "/tmp/sway.sock"
686
+ return path
687
+
669
688
def get_windows_whitelist (self ):
670
689
windows = self .get_windows (self .window_blacklist )
671
690
logging .info ("display: {} windows in whitelist" .format (len (windows )))
672
691
673
692
return windows
674
693
675
694
def get_windows (self , blacklist = None ):
676
- cmd = "swaymsg -s {} -t get_tree" .format (sway_socket_path )
695
+ cmd = "swaymsg -s {} -t get_tree" .format (self . socket_path )
677
696
windows = []
678
697
679
698
p = subprocess .Popen (cmd ,
@@ -724,28 +743,25 @@ def workspace_nodes(self, workspace):
724
743
return windows
725
744
726
745
def active_window ():
727
- cmd = 'swaymsg -s {} -t get_tree) | jq ".. | select(.type?) | select(.focused==true).id"' .format (sway_socket_path )
728
-
729
- async def focus_next_window (self ):
730
- await asyncio .sleep (random .random () * 3 )
731
- t = round (time .time () - self .start_time , 1 )
732
- logging .info ("Finished task: {}" .format (t ))
746
+ cmd = 'swaymsg -s {} -t get_tree) | jq ".. | select(.type?) | select(.focused==true).id"' .format (self .socket_path )
733
747
734
- if len (self .switching_windows ) == 0 :
735
- self .switching_windows = self .get_windows_whitelist ()
748
+ def focus_next_window (self ):
749
+ while True :
750
+ logging .info ("Focus change {}" .format (self .switching_windows ))
751
+ time .sleep (3 )
736
752
if len (self .switching_windows ) == 0 :
737
- logging . warning ( "display: Expected windows to display but there is none" )
738
-
739
- return
753
+ self . switching_windows = self . get_windows_whitelist ( )
754
+ if len ( self . switching_windows ) == 0 :
755
+ logging . warning ( "display: Expected windows to display but there is none" )
740
756
741
- next_window = self .switching_windows .pop ()
742
- logging .info ("display: Switching focus to: " .format (next_window ["id" ]))
743
- cmd = "swaymsg -s sway_socket_path [con_id={}] focus" .format (next_window ["id" ], sway_socket_path )
757
+ continue
744
758
745
- p = subprocess .Popen (cmd ,
746
- shell = True )
759
+ next_window = self .switching_windows .pop ()
760
+ logging .info ("display: Switching focus to: " .format (next_window ["id" ]))
761
+ cmd = "swaymsg -s {} [con_id={}] focus" .format (self .socket_path , next_window ["id" ])
762
+ p = subprocess .Popen (cmd , shell = True )
763
+ p .communicate ()[0 ]
747
764
748
- p .communicate ()[0 ]
749
765
750
766
async def fullscreen_next_window (self ):
751
767
await asyncio .sleep (random .random () * 3 )
@@ -762,7 +778,7 @@ async def fullscreen_next_window(self):
762
778
next_window = self .switching_windows .pop ()
763
779
logging .info ("display: Switching focus to: " .format (next_window ["id" ]))
764
780
765
- cmd = "swaymsg -s sway_socket_path [con_id={}] fullscreen" .format (next_window ["id" ], sway_socket_path )
781
+ cmd = "swaymsg -s {} [con_id={}] fullscreen" .format (self . socket_path , next_window ["id" ])
766
782
767
783
p = subprocess .Popen (cmd ,
768
784
shell = True )
@@ -779,7 +795,7 @@ async def task_scheduler(self, interval_s, interval_function):
779
795
)
780
796
781
797
def switch_workspace (self ):
782
- cmd = "swaymsg -s sway_socket_path workspace {}" .format (next_ws , sway_socket_path )
798
+ cmd = "swaymsg -s {} workspace {}" .format (self . socket_path , next_ws )
783
799
784
800
p = subprocess .Popen (cmd ,
785
801
shell = True ,
@@ -979,6 +995,7 @@ def __init__(self, threads):
979
995
local_ip = System .net_local_iface_address (probe_ip )
980
996
981
997
display = Display (local_ip , listen_port )
998
+
982
999
nwins = len (display .get_windows ())
983
1000
if nwins > 0 :
984
1001
logging .warning ("Expected no windows but found {}"
0 commit comments