+ return screen_area(c->desktop, screen_monitor_pointer(), NULL);
+}
+
+/* use the following priority lists for pick_head()
+
+ When a window is being placed in the FOREGROUND, use a monitor chosen in
+ the following order:
+ 1. same monitor as parent
+ 2. primary monitor if placement=PRIMARY
+ active monitor if placement=ACTIVE
+ pointer monitor if placement=MOUSE
+ 3. primary monitor
+ 4. other monitors where the window has group members on the same desktop
+ 5. other monitors where the window has group members on other desktops
+ 6. other monitors
+
+ When a window is being placed in the BACKGROUND, use a monitor chosen in the
+ following order:
+ 1. same monitor as parent
+ 2. other monitors where the window has group members on the same desktop
+ 2a. primary monitor in this set
+ 2b. other monitors in this set
+ 3. other monitors where the window has group members on other desktops
+ 3a. primary monitor in this set
+ 3b. other monitors in this set
+ 4. other monitors
+ 4a. primary monitor in this set
+ 4b. other monitors in this set
+*/
+
+/*! One for each possible head, used to sort them in order of precedence. */
+typedef struct {
+ guint monitor;
+ guint flags;
+} ObPlaceHead;
+
+/*! Flags for ObPlaceHead */
+enum {
+ HEAD_PARENT = 1 << 0, /* parent's monitor */
+ HEAD_PLACED = 1 << 1, /* chosen monitor by placement */
+ HEAD_PRIMARY = 1 << 2, /* primary monitor */
+ HEAD_GROUP_DESK = 1 << 3, /* has a group member on the same desktop */
+ HEAD_GROUP = 1 << 4, /* has a group member on another desktop */
+};
+
+gint cmp_foreground(const void *a, const void *b)
+{
+ const ObPlaceHead *h1 = a;
+ const ObPlaceHead *h2 = b;
+ gint i = 0;
+
+ if (h1->monitor == h2->monitor) return 0;
+
+ if (h1->flags & HEAD_PARENT) --i;
+ if (h2->flags & HEAD_PARENT) ++i;
+ if (i) return i;
+
+ if (h1->flags & HEAD_PLACED) --i;
+ if (h2->flags & HEAD_PLACED) ++i;
+ if (i) return i;
+
+ if (h1->flags & HEAD_PRIMARY) --i;
+ if (h2->flags & HEAD_PRIMARY) ++i;
+ if (i) return i;
+
+ if (h1->flags & HEAD_GROUP_DESK) --i;
+ if (h2->flags & HEAD_GROUP_DESK) ++i;
+ if (i) return i;
+
+ if (h1->flags & HEAD_GROUP) --i;
+ if (h2->flags & HEAD_GROUP) ++i;
+ if (i) return i;
+
+ return h1->monitor - h2->monitor;
+}
+
+gint cmp_background(const void *a, const void *b)
+{
+ const ObPlaceHead *h1 = a;
+ const ObPlaceHead *h2 = b;
+ gint i = 0;
+
+ if (h1->monitor == h2->monitor) return 0;
+
+ if (h1->flags & HEAD_PARENT) --i;
+ if (h2->flags & HEAD_PARENT) ++i;
+ if (i) return i;
+
+ if (h1->flags & HEAD_GROUP_DESK || h2->flags & HEAD_GROUP_DESK) {
+ if (h1->flags & HEAD_GROUP_DESK) --i;
+ if (h2->flags & HEAD_GROUP_DESK) ++i;
+ if (i) return i;
+ if (h1->flags & HEAD_PRIMARY) --i;
+ if (h2->flags & HEAD_PRIMARY) ++i;
+ if (i) return i;