Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3. import i3ipc
  4.  
  5. # NOTE: for documentation look in: https://github.com/altdesktop/i3ipc-python
  6. # for this to work you need python3 and i3ipc installed on your machine.
  7. # Install it with pip3 install i3ipc.
  8.  
  9. # Initiate i3ipc library.
  10. i3 = i3ipc.Connection()
  11.  
  12. # We need tree of containers to find focused and the biggest one.
  13. tree = i3.get_tree()
  14.  
  15. # Class of currently focused container.
  16. focused = tree.find_focused()
  17.  
  18. # Check if focused is floating.
  19. # Possible states are: 'auto_on', 'auto_off', 'user_on', 'user_off'
  20. focused_floating_state = 'on' in focused.floating
  21.  
  22.  
  23. def find_biggest_container(list_con):
  24.     """Gets list of leaves on current workspace as input and returns
  25.    largest one (by area) that isn't already focused."""
  26.  
  27.     largest = 0
  28.     largest_container = list_con[0]
  29.     for container in list_con:
  30.         y = container.rect.height
  31.         x = container.rect.width
  32.         # It makes no sense to swap focused with itself
  33.         if x * y >= largest and not container.focused:
  34.             largest = x * y
  35.             largest_container = container
  36.  
  37.     return largest_container
  38.  
  39.  
  40. # Get swappin'
  41. if focused_floating_state:  # If currently focused is floating, do nothing.
  42.     pass
  43. else:
  44.     # List of containers on focused workspace.
  45.     list_con = focused.workspace().leaves()
  46.  
  47.     # Firstly we need con_id (i3 container id) of the largest container - swapee
  48.     largest_con_id = find_biggest_container(list_con).id
  49.     # and then we swap it.
  50.     i3.command('swap container with con_id {}'.format(largest_con_id))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement