diff --git a/common/array.h b/common/array.h
index 8d3a4e1..c03b08a 100644
--- a/common/array.h
+++ b/common/array.h
@@ -3,6 +3,7 @@
  *
  * Copyright © 2009 Julien Danjou <julien@danjou.info>
  * Copyright © 2008 Pierre Habouzit <madcoder@debian.org>
+ * Copyright © 2012 Google, Inc. <durandal@google.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -56,6 +57,7 @@
             dtor(&arr->tab[i]);                                             \
         }                                                                   \
         p_delete(&arr->tab);                                                \
+        arr->len = arr->size = 0;                                           \
     }                                                                       \
     static inline void pfx##_array_delete(pfx##_array_t **arrp) {           \
         if (*arrp) {                                                        \
diff --git a/screen.c b/screen.c
index 3dc70d4..af24e3f 100644
--- a/screen.c
+++ b/screen.c
@@ -2,6 +2,7 @@
  * screen.c - screen management
  *
  * Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
+ * Copyright © 2012 Google, Inc. <durandal@google.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -122,7 +123,7 @@ screen_scan_randr(void)
 
                     int len = xcb_randr_get_output_info_name_length(output_info_r);
                     /* name is not NULL terminated */
-                    char *name = memcpy(p_new(char *, len + 1), xcb_randr_get_output_info_name(output_info_r), len);
+                    char *name = memcpy(p_new(char, len + 1), xcb_randr_get_output_info_name(output_info_r), len);
                     name[len] = '\0';
 
                     screen_output_array_append(&new_screen.outputs,
@@ -662,9 +663,70 @@ luaA_screen_count(lua_State *L)
     return 1;
 }
 
+/** Override the autodetected screen config, e.g. to fake multiple displays.
+ * \param L The Lua VM state.
+ * \return The number of elements pushed on stack.
+ * \luastack
+ * \lparam A table structure describing the desired screen layout.
+ */
+static int
+luaA_screen_override(lua_State *L)
+{
+    if (!lua_istable(L, 1)) return 0;
+    foreach(screen, globalconf.screens) {
+        foreach(output, screen->outputs)
+            p_delete(&output->name);
+        screen_output_array_wipe(&screen->outputs);
+    }
+
+    screen_array_wipe(&globalconf.screens);
+    const int screens = luaL_getn(L, 1);
+    for (int screen = 1; screen <= screens; screen++) {
+        lua_rawgeti(L, 1, screen);
+        if (!lua_istable(L, 2)) {
+            lua_pop(L, 1);
+            continue;
+        }
+        lua_rawgeti(L, 2, 1);
+        lua_rawgeti(L, 2, 2);
+        lua_rawgeti(L, 2, 3);
+        lua_rawgeti(L, 2, 4);
+        lua_rawgeti(L, 2, 5);
+        screen_t new_screen;
+        p_clear(&new_screen, 1);
+        new_screen.geometry.x = lua_tonumber(L, 3);
+        new_screen.geometry.y = lua_tonumber(L, 4);
+        new_screen.geometry.width = lua_tonumber(L, 5);
+        new_screen.geometry.height = lua_tonumber(L, 6);
+        const int outputs = luaL_getn(L, 7);
+        for (int output = 1; output <= outputs; output++) {
+            lua_rawgeti(L, 7, output);
+            if (!lua_istable(L, 8)) {
+                lua_pop(L, 1);
+                continue;
+            }
+            lua_rawgeti(L, 8, 1);
+            lua_rawgeti(L, 8, 2);
+            lua_rawgeti(L, 8, 3);
+            size_t name_len = lua_strlen(L, 9);
+            char *name = memcpy(p_new(char, name_len + 1), lua_tostring(L, 9), name_len);
+            name[name_len] = '\0';
+            screen_output_array_append(&new_screen.outputs,
+                                       (screen_output_t) { .name = name,
+                                                           .mm_width = lua_tonumber(L, 10),
+                                                           .mm_height = lua_tonumber(L, 11) });
+            lua_pop(L, 4);
+        }
+        screen_add(new_screen);
+        lua_pop(L, 6);
+    }
+    return 0;
+}
+
 const struct luaL_reg awesome_screen_methods[] =
 {
     { "count", luaA_screen_count },
+    { "override", luaA_screen_override },
     { "__index", luaA_screen_module_index },
     { NULL, NULL }
 };
