Created
February 26, 2011 16:16
-
-
Save t9md/845350 to your computer and use it in GitHub Desktop.
wrapper script for me in Ubuntu marveric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# DIRECTION=ARGV[0] | |
# A move and resize argument has the format 'g,x,y,w,h'. All five | |
# components are integers. The first value, g, is the gravity of | |
# the window, with 0 being the most common value (the default | |
# value for the window). Please see the EWMH specification for | |
# other values. | |
# The four remaining values are a standard geometry specification: | |
# x,y is the position of the top left corner of the window, and | |
# w,h is the width and height of the window, with the exception | |
# that the value of -1 in any position is interpreted to mean that | |
# the current geometry value should not be modified. | |
class Window | |
attr_reader :w, :h | |
RESET_CMD =" -b remove,maximized_vert,maximized_horz" | |
def wmctrl(geometory) | |
cmd = "wmctrl -r :ACTIVE: #{RESET_CMD};wmctrl -r :ACTIVE: -e 0,#{geometory.join(',')}" | |
if NOOP | |
puts cmd | |
return | |
end | |
system cmd | |
end | |
def winctrl_select(appname, launch_cmd) | |
cmd = "wmctrl -a #{appname} || #{launch_cmd} " | |
if NOOP | |
puts cmd | |
return | |
end | |
system cmd | |
end | |
def select_gvim() winctrl_select("GVIM", "gvim"); end | |
def select_ff() winctrl_select("Firefox", "firefox"); end | |
def initialize | |
@w , @h = `wmctrl -d 1`.split("\n").first.scan(/DG: (\d+x\d+) /).to_s.split('x').map(&:to_i) | |
[@w, @h] | |
end | |
# [ x, y, w, h ] | |
def left() wmctrl [0,0, w/2, h] ; end | |
def right() wmctrl [w/2,0, w/2, h] ; end | |
def up() wmctrl [0,0, w, h/2] ; end | |
def down() wmctrl [0,h/2, w, h/2] ; end | |
end | |
COMMANDS=%w(left right up down select_gvim select_ff) | |
def help | |
warn "#$0 #{COMMANDS.join('|')}" | |
end | |
NOOP = ARGV.delete('-n') | |
command = ARGV[0] | |
unless COMMANDS.include?(command) | |
help | |
exit 1 | |
end | |
Window.new.send command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment