Share code to to classify pointer location in frame

This commit is contained in:
Kristian Høgsberg
2012-05-22 16:38:53 -04:00
parent a61ca06b49
commit f96e6c00d9
4 changed files with 104 additions and 65 deletions
+40
View File
@@ -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;
}
+19
View File
@@ -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