+
+const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
+{
+ ObClientIcon *ret;
+ static ObClientIcon deficon;
+
+ if (!(ret = client_icon_recursive(self, w, h))) {
+ deficon.width = deficon.height = 48;
+ deficon.data = ob_rr_theme->def_win_icon;
+ ret = &deficon;
+ }
+ return ret;
+}
+
+void client_set_layer(ObClient *self, gint layer)
+{
+ if (layer < 0) {
+ self->below = TRUE;
+ self->above = FALSE;
+ } else if (layer == 0) {
+ self->below = self->above = FALSE;
+ } else {
+ self->below = FALSE;
+ self->above = TRUE;
+ }
+ client_calc_layer(self);
+ client_change_state(self); /* reflect this in the state hints */
+}
+
+void client_set_undecorated(ObClient *self, gboolean undecorated)
+{
+ if (self->undecorated != undecorated) {
+ self->undecorated = undecorated;
+ client_setup_decor_and_functions(self);
+ /* Make sure the client knows it might have moved. Maybe there is a
+ * better way of doing this so only one client_configure is sent, but
+ * since 125 of these are sent per second when moving the window (with
+ * user = FALSE) i doubt it matters much.
+ */
+ client_configure(self, self->area.x, self->area.y,
+ self->area.width, self->area.height, TRUE, TRUE);
+ client_change_state(self); /* reflect this in the state hints */
+ }
+}
+
+guint client_monitor(ObClient *self)
+{
+ return screen_find_monitor(&self->frame->area);
+}
+
+ObClient *client_search_top_parent(ObClient *self)
+{
+ while (self->transient_for && self->transient_for != OB_TRAN_GROUP &&
+ client_normal(self))
+ self = self->transient_for;
+ return self;
+}
+
+GSList *client_search_all_top_parents(ObClient *self)
+{
+ GSList *ret = NULL;
+
+ /* move up the direct transient chain as far as possible */
+ while (self->transient_for && self->transient_for != OB_TRAN_GROUP)
+ self = self->transient_for;
+
+ if (!self->transient_for)
+ ret = g_slist_prepend(ret, self);
+ else {
+ GSList *it;
+
+ g_assert(self->group);
+
+ for (it = self->group->members; it; it = g_slist_next(it)) {
+ ObClient *c = it->data;
+
+ if (!c->transient_for && client_normal(c))
+ ret = g_slist_prepend(ret, c);
+ }
+
+ if (ret == NULL) /* no group parents */
+ ret = g_slist_prepend(ret, self);
+ }
+
+ return ret;
+}
+
+ObClient *client_search_focus_parent(ObClient *self)
+{
+ if (self->transient_for) {
+ if (self->transient_for != OB_TRAN_GROUP) {
+ if (client_focused(self->transient_for))
+ return self->transient_for;
+ } else {
+ GSList *it;
+
+ for (it = self->group->members; it; it = g_slist_next(it)) {
+ ObClient *c = it->data;
+
+ /* checking transient_for prevents infinate loops! */
+ if (c != self && !c->transient_for)
+ if (client_focused(c))
+ return c;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+ObClient *client_search_parent(ObClient *self, ObClient *search)
+{
+ if (self->transient_for) {
+ if (self->transient_for != OB_TRAN_GROUP) {
+ if (self->transient_for == search)
+ return search;
+ } else {
+ GSList *it;
+
+ for (it = self->group->members; it; it = g_slist_next(it)) {
+ ObClient *c = it->data;
+
+ /* checking transient_for prevents infinate loops! */
+ if (c != self && !c->transient_for)
+ if (c == search)
+ return search;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+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);
+}
+
+#define WANT_EDGE(cur, c) \
+ if(cur == c) \
+ continue; \
+ if(!client_normal(cur)) \
+ continue; \
+ if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
+ continue; \
+ if(cur->iconic) \
+ continue; \
+ if(cur->layer < c->layer && !config_resist_layers_below) \
+ continue;
+
+#define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
+ if ((his_edge_start >= my_edge_start && \
+ his_edge_start <= my_edge_end) || \
+ (my_edge_start >= his_edge_start && \
+ my_edge_start <= his_edge_end)) \
+ dest = his_offset;
+
+/* 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.
+ */
+gint client_directional_edge_search(ObClient *c, ObDirection dir, gboolean hang)
+{
+ gint dest, monitor_dest;
+ gint my_edge_start, my_edge_end, my_offset;
+ GList *it;
+ Rect *a, *monitor;
+
+ if(!client_list)
+ return -1;
+
+ a = screen_area(c->desktop);
+ monitor = screen_area_monitor(c->desktop, client_monitor(c));
+
+ 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 + (hang ? c->frame->area.height : 0);
+
+ /* default: top of screen */
+ dest = a->y + (hang ? c->frame->area.height : 0);
+ monitor_dest = monitor->y + (hang ? c->frame->area.height : 0);
+ /* if the monitor edge comes before the screen edge, */
+ /* use that as the destination instead. (For xinerama) */
+ if (monitor_dest != dest && my_offset > monitor_dest)
+ dest = monitor_dest;
+
+ for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
+ gint his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ WANT_EDGE(cur, c)
+
+ his_edge_start = cur->frame->area.x;
+ his_edge_end = cur->frame->area.x + cur->frame->area.width;
+ his_offset = cur->frame->area.y +
+ (hang ? 0 : cur->frame->area.height);
+
+ if(his_offset + 1 > my_offset)
+ continue;
+
+ if(his_offset < dest)
+ continue;
+
+ HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
+ }
+ 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 + (hang ? 0 : c->frame->area.height);
+
+ /* default: bottom of screen */
+ dest = a->y + a->height - (hang ? c->frame->area.height : 0);
+ monitor_dest = monitor->y + monitor->height -
+ (hang ? c->frame->area.height : 0);
+ /* if the monitor edge comes before the screen edge, */
+ /* use that as the destination instead. (For xinerama) */
+ if (monitor_dest != dest && my_offset < monitor_dest)
+ dest = monitor_dest;
+
+ for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
+ gint his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ WANT_EDGE(cur, c)
+
+ his_edge_start = cur->frame->area.x;
+ his_edge_end = cur->frame->area.x + cur->frame->area.width;
+ his_offset = cur->frame->area.y +
+ (hang ? cur->frame->area.height : 0);
+
+
+ if(his_offset - 1 < my_offset)
+ continue;
+
+ if(his_offset > dest)
+ continue;
+
+ HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
+ }
+ 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 + (hang ? c->frame->area.width : 0);
+
+ /* default: leftmost egde of screen */
+ dest = a->x + (hang ? c->frame->area.width : 0);
+ monitor_dest = monitor->x + (hang ? c->frame->area.width : 0);
+ /* if the monitor edge comes before the screen edge, */
+ /* use that as the destination instead. (For xinerama) */
+ if (monitor_dest != dest && my_offset > monitor_dest)
+ dest = monitor_dest;
+
+ for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
+ gint his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ WANT_EDGE(cur, c)
+
+ his_edge_start = cur->frame->area.y;
+ his_edge_end = cur->frame->area.y + cur->frame->area.height;
+ his_offset = cur->frame->area.x +
+ (hang ? 0 : cur->frame->area.width);
+
+ if(his_offset + 1 > my_offset)
+ continue;
+
+ if(his_offset < dest)
+ continue;
+
+ HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
+ }
+ 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 + (hang ? 0 : c->frame->area.width);
+
+ /* default: rightmost edge of screen */
+ dest = a->x + a->width - (hang ? c->frame->area.width : 0);
+ monitor_dest = monitor->x + monitor->width -
+ (hang ? c->frame->area.width : 0);
+ /* if the monitor edge comes before the screen edge, */
+ /* use that as the destination instead. (For xinerama) */
+ if (monitor_dest != dest && my_offset < monitor_dest)
+ dest = monitor_dest;
+
+ for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
+ gint his_edge_start, his_edge_end, his_offset;
+ ObClient *cur = it->data;
+
+ WANT_EDGE(cur, c)
+
+ his_edge_start = cur->frame->area.y;
+ his_edge_end = cur->frame->area.y + cur->frame->area.height;
+ his_offset = cur->frame->area.x +
+ (hang ? cur->frame->area.width : 0);
+
+ if(his_offset - 1 < my_offset)
+ continue;
+
+ if(his_offset > dest)
+ continue;
+
+ HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
+ }
+ break;
+ case OB_DIRECTION_NORTHEAST:
+ case OB_DIRECTION_SOUTHEAST:
+ case OB_DIRECTION_NORTHWEST:
+ case OB_DIRECTION_SOUTHWEST:
+ /* not implemented */
+ default:
+ g_assert_not_reached();
+ dest = 0; /* suppress warning */
+ }
+ return dest;
+}
+
+ObClient* client_under_pointer()
+{
+ gint x, y;
+ GList *it;
+ ObClient *ret = NULL;
+
+ if (screen_pointer_pos(&x, &y)) {
+ for (it = stacking_list; it; it = g_list_next(it)) {
+ if (WINDOW_IS_CLIENT(it->data)) {
+ ObClient *c = WINDOW_AS_CLIENT(it->data);
+ if (c->frame->visible &&
+ RECT_CONTAINS(c->frame->area, x, y)) {
+ ret = c;
+ break;
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+gboolean client_has_group_siblings(ObClient *self)
+{
+ return self->group && self->group->members->next;
+}
+
+gboolean client_has_application_group_siblings(ObClient *self)
+{
+ GSList *it;
+
+ if (!self->group) return FALSE;
+
+ for (it = self->group->members; it; it = g_slist_next(it)) {
+ ObClient *c = it->data;
+ if (c != self && client_application(c))
+ return TRUE;
+ }
+ return FALSE;
+}