+ *y += self->size.top;
+ break;
+ }
+}
+
+static void flash_done(gpointer data)
+{
+ ObFrame *self = data;
+
+ if (self->focused != self->flash_on)
+ frame_adjust_focus(self, self->focused);
+}
+
+static gboolean flash_timeout(gpointer data)
+{
+ ObFrame *self = data;
+ GTimeVal now;
+
+ g_get_current_time(&now);
+ if (now.tv_sec > self->flash_end.tv_sec ||
+ (now.tv_sec == self->flash_end.tv_sec &&
+ now.tv_usec >= self->flash_end.tv_usec))
+ self->flashing = FALSE;
+
+ if (!self->flashing)
+ return FALSE; /* we are done */
+
+ self->flash_on = !self->flash_on;
+ if (!self->focused) {
+ frame_adjust_focus(self, self->flash_on);
+ self->focused = FALSE;
+ }
+
+ return TRUE; /* go again */
+}
+
+void frame_flash_start(ObFrame *self)
+{
+ self->flash_on = self->focused;
+
+ if (!self->flashing)
+ ob_main_loop_timeout_add(ob_main_loop,
+ G_USEC_PER_SEC * 0.6,
+ flash_timeout,
+ self,
+ g_direct_equal,
+ flash_done);
+ g_get_current_time(&self->flash_end);
+ g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5);
+
+ self->flashing = TRUE;
+}
+
+void frame_flash_stop(ObFrame *self)
+{
+ self->flashing = FALSE;
+}
+
+static gulong frame_animate_iconify_time_left(ObFrame *self,
+ const GTimeVal *now)
+{
+ glong sec, usec;
+ sec = self->iconify_animation_end.tv_sec - now->tv_sec;
+ usec = self->iconify_animation_end.tv_usec - now->tv_usec;
+ if (usec < 0) {
+ usec += G_USEC_PER_SEC;
+ sec--;
+ }
+ /* no negative values */
+ return MAX(sec * G_USEC_PER_SEC + usec, 0);
+}
+
+static gboolean frame_animate_iconify(gpointer p)
+{
+ ObFrame *self = p;
+ gint x, y, w, h;
+ gint iconx, icony, iconw;
+ GTimeVal now;
+ gulong time;
+ gboolean iconifying;
+
+ if (self->client->icon_geometry.width == 0) {
+ /* there is no icon geometry set so just go straight down */
+ Rect *a = screen_physical_area();
+ iconx = self->area.x + self->area.width / 2 + 32;
+ icony = a->y + a->width;
+ iconw = 64;
+ } else {
+ iconx = self->client->icon_geometry.x;
+ icony = self->client->icon_geometry.y;
+ iconw = self->client->icon_geometry.width;
+ }
+
+ iconifying = self->iconify_animation_going > 0;
+
+ /* how far do we have left to go ? */
+ g_get_current_time(&now);
+ time = frame_animate_iconify_time_left(self, &now);
+
+ if (time == 0 || iconifying) {
+ /* start where the frame is supposed to be */
+ x = self->area.x;
+ y = self->area.y;
+ w = self->area.width - self->bwidth * 2;
+ h = self->area.height - self->bwidth * 2;
+ } else {
+ /* start at the icon */
+ x = iconx;
+ y = icony;
+ w = iconw;
+ h = self->innersize.top; /* just the titlebar */
+ }
+
+ if (time > 0) {
+ glong dx, dy, dw;
+ glong elapsed;
+
+ dx = self->area.x - iconx;
+ dy = self->area.y - icony;
+ dw = self->area.width - self->bwidth * 2 - iconw;
+ /* if restoring, we move in the opposite direction */
+ if (!iconifying) { dx = -dx; dy = -dy; dw = -dw; }
+
+ elapsed = FRAME_ANIMATE_ICONIFY_TIME - time;
+ x = x - (dx * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
+ y = y - (dy * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
+ w = w - (dw * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
+ h = self->innersize.top; /* just the titlebar */
+ }
+
+ if (time == 0)
+ frame_end_iconify_animation(self);
+ else {
+ XMoveResizeWindow(ob_display, self->window, x, y, w, h);
+ XFlush(ob_display);
+ }
+
+ return time > 0; /* repeat until we're out of time */
+}
+
+void frame_end_iconify_animation(ObFrame *self)
+{
+ /* see if there is an animation going */
+ if (self->iconify_animation_going == 0) return;
+
+ if (!self->visible)
+ XUnmapWindow(ob_display, self->window);
+
+ /* we're not animating any more ! */
+ self->iconify_animation_going = 0;
+
+ XMoveResizeWindow(ob_display, self->window,
+ self->area.x, self->area.y,
+ self->area.width - self->bwidth * 2,
+ self->area.height - self->bwidth * 2);
+ XFlush(ob_display);
+}
+
+void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying)
+{
+ gulong time;
+ gboolean new_anim = FALSE;
+ gboolean set_end = TRUE;
+ GTimeVal now;
+
+ /* if there is no titlebar, just don't animate for now
+ XXX it would be nice tho.. */
+ if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
+ return;
+
+ /* get the current time */
+ g_get_current_time(&now);
+
+ /* get how long until the end */
+ time = FRAME_ANIMATE_ICONIFY_TIME;
+ if (self->iconify_animation_going) {
+ if (!!iconifying != (self->iconify_animation_going > 0)) {
+ /* animation was already going on in the opposite direction */
+ time = time - frame_animate_iconify_time_left(self, &now);
+ } else
+ /* animation was already going in the same direction */
+ set_end = FALSE;
+ } else
+ new_anim = TRUE;
+ self->iconify_animation_going = iconifying ? 1 : -1;
+
+ /* set the ending time */
+ if (set_end) {
+ self->iconify_animation_end.tv_sec = now.tv_sec;
+ self->iconify_animation_end.tv_usec = now.tv_usec;
+ g_time_val_add(&self->iconify_animation_end, time);
+ }
+
+ if (new_anim) {
+ ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
+ self, FALSE);
+ ob_main_loop_timeout_add(ob_main_loop,
+ FRAME_ANIMATE_ICONIFY_STEP_TIME,
+ frame_animate_iconify, self,
+ g_direct_equal, NULL);
+
+ /* do the first step */
+ frame_animate_iconify(self);
+
+ /* show it during the animation even if it is not "visible" */
+ if (!self->visible)
+ XMapWindow(ob_display, self->window);