Avoid initializing a VLA of 0 length
[dana/openbox.git] / openbox / place.c
index d2d66e0..91f87dc 100644 (file)
@@ -257,13 +257,13 @@ static Rect* choose_monitor(ObClient *c, gboolean client_to_be_foregrounded,
 static gboolean place_under_mouse(ObClient *client, gint *x, gint *y,
                                   Size frame_size)
 {
-    if (config_place_policy != OB_PLACE_POLICY_MOUSE)
-        return FALSE;
-
     gint l, r, t, b;
     gint px, py;
     Rect *area;
 
+    if (config_place_policy != OB_PLACE_POLICY_MOUSE)
+        return FALSE;
+
     ob_debug("placing under mouse");
 
     if (!screen_pointer_pos(&px, &py))
@@ -322,28 +322,32 @@ static void place_per_app_setting_size(ObClient *client, Rect *screen,
                                        gint *w, gint *h,
                                        ObAppSettings *settings)
 {
-    if (!settings || !settings->size_given)
+    if (!settings)
         return;
 
-    ob_debug("sizing by per-app settings");
-
-    g_assert(settings->width_num > 0);
+    g_assert(settings->width_num >= 0);
     g_assert(settings->width_denom >= 0);
-    g_assert(settings->height_num > 0);
+    g_assert(settings->height_num >= 0);
     g_assert(settings->height_denom >= 0);
 
-    if (!settings->width_denom)
-        *w = settings->width_num;
-    else {
-        *w = screen->width * settings->width_num / settings->width_denom;
-        *w = MIN(*w, screen->width);
+    if (settings->width_num) {
+        ob_debug("setting width by per-app settings");
+        if (!settings->width_denom)
+            *w = settings->width_num;
+        else {
+            *w = screen->width * settings->width_num / settings->width_denom;
+            *w = MIN(*w, screen->width);
+        }
     }
 
-    if (!settings->height_denom)
-        *h = settings->height_num;
-    else {
-        *h = screen->height * settings->height_num / settings->height_denom;
-        *h = MIN(*h, screen->height);
+    if (settings->height_num) {
+        ob_debug("setting height by per-app settings");
+        if (!settings->height_denom)
+            *h = settings->height_num;
+        else {
+            *h = screen->height * settings->height_num / settings->height_denom;
+            *h = MIN(*h, screen->height);
+        }
     }
 }
 
@@ -402,8 +406,19 @@ static gboolean place_least_overlap(ObClient *c, Rect *head, int *x, int *y,
     GSList* potential_overlap_clients = NULL;
     gint n_client_rects = config_dock_hide ? 0 : 1;
 
-    /* if we're "showing desktop", ignore all existing windows */
-    if (!screen_showing_desktop) {
+    /* If we're "showing desktop", and going to allow this window to
+       be shown now, then ignore all existing windows */
+    gboolean ignore_windows = FALSE;
+    switch (screen_show_desktop_mode) {
+    case SCREEN_SHOW_DESKTOP_NO:
+    case SCREEN_SHOW_DESKTOP_UNTIL_WINDOW:
+        break;
+    case SCREEN_SHOW_DESKTOP_UNTIL_TOGGLE:
+        ignore_windows = TRUE;
+        break;
+    }
+
+    if (!ignore_windows) {
         GList* it;
         for (it = client_list; it != NULL; it = g_list_next(it)) {
             ObClient* maybe_client = (ObClient*)it->data;
@@ -428,24 +443,27 @@ static gboolean place_least_overlap(ObClient *c, Rect *head, int *x, int *y,
             n_client_rects += 1;
         }
     }
-    Rect client_rects[n_client_rects];
-
-    GSList* it;
-    guint i = 0;
-    if (!config_dock_hide)
-        dock_get_area(&client_rects[i++]);
-    for (it = potential_overlap_clients; it != NULL; it = g_slist_next(it)) {
-        ObClient* potential_overlap_client = (ObClient*)it->data;
-        client_rects[i] = potential_overlap_client->frame->area;
-        i += 1;
-    }
-    g_slist_free(potential_overlap_clients);
 
-    Point result;
-    place_overlap_find_least_placement(client_rects, n_client_rects, head,
-                                       &frame_size, &result);
-    *x = result.x;
-    *y = result.y;
+    if (n_client_rects) {
+        Rect client_rects[n_client_rects];
+        GSList* it;
+        Point result;
+        guint i = 0;
+
+        if (!config_dock_hide)
+            dock_get_area(&client_rects[i++]);
+        for (it = potential_overlap_clients; it != NULL; it = g_slist_next(it)) {
+            ObClient* potential_overlap_client = (ObClient*)it->data;
+            client_rects[i] = potential_overlap_client->frame->area;
+            i += 1;
+        }
+        g_slist_free(potential_overlap_clients);
+
+        place_overlap_find_least_placement(client_rects, n_client_rects, head,
+                                           &frame_size, &result);
+        *x = result.x;
+        *y = result.y;
+    }
 
     return TRUE;
 }