Class: Wmctile::WindowManager
- Inherits:
-
ClassWithDmenu
- Object
- Class
- ClassWithDmenu
- Wmctile::WindowManager
- Defined in:
- lib/wmctile/window_manager.rb
Instance Attribute Summary collapse
-
#h ⇒ Object
Returns the value of attribute h.
-
#w ⇒ Object
Returns the value of attribute w.
-
#windows(all_workspaces = false) ⇒ Object
Returns the value of attribute windows.
-
#workspace ⇒ Object
Returns the value of attribute workspace.
Instance Method Summary collapse
- #ask_for_window(all_workspaces = false) ⇒ Object
-
#build_win_list(all_workspaces = false) ⇒ Object
window lists ##################.
-
#calculate_snap(where, portion = 0.5) ⇒ Object
window size calculators #######.
- #find_in_windows(window_string, all_workspaces = false) ⇒ Object
- #find_window(window_string, all_workspaces = false) ⇒ Object
- #find_windows(window_string, all_workspaces = false) ⇒ Object
- #get_active_window ⇒ Object
-
#get_window(window_str = nil, all_workspaces = false) ⇒ Object
window getters ################.
- #height(portion = 1) ⇒ Object
- #init_dimensions ⇒ Object
-
#initialize(settings) ⇒ WindowManager
constructor
init ##########################.
-
#width(portion = 1) ⇒ Object
dimension getters #############.
Methods inherited from ClassWithDmenu
Methods inherited from Class
Constructor Details
#initialize(settings) ⇒ WindowManager
init ##########################
6 7 8 9 |
# File 'lib/wmctile/window_manager.rb', line 6 def initialize settings @settings = settings self.init_dimensions end |
Instance Attribute Details
#h ⇒ Object
Returns the value of attribute h.
2 3 4 |
# File 'lib/wmctile/window_manager.rb', line 2 def h @h end |
#w ⇒ Object
Returns the value of attribute w.
2 3 4 |
# File 'lib/wmctile/window_manager.rb', line 2 def w @w end |
#windows(all_workspaces = false) ⇒ Object
Returns the value of attribute windows.
2 3 4 |
# File 'lib/wmctile/window_manager.rb', line 2 def windows @windows end |
#workspace ⇒ Object
Returns the value of attribute workspace.
2 3 4 |
# File 'lib/wmctile/window_manager.rb', line 2 def workspace @workspace end |
Instance Method Details
#ask_for_window(all_workspaces = false) ⇒ Object
105 106 107 |
# File 'lib/wmctile/window_manager.rb', line 105 def ask_for_window all_workspaces = false self. self.windows.map(&:dmenu_item) end |
#build_win_list(all_workspaces = false) ⇒ Object
window lists ##################
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/wmctile/window_manager.rb', line 111 def build_win_list all_workspaces = false unless all_workspaces variable_name = '@windows_on_workspace' else variable_name = '@windows_all' end unless instance_variable_get(variable_name) unless all_workspaces cmd = "wmctrl -lx | grep \" #{ @workspace } \"" else cmd = "wmctrl -lx" end arr = cmd(cmd).split("\n") new_list = arr.map { |w| Wmctile::Window.new(w, @settings) } name_length = new_list.map(&:get_name_length).max new_list.each { |w| w.set_name_length(name_length) } instance_variable_set(variable_name, new_list) end instance_variable_get(variable_name) end |
#calculate_snap(where, portion = 0.5) ⇒ Object
window size calculators #######
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/wmctile/window_manager.rb', line 148 def calculate_snap where, portion = 0.5 return case where when 'left' { :x => @settings.panel_width, :y => @settings.panel_height, :height => self.height, :width => self.width(portion) } when 'right' { :x => self.width(portion), :y => @settings.panel_height, :height => self.height, :width => self.width(1-portion) } when 'top' { :x => @settings.panel_width, :y => @settings.panel_height, :height => self.height(portion), :width => self.width } when 'bottom' { :x => @settings.panel_width, :y => @settings.panel_height + self.height(1-portion), :height => self.height(portion), :width => self.width } else nil end end |
#find_in_windows(window_string, all_workspaces = false) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/wmctile/window_manager.rb', line 78 def find_in_windows window_string, all_workspaces = false if window_string.nil? self.ask_for_window all_workspaces else windows = self.find_windows window_string, all_workspaces if windows ids = windows.collect(&:id) active_win = self.get_active_window if ids.include? active_win.id # cycle through the windows i = ids.index active_win.id # try the next one if ids[i+1] window = windows[i+1] # fallback to the first one else window = windows.first end else # switch to the first one window = windows.first end return window end return nil end end |
#find_window(window_string, all_workspaces = false) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wmctile/window_manager.rb', line 56 def find_window window_string, all_workspaces = false cmd = "wmctrl -lx | grep -F #{ window_string }" cmd += ' | grep -E \'0x\w+\s+' + @workspace.to_s + '\s+\'' unless all_workspaces window_string = self.cmd cmd window_string = window_string.split("\n").first if window_string.nil? return nil else return Wmctile::Window.new window_string, @settings end end |
#find_windows(window_string, all_workspaces = false) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/wmctile/window_manager.rb', line 67 def find_windows window_string, all_workspaces = false cmd = "wmctrl -lx | grep -F #{ window_string }" cmd += ' | grep -E \'0x\w+\s+' + @workspace.to_s + '\s+\'' unless all_workspaces window_strings = self.cmd cmd window_strings = window_strings.split("\n") if window_string.nil? return nil else return window_strings.map { |w| Wmctile::Window.new w, @settings } end end |
#get_active_window ⇒ Object
52 53 54 55 |
# File 'lib/wmctile/window_manager.rb', line 52 def get_active_window win_id = self.cmd('wmctrl -a :ACTIVE: -v 2>&1').split('Using window: ').last Wmctile::Window.new win_id, @settings end |
#get_window(window_str = nil, all_workspaces = false) ⇒ Object
window getters ################
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wmctile/window_manager.rb', line 31 def get_window window_str = nil, all_workspaces = false if window_str.nil? window = self.ask_for_window all_workspaces else if window_str == ':ACTIVE:' window = self.get_active_window else window = self.find_window window_str, all_workspaces unless window # does window_str have an icon bundle in it? (aka evince.Evince) if window_str =~ /[a-z0-9]+\.[a-z0-9]+/i icon = window_str.split('.').first else icon = nil end self.notify 'No window found', "#{ window_str }", icon end end end window end |
#height(portion = 1) ⇒ Object
25 26 27 |
# File 'lib/wmctile/window_manager.rb', line 25 def height portion = 1 @h * portion end |
#init_dimensions ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/wmctile/window_manager.rb', line 10 def init_dimensions # legacy (but fast) method via wmctrl # dimensions = cmd("wmctrl -d | awk '{ print $9 }' | head -n1").split('x') # xrandr is slower, but offers more information dimensions = cmd("xrandr | grep -E '\sconnected\s[0-9]+x[0-9]+\+0' | awk '{print $3}' | awk -F'+' '{print $1}'").split('x') @w = dimensions[0].to_i - 2*@settings.window_border @h = dimensions[1].to_i - 2*@settings.window_border - @settings.panel_height @workspace = cmd("wmctrl -d | grep '\*' | awk '{ print $1 }'").to_i end |
#width(portion = 1) ⇒ Object
dimension getters #############
22 23 24 |
# File 'lib/wmctile/window_manager.rb', line 22 def width portion = 1 @w * portion end |