summaryrefslogtreecommitdiff
path: root/openbox/menuframe.c
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2014-10-06 19:38:51 +0200
committerMikael Magnusson <mikachu@gmail.com>2014-10-06 22:05:26 +0200
commitc5c5b7b455334ec2987b0f04e18d817f6d3767d0 (patch)
treef1344f89cdc7e0ee62df3f2133c9be4aa23e26b3 /openbox/menuframe.c
parent238ab3f742644af7f3b4d2a7a7860fedd290ad29 (diff)
Resolve gravity coords in menuframe so it can use the widths
Diffstat (limited to 'openbox/menuframe.c')
-rw-r--r--openbox/menuframe.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/openbox/menuframe.c b/openbox/menuframe.c
index 3252bb3c..aa646779 100644
--- a/openbox/menuframe.c
+++ b/openbox/menuframe.c
@@ -232,10 +232,42 @@ void menu_frame_move(ObMenuFrame *self, gint x, gint y)
XMoveWindow(obt_display, self->window, self->area.x, self->area.y);
}
-static void menu_frame_place_topmenu(ObMenuFrame *self, gint *x, gint *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);
+
if (config_menu_middle) {
gint myx;
@@ -989,20 +1021,24 @@ static gboolean menu_frame_show(ObMenuFrame *self)
return TRUE;
}
-gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y,
- gboolean mouse)
+gboolean menu_frame_show_topmenu(ObMenuFrame *self, GravityPoint pos,
+ gint monitor, gboolean mouse)
{
gint px, py;
+ gint x, y;
if (menu_frame_is_visible(self))
return TRUE;
if (!menu_frame_show(self))
return FALSE;
- if (self->menu->place_func)
+ if (self->menu->place_func) {
+ x = pos.x.pos;
+ y = pos.y.pos;
self->menu->place_func(self, &x, &y, mouse, self->menu->data);
- else
- menu_frame_place_topmenu(self, &x, &y);
+ } else {
+ menu_frame_place_topmenu(self, &pos, &x, &y, monitor);
+ }
menu_frame_move(self, x, y);