Method: Wuffl::Actions.get_resolution
- Defined in:
- lib/wuffl/actions.rb
.get_resolution ⇒ Object
get the resolution of the display
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wuffl/actions.rb', line 20 def self.get_resolution = get_op_sys case when 'windows' output_dimensions = `wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value` begin_hor_res = output_dimensions.index("HorizontalResolution") begin_ver_res = output_dimensions.index("VerticalResolution") begin_video_mode = output_dimensions.index("VideoMode") length_hor = "HorizontalResolution=".length length_ver = "VerticalResolution=".length length_video = "VideoMode=".length char_hor = output_dimensions[begin_hor_res + length_hor] char_ver = output_dimensions[begin_ver_res + length_ver] char_video = output_dimensions[begin_video_mode + length_video] if char_hor != char_hor.to_i.to_s output_dimensions.sub!("HorizontalResolution", "") end if char_ver != char_ver.to_i.to_s output_dimensions.sub!("VerticalResolution", "") end if char_video != char_video.to_i.to_s output_dimensions.sub!("VideoMode", "") end # Horizontal Resolution of the screen hor_res_begin_index = output_dimensions.index("HorizontalResolution") + "HorizontalResolution=".length hor_res_end_index = output_dimensions.index("CurrentVertical") - 3 win_width = output_dimensions.slice(hor_res_begin_index..hor_res_end_index).to_i # Vertical Resolution of the screen ver_res_begin_index = output_dimensions.index("VerticalResolution") + "VerticalResolution=".length ver_res_end_index = output_dimensions.index("VideoMode") - 3 win_height = output_dimensions.slice(ver_res_begin_index..ver_res_end_index).to_i else if == "mac" output_dimensions = `system_profiler SPDisplaysDataType |grep Resolution`.chomp.tr(" ", "") end_index = output_dimensions.index("Retina") - 1 elsif == "linux" output_dimensions = `xdpyinfo | grep dimensions`.chomp.tr(" ", "") end_index = output_dimensions.index("p") - 1 end start_index = output_dimensions.index(":") + 1 resolution = output_dimensions.slice(start_index..end_index) win_width = resolution.slice(0..resolution.index("x")-1).to_i win_height = resolution.slice(resolution.index("x")+1.. resolution.length-1).to_i end return [win_width, win_height] end |