X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fframe.c;h=be4e688dff71c89ae6e7ec79f09467292ee3e73d;hb=82b2f0aa7a1723632e8d3cf7dc772e4bdb66868a;hp=eb223f64737e90ce0e0ef15eda752ba37081e48c;hpb=3993847dd4142efc1c111c9d603465d9261c1999;p=chaz%2Fopenbox diff --git a/openbox/frame.c b/openbox/frame.c index eb223f64..be4e688d 100644 --- a/openbox/frame.c +++ b/openbox/frame.c @@ -27,15 +27,23 @@ #include "mainloop.h" #include "focus.h" #include "moveresize.h" +#include "screen.h" #include "render/theme.h" -#define PLATE_EVENTMASK (SubstructureRedirectMask | ButtonPressMask | \ - FocusChangeMask) +#define PLATE_EVENTMASK (SubstructureRedirectMask | FocusChangeMask) #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \ ButtonPressMask | ButtonReleaseMask) #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \ ButtonMotionMask | \ EnterWindowMask | LeaveWindowMask) +/* The inner window does not need enter/leave events. + If it does get them, then it needs its own context for enter events + because sloppy focus will focus the window when you enter the inner window + from the frame. */ +#define INNER_EVENTMASK (ButtonPressMask) + +#define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */ +#define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */ #define FRAME_HANDLE_Y(f) (f->innersize.top + f->client->area.height + \ f->cbwidth_y) @@ -46,6 +54,7 @@ static gboolean flash_timeout(gpointer data); static void set_theme_statics(ObFrame *self); static void free_theme_statics(ObFrame *self); +static gboolean frame_animate_iconify(gpointer self); static Window createWindow(Window parent, Visual *visual, gulong mask, XSetWindowAttributes *attrib) @@ -100,7 +109,7 @@ ObFrame *frame_new(ObClient *client) self->window = createWindow(RootWindow(ob_display, ob_screen), visual, mask, &attrib); - attrib.event_mask = ELEMENT_EVENTMASK; + attrib.event_mask = INNER_EVENTMASK; self->inner = createWindow(self->window, visual, mask, &attrib); mask &= ~CWEventMask; @@ -165,6 +174,8 @@ static void set_theme_statics(ObFrame *self) /* set colors/appearance/sizes for stuff that doesn't change */ XSetWindowBorder(ob_display, self->window, RrColorPixel(ob_rr_theme->frame_b_color)); + XSetWindowBorder(ob_display, self->inner, + RrColorPixel(ob_rr_theme->frame_b_color)); XSetWindowBorder(ob_display, self->title, RrColorPixel(ob_rr_theme->frame_b_color)); XSetWindowBorder(ob_display, self->handle, @@ -247,11 +258,12 @@ void frame_hide(ObFrame *self) { if (self->visible) { self->visible = FALSE; - self->client->ignore_unmaps += 1; + if (!frame_iconify_animating(self)) + XUnmapWindow(ob_display, self->window); /* we unmap the client itself so that we can get MapRequest events, and because the ICCCM tells us to! */ - XUnmapWindow(ob_display, self->window); XUnmapWindow(ob_display, self->client->window); + self->client->ignore_unmaps += 1; } } @@ -342,6 +354,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, /* set border widths */ if (!fake) { XSetWindowBorderWidth(ob_display, self->window, self->bwidth); + XSetWindowBorderWidth(ob_display, self->inner, self->bwidth); XSetWindowBorderWidth(ob_display, self->title, self->rbwidth); XSetWindowBorderWidth(ob_display, self->handle, self->rbwidth); XSetWindowBorderWidth(ob_display, self->lgrip, self->rbwidth); @@ -426,8 +439,10 @@ void frame_adjust_area(ObFrame *self, gboolean moved, /* move and resize the inner border window which contains the plate */ XMoveResizeWindow(ob_display, self->inner, - self->innersize.left - self->cbwidth_x, - self->innersize.top - self->cbwidth_y, + self->innersize.left - self->cbwidth_x - + self->bwidth, + self->innersize.top - self->cbwidth_y - + self->bwidth, self->client->area.width + self->cbwidth_x * 2, self->client->area.height + @@ -457,21 +472,28 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->client->area.height + self->size.top + self->size.bottom)); - if (moved) { + if (moved || resized) { /* find the new coordinates, done after setting the frame.size, for frame_client_gravity. */ self->area.x = self->client->area.x; self->area.y = self->client->area.y; - frame_client_gravity(self, &self->area.x, &self->area.y); + frame_client_gravity(self, &self->area.x, &self->area.y, + self->client->area.width, + self->client->area.height); } if (!fake) { - /* move and resize the top level frame. - shading can change without being moved or resized */ - XMoveResizeWindow(ob_display, self->window, - self->area.x, self->area.y, - self->area.width - self->bwidth * 2, - self->area.height - self->bwidth * 2); + if (!frame_iconify_animating(self)) + /* move and resize the top level frame. + shading can change without being moved or resized. + + but don't do this during an iconify animation. it will be + reflected afterwards. + */ + XMoveResizeWindow(ob_display, self->window, + self->area.x, self->area.y, + self->area.width - self->bwidth * 2, + self->area.height - self->bwidth * 2); if (resized) { framerender_frame(self); @@ -486,6 +508,8 @@ void frame_adjust_area(ObFrame *self, gboolean moved, vals[3] = self->size.bottom; PROP_SETA32(self->client->window, net_frame_extents, cardinal, vals, 4); + PROP_SETA32(self->client->window, kde_net_wm_frame_strut, + cardinal, vals, 4); } /* if this occurs while we are focus cycling, the indicator needs to @@ -498,6 +522,13 @@ void frame_adjust_area(ObFrame *self, gboolean moved, ob_rr_theme->label_height); } +void frame_adjust_client_area(ObFrame *self) +{ + /* resize the plate */ + XResizeWindow(ob_display, self->plate, + self->client->area.width, self->client->area.height); +} + void frame_adjust_state(ObFrame *self) { framerender_frame(self); @@ -510,13 +541,6 @@ void frame_adjust_focus(ObFrame *self, gboolean hilite) XFlush(ob_display); } -void frame_adjust_client_area(ObFrame *self) -{ - /* resize the plate */ - XResizeWindow(ob_display, self->plate, - self->client->area.width, self->client->area.height); -} - void frame_adjust_title(ObFrame *self) { framerender_frame(self); @@ -581,6 +605,10 @@ void frame_release_client(ObFrame *self, ObClient *client) g_assert(self->client == client); + /* if there was any animation going on, kill it */ + ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify, + self, FALSE); + /* check if the app has already reparented its window away */ while (XCheckTypedWindowEvent(ob_display, client->window, ReparentNotify, &ev)) @@ -824,7 +852,7 @@ ObFrameContext frame_context(ObClient *client, Window win) } self = client->frame; - if (win == self->plate) { + if (win == self->inner || win == self->plate) { /* conceptually, this is the desktop, as far as users are concerned */ if (client->type == OB_CLIENT_TYPE_DESKTOP) @@ -833,7 +861,6 @@ ObFrameContext frame_context(ObClient *client, Window win) } if (win == self->window) return OB_FRAME_CONTEXT_FRAME; - if (win == self->inner) return OB_FRAME_CONTEXT_FRAME; if (win == self->title) return OB_FRAME_CONTEXT_TITLEBAR; if (win == self->label) return OB_FRAME_CONTEXT_TITLEBAR; if (win == self->handle) return OB_FRAME_CONTEXT_HANDLE; @@ -853,7 +880,7 @@ ObFrameContext frame_context(ObClient *client, Window win) return OB_FRAME_CONTEXT_NONE; } -void frame_client_gravity(ObFrame *self, gint *x, gint *y) +void frame_client_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h) { /* horizontal */ switch (self->client->gravity) { @@ -866,13 +893,13 @@ void frame_client_gravity(ObFrame *self, gint *x, gint *y) case NorthGravity: case SouthGravity: case CenterGravity: - *x -= (self->size.left + self->size.right) / 2; + *x -= (self->size.left + w) / 2; break; case NorthEastGravity: case SouthEastGravity: case EastGravity: - *x -= self->size.left + self->size.right; + *x -= (self->size.left + self->size.right + w) - 1; break; case ForgetGravity: @@ -892,13 +919,13 @@ void frame_client_gravity(ObFrame *self, gint *x, gint *y) case CenterGravity: case EastGravity: case WestGravity: - *y -= (self->size.top + self->size.bottom) / 2; + *y -= (self->size.top + h) / 2; break; case SouthWestGravity: case SouthEastGravity: case SouthGravity: - *y -= self->size.top + self->size.bottom; + *y -= (self->size.top + self->size.bottom + h) - 1; break; case ForgetGravity: @@ -908,7 +935,7 @@ void frame_client_gravity(ObFrame *self, gint *x, gint *y) } } -void frame_frame_gravity(ObFrame *self, gint *x, gint *y) +void frame_frame_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h) { /* horizontal */ switch (self->client->gravity) { @@ -920,12 +947,12 @@ void frame_frame_gravity(ObFrame *self, gint *x, gint *y) case NorthGravity: case CenterGravity: case SouthGravity: - *x += (self->size.left + self->size.right) / 2; + *x += (self->size.left + w) / 2; break; case NorthEastGravity: case EastGravity: case SouthEastGravity: - *x += self->size.left + self->size.right; + *x += (self->size.left + self->size.right + w) - 1; break; case StaticGravity: case ForgetGravity: @@ -943,12 +970,12 @@ void frame_frame_gravity(ObFrame *self, gint *x, gint *y) case WestGravity: case CenterGravity: case EastGravity: - *y += (self->size.top + self->size.bottom) / 2; + *y += (self->size.top + h) / 2; break; case SouthWestGravity: case SouthGravity: case SouthEastGravity: - *y += self->size.top + self->size.bottom; + *y += (self->size.top + self->size.bottom + h) - 1; break; case StaticGravity: case ForgetGravity: @@ -1009,3 +1036,155 @@ 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); + } +}