From 1b3afcff1fea0d1334b50dff378a6667e264b557 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Mon, 6 Oct 2014 19:52:14 +0200 Subject: Move common gravity application to screen.c --- openbox/screen.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'openbox/screen.c') diff --git a/openbox/screen.c b/openbox/screen.c index 0198c36c..4b75b3e7 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -1928,3 +1928,30 @@ gboolean screen_compare_desktops(guint a, guint b) b = screen_desktop; return a == b; } + +void screen_apply_gravity_point(gint *x, gint *y, gint width, gint height, + GravityPoint *position, const Rect *area) +{ + if (position->x.center) + *x = area->width / 2 - width / 2; + else { + *x = position->x.pos; + if (position->x.denom) + *x = (*x * area->width) / position->x.denom; + if (position->x.opposite) + *x = area->width - width - *x; + } + + if (position->y.center) + *y = area->height / 2 - height / 2; + else { + *y = position->y.pos; + if (position->y.denom) + *y = (*y * area->height) / position->y.denom; + if (position->y.opposite) + *y = area->height - height - *y; + } + + *x += area->x; + *y += area->y; +} -- cgit v1.2.3