@@ -545,7 +545,13 @@ def ensure_directory_exists(filepath):
545545
546546
547547def rofi_file_selector (
548- dirs , extension , prompt , current_selection = None , extra_flags = None , display_func = None , recursive = True
548+ dirs ,
549+ extension ,
550+ prompt ,
551+ current_selection = None ,
552+ extra_flags = None ,
553+ display_func = None ,
554+ recursive = True ,
549555):
550556 """
551557 Generic rofi file selector for files in given dirs with given extension.
@@ -557,11 +563,17 @@ def rofi_file_selector(
557563 file_roots = []
558564 for d in dirs :
559565 if recursive :
560- found = [f for f in glob .glob (os .path .join (d , f"**/*{ extension } " ), recursive = True )
561- if "/backup/" not in f and "\\ backup\\ " not in f ]
566+ found = [
567+ f
568+ for f in glob .glob (os .path .join (d , f"**/*{ extension } " ), recursive = True )
569+ if "/backup/" not in f and "\\ backup\\ " not in f
570+ ]
562571 else :
563- found = [f for f in glob .glob (os .path .join (d , f"*{ extension } " ), recursive = False )
564- if "/backup/" not in f and "\\ backup\\ " not in f ]
572+ found = [
573+ f
574+ for f in glob .glob (os .path .join (d , f"*{ extension } " ), recursive = False )
575+ if "/backup/" not in f and "\\ backup\\ " not in f
576+ ]
565577 files .extend (found )
566578 file_roots .extend ([d ] * len (found ))
567579 # Remove duplicates
@@ -581,8 +593,10 @@ def rofi_file_selector(
581593 if display_func :
582594 names = [display_func (f , r ) for f , r in zip (files , file_roots )]
583595 else :
596+
584597 def strip_prefix (s ):
585598 return os .path .splitext (os .path .basename (s ))[0 ]
599+
586600 names = [strip_prefix (f ) for f in files ]
587601 if current_selection :
588602 if display_func :
@@ -595,21 +609,38 @@ def strip_prefix(s):
595609 if not current_name :
596610 current_name = names [0 ]
597611 else :
612+
598613 def strip_prefix (s ):
599614 return os .path .splitext (os .path .basename (s ))[0 ]
615+
600616 current_name = strip_prefix (current_selection )
601617 else :
602618 current_name = names [0 ]
603619 hyprland = HYPRLAND .HyprctlWrapper ()
604- override_string = hyprland .get_rofi_override_string ()
605- rofi_pos_string = hyprland .get_rofi_pos ()
606- rofi_flags = [
607- "-p" , prompt ,
608- "-select" , current_name ,
609- "-theme" , "clipboard" ,
610- "-theme-str" , override_string ,
611- "-theme-str" , rofi_pos_string ,
612- ]
620+ try :
621+ override_string = hyprland .get_rofi_override_string ()
622+ rofi_pos_string = hyprland .get_rofi_pos ()
623+ rofi_flags = [
624+ "-p" ,
625+ prompt ,
626+ "-select" ,
627+ current_name ,
628+ "-theme" ,
629+ "clipboard" ,
630+ "-theme-str" ,
631+ override_string ,
632+ "-theme-str" ,
633+ rofi_pos_string ,
634+ ]
635+ except (OSError , EnvironmentError ):
636+ rofi_flags = [
637+ "-p" ,
638+ prompt ,
639+ "-select" ,
640+ current_name ,
641+ "-theme" ,
642+ "clipboard" ,
643+ ]
613644 if extra_flags :
614645 rofi_flags .extend (extra_flags )
615646 selected = rofi_dmenu (names , rofi_flags )
@@ -635,7 +666,11 @@ def rofi_style_selector(current_layout=None):
635666 update_border_radius ()
636667 generate_includes ()
637668 update_global_css ()
638- notify .send ("Waybar" , f"Style changed to { os .path .basename (selected_style )} " , replace_id = 9 )
669+ notify .send (
670+ "Waybar" ,
671+ f"Style changed to { os .path .basename (selected_style )} " ,
672+ replace_id = 9 ,
673+ )
639674 run_waybar_command ("killall waybar; waybar & disown" )
640675 sys .exit (0 )
641676
@@ -653,11 +688,17 @@ def rofi_selector():
653688 else :
654689 layout_roots .append ("" )
655690 current_layout_path = get_state_value ("WAYBAR_LAYOUT_PATH" )
691+
656692 def display_func (f , root ):
657693 rel = os .path .relpath (f , root ) if root else os .path .basename (f )
658694 return rel .replace (".jsonc" , "" )
695+
659696 selected_layout = rofi_file_selector (
660- LAYOUT_DIRS , ".jsonc" , "Select layout:" , current_layout_path , display_func = display_func
697+ LAYOUT_DIRS ,
698+ ".jsonc" ,
699+ "Select layout:" ,
700+ current_layout_path ,
701+ display_func = display_func ,
661702 )
662703 if selected_layout :
663704 # Find the layout pair
@@ -672,15 +713,22 @@ def display_func(f, root):
672713 style_path = resolve_style_path (selected_layout )
673714 shutil .copyfile (selected_layout , CONFIG_JSONC )
674715 set_state_value ("WAYBAR_LAYOUT_PATH" , selected_layout )
675- set_state_value ("WAYBAR_LAYOUT_NAME" , os .path .basename (selected_layout ).replace (".jsonc" , "" ))
716+ set_state_value (
717+ "WAYBAR_LAYOUT_NAME" ,
718+ os .path .basename (selected_layout ).replace (".jsonc" , "" ),
719+ )
676720 set_state_value ("WAYBAR_STYLE_PATH" , style_path )
677721 style_filepath = os .path .join (str (xdg_config_home ()), "waybar" , "style.css" )
678722 write_style_file (style_filepath , style_path )
679723 update_icon_size ()
680724 update_border_radius ()
681725 generate_includes ()
682726 update_global_css ()
683- notify .send ("Waybar" , f"Layout changed to { display_func (selected_layout , os .path .dirname (selected_layout ))} " , replace_id = 9 )
727+ notify .send (
728+ "Waybar" ,
729+ f"Layout changed to { display_func (selected_layout , os .path .dirname (selected_layout ))} " ,
730+ replace_id = 9 ,
731+ )
684732 run_waybar_command ("killall waybar; waybar & disown" )
685733 ensure_state_file ()
686734 sys .exit (0 )
@@ -699,20 +747,24 @@ def rofi_selector_no_exit():
699747 )
700748 logger .debug (f"Current layout from state: { current_layout_name } " )
701749 hyprland = HYPRLAND .HyprctlWrapper ()
702- override_string = hyprland .get_rofi_override_string ()
703- rofi_pos_string = hyprland .get_rofi_pos ()
750+ try :
751+ override_string = hyprland .get_rofi_override_string ()
752+ rofi_pos_string = hyprland .get_rofi_pos ()
753+ except (OSError , EnvironmentError ):
754+ override_string = ""
755+ rofi_pos_string = ""
704756 rofi_flags = [
705757 "-p" ,
706758 "Select layout:" ,
707759 "-select" ,
708760 current_layout_name ,
709761 "-theme" ,
710762 "clipboard" ,
711- "-theme-str" ,
712- override_string ,
713- "-theme-str" ,
714- rofi_pos_string ,
715763 ]
764+ if override_string :
765+ rofi_flags += ["-theme-str" , override_string ]
766+ if rofi_pos_string :
767+ rofi_flags += ["-theme-str" , rofi_pos_string ]
716768 selected_layout = rofi_dmenu (
717769 layout_names ,
718770 rofi_flags ,
@@ -1343,11 +1395,14 @@ def is_waybar_running_for_current_user():
13431395 """Check if Waybar or Waybar-wrapped is running for the current user only."""
13441396 user = os .getenv ("USER" )
13451397 for proc_name in ["waybar" , "waybar-wrapped" ]:
1346- result = subprocess .run (["pgrep" , "-u" , user , "-x" , proc_name ], capture_output = True )
1398+ result = subprocess .run (
1399+ ["pgrep" , "-u" , user , "-x" , proc_name ], capture_output = True
1400+ )
13471401 if result .returncode == 0 :
13481402 return True
13491403 return False
13501404
1405+
13511406def watch_waybar ():
13521407 signal .signal (signal .SIGTERM , signal_handler )
13531408 signal .signal (signal .SIGINT , signal_handler )
@@ -1375,7 +1430,9 @@ def main():
13751430 # Check for lock file early and inform user on any invocation
13761431 lock_file = os .path .join (str (xdg_runtime_dir ()), "hyde" , "waybar_hide.lock" )
13771432 if os .path .exists (lock_file ):
1378- print ("Waybar is currently hidden due to lock file. Use 'waybar.py --hide 0' to show waybar." )
1433+ print (
1434+ "Waybar is currently hidden due to lock file. Use 'waybar.py --hide 0' to show waybar."
1435+ )
13791436
13801437 logger .debug (f"Looking for state file at: { STATE_FILE } " )
13811438
@@ -1573,15 +1630,21 @@ def main():
15731630 # Remove hide lock file when starting watch mode to avoid confusion
15741631 lock_file = os .path .join (str (xdg_runtime_dir ()), "hyde" , "waybar_hide.lock" )
15751632 if os .path .exists (lock_file ):
1576- logger .warning (f"Found waybar hide lock file at { lock_file } , removing it to start watch mode" )
1577- logger .info ("Waybar is currently hidden due to lock file. Use 'waybar.py --hide 0' to show waybar." )
1633+ logger .warning (
1634+ f"Found waybar hide lock file at { lock_file } , removing it to start watch mode"
1635+ )
1636+ logger .info (
1637+ "Waybar is currently hidden due to lock file. Use 'waybar.py --hide 0' to show waybar."
1638+ )
15781639 os .remove (lock_file )
15791640 watch_waybar ()
15801641 else :
15811642 # Check if waybar should be hidden before starting
15821643 lock_file = os .path .join (str (xdg_runtime_dir ()), "hyde" , "waybar_hide.lock" )
15831644 if os .path .exists (lock_file ):
1584- logger .warning (f"Waybar hide lock file exists at { lock_file } , not starting waybar. Use --hide 0 to show waybar or remove the lock file manually." )
1645+ logger .warning (
1646+ f"Waybar hide lock file exists at { lock_file } , not starting waybar. Use --hide 0 to show waybar or remove the lock file manually."
1647+ )
15851648 return
15861649
15871650 update_icon_size ()
0 commit comments