aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason <ammgws@users.noreply.github.com>2020-02-18 20:19:41 +0900
committerGitHub <noreply@github.com>2020-02-18 20:19:41 +0900
commit93d86f4c289ac5f6fbd4d2ddecbd8615bb456daa (patch)
tree292b45ac1e1ed58b112436b085ca4fa1dc07d596
parenta4b07d72721ce641219aea412148a8faf20dc84b (diff)
downloadautotiling-93d86f4c289ac5f6fbd4d2ddecbd8615bb456daa.tar.gz
Check if con exists before querying submembers
On sway, sometimes there is no focused container returned (think it happens either before or after swaylock runs), so `con` is None. ``` >autotiling Error: 'NoneType' object has no attribute 'floating' ```
-rwxr-xr-xautotiling.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/autotiling.py b/autotiling.py
index cca9c79..9cd6aa5 100755
--- a/autotiling.py
+++ b/autotiling.py
@@ -24,21 +24,22 @@ i3 = Connection()
def switch_splitting(i3, e):
try:
con = i3.get_tree().find_focused()
- if con.floating: # We're on i3: on sway it would be None
- is_floating = '_on' in con.floating # May be 'auto_on' or 'user_on'
- is_full_screen = con.fullscreen_mode == 1
- else: # We are on sway
- is_floating = con.type == 'floating_con'
- # On sway on 1st focus the parent container returns 1, then forever the focused container itself
- is_full_screen = con.fullscreen_mode == 1 or con.parent.fullscreen_mode == 1
-
- is_stacked = con.parent.layout == 'stacked'
- is_tabbed = con.parent.layout == 'tabbed'
-
- # Let's exclude floating containers, stacked layouts, tabbed layouts and full screen mode
- if not is_floating and not is_stacked and not is_tabbed and not is_full_screen:
- new_layout = 'splitv' if con.rect.height > con.rect.width else 'splith'
- i3.command(new_layout)
+ if con:
+ if con.floating: # We're on i3: on sway it would be None
+ is_floating = '_on' in con.floating # May be 'auto_on' or 'user_on'
+ is_full_screen = con.fullscreen_mode == 1
+ else: # We are on sway
+ is_floating = con.type == 'floating_con'
+ # On sway on 1st focus the parent container returns 1, then forever the focused container itself
+ is_full_screen = con.fullscreen_mode == 1 or con.parent.fullscreen_mode == 1
+
+ is_stacked = con.parent.layout == 'stacked'
+ is_tabbed = con.parent.layout == 'tabbed'
+
+ # Let's exclude floating containers, stacked layouts, tabbed layouts and full screen mode
+ if not is_floating and not is_stacked and not is_tabbed and not is_full_screen:
+ new_layout = 'splitv' if con.rect.height > con.rect.width else 'splith'
+ i3.command(new_layout)
except Exception as e:
print('Error: {}'.format(e))