Module: WindowResizer
- Defined in:
- lib/window_resizer.rb
Overview
A basic utility module that wraps command line tools xrandr (for detecting current X screen resolution) and wmctrl (for setting current window’s position and size)
Class Method Summary collapse
-
.resize_current_to(options) ⇒ Object
Will resize the current window to :positions => => 123, :y => 123 and with :resize_factors => => 0.85, :y => 0.76.
-
.resolution ⇒ Object
Getter for current resolution.
-
.update_resolutions ⇒ Object
Retrieve and assign the current X screen resolution by invoking xrandr and parsing the output.
Class Method Details
.resize_current_to(options) ⇒ Object
Will resize the current window to :positions => => 123, :y => 123 and with :resize_factors => => 0.85, :y => 0.76
Resize factors are relative to full screen resolution, so 1.0 is 1920 pixels X in a 1920*1200 resolution, 0.5 would be 960 and so on…
Position can also be :left, :center, :right for :x, :top, :bottom, :center for :y
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/window_resizer.rb', line 30 def self.resize_current_to() raise "Please specify :positions => {:x => 123, :y => 123} and :resize_factors => {:x => 0.85, :y => 0.76}" if not [:positions] or not [:resize_factors] # Calculate desired window sizes window_sizes = {:x => (resolution[:x]*[:resize_factors][:x]).to_i, :y => (resolution[:y]*[:resize_factors][:y]).to_i} [:positions] = process_positions([:positions], window_sizes) # Invoke wmctrl with the given parameters `wmctrl -r :ACTIVE: -e 4,#{[:positions][:x]},#{[:positions][:y]},#{window_sizes[:x]},#{window_sizes[:y]}` end |
.resolution ⇒ Object
Getter for current resolution
9 10 11 |
# File 'lib/window_resizer.rb', line 9 def self.resolution @@resolution ||= update_resolutions end |
.update_resolutions ⇒ Object
Retrieve and assign the current X screen resolution by invoking xrandr and parsing the output
16 17 18 19 |
# File 'lib/window_resizer.rb', line 16 def self.update_resolutions `xrandr` =~ /current ([^x]*)x([^,]*),/ @@resolution = {:x => $1.strip.chomp.to_i, :y => $2.strip.chomp.to_i} end |