Skip to content

Instantly share code, notes, and snippets.

@Hammer2900
Created July 24, 2019 05:09
Show Gist options
  • Save Hammer2900/c7123449bcc5ce54a8bea58987f91b16 to your computer and use it in GitHub Desktop.
Save Hammer2900/c7123449bcc5ce54a8bea58987f91b16 to your computer and use it in GitHub Desktop.
i3 control window position
import i3ipc
i3 = i3ipc.Connection()
def center_window():
"""
Float and center window, i3wm.
:return:
"""
a = i3.get_tree().find_focused()
if a.floating == 'user_on':
a.command('floating disable')
return
workspace_name = a.workspace().name
rect = a.workspace().rect
a.command('floating enable')
new_window_width = rect.width / 2
window_position = new_window_width / 2
a.command(f'move position {window_position:.0f} {rect.y + 25}')
a.command(f'resize set {new_window_width:.0f} {rect.height - 50}')
a.command(f'move container to workspace {workspace_name}')
# a.command(f'[con_id="{a.id}"] resize set 50 ppt 50 ppt')
a.command(f'[con_id="{a.id}"] focus')
a.command(f'workspace {workspace_name}')
# os.system(f'xdotool mousemove --window {a.id} 0 0')
center_window()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment