sway: improve lock, add inhibit file
This commit is contained in:
		
							parent
							
								
									ce20a704d4
								
							
						
					
					
						commit
						381755c4b8
					
				
					 2 changed files with 44 additions and 7 deletions
				
			
		
							
								
								
									
										48
									
								
								bin/lock
									
										
									
									
									
								
							
							
						
						
									
										48
									
								
								bin/lock
									
										
									
									
									
								
							|  | @ -4,9 +4,10 @@ SCROT_APP=grim | |||
| SCROT_ARGS=" -t jpeg" | ||||
| LOCK_APP=swaylock | ||||
| LOCK_ARGS=" -f -c 000000 -i $IMAGE" | ||||
| INHIBIT_FILE=$HOME/.inhibit | ||||
| 
 | ||||
| 
 | ||||
| function _app_exists() { | ||||
| function _check_app() { | ||||
|   which $1 &> /dev/null | ||||
|   if [ $? -ne 0 ]; then | ||||
|     echo "ERROR: missing app \"$1\"" | ||||
|  | @ -14,12 +15,36 @@ function _app_exists() { | |||
|   fi | ||||
| } | ||||
| 
 | ||||
| function _check_inhibit() { | ||||
|   if [ -e $INHIBIT_FILE ]; then | ||||
|     echo "ERROR: found inhibit file $INHIBIT_FILE" | ||||
|     exit 1 | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| function _inhibit() { | ||||
|   case "$1" in | ||||
|     0|off) | ||||
|       rm -f $INHIBIT_FILE | ||||
|       echo "inhibit disabled" | ||||
|       ;; | ||||
|     1|on) | ||||
|       touch $INHIBIT_FILE | ||||
|       echo "inhibit enabled" | ||||
|       ;; | ||||
|     *) | ||||
|       echo "ERROR: unknown argument: $1" | ||||
|       ;; | ||||
|   esac | ||||
| } | ||||
| 
 | ||||
| function _clean() { | ||||
|   rm -vf $IMAGE | ||||
| } | ||||
| 
 | ||||
| function _lock() { | ||||
|   _app_exists $LOCK_APP | ||||
|   _check_inhibit | ||||
|   _check_app $LOCK_APP | ||||
|   $LOCK_APP $LOCK_ARGS | ||||
| } | ||||
| 
 | ||||
|  | @ -32,24 +57,32 @@ function _on() { | |||
| } | ||||
| 
 | ||||
| function _screenshot() { | ||||
|   _app_exists $SCROT_APP | ||||
|   _check_app $SCROT_APP | ||||
|   $SCROT_APP $SCROT_ARGS $IMAGE | ||||
|   convert -blur 4x4 $IMAGE $IMAGE | ||||
| } | ||||
| 
 | ||||
| function _suspend() { | ||||
|   _check_inhibit | ||||
|   systemctl suspend-then-hibernate | ||||
| } | ||||
| 
 | ||||
| mkdir -p $HOME/log | ||||
| echo "lock: $(date) args: $*" >> $HOME/log/lock.log | ||||
| 
 | ||||
| case "$1" in | ||||
|   inhibit) | ||||
|     _inhibit $2 | ||||
|     ;; | ||||
|   lock) | ||||
|     _on | ||||
|     _screenshot | ||||
|     _lock | ||||
|     _clean | ||||
|     # _clean | ||||
|     ;; | ||||
|   lockonly) | ||||
|     _lock | ||||
|     _clean | ||||
|     # _clean | ||||
|     ;; | ||||
|   off) | ||||
|     _screenshot | ||||
|  | @ -57,12 +90,15 @@ case "$1" in | |||
|     ;; | ||||
|   on) | ||||
|     _on | ||||
|     _clean | ||||
|     # _clean | ||||
|     ;; | ||||
|   screenshot) | ||||
|     _on | ||||
|     _screenshot | ||||
|     ;; | ||||
|   suspend) | ||||
|     _suspend | ||||
|     ;; | ||||
|   *) | ||||
|     echo "invalid argument \"$1\"." | ||||
|     echo "arguments: [lock|lockonly|off|on|screenshot]" | ||||
|  |  | |||
							
								
								
									
										3
									
								
								config
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								config
									
										
									
									
									
								
							|  | @ -37,7 +37,7 @@ exec swayidle -w \ | |||
|            resume '$lock_cmd on' \ | ||||
|        timeout 900 '$lock_cmd lockonly' \ | ||||
|        timeout 1800 '$lock_cmd suspend' \ | ||||
|        before-sleep 'systemctl suspend-then-hibernat' | ||||
|        before-sleep '$lock_cmd lock' | ||||
| bindsym $mod+Ctrl+Escape exec '$lock_cmd lock' | ||||
| 
 | ||||
| ### Input configuration | ||||
|  | @ -56,6 +56,7 @@ bindsym $mod+Return exec $term | |||
| 
 | ||||
| # Kill focused window | ||||
| bindsym $mod+Shift+q kill | ||||
| bindsym --release button2 kill | ||||
| 
 | ||||
| # Start your launcher | ||||
| bindsym $mod+p exec $menu | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue