+
+guint client_monitor(ObClient *self)
+{
+ guint i;
+
+ for (i = 0; i < screen_num_monitors; ++i) {
+ Rect *area = screen_physical_area_monitor(i);
+ if (RECT_INTERSECTS_RECT(*area, self->frame->area))
+ break;
+ }
+ if (i == screen_num_monitors) i = 0;
+ g_assert(i < screen_num_monitors);
+ return i;
+}
+
+ObClient *client_search_top_transient(ObClient *self)
+{
+ /* move up the transient chain as far as possible */
+ if (self->transient_for) {
+ if (self->transient_for != OB_TRAN_GROUP) {
+ return client_search_top_transient(self->transient_for);
+ } else {
+ GSList *it;
+
+ for (it = self->group->members; it; it = it->next) {
+ ObClient *c = it->data;
+
+ /* checking transient_for prevents infinate loops! */
+ if (c != self && !c->transient_for)
+ break;
+ }
+ if (it)
+ return it->data;
+ }
+ }
+
+ return self;
+}
+
+ObClient *client_search_transient(ObClient *self, ObClient *search)
+{
+ GSList *sit;
+
+ for (sit = self->transients; sit; sit = g_slist_next(sit)) {
+ if (sit->data == search)
+ return search;
+ if (client_search_transient(sit->data, search))
+ return search;
+ }
+ return NULL;
+}
+
+void client_update_sm_client_id(ObClient *self)
+{
+ g_free(self->sm_client_id);
+ self->sm_client_id = NULL;
+
+ if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
+ self->group)
+ PROP_GETS(self->group->leader, sm_client_id, locale,
+ &self->sm_client_id);
+}
+
+/* finds the nearest edge in the given direction from the current client
+ * note to self: the edge is the -frame- edge (the actual one), not the
+ * client edge.
+ */
+int client_directional_edge_search(ObClient *c, ObDirection dir)
+{
+ int dest;
+ int my_edge_start, my_edge_end, my_offset;
+ GList *it;
+ Rect *a;
+
+ if(!client_list)
+ return -1;
+
+ a = screen_area(c->desktop);
+
+ switch(dir) {
+ case OB_DIRECTION_NORTH:
+ my_edge_start = c->frame->area.x;
+ my_edge_end = c->frame->area.x + c->frame->area.width;
+ my_offset = c->frame->area.y;
+
+ dest = a->y; /* default: top of screen */
+
+ for(it = g_list_first(client_list); it; it = it->next) {
+ int his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ if(cur == c)
+ continue;
+ if(!client_normal(cur))
+ continue;
+ if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
+ continue;
+ if(cur->iconic)
+ continue;
+
+ his_edge_start = cur->frame->area.x;
+ his_edge_end = cur->frame->area.x + cur->frame->area.width;
+ his_offset = cur->frame->area.y + cur->frame->area.height;
+
+ if(his_offset + 1 > my_offset)
+ continue;
+
+ if(his_offset < dest)
+ continue;
+
+ if(his_edge_start >= my_edge_start &&
+ his_edge_start <= my_edge_end)
+ dest = his_offset;
+
+ if(my_edge_start >= his_edge_start &&
+ my_edge_start <= his_edge_end)
+ dest = his_offset;
+
+ }
+ break;
+ case OB_DIRECTION_SOUTH:
+ my_edge_start = c->frame->area.x;
+ my_edge_end = c->frame->area.x + c->frame->area.width;
+ my_offset = c->frame->area.y + c->frame->area.height;
+
+ dest = a->y + a->height; /* default: bottom of screen */
+
+ for(it = g_list_first(client_list); it; it = it->next) {
+ int his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ if(cur == c)
+ continue;
+ if(!client_normal(cur))
+ continue;
+ if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
+ continue;
+ if(cur->iconic)
+ continue;
+
+ his_edge_start = cur->frame->area.x;
+ his_edge_end = cur->frame->area.x + cur->frame->area.width;
+ his_offset = cur->frame->area.y;
+
+
+ if(his_offset - 1 < my_offset)
+ continue;
+
+ if(his_offset > dest)
+ continue;
+
+ if(his_edge_start >= my_edge_start &&
+ his_edge_start <= my_edge_end)
+ dest = his_offset;
+
+ if(my_edge_start >= his_edge_start &&
+ my_edge_start <= his_edge_end)
+ dest = his_offset;
+
+ }
+ break;
+ case OB_DIRECTION_WEST:
+ my_edge_start = c->frame->area.y;
+ my_edge_end = c->frame->area.y + c->frame->area.height;
+ my_offset = c->frame->area.x;
+
+ dest = a->x; /* default: leftmost egde of screen */
+
+ for(it = g_list_first(client_list); it; it = it->next) {
+ int his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ if(cur == c)
+ continue;
+ if(!client_normal(cur))
+ continue;
+ if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
+ continue;
+ if(cur->iconic)
+ continue;
+
+ his_edge_start = cur->frame->area.y;
+ his_edge_end = cur->frame->area.y + cur->frame->area.height;
+ his_offset = cur->frame->area.x + cur->frame->area.width;
+
+ if(his_offset + 1 > my_offset)
+ continue;
+
+ if(his_offset < dest)
+ continue;
+
+ if(his_edge_start >= my_edge_start &&
+ his_edge_start <= my_edge_end)
+ dest = his_offset;
+
+ if(my_edge_start >= his_edge_start &&
+ my_edge_start <= his_edge_end)
+ dest = his_offset;
+
+
+ }
+ break;
+ case OB_DIRECTION_EAST:
+ my_edge_start = c->frame->area.y;
+ my_edge_end = c->frame->area.y + c->frame->area.height;
+ my_offset = c->frame->area.x + c->frame->area.width;
+
+ dest = a->x + a->width; /* default: rightmost edge of screen */
+
+ for(it = g_list_first(client_list); it; it = it->next) {
+ int his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ if(cur == c)
+ continue;
+ if(!client_normal(cur))
+ continue;
+ if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
+ continue;
+ if(cur->iconic)
+ continue;
+
+ his_edge_start = cur->frame->area.y;
+ his_edge_end = cur->frame->area.y + cur->frame->area.height;
+ his_offset = cur->frame->area.x;
+
+ if(his_offset - 1 < my_offset)
+ continue;
+
+ if(his_offset > dest)
+ continue;
+
+ if(his_edge_start >= my_edge_start &&
+ his_edge_start <= my_edge_end)
+ dest = his_offset;
+
+ if(my_edge_start >= his_edge_start &&
+ my_edge_start <= his_edge_end)
+ dest = his_offset;
+
+ }
+ break;
+ case OB_DIRECTION_NORTHEAST:
+ case OB_DIRECTION_SOUTHEAST:
+ case OB_DIRECTION_NORTHWEST:
+ case OB_DIRECTION_SOUTHWEST:
+ /* not implemented */
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ return dest;
+}