X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fplace.c;h=0b8309a22ba74d6c867c1b673c27022ad60f101c;hb=897c70e8dd8e3f01c5f90f5a89c82762508e6667;hp=6d36e1bd43ecbd0539f9b1c6423e24b16cb3c875;hpb=7f11e15bb8bdb4e6fc6cd012b0ff3c92900a7b70;p=chaz%2Fopenbox diff --git a/openbox/place.c b/openbox/place.c index 6d36e1bd..0b8309a2 100644 --- a/openbox/place.c +++ b/openbox/place.c @@ -23,6 +23,7 @@ #include "frame.h" #include "focus.h" #include "config.h" +#include "debug.h" static void add_choice(guint *choice, guint mychoice) { @@ -52,12 +53,16 @@ static Rect *pick_pointer_head(ObClient *c) g_assert_not_reached(); } +/*! Pick a monitor to place a window on. + The returned array value should be freed with g_free. The areas within the + array should not be freed. */ static Rect **pick_head(ObClient *c) { Rect **area; guint *choice; guint i; gint px, py; + ObClient *p; area = g_new(Rect*, screen_num_monitors); choice = g_new(guint, screen_num_monitors); @@ -65,8 +70,10 @@ static Rect **pick_head(ObClient *c) choice[i] = screen_num_monitors; /* make them all invalid to start */ /* try direct parent first */ - if (c->transient_for && c->transient_for != OB_TRAN_GROUP) { - add_choice(choice, client_monitor(c->transient_for)); + if ((p = client_direct_parent(c))) { + add_choice(choice, client_monitor(p)); + ob_debug("placement adding choice %d for parent\n", + client_monitor(p)); } /* more than one window in its group (more than just this window) */ @@ -79,25 +86,36 @@ static Rect **pick_head(ObClient *c) if (itc != c && (itc->desktop == c->desktop || itc->desktop == DESKTOP_ALL || c->desktop == DESKTOP_ALL)) + { add_choice(choice, client_monitor(it->data)); + ob_debug("placement adding choice %d for group sibling\n", + 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) + if (itc != c) { add_choice(choice, client_monitor(it->data)); + ob_debug("placement adding choice %d for group sibling on " + "another desktop\n", client_monitor(it->data)); + } } } - if (focus_client) + if (focus_client) { add_choice(choice, client_monitor(focus_client)); + ob_debug("placement adding choice %d for focused window\n", + client_monitor(focus_client)); + } screen_pointer_pos(&px, &py); for (i = 0; i < screen_num_monitors; i++) if (RECT_CONTAINS(*screen_physical_area_monitor(i), px, py)) { add_choice(choice, i); + ob_debug("placement adding choice %d for mouse pointer\n", i); break; } @@ -126,9 +144,9 @@ static gboolean place_random(ObClient *client, gint *x, gint *y) b = areas[i]->y + areas[i]->height - client->frame->area.height; if (r > l) *x = g_random_int_range(l, r + 1); - else *x = 0; + else *x = areas[i]->x; if (b > t) *y = g_random_int_range(t, b + 1); - else *y = 0; + else *y = areas[i]->y; g_free(areas); @@ -251,13 +269,16 @@ typedef enum } ObSmartType; #define SMART_IGNORE(placer, c) \ - (placer == c || !c->frame->visible || c->shaded || !client_normal(c) || \ + (placer == c || c->shaded || !c->frame->visible || \ + c->type == OB_CLIENT_TYPE_SPLASH || c->type == OB_CLIENT_TYPE_DESKTOP || \ + ((c->type == OB_CLIENT_TYPE_MENU || c->type == OB_CLIENT_TYPE_TOOLBAR) &&\ + client_has_parent(c)) || \ (c->desktop != DESKTOP_ALL && \ c->desktop != (placer->desktop == DESKTOP_ALL ? \ screen_desktop : placer->desktop))) static gboolean place_smart(ObClient *client, gint *x, gint *y, - ObSmartType type) + ObSmartType type, gboolean ignore_max) { gboolean ret = FALSE; GSList *spaces = NULL, *sit; @@ -273,7 +294,7 @@ static gboolean place_smart(ObClient *client, gint *x, gint *y, areas = pick_head(client); - for (i = 0; i < screen_num_monitors; ++i) { + for (i = 0; i < screen_num_monitors && !ret; ++i) { spaces = area_add(spaces, areas[i]); /* stay out from under windows in higher layers */ @@ -282,7 +303,8 @@ static gboolean place_smart(ObClient *client, gint *x, gint *y, if (WINDOW_IS_CLIENT(it->data)) { c = it->data; - if (c->fullscreen) + if (ignore_max && + (c->fullscreen || (c->max_vert && c->max_horz))) continue; } else continue; @@ -306,7 +328,8 @@ static gboolean place_smart(ObClient *client, gint *x, gint *y, if (WINDOW_IS_CLIENT(it->data)) { c = it->data; - if (c->fullscreen) + if (ignore_max && + (c->fullscreen || (c->max_vert && c->max_horz))) continue; } else continue; @@ -388,60 +411,64 @@ static gboolean place_under_mouse(ObClient *client, gint *x, gint *y) static gboolean place_per_app_setting(ObClient *client, gint *x, gint *y, ObAppSettings *settings) { - Rect *screen; + Rect *screen = NULL; if (!settings || (settings && !settings->pos_given)) return FALSE; /* Find which head the pointer is on */ - if (settings->head == -1) + if (settings->monitor == 0) screen = pick_pointer_head(client); - else - screen = screen_area_monitor(client->desktop, settings->head); + else if (settings->monitor > 0 && + (guint)settings->monitor <= screen_num_monitors) + screen = screen_area_monitor(client->desktop, + (guint)settings->monitor - 1); + else { + Rect **all = NULL; + all = pick_head(client); + screen = all[0]; + g_free(all); /* the areas themselves don't need to be freed */ + } if (settings->center_x) *x = screen->x + screen->width / 2 - client->area.width / 2; + else if (settings->opposite_x) + *x = screen->x + screen->width - client->frame->area.width - + settings->position.x; else *x = screen->x + settings->position.x; if (settings->center_y) *y = screen->y + screen->height / 2 - client->area.height / 2; + else if (settings->opposite_y) + *y = screen->y + screen->height - client->frame->area.height - + settings->position.y; else *y = screen->y + settings->position.y; return TRUE; } -static gboolean place_transient(ObClient *client, gint *x, gint *y) +static gboolean place_transient_splash(ObClient *client, gint *x, gint *y) { - if (client->transient_for) { - if (client->transient_for != OB_TRAN_GROUP) { - ObClient *c = client; - ObClient *p = client->transient_for; - *x = (p->frame->area.width - c->frame->area.width) / 2 + - p->frame->area.x; - *y = (p->frame->area.height - c->frame->area.height) / 2 + - p->frame->area.y; - return TRUE; - } else { - GSList *it; - gboolean first = TRUE; - gint l, r, t, b; - for (it = client->group->members; it; it = g_slist_next(it)) { - ObClient *m = it->data; - if (!(m == client || m->transient_for)) { - if (first) { - l = RECT_LEFT(m->frame->area); - t = RECT_TOP(m->frame->area); - r = RECT_RIGHT(m->frame->area); - b = RECT_BOTTOM(m->frame->area); - first = FALSE; - } else { - l = MIN(l, RECT_LEFT(m->frame->area)); - t = MIN(t, RECT_TOP(m->frame->area)); - r = MAX(r, RECT_RIGHT(m->frame->area)); - b = MAX(b, RECT_BOTTOM(m->frame->area)); - } + if (client->type == OB_CLIENT_TYPE_DIALOG) { + GSList *it; + gboolean first = TRUE; + gint l, r, t, b; + for (it = client->parents; it; it = g_slist_next(it)) { + ObClient *m = it->data; + if (!m->iconic) { + if (first) { + l = RECT_LEFT(m->frame->area); + t = RECT_TOP(m->frame->area); + r = RECT_RIGHT(m->frame->area); + b = RECT_BOTTOM(m->frame->area); + first = FALSE; + } else { + l = MIN(l, RECT_LEFT(m->frame->area)); + t = MIN(t, RECT_TOP(m->frame->area)); + r = MAX(r, RECT_RIGHT(m->frame->area)); + b = MAX(b, RECT_BOTTOM(m->frame->area)); } } if (!first) { @@ -451,6 +478,21 @@ static gboolean place_transient(ObClient *client, gint *x, gint *y) } } } + + if (client->type == OB_CLIENT_TYPE_DIALOG || + client->type == OB_CLIENT_TYPE_SPLASH) + { + Rect **areas; + + areas = pick_head(client); + + *x = (areas[0]->width - client->frame->area.width) / 2 + areas[0]->x; + *y = (areas[0]->height - client->frame->area.height) / 2 + areas[0]->y; + + g_free(areas); + return TRUE; + } + return FALSE; } @@ -461,18 +503,21 @@ gboolean place_client(ObClient *client, gint *x, gint *y, gboolean ret = FALSE; if (client->positioned) return FALSE; - if (place_transient(client, x, y)) + if (place_transient_splash(client, x, y)) ret = TRUE; else if (!( place_per_app_setting(client, x, y, settings) || ((config_place_policy == OB_PLACE_POLICY_MOUSE) ? place_under_mouse(client, x, y) : - place_smart(client, x, y, SMART_FULL) || - place_smart(client, x, y, SMART_GROUP) || - place_smart(client, x, y, SMART_FOCUSED) || + place_smart(client, x, y, SMART_FULL, FALSE) || + place_smart(client, x, y, SMART_FULL, TRUE) || + place_smart(client, x, y, SMART_GROUP, FALSE) || + place_smart(client, x, y, SMART_GROUP, TRUE) || + place_smart(client, x, y, SMART_FOCUSED, TRUE) || place_random(client, x, y)))) g_assert_not_reached(); /* the last one better succeed */ /* get where the client should be */ - frame_frame_gravity(client->frame, x, y); + frame_frame_gravity(client->frame, x, y, + client->area.width, client->area.height); return ret; }