+void plugin_setup_config()
+{
+}
+
+static int drag_threshold = 3;
+
+/* GData of GSList*s of PointerBinding*s. */
+static GData *bound_contexts;
+
+struct foreach_grab_temp {
+ Client *client;
+ gboolean grab;
+};
+
+static void foreach_grab(GQuark key, gpointer data, gpointer user_data)
+{
+ struct foreach_grab_temp *d = user_data;
+ GSList *it;
+ for (it = data; it != NULL; it = it->next) {
+ /* grab/ungrab the button */
+ MouseBinding *b = it->data;
+ Window win;
+ int mode;
+ unsigned int mask;
+
+ if (key == g_quark_try_string("frame")) {
+ win = d->client->frame->window;
+ mode = GrabModeAsync;
+ mask = ButtonPressMask | ButtonMotionMask | ButtonReleaseMask;
+ } else if (key == g_quark_try_string("client")) {
+ win = d->client->frame->plate;
+ mode = GrabModeSync; /* this is handled in event */
+ mask = ButtonPressMask; /* can't catch more than this with Sync
+ mode the release event is manufactured
+ in event */
+ } else return;
+
+ if (d->grab)
+ grab_button(b->button, b->state, win, mask, mode);
+ else
+ ungrab_button(b->button, b->state, win);
+ }
+}
+
+static void grab_for_client(Client *client, gboolean grab)
+{
+ struct foreach_grab_temp bt;
+ bt.client = client;
+ bt.grab = grab;
+ g_datalist_foreach(&bound_contexts, foreach_grab, &bt);
+}
+
+static void grab_all_clients(gboolean grab)
+{
+ GSList *it;
+
+ for (it = client_list; it != NULL; it = it->next)
+ grab_for_client(it->data, grab);
+}
+
+static void foreach_clear(GQuark key, gpointer data, gpointer user_data)
+{
+ GSList *it;
+ user_data = user_data;
+ for (it = data; it != NULL; it = it->next) {
+ int i;
+
+ MouseBinding *b = it->data;
+ for (i = 0; i < NUM_MOUSEACTION; ++i)
+ if (b->action[i] != NULL)
+ action_free(b->action[i]);
+ g_free(b);
+ }
+ g_slist_free(data);
+}
+
+static void fire_button(MouseAction a, GQuark context, Client *c, guint state,
+ guint button)
+{
+ GSList *it;
+ MouseBinding *b;
+
+ for (it = g_datalist_id_get_data(&bound_contexts, context);
+ it != NULL; it = it->next) {
+ b = it->data;
+ if (b->state == state && b->button == button)
+ break;
+ }
+ /* if not bound, then nothing to do! */
+ if (it == NULL) return;
+
+ if (b->action[a] != NULL && b->action[a]->func != NULL) {
+ b->action[a]->data.any.c = c;
+
+ g_assert(!(b->action[a]->func == action_move ||
+ b->action[a]->func == action_resize));
+
+ b->action[a]->func(&b->action[a]->data);
+ }
+}
+
+/* corner should be the opposite corner of the window in which the pointer
+ clicked, Corner_TopLeft if a good default if there is no client */
+static void fire_motion(MouseAction a, GQuark context, Client *c, guint state,
+ guint button, int cx, int cy, int cw, int ch,
+ int dx, int dy, gboolean final, Corner corner)
+{
+ GSList *it;
+ MouseBinding *b;
+
+ for (it = g_datalist_id_get_data(&bound_contexts, context);
+ it != NULL; it = it->next) {
+ b = it->data;
+ if (b->state == state && b->button == button)
+ break;
+ }
+ /* if not bound, then nothing to do! */
+ if (it == NULL) return;
+
+ if (b->action[a] != NULL && b->action[a]->func != NULL) {
+ b->action[a]->data.any.c = c;
+
+ if (b->action[a]->func == action_move) {
+ b->action[a]->data.move.x = cx + dx;
+ b->action[a]->data.move.y = cy + dy;
+ b->action[a]->data.move.final = final;
+ } else if (b->action[a]->func == action_resize) {
+ b->action[a]->data.resize.corner = corner;
+ switch (corner) {
+ case Corner_TopLeft:
+ b->action[a]->data.resize.x = cw + dx;
+ b->action[a]->data.resize.y = ch + dy;
+ break;
+ case Corner_TopRight:
+ b->action[a]->data.resize.x = cw - dx;
+ b->action[a]->data.resize.y = ch + dy;
+ break;
+ case Corner_BottomLeft:
+ b->action[a]->data.resize.x = cw + dx;
+ b->action[a]->data.resize.y = ch - dy;
+ break;
+ case Corner_BottomRight:
+ b->action[a]->data.resize.x = cw - dx;
+ b->action[a]->data.resize.y = ch - dy;
+ break;
+ }
+ b->action[a]->data.resize.final = final;
+ }
+ b->action[a]->func(&b->action[a]->data);
+ }
+}
+
+static Corner pick_corner(int x, int y, int cx, int cy, int cw, int ch)
+{
+ if (x - cx < cw / 2) {
+ if (y - cy < ch / 2)
+ return Corner_BottomRight;
+ else
+ return Corner_TopRight;
+ } else {
+ if (y - cy < ch / 2)
+ return Corner_BottomLeft;
+ else
+ return Corner_TopLeft;
+ }
+}