Top Level Namespace
Instance Method Summary collapse
- #current_screen_resolution ⇒ Object
- #find_opened_window(old_window_ids_list) ⇒ Object
- #full_desktop_resolution ⇒ Object
- #get_absolute_coordrinates_for_viewport(viewport, x, y) ⇒ Object
- #maximized?(window_id) ⇒ Boolean
-
#move_to_screen_on_the_right(window_id, current_x, current_y) ⇒ Object
Moves window to another screen (in case you have two monitors, for example).
- #position_and_resize_active_window(window_id:, x:, y:, w:, h:, viewport:, display: nil, fullscreen: nil) ⇒ Object
- #viewports_coordinates ⇒ Object
- #viewports_matrix ⇒ Object
- #window_ids_list ⇒ Object
Instance Method Details
#current_screen_resolution ⇒ Object
1 2 3 |
# File 'lib/desktopen.rb', line 1 def current_screen_resolution @current_screen_resolution ||= `xrandr`.split("\n").first.match(/current (\d+) x (\d+),/)[1..2].map(&:to_i) end |
#find_opened_window(old_window_ids_list) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/desktopen.rb', line 73 def find_opened_window(old_window_ids_list) new_windows = window_ids_list - old_window_ids_list if @find_window_by_pid_attempt < 50 && new_windows.empty? sleep(0.1) @find_window_by_pid_attempt += 1 find_opened_window(old_window_ids_list) else new_windows.last end end |
#full_desktop_resolution ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/desktopen.rb', line 5 def full_desktop_resolution return @full_desktop_resolution if @full_desktop_resolution @full_desktop_resolution = [] `wmctrl -d`.split("\n").each do |line| if line.match(/\* DG/) @full_desktop_resolution = line.match(/\* DG: (\d+)x(\d+)/)[1..2].map(&:to_i) break; end end @full_desktop_resolution end |
#get_absolute_coordrinates_for_viewport(viewport, x, y) ⇒ Object
38 39 40 41 42 |
# File 'lib/desktopen.rb', line 38 def (, x, y) = [-1].first = [-1].last [ + x, + y] end |
#maximized?(window_id) ⇒ Boolean
65 66 67 |
# File 'lib/desktopen.rb', line 65 def maximized?(window_id) `xwininfo -all -id #{window_id} | grep Maximized`.split("\n").size == 2 end |
#move_to_screen_on_the_right(window_id, current_x, current_y) ⇒ Object
Moves window to another screen (in case you have two monitors, for example). Currently doesn’t support more than that because I don’t personally need it and it complicates things quite a bit.
87 88 89 90 |
# File 'lib/desktopen.rb', line 87 def move_to_screen_on_the_right(window_id, current_x, current_y) window_id = window_id.sub('0x', '').to_i(16) # converting to dec `/usr/bin/xdotool windowmove #{window_id} #{current_x + @current_screen_resolution[0]/2} #{current_y}` end |
#position_and_resize_active_window(window_id:, x:, y:, w:, h:, viewport:, display: nil, fullscreen: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/desktopen.rb', line 44 def position_and_resize_active_window(window_id:, x:, y:, w:, h:, viewport:, display: nil, fullscreen: nil) if fullscreen #display = y x, y = (.to_i, 10, 10) `wmctrl -i -r #{window_id} -e "0,#{x},#{y},700,500"` unless maximized?(window_id) `wmctrl -i -r #{window_id} -b toggle,maximized_vert,maximized_horz` end else x, y = (.to_i, x.to_i, y.to_i) # Unmaximize first if maximized?(window_id) `wmctrl -i -r #{window_id} -b toggle,maximized_vert,maximized_horz` end `wmctrl -i -r #{window_id} -e "0,#{x.to_i},#{y.to_i},#{w.to_i},#{h.to_i}"` end # Moving to screen 2 move_to_screen_on_the_right(window_id, x.to_i, y.to_i) if display.to_i == 2 end |
#viewports_coordinates ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/desktopen.rb', line 24 def return if = [] x,y = current_screen_resolution [:rows].times do |ri| [:columns].times do |ci| << [x*ci, y*ri] end end end |
#viewports_matrix ⇒ Object
17 18 19 20 21 22 |
# File 'lib/desktopen.rb', line 17 def return if columns = full_desktop_resolution[0]/current_screen_resolution[0] rows = full_desktop_resolution[1]/current_screen_resolution[1] { columns: columns, rows: rows } end |
#window_ids_list ⇒ Object
69 70 71 |
# File 'lib/desktopen.rb', line 69 def window_ids_list `wmctrl -l`.split("\n").map { |line| line.gsub(/\s.*\Z/, '') } end |