zebulon_fr

Console size handling with xdotool (short example)

Mar 19th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. GetWindowSize() {
  4.   local SIZE=$(xdotool getactivewindow getwindowgeometry | grep Geometry | cut -d: -f2)
  5.   let WINDOWWIDTH=$(echo $SIZE | cut -dx -f1)
  6.   let WINDOWHEIGHT=$(echo $SIZE | cut -dx -f2)
  7. }
  8.  
  9. MaximizeWindow() {
  10.   xdotool getactivewindow windowsize 100% 100%
  11. }
  12.  
  13. RestoreWindowSize() {
  14.   xdotool getactivewindow windowsize $WINDOWWIDTH $WINDOWHEIGHT
  15. }
  16.  
  17. # Text in bold
  18. Bold() {
  19.   echo -en '\e[1m'"$*"'\e[21m'
  20. }
  21.  
  22. Cleanup() {
  23.   RestoreWindowSize
  24.   sleep 2
  25. }
  26.  
  27. # Initializations
  28. GetWindowSize
  29. trap Cleanup 0 1 2
  30.  
  31. # Test stuff...
  32. echo 'Test about console size handling with '`Bold xdotool`
  33. sleep 2
  34. MaximizeWindow
  35. echo 'Console have been '`Bold maximised`'.'
  36. sleep 2
  37. echo 'Test finished.'
  38. echo 'Console will return back to its '`Bold initial size`'.'
  39. sleep 2
Advertisement
Add Comment
Please, Sign In to add comment