X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=plugins%2Fresistance%2Fresistance.c;h=f5e68052051e795a5cee139729ebfab6c57ece98;hb=1045079482453424f8320de99639390e3020eb72;hp=f9f00a6b4a442a05f60227eb3b7934e128210086;hpb=5d58b4fff0c1d99c992e729a2fab572ac89157d2;p=chaz%2Fopenbox diff --git a/plugins/resistance/resistance.c b/plugins/resistance/resistance.c index f9f00a6b..f5e68052 100644 --- a/plugins/resistance/resistance.c +++ b/plugins/resistance/resistance.c @@ -9,9 +9,8 @@ static int win_resistance; static int edge_resistance; -static gboolean resist_windows; -static void parse_xml(xmlDocPtr doc, xmlNodePtr node, void *d) +static void parse_xml(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d) { xmlNodePtr n; @@ -20,16 +19,13 @@ static void parse_xml(xmlDocPtr doc, xmlNodePtr node, void *d) win_resistance = parse_int(doc, n); if ((n = parse_find_node("screen_edge_strength", node))) edge_resistance = parse_int(doc, n); - if ((n = parse_find_node("windows", node))) - resist_windows = parse_bool(doc, n); } -void plugin_setup_config() +void plugin_setup_config(ObParseInst *i) { win_resistance = edge_resistance = DEFAULT_RESISTANCE; - resist_windows = DEFAULT_RESIST_WINDOWS; - parse_register("resistance", parse_xml, NULL); + parse_register(i, "resistance", parse_xml, NULL); } static void resist_move(ObClient *c, int *x, int *y) @@ -57,7 +53,7 @@ static void resist_move(ObClient *c, int *x, int *y) cb = ct + c->frame->area.height - 1; /* snap to other clients */ - if (resist_windows) + if (win_resistance) for (it = stacking_list; it != NULL; it = it->next) { ObClient *target; int tl, tt, tr, tb; /* 1 past the target's edges on each side */ @@ -112,26 +108,28 @@ static void resist_move(ObClient *c, int *x, int *y) } /* get the screen boundaries */ - for (i = 0; i < screen_num_monitors; ++i) { - area = screen_area_monitor(c->desktop, i); - - if (!RECT_INTERSECTS_RECT(*area, c->frame->area)) - continue; - - al = area->x; - at = area->y; - ar = al + area->width - 1; - ab = at + area->height - 1; - - /* snap to screen edges */ - if (cl >= al && l < al && l >= al - edge_resistance) - *x = al; - else if (cr <= ar && r > ar && r <= ar + edge_resistance) - *x = ar - w + 1; - if (ct >= at && t < at && t >= at - edge_resistance) - *y = at; - else if (cb <= ab && b > ab && b < ab + edge_resistance) - *y = ab - h + 1; + if (edge_resistance) { + for (i = 0; i < screen_num_monitors; ++i) { + area = screen_area_monitor(c->desktop, i); + + if (!RECT_INTERSECTS_RECT(*area, c->frame->area)) + continue; + + al = area->x; + at = area->y; + ar = al + area->width - 1; + ab = at + area->height - 1; + + /* snap to screen edges */ + if (cl >= al && l < al && l >= al - edge_resistance) + *x = al; + else if (cr <= ar && r > ar && r <= ar + edge_resistance) + *x = ar - w + 1; + if (ct >= at && t < at && t >= at - edge_resistance) + *y = at; + else if (cb <= ab && b > ab && b < ab + edge_resistance) + *y = ab - h + 1; + } } } @@ -163,7 +161,7 @@ static void resist_size(ObClient *c, int *w, int *h, ObCorner corn) ab = at + area->height - 1; /* snap to other windows */ - if (resist_windows) { + if (win_resistance) { for (it = stacking_list; it != NULL; it = it->next) { if (!WINDOW_IS_CLIENT(it->data)) continue; @@ -227,41 +225,43 @@ static void resist_size(ObClient *c, int *w, int *h, ObCorner corn) } /* snap to screen edges */ - - /* horizontal snapping */ - switch (corn) { - case OB_CORNER_TOPLEFT: - case OB_CORNER_BOTTOMLEFT: - dlt = l; - drb = r + *w - c->frame->area.width; - if (r <= ar && drb > ar && drb <= ar + edge_resistance) - *w = ar - l + 1; - break; - case OB_CORNER_TOPRIGHT: - case OB_CORNER_BOTTOMRIGHT: - dlt = l - *w + c->frame->area.width; - drb = r; - if (l >= al && dlt < al && dlt >= al - edge_resistance) - *w = r - al + 1; - break; - } - /* vertical snapping */ - switch (corn) { - case OB_CORNER_TOPLEFT: - case OB_CORNER_TOPRIGHT: - dlt = t; - drb = b + *h - c->frame->area.height; - if (b <= ab && drb > ab && drb <= ab + edge_resistance) - *h = ab - t + 1; - break; - case OB_CORNER_BOTTOMLEFT: - case OB_CORNER_BOTTOMRIGHT: - dlt = t - *h + c->frame->area.height; - drb = b; - if (t >= at && dlt < at && dlt >= at - edge_resistance) - *h = b - at + 1; - break; + if (edge_resistance) { + /* horizontal snapping */ + switch (corn) { + case OB_CORNER_TOPLEFT: + case OB_CORNER_BOTTOMLEFT: + dlt = l; + drb = r + *w - c->frame->area.width; + if (r <= ar && drb > ar && drb <= ar + edge_resistance) + *w = ar - l + 1; + break; + case OB_CORNER_TOPRIGHT: + case OB_CORNER_BOTTOMRIGHT: + dlt = l - *w + c->frame->area.width; + drb = r; + if (l >= al && dlt < al && dlt >= al - edge_resistance) + *w = r - al + 1; + break; + } + + /* vertical snapping */ + switch (corn) { + case OB_CORNER_TOPLEFT: + case OB_CORNER_TOPRIGHT: + dlt = t; + drb = b + *h - c->frame->area.height; + if (b <= ab && drb > ab && drb <= ab + edge_resistance) + *h = ab - t + 1; + break; + case OB_CORNER_BOTTOMLEFT: + case OB_CORNER_BOTTOMRIGHT: + dlt = t - *h + c->frame->area.height; + drb = b; + if (t >= at && dlt < at && dlt >= at - edge_resistance) + *h = b - at + 1; + break; + } } }