colszowka-window_resizer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +1 -0
 - data/bin/resize_current_window +59 -0
 - data/lib/window_resizer.rb +85 -0
 - metadata +75 -0
 
    
        data/README.textile
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Todooo
         
     | 
| 
         @@ -0,0 +1,59 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'optparse'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require File.join(File.dirname(__FILE__), '../lib', 'window_resizer')
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # Set up options hash
         
     | 
| 
      
 7 
     | 
    
         
            +
            options = {:resize_factors => {}, :positions => {} }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            opt_parser = OptionParser.new do |opts|
         
     | 
| 
      
 10 
     | 
    
         
            +
              opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              opts.on("-x X", "--width-ratio X", Float, "Resize ratio for window width relative to screen resolution. Defaults to 0.85") do |x|
         
     | 
| 
      
 13 
     | 
    
         
            +
                options[:resize_factors][:x] = x
         
     | 
| 
      
 14 
     | 
    
         
            +
                # Fall back to default
         
     | 
| 
      
 15 
     | 
    
         
            +
                options[:resize_factors][:x] ||= 0.85
         
     | 
| 
      
 16 
     | 
    
         
            +
                # Show error if resize ratio is invalid
         
     | 
| 
      
 17 
     | 
    
         
            +
                if options[:resize_factors][:x] < 0.1 or options[:resize_factors][:x] > 1.0
         
     | 
| 
      
 18 
     | 
    
         
            +
                  raise OptionParser::InvalidArgument, "Width resize ratio must be > 0.1 and <= 1.0"
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
              
         
     | 
| 
      
 22 
     | 
    
         
            +
              opts.on("-y X", "--height-ratio X", Float, "Resize ratio for window height relative to screen resolution. Defaults to 0.85") do |y|
         
     | 
| 
      
 23 
     | 
    
         
            +
                options[:resize_factors][:y] = y
         
     | 
| 
      
 24 
     | 
    
         
            +
                # Fall back to default
         
     | 
| 
      
 25 
     | 
    
         
            +
                options[:resize_factors][:y] ||= 0.85
         
     | 
| 
      
 26 
     | 
    
         
            +
                # Show error if resize ratio is invalid
         
     | 
| 
      
 27 
     | 
    
         
            +
                if options[:resize_factors][:y] < 0.1 or options[:resize_factors][:y] > 1.0
         
     | 
| 
      
 28 
     | 
    
         
            +
                  raise OptionParser::InvalidArgument, "Height resize ratio must be > 0.1 and <= 1.0"
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
              
         
     | 
| 
      
 32 
     | 
    
         
            +
              opts.on("--left", "Change window position to left screen border") do
         
     | 
| 
      
 33 
     | 
    
         
            +
                options[:positions][:x] = :left
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
              opts.on("--right", "Change window position to right screen border") do
         
     | 
| 
      
 36 
     | 
    
         
            +
                options[:positions][:x] = :right
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
              opts.on("--top", "Change window position to upper screen border") do
         
     | 
| 
      
 39 
     | 
    
         
            +
                options[:positions][:y] = :top
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
              opts.on("--bottom", "Change window position to lower screen border") do
         
     | 
| 
      
 42 
     | 
    
         
            +
                options[:positions][:y] = :bottom
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
              
         
     | 
| 
      
 45 
     | 
    
         
            +
              # Fall back to centered positions of none given
         
     | 
| 
      
 46 
     | 
    
         
            +
              options[:positions][:x] ||= :center
         
     | 
| 
      
 47 
     | 
    
         
            +
              options[:positions][:y] ||= :center
         
     | 
| 
      
 48 
     | 
    
         
            +
            end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            # Parse options and exit on failure
         
     | 
| 
      
 51 
     | 
    
         
            +
            begin
         
     | 
| 
      
 52 
     | 
    
         
            +
              opt_parser.parse!
         
     | 
| 
      
 53 
     | 
    
         
            +
            rescue => err
         
     | 
| 
      
 54 
     | 
    
         
            +
              puts "Whoops! #{err}"
         
     | 
| 
      
 55 
     | 
    
         
            +
              exit
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            # Invoke the window resizer
         
     | 
| 
      
 59 
     | 
    
         
            +
            WindowResizer.resize_current_to options
         
     | 
| 
         @@ -0,0 +1,85 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #
         
     | 
| 
      
 2 
     | 
    
         
            +
            # A basic utility module that wraps command line tools xrandr (for detecting current X screen resolution)
         
     | 
| 
      
 3 
     | 
    
         
            +
            # and wmctrl (for setting current window's position and size)
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            module WindowResizer
         
     | 
| 
      
 6 
     | 
    
         
            +
              #
         
     | 
| 
      
 7 
     | 
    
         
            +
              # Getter for current resolution
         
     | 
| 
      
 8 
     | 
    
         
            +
              #
         
     | 
| 
      
 9 
     | 
    
         
            +
              def self.resolution
         
     | 
| 
      
 10 
     | 
    
         
            +
                @@resolution ||= update_resolutions
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
              
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              # Retrieve and assign the current X screen resolution by invoking xrandr and parsing the output
         
     | 
| 
      
 15 
     | 
    
         
            +
              #
         
     | 
| 
      
 16 
     | 
    
         
            +
              def self.update_resolutions
         
     | 
| 
      
 17 
     | 
    
         
            +
                `xrandr` =~ /current ([^x]*)x([^,]*),/
         
     | 
| 
      
 18 
     | 
    
         
            +
                @@resolution = {:x => $1.strip.chomp.to_i, :y => $2.strip.chomp.to_i} 
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
              #
         
     | 
| 
      
 22 
     | 
    
         
            +
              # Will resize the current window to :positions => {:x => 123, :y => 123} 
         
     | 
| 
      
 23 
     | 
    
         
            +
              # and with :resize_factors => {:x => 0.85, :y => 0.76}
         
     | 
| 
      
 24 
     | 
    
         
            +
              #
         
     | 
| 
      
 25 
     | 
    
         
            +
              # Resize factors are relative to full screen resolution, so 1.0 is 1920 pixels X in a 1920*1200 
         
     | 
| 
      
 26 
     | 
    
         
            +
              # resolution, 0.5 would be 960 and so on...
         
     | 
| 
      
 27 
     | 
    
         
            +
              # 
         
     | 
| 
      
 28 
     | 
    
         
            +
              # Position can also be :left, :center, :right for :x, :top, :bottom, :center for :y
         
     | 
| 
      
 29 
     | 
    
         
            +
              #
         
     | 
| 
      
 30 
     | 
    
         
            +
              def self.resize_current_to(options)
         
     | 
| 
      
 31 
     | 
    
         
            +
                raise "Please specify :positions => {:x => 123, :y => 123} and :resize_factors => {:x => 0.85, :y => 0.76}" if not options[:positions] or not options[:resize_factors]
         
     | 
| 
      
 32 
     | 
    
         
            +
                # Calculate desired window sizes 
         
     | 
| 
      
 33 
     | 
    
         
            +
                window_sizes = {:x => (resolution[:x]*options[:resize_factors][:x]).to_i, 
         
     | 
| 
      
 34 
     | 
    
         
            +
                                :y => (resolution[:y]*options[:resize_factors][:y]).to_i}
         
     | 
| 
      
 35 
     | 
    
         
            +
                
         
     | 
| 
      
 36 
     | 
    
         
            +
                options[:positions] = process_positions(options[:positions], window_sizes)
         
     | 
| 
      
 37 
     | 
    
         
            +
                
         
     | 
| 
      
 38 
     | 
    
         
            +
                # Invoke wmctrl with the given parameters
         
     | 
| 
      
 39 
     | 
    
         
            +
                `wmctrl -r :ACTIVE: -e 4,#{options[:positions][:x]},#{options[:positions][:y]},#{window_sizes[:x]},#{window_sizes[:y]}`
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
              
         
     | 
| 
      
 42 
     | 
    
         
            +
              protected
         
     | 
| 
      
 43 
     | 
    
         
            +
              
         
     | 
| 
      
 44 
     | 
    
         
            +
              #
         
     | 
| 
      
 45 
     | 
    
         
            +
              # Will evaluate given symbols for automatic position calculation
         
     | 
| 
      
 46 
     | 
    
         
            +
              # positions[:x] can be :left, :right or :center
         
     | 
| 
      
 47 
     | 
    
         
            +
              # positions[:y] can be :top, :bottom, :center
         
     | 
| 
      
 48 
     | 
    
         
            +
              #
         
     | 
| 
      
 49 
     | 
    
         
            +
              def self.process_positions(positions, window_sizes)
         
     | 
| 
      
 50 
     | 
    
         
            +
                if positions[:x].instance_of?(Symbol)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  positions[:x] = send("#{positions[:x]}_position_for_x", window_sizes)
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
                
         
     | 
| 
      
 54 
     | 
    
         
            +
                if positions[:y].instance_of?(Symbol)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  positions[:y] = send("#{positions[:y]}_position_for_y", window_sizes)
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
                
         
     | 
| 
      
 58 
     | 
    
         
            +
                positions
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
              
         
     | 
| 
      
 61 
     | 
    
         
            +
              def self.left_position_for_x(sizes)
         
     | 
| 
      
 62 
     | 
    
         
            +
                0
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
              
         
     | 
| 
      
 65 
     | 
    
         
            +
              def self.right_position_for_x(sizes)
         
     | 
| 
      
 66 
     | 
    
         
            +
                resolution[:x]-sizes[:x]
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
              
         
     | 
| 
      
 69 
     | 
    
         
            +
              def self.center_position_for_x(sizes)
         
     | 
| 
      
 70 
     | 
    
         
            +
                (resolution[:x]-sizes[:x])/2+rand(30)
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
              
         
     | 
| 
      
 73 
     | 
    
         
            +
              def self.top_position_for_y(sizes)
         
     | 
| 
      
 74 
     | 
    
         
            +
                0
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
              
         
     | 
| 
      
 77 
     | 
    
         
            +
              def self.bottom_position_for_y(sizes)
         
     | 
| 
      
 78 
     | 
    
         
            +
                resolution[:y]-sizes[:y]
         
     | 
| 
      
 79 
     | 
    
         
            +
              end
         
     | 
| 
      
 80 
     | 
    
         
            +
              
         
     | 
| 
      
 81 
     | 
    
         
            +
              def self.center_position_for_y(sizes)
         
     | 
| 
      
 82 
     | 
    
         
            +
                (resolution[:y]-sizes[:y])/2+rand(30)
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
      
 84 
     | 
    
         
            +
              
         
     | 
| 
      
 85 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,75 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: colszowka-window_resizer
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Christoph Olszowka
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-03-31 00:00:00 -07:00
         
     | 
| 
      
 13 
     | 
    
         
            +
            default_executable: 
         
     | 
| 
      
 14 
     | 
    
         
            +
            dependencies: 
         
     | 
| 
      
 15 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 16 
     | 
    
         
            +
              name: mime-types
         
     | 
| 
      
 17 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 18 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 19 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 20 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 21 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 22 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 23 
     | 
    
         
            +
                    version: "1.15"
         
     | 
| 
      
 24 
     | 
    
         
            +
                version: 
         
     | 
| 
      
 25 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 26 
     | 
    
         
            +
              name: diff-lcs
         
     | 
| 
      
 27 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 28 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 29 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: 1.1.2
         
     | 
| 
      
 34 
     | 
    
         
            +
                version: 
         
     | 
| 
      
 35 
     | 
    
         
            +
            description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
         
     | 
| 
      
 36 
     | 
    
         
            +
            email: tom@mojombo.com
         
     | 
| 
      
 37 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 44 
     | 
    
         
            +
            - bin/resize_current_window
         
     | 
| 
      
 45 
     | 
    
         
            +
            - lib/window_resizer.rb
         
     | 
| 
      
 46 
     | 
    
         
            +
            - README.textile
         
     | 
| 
      
 47 
     | 
    
         
            +
            has_rdoc: true
         
     | 
| 
      
 48 
     | 
    
         
            +
            homepage: http://github.com/colszowka/window_resizer
         
     | 
| 
      
 49 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 50 
     | 
    
         
            +
            rdoc_options: 
         
     | 
| 
      
 51 
     | 
    
         
            +
            - --inline-source
         
     | 
| 
      
 52 
     | 
    
         
            +
            - --charset=UTF-8
         
     | 
| 
      
 53 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 54 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 55 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 56 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 57 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 58 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 59 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 60 
     | 
    
         
            +
              version: 
         
     | 
| 
      
 61 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 62 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 63 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 64 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 65 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 66 
     | 
    
         
            +
              version: 
         
     | 
| 
      
 67 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 70 
     | 
    
         
            +
            rubygems_version: 1.2.0
         
     | 
| 
      
 71 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 72 
     | 
    
         
            +
            specification_version: 2
         
     | 
| 
      
 73 
     | 
    
         
            +
            summary: A shell script for resizing and positioning the active window in the X window system
         
     | 
| 
      
 74 
     | 
    
         
            +
            test_files: []
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     |