controller: add auto-connect service
This commit is contained in:
		
							parent
							
								
									ad12a22346
								
							
						
					
					
						commit
						49074303af
					
				
					 3 changed files with 44 additions and 12 deletions
				
			
		
							
								
								
									
										26
									
								
								scripts/auto_connect_gamepad
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								scripts/auto_connect_gamepad
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,26 @@ | ||||||
|  | #!/bin/sh | ||||||
|  | 
 | ||||||
|  | list_paired_controllers() { | ||||||
|  |     bluetoothctl devices Paired | grep -i 'controller' | cut -d' ' -f2 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | count_connected_controllers() { | ||||||
|  |     bluetoothctl devices Connected | grep -i 'controller' | wc -l | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | try_to_connect_to_all_controllers() { | ||||||
|  |     list_paired_controllers | while read paired_controller; do | ||||||
|  |         echo "Trying to connect to controller $paired_controller" | ||||||
|  |         bluetoothctl connect "$paired_controller" | ||||||
|  |     done | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | while true; do | ||||||
|  |     echo "looping" | ||||||
|  |     if test "$(count_connected_controllers)" -ne 0 ; then | ||||||
|  |         echo "there is a controller connected, not attempting to connect to any other" | ||||||
|  |         sleep 10s | ||||||
|  |         continue | ||||||
|  |     fi | ||||||
|  |     try_to_connect_to_all_controllers | ||||||
|  | done | ||||||
|  | @ -125,6 +125,7 @@ | ||||||
|       zbar |       zbar | ||||||
|       wl-clipboard |       wl-clipboard | ||||||
|     ]; |     ]; | ||||||
|  |     auto_connect_gamepad = [ bluez ]; | ||||||
|   } |   } | ||||||
|   // lib.mapAttrs import_script { |   // lib.mapAttrs import_script { | ||||||
|     wdmenu = ./wdmenu.nix; |     wdmenu = ./wdmenu.nix; | ||||||
|  |  | ||||||
|  | @ -1,17 +1,22 @@ | ||||||
|  | { pkgs, lib, ... }: | ||||||
| { | { | ||||||
|   config, |   systemd.user.services = { | ||||||
|   pkgs, |     autoconnect-gamepad = { | ||||||
|   lib, |       Unit = { | ||||||
|   inputs, |         Description = "Attempt to connect to game controllers"; | ||||||
|   ... |         PartOf = [ "graphical-session.target" ]; | ||||||
| }: |         After = [ "graphical-session.target" ]; | ||||||
| { |       }; | ||||||
|   xdg.desktopEntries = { |       Service = { | ||||||
|     connect-controller = { |         ExecStart = lib.getExe pkgs.auto_connect_gamepad; | ||||||
|       name = "Connect Controller"; |       }; | ||||||
|       exec = "bluetoothctl connect 84:30:95:97:1A:79"; |       Install = { | ||||||
|       terminal = false; |         WantedBy = [ "sway-session.target" ]; | ||||||
|  |       }; | ||||||
|     }; |     }; | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   xdg.desktopEntries = { | ||||||
|     disconnect-controller = { |     disconnect-controller = { | ||||||
|       name = "Disconnect Controller"; |       name = "Disconnect Controller"; | ||||||
|       exec = "bluetoothctl disconnect 84:30:95:97:1A:79"; |       exec = "bluetoothctl disconnect 84:30:95:97:1A:79"; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue