From 68a8041b1baefdadf0e27deb764c16d025d105b6 Mon Sep 17 00:00:00 2001 From: Christian Lyzell Date: Mon, 19 Jul 2021 16:46:02 +0200 Subject: [PATCH 1/5] Fix WINDOW::NEW for edge cases --- i3ipc_dynamic_tiling.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/i3ipc_dynamic_tiling.py b/i3ipc_dynamic_tiling.py index aa32343..3948989 100755 --- a/i3ipc_dynamic_tiling.py +++ b/i3ipc_dynamic_tiling.py @@ -933,20 +933,25 @@ def on_window_new(ipc, event): or is_floating or len(info['tiled']) < 2: return + commands = [] if not info['main']['id']: - create_container(ipc, 'main', info['tiled'][0]) - create_container(ipc, 'scnd', info['tiled'][1]) + if info['scnd']['id']: + create_container(ipc, 'main', info['tiled'][0]) + else: + create_container(ipc, 'main', info['tiled'][0]) + create_container(ipc, 'scnd', info['tiled'][1]) + commands.append('[con_id={}] focus' + .format(info['focused'])) elif not info['scnd']['id']: create_container(ipc, 'scnd') else: if info['focused'] in info['main']['children']: - commands = [] commands.append('[con_id={}] move to mark {}' .format(info['focused'], info['scnd']['mark'])) commands.append('[con_id={}] focus' .format(info['focused'])) - execute_commands(ipc, commands, '') + execute_commands(ipc, commands, '') def on_window_focus(ipc, event): """React on window focus event. From 43130ee5595c09a86870c9c6cd56e52a913fbbaa Mon Sep 17 00:00:00 2001 From: Christian Lyzell Date: Mon, 19 Jul 2021 16:54:52 +0200 Subject: [PATCH 2/5] Create main from scnd after focus. --- i3ipc_dynamic_tiling.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/i3ipc_dynamic_tiling.py b/i3ipc_dynamic_tiling.py index 3948989..4868a56 100755 --- a/i3ipc_dynamic_tiling.py +++ b/i3ipc_dynamic_tiling.py @@ -883,7 +883,7 @@ def on_workspace_focus(ipc, event): """ logging.info('Workspace::Focus::%s', event.current.name) info = get_workspace_info(ipc, event.current) - command = [] + commands = [] if info['mode'] != 'manual': if info['glbl']['layout'] == 'tabbed' or info['mode'] == 'monocle': if DATA['hide_bar']: @@ -904,12 +904,17 @@ def on_workspace_focus(ipc, event): info = get_workspace_info(ipc) if info['scnd']['id']: for i in info['unmanaged']: - command.append('[con_id={}] move to mark {}' + commands.append('[con_id={}] move to mark {}' .format(i, info['scnd']['mark'])) + else: + if info['scnd']['id'] and not info['main']['id']: + create_container(ipc, 'main', info['tiled'][0]) + commands.append('[con_id={}] focus' + .format(info['focused'])) else: if DATA['hide_bar']: os.system("polybar-msg cmd show 1>/dev/null") - execute_commands(ipc, command) + execute_commands(ipc, commands) def on_window_new(ipc, event): From 248f406617d6a3eadfd9a968818e82657e8c2b6a Mon Sep 17 00:00:00 2001 From: Christian Lyzell Date: Mon, 19 Jul 2021 17:24:55 +0200 Subject: [PATCH 3/5] Improve the workspace focus logic. --- i3ipc_dynamic_tiling.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/i3ipc_dynamic_tiling.py b/i3ipc_dynamic_tiling.py index 4868a56..2d0bf01 100755 --- a/i3ipc_dynamic_tiling.py +++ b/i3ipc_dynamic_tiling.py @@ -885,27 +885,41 @@ def on_workspace_focus(ipc, event): info = get_workspace_info(ipc, event.current) commands = [] if info['mode'] != 'manual': + + # Toggle bar appropriatly. if info['glbl']['layout'] == 'tabbed' or info['mode'] == 'monocle': if DATA['hide_bar']: os.system("polybar-msg cmd hide 1>/dev/null") else: if DATA['hide_bar']: os.system("polybar-msg cmd show 1>/dev/null") + + # Make sure the layout is set. if info['name'] not in I3DT_LAYOUT: I3DT_LAYOUT[info['name']] = {'main': 'splitv', 'scnd': 'splitv'} + + # Make sure that all windows are managed. if info['unmanaged']: + focused = info['focused'] + # Create the containers. if info['main']['id']: if not info['scnd']['id']: create_container(ipc, 'scnd', info['unmanaged'][0]) - elif len(info['unmanaged']) > 1: - unmanaged = info['unmanaged'] - create_container(ipc, 'main', unmanaged[0]) - create_container(ipc, 'scnd', unmanaged[1]) + else: + create_container(ipc, 'main', info['unmanaged'][0]) + if not info['scnd']['id'] \ + and len(info['unmanaged']) > 1: + create_container(ipc, 'scnd', info['unmanaged'][1]) + + # Move the remaining unmanaged windows to the secondary container. info = get_workspace_info(ipc) if info['scnd']['id']: for i in info['unmanaged']: commands.append('[con_id={}] move to mark {}' .format(i, info['scnd']['mark'])) + + commands.append('[con_id={}] focus' + .format(focused)) else: if info['scnd']['id'] and not info['main']['id']: create_container(ipc, 'main', info['tiled'][0]) From 0f899319f4008c84a3510894647529622ff858c5 Mon Sep 17 00:00:00 2001 From: chlyz Date: Mon, 19 Jul 2021 20:47:57 +0200 Subject: [PATCH 4/5] Simplify logic for new window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Julian RĂ¼th --- i3ipc_dynamic_tiling.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/i3ipc_dynamic_tiling.py b/i3ipc_dynamic_tiling.py index 2d0bf01..5b2c94b 100755 --- a/i3ipc_dynamic_tiling.py +++ b/i3ipc_dynamic_tiling.py @@ -954,10 +954,8 @@ def on_window_new(ipc, event): commands = [] if not info['main']['id']: - if info['scnd']['id']: - create_container(ipc, 'main', info['tiled'][0]) - else: - create_container(ipc, 'main', info['tiled'][0]) + create_container(ipc, 'main', info['tiled'][0]) + if not info['scnd']['id']: create_container(ipc, 'scnd', info['tiled'][1]) commands.append('[con_id={}] focus' .format(info['focused'])) From 880d0d3b7ca3d5d6f934c8715808a2185f4f162f Mon Sep 17 00:00:00 2001 From: Christian Lyzell Date: Mon, 19 Jul 2021 20:52:26 +0200 Subject: [PATCH 5/5] More temporary logging. --- i3ipc_dynamic_tiling.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/i3ipc_dynamic_tiling.py b/i3ipc_dynamic_tiling.py index 5b2c94b..7436f10 100755 --- a/i3ipc_dynamic_tiling.py +++ b/i3ipc_dynamic_tiling.py @@ -150,6 +150,8 @@ def get_workspace_info(ipc, workspace=None): for cid in info['scnd']['children']: info['unmanaged'].remove(cid) + logging.debug('Workspace info: %s', info) + return info @@ -232,15 +234,10 @@ def create_container(ipc, name, con_id=None): focused container id) """ - logging.debug('Create container: %s', name) # Get workspace information. info = get_workspace_info(ipc) - # Exit if container already exists. - if info[name]['id']: - raise ValueError('Container already exist!') - # Get the window that should be contained and make sure it is # focused. command = [] @@ -250,6 +247,13 @@ def create_container(ipc, name, con_id=None): else: command.append('[con_id={}] focus'.format(con_id)) + logging.debug('Create container: %s:%s', name, con_id) + + # Exit if container already exists. + if info[name]['id']: + logging.error('Container already exist!') + return + # Remove any marks that may exist. command.append('[con_id={}] unmark'.format(con_id)) @@ -901,6 +905,7 @@ def on_workspace_focus(ipc, event): # Make sure that all windows are managed. if info['unmanaged']: focused = info['focused'] + # Create the containers. if info['main']['id']: if not info['scnd']['id']: