+gboolean client_mouse_focusable(ObClient *self)
+{
+ return !(self->type == OB_CLIENT_TYPE_MENU ||
+ self->type == OB_CLIENT_TYPE_TOOLBAR ||
+ self->type == OB_CLIENT_TYPE_SPLASH ||
+ self->type == OB_CLIENT_TYPE_DOCK);
+}
+
+gboolean client_enter_focusable(ObClient *self)
+{
+ /* you can focus desktops but it shouldn't on enter */
+ return (client_mouse_focusable(self) &&
+ self->type != OB_CLIENT_TYPE_DESKTOP);
+}
+
+
+static void client_apply_startup_state(ObClient *self,
+ gint x, gint y, gint w, gint h)
+{
+ /* save the states that we are going to apply */
+ gboolean iconic = self->iconic;
+ gboolean fullscreen = self->fullscreen;
+ gboolean undecorated = self->undecorated;
+ gboolean shaded = self->shaded;
+ gboolean demands_attention = self->demands_attention;
+ gboolean max_horz = self->max_horz;
+ gboolean max_vert = self->max_vert;
+ Rect oldarea;
+ gint l;
+
+ /* turn them all off in the client, so they won't affect the window
+ being placed */
+ self->iconic = self->fullscreen = self->undecorated = self->shaded =
+ self->demands_attention = self->max_horz = self->max_vert = FALSE;
+
+ /* move the client to its placed position, or it it's already there,
+ generate a ConfigureNotify telling the client where it is.
+
+ do this after adjusting the frame. otherwise it gets all weird and
+ clients don't work right
+
+ do this before applying the states so they have the correct
+ pre-max/pre-fullscreen values
+ */
+ client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
+ ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
+ self->window, x, y, w, h);
+ /* save the area, and make it where it should be for the premax stuff */
+ oldarea = self->area;
+ RECT_SET(self->area, x, y, w, h);
+
+ /* apply the states. these are in a carefully crafted order.. */
+
+ if (iconic)
+ client_iconify(self, TRUE, FALSE, TRUE);
+ if (fullscreen)
+ client_fullscreen(self, TRUE);
+ if (undecorated)
+ client_set_undecorated(self, TRUE);
+ if (shaded)
+ client_shade(self, TRUE);
+ if (demands_attention)
+ client_hilite(self, TRUE);
+
+ if (max_vert && max_horz)
+ client_maximize(self, TRUE, 0);
+ else if (max_vert)
+ client_maximize(self, TRUE, 2);
+ else if (max_horz)
+ client_maximize(self, TRUE, 1);
+
+ /* if the window hasn't been configured yet, then do so now, in fact the
+ x,y,w,h may _not_ be the same as the area rect, which can end up
+ meaning that the client isn't properly moved/resized by the fullscreen
+ function
+ pho can cause this because it maps at size of the screen but not 0,0
+ so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
+ then fullscreen'ing makes it go to 0,0 which it thinks it already is at
+ cuz thats where the pre-fullscreen will be. however the actual area is
+ not, so this needs to be called even if we have fullscreened/maxed
+ */
+ self->area = oldarea;
+ client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
+
+ /* set the desktop hint, to make sure that it always exists */
+ PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
+
+ /* nothing to do for the other states:
+ skip_taskbar
+ skip_pager
+ modal
+ above
+ below
+ */
+}
+
+void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
+{
+ /* these should be the current values. this is for when you're not moving,
+ just resizing */
+ g_assert(*x == self->area.x);
+ g_assert(oldw == self->area.width);
+
+ /* horizontal */
+ switch (self->gravity) {
+ default:
+ case NorthWestGravity:
+ case WestGravity:
+ case SouthWestGravity:
+ case StaticGravity:
+ case ForgetGravity:
+ break;
+ case NorthGravity:
+ case CenterGravity:
+ case SouthGravity:
+ *x -= (neww - oldw) / 2;
+ break;
+ case NorthEastGravity:
+ case EastGravity:
+ case SouthEastGravity:
+ *x -= neww - oldw;
+ break;
+ }
+}
+
+void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
+{
+ /* these should be the current values. this is for when you're not moving,
+ just resizing */
+ g_assert(*y == self->area.y);
+ g_assert(oldh == self->area.height);
+
+ /* vertical */
+ switch (self->gravity) {
+ default:
+ case NorthWestGravity:
+ case NorthGravity:
+ case NorthEastGravity:
+ case StaticGravity:
+ case ForgetGravity:
+ break;
+ case WestGravity:
+ case CenterGravity:
+ case EastGravity:
+ *y -= (newh - oldh) / 2;
+ break;
+ case SouthWestGravity:
+ case SouthGravity:
+ case SouthEastGravity:
+ *y -= newh - oldh;
+ break;
+ }
+}
+
+void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
+ gint *logicalw, gint *logicalh,
+ gboolean user)
+{
+ Rect desired = {*x, *y, *w, *h};
+ frame_rect_to_frame(self->frame, &desired);
+
+ /* make the frame recalculate its dimentions n shit without changing
+ anything visible for real, this way the constraints below can work with
+ the updated frame dimensions. */
+ frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
+
+ /* gets the frame's position */
+ frame_client_gravity(self->frame, x, y);
+
+ /* these positions are frame positions, not client positions */
+
+ /* set the size and position if fullscreen */
+ if (self->fullscreen) {
+ Rect *a;
+ guint i;
+
+ i = screen_find_monitor(&desired);
+ a = screen_physical_area_monitor(i);
+
+ *x = a->x;
+ *y = a->y;
+ *w = a->width;
+ *h = a->height;
+
+ user = FALSE; /* ignore if the client can't be moved/resized when it
+ is fullscreening */
+
+ g_free(a);
+ } else if (self->max_horz || self->max_vert) {
+ Rect *a;
+ guint i;
+
+ /* use all possible struts when maximizing to the full screen */
+ i = screen_find_monitor(&desired);
+ a = screen_area(self->desktop, i,
+ (self->max_horz && self->max_vert ? NULL : &desired));
+
+ /* set the size and position if maximized */
+ if (self->max_horz) {
+ *x = a->x;
+ *w = a->width - self->frame->size.left - self->frame->size.right;
+ }
+ if (self->max_vert) {
+ *y = a->y;
+ *h = a->height - self->frame->size.top - self->frame->size.bottom;
+ }
+
+ user = FALSE; /* ignore if the client can't be moved/resized when it
+ is maximizing */
+
+ g_free(a);
+ }
+
+ /* gets the client's position */
+ frame_frame_gravity(self->frame, x, y);
+
+ /* work within the prefered sizes given by the window */
+ if (!(*w == self->area.width && *h == self->area.height)) {
+ gint basew, baseh, minw, minh;
+ gint incw, inch;
+ gfloat minratio, maxratio;
+
+ incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
+ inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
+ minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
+ 0 : self->min_ratio;
+ maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
+ 0 : self->max_ratio;
+
+ /* base size is substituted with min size if not specified */
+ if (self->base_size.width || self->base_size.height) {
+ basew = self->base_size.width;
+ baseh = self->base_size.height;
+ } else {
+ basew = self->min_size.width;
+ baseh = self->min_size.height;
+ }
+ /* min size is substituted with base size if not specified */
+ if (self->min_size.width || self->min_size.height) {
+ minw = self->min_size.width;
+ minh = self->min_size.height;
+ } else {
+ minw = self->base_size.width;
+ minh = self->base_size.height;
+ }
+
+ /* if this is a user-requested resize, then check against min/max
+ sizes */
+
+ /* smaller than min size or bigger than max size? */
+ if (*w > self->max_size.width) *w = self->max_size.width;
+ if (*w < minw) *w = minw;
+ if (*h > self->max_size.height) *h = self->max_size.height;
+ if (*h < minh) *h = minh;
+
+ *w -= basew;
+ *h -= baseh;
+
+ /* keep to the increments */
+ *w /= incw;
+ *h /= inch;
+
+ /* you cannot resize to nothing */
+ if (basew + *w < 1) *w = 1 - basew;
+ if (baseh + *h < 1) *h = 1 - baseh;
+
+ /* save the logical size */
+ *logicalw = incw > 1 ? *w : *w + basew;
+ *logicalh = inch > 1 ? *h : *h + baseh;
+
+ *w *= incw;
+ *h *= inch;
+
+ *w += basew;
+ *h += baseh;
+
+ /* adjust the height to match the width for the aspect ratios.
+ for this, min size is not substituted for base size ever. */
+ *w -= self->base_size.width;
+ *h -= self->base_size.height;
+
+ if (minratio)
+ if (*h * minratio > *w) {
+ *h = (gint)(*w / minratio);
+
+ /* you cannot resize to nothing */
+ if (*h < 1) {
+ *h = 1;
+ *w = (gint)(*h * minratio);
+ }
+ }
+ if (maxratio)
+ if (*h * maxratio < *w) {
+ *h = (gint)(*w / maxratio);
+
+ /* you cannot resize to nothing */
+ if (*h < 1) {
+ *h = 1;
+ *w = (gint)(*h * minratio);
+ }
+ }
+
+ *w += self->base_size.width;
+ *h += self->base_size.height;
+ }
+
+ /* these override the above states! if you cant move you can't move! */
+ if (user) {
+ if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
+ *x = self->area.x;
+ *y = self->area.y;
+ }
+ if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
+ *w = self->area.width;
+ *h = self->area.height;
+ }
+ }
+
+ g_assert(*w > 0);
+ g_assert(*h > 0);
+}
+
+
+void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
+ gboolean user, gboolean final, gboolean force_reply)
+{
+ gint oldw, oldh;
+ gboolean send_resize_client;
+ gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
+ gboolean fmoved, fresized;
+ guint fdecor = self->frame->decorations;
+ gboolean fhorz = self->frame->max_horz;
+ gboolean fvert = self->frame->max_vert;
+ gint logicalw, logicalh;
+
+ /* find the new x, y, width, and height (and logical size) */
+ client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
+
+ /* set the logical size if things changed */
+ if (!(w == self->area.width && h == self->area.height))
+ SIZE_SET(self->logical_size, logicalw, logicalh);
+
+ /* figure out if we moved or resized or what */
+ moved = (x != self->area.x || y != self->area.y);
+ resized = (w != self->area.width || h != self->area.height);
+
+ oldw = self->area.width;
+ oldh = self->area.height;
+ RECT_SET(self->area, x, y, w, h);
+
+ /* for app-requested resizes, always resize if 'resized' is true.
+ for user-requested ones, only resize if final is true, or when
+ resizing in redraw mode */
+ send_resize_client = ((!user && resized) ||
+ (user && (final ||
+ (resized && config_resize_redraw))));
+
+ /* if the client is enlarging, then resize the client before the frame */
+ if (send_resize_client && (w > oldw || h > oldh)) {
+ XMoveResizeWindow(ob_display, self->window,
+ self->frame->size.left, self->frame->size.top,
+ MAX(w, oldw), MAX(h, oldh));
+ frame_adjust_client_area(self->frame);
+ }
+
+ /* find the frame's dimensions and move/resize it */
+ fmoved = moved;
+ fresized = resized;
+
+ /* if decorations changed, then readjust everything for the frame */
+ if (self->decorations != fdecor ||
+ self->max_horz != fhorz || self->max_vert != fvert)
+ {
+ fmoved = fresized = TRUE;
+ }
+
+ /* adjust the frame */
+ if (fmoved || fresized) {
+ gulong ignore_start;
+ if (!user)
+ ignore_start = event_start_ignore_all_enters();
+
+ frame_adjust_area(self->frame, fmoved, fresized, FALSE);
+
+ if (!user)
+ event_end_ignore_all_enters(ignore_start);
+ }
+
+ if (!user || final) {
+ gint oldrx = self->root_pos.x;
+ gint oldry = self->root_pos.y;
+ /* we have reset the client to 0 border width, so don't include
+ it in these coords */
+ POINT_SET(self->root_pos,
+ self->frame->area.x + self->frame->size.left -
+ self->border_width,
+ self->frame->area.y + self->frame->size.top -
+ self->border_width);
+ if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
+ rootmoved = TRUE;
+ }
+
+ /* This is kinda tricky and should not be changed.. let me explain!
+
+ When user = FALSE, then the request is coming from the application
+ itself, and we are more strict about when to send a synthetic
+ ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
+ in this case (if force_reply is true)
+
+ When user = TRUE, then the request is coming from "us", like when we
+ maximize a window or something. In this case we are more lenient. We
+ used to follow the same rules as above, but _Java_ Swing can't handle
+ this. So just to appease Swing, when user = TRUE, we always send
+ a synthetic ConfigureNotify to give the window its root coordinates.
+ */
+ if ((!user && !resized && (rootmoved || force_reply)) ||
+ (user && final && rootmoved))
+ {
+ XEvent event;
+
+ event.type = ConfigureNotify;
+ event.xconfigure.display = ob_display;
+ event.xconfigure.event = self->window;
+ event.xconfigure.window = self->window;
+
+ ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
+ self->title, self->root_pos.x, self->root_pos.y, w, h);
+
+ /* root window real coords */
+ event.xconfigure.x = self->root_pos.x;
+ event.xconfigure.y = self->root_pos.y;
+ event.xconfigure.width = w;
+ event.xconfigure.height = h;
+ event.xconfigure.border_width = self->border_width;
+ event.xconfigure.above = None;
+ event.xconfigure.override_redirect = FALSE;
+ XSendEvent(event.xconfigure.display, event.xconfigure.window,
+ FALSE, StructureNotifyMask, &event);
+ }
+
+ /* if the client is shrinking, then resize the frame before the client.
+
+ both of these resize sections may run, because the top one only resizes
+ in the direction that is growing
+ */
+ if (send_resize_client && (w <= oldw || h <= oldh)) {
+ frame_adjust_client_area(self->frame);
+ XMoveResizeWindow(ob_display, self->window,
+ self->frame->size.left, self->frame->size.top, w, h);
+ }
+
+ XFlush(ob_display);
+}
+
+void client_fullscreen(ObClient *self, gboolean fs)
+{
+ gint x, y, w, h;
+
+ if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
+ self->fullscreen == fs) return; /* already done */