enlightenment/src/bin/e_resist.c

353 lines
11 KiB
C
Raw Normal View History

#include "e.h"
typedef struct _E_Resist_Rect E_Resist_Rect;
struct _E_Resist_Rect
{
int x, y, w, h;
int v1;
int resist_out;
};
static void _e_resist_rects(Eina_List *rects, int px, int py, int pw, int ph, int x, int y, int w, int h, int *rx, int *ry, int *rw, int *rh);
2006-01-07 02:39:46 -08:00
EAPI int
2015-03-18 13:28:24 -07:00
e_resist_client_position(Eina_List *skiplist,
2012-12-06 04:48:14 -08:00
int px, int py, int pw, int ph,
int x, int y, int w, int h,
int *rx, int *ry, int *rw, int *rh)
{
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
Eina_List *l, *rects = NULL;
E_Resist_Rect *r;
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
E_Client *ec;
E_Desk *desk;
E_Shelf *es;
E_Zone *zone;
2012-06-20 23:19:43 -07:00
2005-06-29 20:25:20 -07:00
if (!e_config->use_resist)
{
2012-12-06 04:48:14 -08:00
*rx = x;
*ry = y;
*rw = w;
*rh = h;
return 0;
}
2012-06-20 23:19:43 -07:00
/* edges of screen */
2012-12-06 04:48:14 -08:00
#define OBSTACLE(_x, _y, _w, _h, _resist) \
{ \
r = E_NEW(E_Resist_Rect, 1); \
r->x = _x; r->y = _y; r->w = _w; r->h = _h; r->v1 = _resist; \
r->resist_out = 0; \
rects = eina_list_append(rects, r); \
}
#define HOLDER(_x, _y, _w, _h, _resist) \
{ \
r = E_NEW(E_Resist_Rect, 1); \
r->x = _x; r->y = _y; r->w = _w; r->h = _h; r->v1 = _resist; \
r->resist_out = 1; \
rects = eina_list_append(rects, r); \
}
2015-03-18 13:28:24 -07:00
EINA_LIST_FOREACH(e_comp->zones, l, zone)
{
2012-12-06 04:48:14 -08:00
HOLDER(zone->x, zone->y, zone->w, zone->h, e_config->desk_resist);
}
/* FIXME: need to add resist or complete BLOCKS for things like ibar */
/* can add code here to add more fake obstacles with custom resist values */
/* here if need be - ie xinerama middle between screens and panels etc. */
E_CLIENT_FOREACH(ec)
{
if (e_client_util_ignored_get(ec) || (!evas_object_visible_get(ec->frame))) continue;
if (ec->offer_resistance && (!eina_list_data_find(skiplist, ec)))
2012-12-06 04:48:14 -08:00
{
OBSTACLE(ec->x, ec->y, ec->w, ec->h, e_config->window_resist);
2012-12-06 04:48:14 -08:00
}
}
desk = e_desk_current_get(e_zone_current_get());
l = e_shelf_list_all();
EINA_LIST_FREE(l, es)
{
if (e_shelf_desk_visible(es, desk))
2012-12-06 04:48:14 -08:00
{
OBSTACLE(es->x + es->zone->x, es->y + es->zone->y, es->w, es->h,
e_config->gadget_resist);
2012-12-06 04:48:14 -08:00
}
}
if (rects)
{
2012-12-06 04:48:14 -08:00
_e_resist_rects(rects,
px, py, pw, ph,
x, y, w, h,
rx, ry, rw, rh);
2012-12-06 04:48:14 -08:00
E_FREE_LIST(rects, E_FREE);
}
return 1;
}
2006-01-07 02:39:46 -08:00
EAPI int
2015-03-18 13:28:24 -07:00
e_resist_gadman_position(Eina_List *skiplist __UNUSED__,
2012-12-06 04:48:14 -08:00
int px, int py, int pw, int ph,
int x, int y, int w, int h,
int *rx, int *ry)
{
Eina_List *l, *rects = NULL;
E_Resist_Rect *r;
E_Shelf *es;
2005-06-29 20:25:20 -07:00
if (!e_config->use_resist)
{
2012-12-06 04:48:14 -08:00
*rx = x;
*ry = y;
return 0;
}
l = e_shelf_list_all();
EINA_LIST_FREE(l, es)
{
if (e_shelf_desk_visible(es, e_desk_current_get(es->zone)))
2012-12-06 04:48:14 -08:00
{
OBSTACLE(es->x + es->zone->x, es->y + es->zone->y, es->w, es->h,
e_config->gadget_resist);
}
}
2012-06-20 23:19:43 -07:00
if (rects)
{
2012-12-06 04:48:14 -08:00
_e_resist_rects(rects,
px, py, pw, ph,
x, y, w, h,
rx, ry, NULL, NULL);
2012-12-06 04:48:14 -08:00
E_FREE_LIST(rects, E_FREE);
}
return 1;
}
static void
_e_resist_rects(Eina_List *rects,
2012-12-06 04:48:14 -08:00
int px, int py, int pw, int ph,
int x, int y, int w, int h,
int *rx, int *ry, int *rw, int *rh)
{
int dx, dy, dw, dh, d, pd;
int resist_x = 0, resist_y = 0;
int resist_w = 0, resist_h = 0;
Eina_List *l;
E_Resist_Rect *r;
dx = x - px;
dy = y - py;
dw = w - pw;
dh = h - ph;
EINA_LIST_FOREACH(rects, l, r)
{
2012-12-06 04:48:14 -08:00
if (E_SPANS_COMMON(r->y, r->h, y, h))
{
if (dx > 0)
{
/* moving right */
if (r->resist_out)
{
/* check right edge of windows against left */
d = x + w - (r->x + r->w);
pd = px + pw - (r->x + r->w);
if ((d > 0) && (pd <= 0) && (d <= r->v1))
{
if (-resist_x < d)
resist_x = -d;
}
}
else
{
/* check left edge of windows against right */
d = r->x - (x + w);
pd = r->x - (px + pw);
if ((d < 0) && (pd >= 0) && (d >= -r->v1))
{
if (resist_x > d)
resist_x = d;
}
}
}
else if (dx < 0)
{
/* moving left */
if (r->resist_out)
{
/* check left edge of windows against right */
d = r->x - x;
pd = r->x - px;
if ((d > 0) && (pd <= 0) && (d <= r->v1))
{
if (resist_x < d)
{
resist_x = d;
resist_w = -d;
}
}
}
else
{
/* check right edge of windows against left */
d = x - (r->x + r->w);
pd = px - (r->x + r->w);
if ((d < 0) && (pd >= 0) && (d >= -r->v1))
{
if (-resist_x > d)
{
resist_x = -d;
resist_w = d;
}
}
}
}
if ((dw > 0) && (dx == 0))
{
/* enlarging window by moving lower corner */
if (r->resist_out)
{
/* check right edge of windows against left */
d = x + w - (r->x + r->w);
pd = px + pw - (r->x + r->w);
if ((d > 0) && (pd <= 0) && (d <= r->v1))
{
if (-resist_w < d)
resist_w = -d;
}
}
else
{
/* check left edge of windows against right */
d = r->x - (x + w);
pd = r->x - (px + pw);
if ((d < 0) && (pd >= 0) && (d >= -r->v1))
{
if (resist_w > d)
resist_w = d;
}
}
}
}
if (E_SPANS_COMMON(r->x, r->w, x, w))
{
if (dy > 0)
{
/* moving down */
if (r->resist_out)
{
/* check bottom edge of windows against top */
d = y + h - (r->y + r->h);
pd = py + ph - (r->y + r->h);
if ((d > 0) && (pd <= 0) && (d <= r->v1))
{
if (-resist_y < d)
resist_y = -d;
}
}
else
{
/* check top edge of windows against bottom */
d = r->y - (y + h);
pd = r->y - (py + ph);
if ((d < 0) && (pd >= 0) && (d >= -r->v1))
{
if (resist_y > d)
resist_y = d;
}
}
}
else if (dy < 0)
{
/* moving up */
if (r->resist_out)
{
/* check top edge of windows against bottom */
d = r->y - y;
pd = r->y - py;
if ((d > 0) && (pd <= 0) && (d <= r->v1))
{
if (resist_y < d)
{
resist_y = d;
resist_h = -d;
}
}
}
else
{
/* moving up - check bottom edge of windows against top */
d = y - (r->y + r->h);
pd = py - (r->y + r->h);
if ((d < 0) && (pd >= 0) && (d >= -r->v1))
{
if (-resist_y > d)
{
resist_y = -d;
resist_h = d;
}
}
}
}
if ((dh > 0) && (dy == 0))
{
/* enlarging window by moving lower corner */
if (r->resist_out)
{
/* check bottom edge of windows against top */
d = y + h - (r->y + r->h);
pd = py + ph - (r->y + r->h);
if ((d > 0) && (pd <= 0) && (d <= r->v1))
{
if (-resist_h < d)
resist_h = -d;
}
}
else
{
/* check top edge of windows against bottom */
d = r->y - (y + h);
pd = r->y - (py + ph);
if ((d < 0) && (pd >= 0) && (d >= -r->v1))
{
if (resist_h > d)
resist_h = d;
}
}
}
}
}
if (rx)
{
2012-12-06 04:48:14 -08:00
if (dx != 0)
*rx = x + resist_x;
else
*rx = x;
}
if (ry)
{
2012-12-06 04:48:14 -08:00
if (dy != 0)
*ry = y + resist_y;
else
*ry = y;
}
if (rw)
{
2012-12-06 04:48:14 -08:00
if (dw != 0)
*rw = w + resist_w;
else
*rw = w;
}
if (rh)
{
2012-12-06 04:48:14 -08:00
if (dh != 0)
*rh = h + resist_h;
else
*rh = h;
}
}
2012-12-06 04:48:14 -08:00