From 88f83dcc36e760e411d247ef1a149f0ad330264c Mon Sep 17 00:00:00 2001 From: numirias Date: Thu, 1 Mar 2018 18:05:48 +0100 Subject: [PATCH] Fall back to default dimensions if layout is unconfigured --- plasma/layout.py | 7 +++++-- tests/test_layout.py | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plasma/layout.py b/plasma/layout.py index fe43866..da689c2 100644 --- a/plasma/layout.py +++ b/plasma/layout.py @@ -27,11 +27,14 @@ class Plasma(Layout): ('border_width_single', 0, 'Border width for single window'), ('margin', 0, 'Layout margin'), ] + # If windows are added before configure() was called, the screen size is + # still unknown, so we need to set some arbitrary initial root dimensions + default_dimensions = (0, 0, 1000, 1000) def __init__(self, **config): Layout.__init__(self, **config) self.add_defaults(Plasma.defaults) - self.root = Node() + self.root = Node(None, *self.default_dimensions) self.focused = None self.add_mode = None @@ -52,7 +55,7 @@ def info(self): def clone(self, group): clone = copy.copy(self) clone.group = group - clone.root = Node() + clone.root = Node(None, *self.default_dimensions) clone.focused = None clone.add_mode = None return clone diff --git a/tests/test_layout.py b/tests/test_layout.py index 86839f8..03bf2b2 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -9,7 +9,7 @@ # We borrow Qtile's testing framework. That's not elegant but the best option. sys.path.insert(0, str(Path(__file__).parents[1] / 'lib')) # noqa: E402 from qtile.libqtile import config -from qtile.libqtile.layout.floating import Floating +from qtile.libqtile.layout import Floating from qtile.test.conftest import no_xinerama, qtile, xephyr, xvfb # noqa: F401 from qtile.test.layouts.layout_utils import assertFocused @@ -217,3 +217,11 @@ def test_recent(self, qtile): assertFocused(qtile, 'a') qtile.c.layout.recent() assertFocused(qtile, 'c') + + def test_bug_10(self): + """Adding nodes when the correct root dimensions are still unknown + should not raise an error. + """ + layout = Plasma() + layout.add(object()) + layout.add(object())