From: Dana Jansens Date: Fri, 21 Mar 2003 09:41:01 +0000 (+0000) Subject: add a dispatched event for interactively moving a window. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=c2cbef62bb5d7e0c3f8c00e95bc885dc1f9ab1da;p=chaz%2Fopenbox add a dispatched event for interactively moving a window. move window snapping/resistance out of the kernel. make the action_move dispatch the new event. --- diff --git a/openbox/Makefile.am b/openbox/Makefile.am index 254025ba..97ec6c1d 100644 --- a/openbox/Makefile.am +++ b/openbox/Makefile.am @@ -27,11 +27,11 @@ ob3_LDADD=@LIBINTL@ ../render/librender.a ob3_LDFLAGS=-export-dynamic ob3_SOURCES=client.c event.c extensions.c focus.c frame.c openbox.c prop.c \ screen.c stacking.c xerror.c themerc.c timer.c dispatch.c \ - engine.c plugin.c action.c grab.c snap.c + engine.c plugin.c action.c grab.c noinst_HEADERS=client.h event.h extensions.h focus.h frame.h geom.h gettext.h \ openbox.h prop.h screen.h stacking.h xerror.h themerc.h dispatch.h \ - timer.h engine.h plugin.h action.h grab.h snap.h + timer.h engine.h plugin.h action.h grab.h MAINTAINERCLEANFILES= Makefile.in diff --git a/openbox/action.c b/openbox/action.c index b05e3450..6a86cf33 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -3,7 +3,7 @@ #include "frame.h" #include "screen.h" #include "action.h" -#include "snap.h" +#include "dispatch.h" #include @@ -402,7 +402,7 @@ void action_move(union ActionData *data) int x = data->move.x; int y = data->move.y; - snap_move(c, &x, &y, c->frame->area.width, c->frame->area.height); + dispatch_move(c, &x, &y); frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */ client_configure(c, Corner_TopLeft, x, y, c->area.width, c->area.height, diff --git a/openbox/dispatch.c b/openbox/dispatch.c index 059f163b..d6f91a2f 100644 --- a/openbox/dispatch.c +++ b/openbox/dispatch.c @@ -212,3 +212,30 @@ void dispatch_signal(int signal) f->h(&obe, f->data); } } + +void dispatch_move(Client *c, int *x, int *y) +{ + guint i; + EventType e = Event_Client_Moving; + GSList *it; + ObEvent obe; + + obe.type = e; + obe.data.c.client = c; + obe.data.c.num[0] = *x; + obe.data.c.num[1] = *y; + + i = 0; + while (e > 1) { + e >>= 1; + ++i; + } + + for (it = funcs[i]; it != NULL; it = it->next) { + Func *f = it->data; + f->h(&obe, f->data); + } + + *x = obe.data.c.num[0]; + *y = obe.data.c.num[1]; +} diff --git a/openbox/dispatch.h b/openbox/dispatch.h index a2838621..c12cce10 100644 --- a/openbox/dispatch.h +++ b/openbox/dispatch.h @@ -25,14 +25,15 @@ typedef enum { Event_Client_Unfocus = 1 << 13, /* unfocused */ Event_Client_Urgent = 1 << 14, /* entered/left urgent state */ Event_Client_Desktop = 1 << 15, /* moved to a new desktop */ + Event_Client_Moving = 1 << 16, /* being interactively moved */ - Event_Ob_Desktop = 1 << 16, /* changed desktops */ - Event_Ob_NumDesktops = 1 << 17, /* changed the number of desktops */ - Event_Ob_ShowDesktop = 1 << 18, /* entered/left show-the-desktop mode */ + Event_Ob_Desktop = 1 << 17, /* changed desktops */ + Event_Ob_NumDesktops = 1 << 18, /* changed the number of desktops */ + Event_Ob_ShowDesktop = 1 << 19, /* entered/left show-the-desktop mode */ - Event_Signal = 1 << 19, /* a signal from the OS */ + Event_Signal = 1 << 20, /* a signal from the OS */ - EVENT_RANGE = 1 << 20 + EVENT_RANGE = 1 << 21 } EventType; typedef struct { @@ -45,6 +46,7 @@ typedef struct { int num[2]; /* Event_Client_Desktop: num[0] = new number, num[1] = old number Event_Client_Urgent: num[0] = urgent state + Event_Client_Moving: num[0] = dest x coord, num[1] = dest y coord */ } EventData_Client; @@ -82,5 +84,8 @@ void dispatch_x(XEvent *e, Client *c); void dispatch_client(EventType e, Client *c, int num0, int num1); void dispatch_ob(EventType e, int num0, int num1); void dispatch_signal(int signal); +/* *x and *y should be set with the destination of the window, they may be + changed by the event handlers */ +void dispatch_move(Client *c, int *x, int *y); #endif diff --git a/openbox/openbox.c b/openbox/openbox.c index 5a7f5a5c..f410f312 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -151,6 +151,7 @@ int main(int argc, char **argv) plugin_open("keyboard"); plugin_open("mouse"); plugin_open("placement"); + plugin_open("resistance"); /* get all the existing windows */ client_manage_all(); diff --git a/openbox/snap.c b/openbox/snap.c deleted file mode 100644 index 02bb5bb5..00000000 --- a/openbox/snap.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "client.h" -#include "frame.h" -#include "stacking.h" -#include "screen.h" - -static int resistance = 10; -static gboolean edge_resistance = TRUE; /* window-to-edge */ -static gboolean window_resistance = TRUE; /* window-to-window */ - -void snap_move(Client *c, int *x, int *y, int w, int h) -{ - GList *it; - Rect *area; - int l, t, r, b; /* requested edges */ - int al, at, ar, ab; /* screen area edges */ - int cl, ct, cr, cb; /* current edges */ - gboolean snapx = FALSE, snapy = FALSE; - - if (!edge_resistance) return; - - /* add the frame to the dimensions */ - l = *x; - t = *y; - r = l + w - 1; - b = t + h - 1; - - cl = c->frame->area.x; - ct = c->frame->area.y; - cr = cl + c->frame->area.width - 1; - cb = ct + c->frame->area.height - 1; - - /* snap to other clients */ - if (window_resistance) - for (it = stacking_list; it != NULL; it = it->next) { - Client *target; - int tl, tt, tr, tb; /* 1 past the target's edges on each side */ - - target = it->data; - - tl = target->frame->area.x - 1; - tt = target->frame->area.y - 1; - tr = tl + target->frame->area.width + 1; - tb = tt + target->frame->area.height + 1; - - /* snapx and snapy ensure that the window snaps to the top-most - window edge available, without going all the way from - bottom-to-top in the stacking list - */ - if (!snapx && cl >= tr && l < tr && l >= tr - resistance) - *x = tr, snapx = TRUE; - else if (!snapx && cr <= tl && r > tl && r <= tl + resistance) - *x = tl - w + 1, snapx = TRUE; - else if (!snapy && ct >= tb && t < tb && t >= tb - resistance) - *y = tb, snapy = TRUE; - else if (!snapy && cb <= tt && b > tt && b <= tt + resistance) - *y = tt - h + 1, snapy = TRUE; - - if (snapx && snapy) break; - } - - /* get the screen boundaries */ - area = screen_area(c->desktop); - 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 - resistance) - *x = al; - else if (cr <= ar && r > ar && r <= ar + resistance) - *x = ar - w + 1; - if (ct >= at && t < at && t >= at - resistance) - *y = at; - else if (cb <= ab && b > ab && b < ab + resistance) - *y = ab - h + 1; -} diff --git a/openbox/snap.h b/openbox/snap.h deleted file mode 100644 index 5bf26272..00000000 --- a/openbox/snap.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __snap_h -#define __snap_h - -#include "client.h" - -void snap_move(Client *c, int *x, int *y, int w, int h); - -#endif