summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-05-22 16:38:53 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-05-22 16:38:53 -0400
commitf96e6c00d9beea04f2be82663fc260b69eb029fc (patch)
treec62f7f2be9df49f552ceadeadd8218fcd43b96f8 /shared
parenta61ca06b495ea29e2cd3388b4a04114bd66b7045 (diff)
downloadweston-f96e6c00d9beea04f2be82663fc260b69eb029fc.tar.gz
weston-f96e6c00d9beea04f2be82663fc260b69eb029fc.tar.bz2
weston-f96e6c00d9beea04f2be82663fc260b69eb029fc.zip
Share code to to classify pointer location in frame
Diffstat (limited to 'shared')
-rw-r--r--shared/cairo-util.c40
-rw-r--r--shared/cairo-util.h19
2 files changed, 59 insertions, 0 deletions
diff --git a/shared/cairo-util.c b/shared/cairo-util.c
index 9fd2e493..649ed985 100644
--- a/shared/cairo-util.c
+++ b/shared/cairo-util.c
@@ -427,3 +427,43 @@ theme_render_frame(struct theme *t,
cairo_show_text(cr, title);
}
}
+
+enum theme_location
+theme_get_location(struct theme *t, int x, int y, int width, int height)
+{
+ int vlocation, hlocation, location;
+ const int grip_size = 8;
+
+ if (x < t->margin)
+ hlocation = THEME_LOCATION_EXTERIOR;
+ else if (t->margin <= x && x < t->margin + grip_size)
+ hlocation = THEME_LOCATION_RESIZING_LEFT;
+ else if (x < width - t->margin - grip_size)
+ hlocation = THEME_LOCATION_INTERIOR;
+ else if (x < width - t->margin)
+ hlocation = THEME_LOCATION_RESIZING_RIGHT;
+ else
+ hlocation = THEME_LOCATION_EXTERIOR;
+
+ if (y < t->margin)
+ vlocation = THEME_LOCATION_EXTERIOR;
+ else if (t->margin <= y && y < t->margin + grip_size)
+ vlocation = THEME_LOCATION_RESIZING_TOP;
+ else if (y < height - t->margin - grip_size)
+ vlocation = THEME_LOCATION_INTERIOR;
+ else if (y < height - t->margin)
+ vlocation = THEME_LOCATION_RESIZING_BOTTOM;
+ else
+ vlocation = THEME_LOCATION_EXTERIOR;
+
+ location = vlocation | hlocation;
+ if (location & THEME_LOCATION_EXTERIOR)
+ location = THEME_LOCATION_EXTERIOR;
+ if (location == THEME_LOCATION_INTERIOR &&
+ y < t->margin + t->titlebar_height)
+ location = THEME_LOCATION_TITLEBAR;
+ else if (location == THEME_LOCATION_INTERIOR)
+ location = THEME_LOCATION_CLIENT_AREA;
+
+ return location;
+}
diff --git a/shared/cairo-util.h b/shared/cairo-util.h
index 6dda7cfb..2fec389a 100644
--- a/shared/cairo-util.h
+++ b/shared/cairo-util.h
@@ -65,4 +65,23 @@ theme_render_frame(struct theme *t,
cairo_t *cr, int width, int height,
const char *title, uint32_t flags);
+enum theme_location {
+ THEME_LOCATION_INTERIOR = 0,
+ THEME_LOCATION_RESIZING_TOP = 1,
+ THEME_LOCATION_RESIZING_BOTTOM = 2,
+ THEME_LOCATION_RESIZING_LEFT = 4,
+ THEME_LOCATION_RESIZING_TOP_LEFT = 5,
+ THEME_LOCATION_RESIZING_BOTTOM_LEFT = 6,
+ THEME_LOCATION_RESIZING_RIGHT = 8,
+ THEME_LOCATION_RESIZING_TOP_RIGHT = 9,
+ THEME_LOCATION_RESIZING_BOTTOM_RIGHT = 10,
+ THEME_LOCATION_RESIZING_MASK = 15,
+ THEME_LOCATION_EXTERIOR = 16,
+ THEME_LOCATION_TITLEBAR = 17,
+ THEME_LOCATION_CLIENT_AREA = 18,
+};
+
+enum theme_location
+theme_get_location(struct theme *t, int x, int y, int width, int height);
+
#endif