Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/ruby -w
  2. $DMENU_ARGS = ARGV.join(' ') + '-i -b'
  3. class String
  4. def starts_with? prefix
  5. prefix = prefix.to_s
  6. self[0, prefix.length] == prefix
  7. end
  8. end
  9. def display prompt, *items
  10. result = %x{echo "#{items.join "\n"}" | dmenu #{$DMENU_ARGS} -p '#{prompt}'}
  11. if $? != 0
  12. exit
  13. end
  14. if block_given?
  15. yield result
  16. else
  17. return result
  18. end
  19. end
  20. def query_xrandr *args
  21. lines = %x{xrandr #{args.join ' '}}.split $/
  22. if block_given?
  23. yield lines
  24. else
  25. return lines
  26. end
  27. end
  28. def get_outputs
  29. query_xrandr '-q' do |lines|
  30. lines.delete_at 0
  31. lines.delete_if {|line| line.starts_with? ' '}
  32. lines.map! {|line| line.split[0]}
  33. if block_given?
  34. yield lines
  35. else
  36. return lines
  37. end
  38. end
  39. end
  40. def get_output_info output
  41. query_xrandr '-q' do |lines|
  42. output_found = false
  43. lines.delete_at 0
  44. lines.reject! do |line|
  45. if output_found
  46. if line.starts_with? ' '
  47. false
  48. else
  49. output_found = false
  50. true
  51. end
  52. else
  53. if line.starts_with? output
  54. output_found = true
  55. true
  56. else
  57. true
  58. end
  59. end
  60. end
  61. lines.map!{|line| line.split(' ').join(' ')}
  62. if block_given?
  63. yield lines
  64. else
  65. return lines
  66. end
  67. end
  68. end
  69. def main
  70. display 'Choose an action', %w{Connect Disconnect Resize Rotate Move List} do |command|
  71. case
  72. when command == 'Connect'
  73. display 'Connect which output?', get_outputs do |output|
  74. end
  75. when command == 'Disconnect'
  76. display 'Disconnect which output?', get_outputs do |output|
  77. query_xrandr '--output', output, '--off'
  78. end
  79. when command == 'Resize'
  80. display 'Resize which output?', get_outputs do |output|
  81. end
  82. when command == 'Rotate'
  83. display 'Rotate which output?', get_outputs do |output|
  84. end
  85. when command == 'Move'
  86. display 'Move which output?', get_outputs do |output|
  87. end
  88. when command == 'List'
  89. display 'Available outputs:', get_outputs do |output|
  90. get_output_info output do |info|
  91. resolutions = info.map {|line| line.split(' ')[0]}
  92. display "#{output} resolutions:", resolutions do |resolution|
  93. res_line = info.select {|line| line.starts_with? resolution}[0]
  94. refresh_rates = res_line.split ' '
  95. refresh_rates.delete_at(0)
  96. display "#{output}@#{resolution} refresh rates:", refresh_rates
  97. end
  98. end
  99. end
  100. end
  101. end
  102. end
  103. main