Last active
March 29, 2019 11:29
-
-
Save SamSaffron/6a001994394561eade0dca7da7673927 to your computer and use it in GitHub Desktop.
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 | |
# replacement for i3 move left / right command, behavior changes depending on if your window in floated or not | |
require 'i3ipc' | |
class Mover | |
def initialize | |
@i3 = I3Ipc::Connection.new | |
end | |
def recurse(nodes, focused = false, &blk) | |
nodes.each do |n| | |
blk.call n, n.focused || focused | |
recurse(n.nodes, &blk) | |
recurse(n.floating_nodes, &blk) | |
end | |
end | |
def is_floating? | |
recurse(@i3.tree.nodes) do |n, focused| | |
if n.respond_to? :window_properties | |
return n.floating == "user_on" if focused | |
end | |
end | |
end | |
def move(dir) | |
@i3.command("mark _last") | |
if is_floating? | |
@i3.command("move to output #{dir}") | |
else | |
@i3.command("move #{dir}") | |
end | |
@i3.command('[con_mark="_last"] focus') | |
end | |
def close | |
@i3.close | |
@i3 = nil | |
end | |
end | |
m = Mover.new | |
case ARGV[0] | |
when "left" then | |
m.move("left") | |
when "right" then | |
m.move("right") | |
else | |
puts "unknown command" | |
exit 1 | |
end | |
m.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment