]> Dogcows Code - chaz/openbox/blobdiff - plugins/placement/placement.c
missed prefix of define
[chaz/openbox] / plugins / placement / placement.c
index d03fb4b361735879e4ea9352b96cb16e01e731dc..e1c29df60a51bc07f172b5fdd7dbd3486af33809 100644 (file)
@@ -26,6 +26,40 @@ void plugin_setup_config()
     parse_register("placement", parse_xml, NULL);
 }
 
+static Rect* pick_head(ObClient *c)
+{
+    /* try direct parent first */
+    if (c->transient_for && c->transient_for != OB_TRAN_GROUP) {
+        return screen_area_monitor(c->desktop,
+                                   client_monitor(c->transient_for));
+    }
+
+    /* more than one guy in his group (more than just him) */
+    if (c->group && c->group->members->next) {
+        GSList *it;
+
+        /* try on the client's desktop */
+        for (it = c->group->members; it; it = g_slist_next(it)) {
+            ObClient *itc = it->data;            
+            if (itc != c &&
+                (itc->desktop == c->desktop ||
+                 itc->desktop == DESKTOP_ALL || c->desktop == DESKTOP_ALL))
+                return screen_area_monitor(c->desktop,
+                                           client_monitor(it->data));
+        }
+
+        /* try on all desktops */
+        for (it = c->group->members; it; it = g_slist_next(it)) {
+            ObClient *itc = it->data;            
+            if (itc != c)
+                return screen_area_monitor(c->desktop,
+                                           client_monitor(it->data));
+        }
+    }
+
+    return NULL;
+}
+
 static void place_random(ObClient *c)
 {
     int l, r, t, b;
@@ -33,9 +67,11 @@ static void place_random(ObClient *c)
     Rect *area;
 
     if (ob_state() == OB_STATE_STARTING) return;
-
-    area = screen_area_monitor(c->desktop,
-                               g_random_int_range(0, screen_num_monitors));
+    
+    area = pick_head(c);
+    if (!area)
+        area = screen_area_monitor(c->desktop,
+                                   g_random_int_range(0, screen_num_monitors));
 
     l = area->x;
     t = area->y;
@@ -63,9 +99,9 @@ static void event(ObEvent *e, void *foo)
         if (e->data.c.client->transient_for != OB_TRAN_GROUP) {
             ObClient *c = e->data.c.client;
             ObClient *p = e->data.c.client->transient_for;
-            int x = (c->frame->area.width - p->frame->area.width) / 2 +
+            int x = (p->frame->area.width - c->frame->area.width) / 2 +
                 p->frame->area.x;
-            int y = (c->frame->area.height - p->frame->area.height) / 2 +
+            int y = (p->frame->area.height - c->frame->area.height) / 2 +
                 p->frame->area.y;
             client_configure(c, OB_CORNER_TOPLEFT, x, y,
                              c->area.width, c->area.height,
@@ -104,6 +140,24 @@ static void event(ObEvent *e, void *foo)
         }
     }
 
+    /* center parentless dialogs on the screen */
+    if (e->data.c.client->type == OB_CLIENT_TYPE_DIALOG) {
+        Rect *area;
+        ObClient *c = e->data.c.client;
+        int x, y;
+
+        area = pick_head(c);
+        if (!area)
+            area = screen_area_monitor(c->desktop, 0);
+
+        x = (area->width - c->frame->area.width) / 2 + area->x;
+        y = (area->height - c->frame->area.height) / 2 + area->y;
+        client_configure(c, OB_CORNER_TOPLEFT, x, y,
+                         c->area.width, c->area.height,
+                         TRUE, TRUE);
+        return;
+    }
+
     if (!history || !place_history(e->data.c.client))
         place_random(e->data.c.client);
 }
This page took 0.023479 seconds and 4 git commands to generate.