Move common gravity application to screen.c
authorMikael Magnusson <mikachu@gmail.com>
Mon, 6 Oct 2014 17:52:14 +0000 (19:52 +0200)
committerMikael Magnusson <mikachu@gmail.com>
Mon, 6 Oct 2014 20:05:26 +0000 (22:05 +0200)
openbox/menuframe.c
openbox/place.c
openbox/screen.c
openbox/screen.h

index aa64677..2010454 100644 (file)
@@ -232,41 +232,13 @@ void menu_frame_move(ObMenuFrame *self, gint x, gint y)
     XMoveWindow(obt_display, self->window, self->area.x, self->area.y);
 }
 
-static void calc_position(ObMenuFrame *self, GravityPoint *position,
-                          gint *x, gint *y, gint monitor)
-{
-    const Rect *area = screen_physical_area_monitor(monitor);
-
-    if (position->x.center)
-        *x = area->width / 2 - self->area.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 - self->area.width - *x;
-    }
-
-    if (position->y.center)
-        *y = area->height / 2 - self->area.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 - self->area.height - *y;
-    }
-
-    *x += area->x;
-    *y += area->y;
-}
-
 static void menu_frame_place_topmenu(ObMenuFrame *self, GravityPoint *pos,
                                      gint *x, gint *y, gint monitor)
 {
     gint dx, dy;
 
-    calc_position(self, pos, x, y, monitor);
+    screen_apply_gravity_point(x, y, self->area.width, self->area.height,
+                               pos, screen_physical_area_monitor(monitor));
 
     if (config_menu_middle) {
         gint myx;
index 1dc16c4..aa3ff63 100644 (file)
@@ -295,28 +295,8 @@ static gboolean place_per_app_setting_position(ObClient *client, Rect *screen,
 
     ob_debug("placing by per-app settings");
 
-    if (settings->position.x.center)
-        *x = screen->width / 2 - client->area.width / 2;
-    else {
-        *x = settings->position.x.pos;
-        if (settings->position.x.denom)
-            *x = (*x * screen->width) / settings->position.x.denom;
-        if (settings->position.x.opposite)
-            *x = screen->width - frame_size.width - *x;
-    }
-
-    if (settings->position.y.center)
-        *y = screen->height / 2 - client->area.height / 2;
-    else {
-        *y = settings->position.y.pos;
-        if (settings->position.y.denom)
-            *y = (*y * screen->height) / settings->position.y.denom;
-        if (settings->position.y.opposite)
-            *y = screen->height - frame_size.height - *y;
-    }
-
-    *x += screen->x;
-    *y += screen->y;
+    screen_apply_gravity_point(x, y, frame_size.width, frame_size.height,
+                               &settings->position, screen);
 
     return TRUE;
 }
index 0198c36..4b75b3e 100644 (file)
@@ -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;
+}
index 673a994..56fa6c9 100644 (file)
@@ -182,4 +182,9 @@ guint screen_monitor_pointer(void);
 */
 gboolean screen_compare_desktops(guint a, guint b);
 
+/*! Resolve a gravity point into absolute coordinates.
+ * width and height are the size of the object being placed, used for
+ * aligning to right/bottom edges of the area. */
+void screen_apply_gravity_point(gint *x, gint *y, gint width, gint height,
+                                GravityPoint *position, const Rect *area);
 #endif