X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=plugins%2Fmouse%2Fmouse.c;h=b2173c25156a9a2a3c870a7a59a3cb4cf4b71e67;hb=5cf61ee02354c1c9f80c11f3796afc4b948055d6;hp=90c92422d333fdc8a5f8d9a039acaef35daa0fa2;hpb=d58799bc25333d6ace95325072c39072aa0e757c;p=chaz%2Fopenbox diff --git a/plugins/mouse/mouse.c b/plugins/mouse/mouse.c index 90c92422..b2173c25 100644 --- a/plugins/mouse/mouse.c +++ b/plugins/mouse/mouse.c @@ -3,10 +3,7 @@ #include "kernel/action.h" #include "kernel/event.h" #include "kernel/client.h" -#include "kernel/frame.h" #include "kernel/grab.h" -#include "kernel/engine.h" -#include "kernel/config.h" #include "kernel/parse.h" #include "kernel/frame.h" #include "translate.h" @@ -14,19 +11,35 @@ #include "mouseparse.h" #include +static int threshold; +static int dclicktime; + +static void parse_assign(char *name, ParseToken *value) +{ + if (!g_ascii_strcasecmp(name, "dragthreshold")) { + if (value->type != TOKEN_INTEGER) + yyerror("invalid value"); + else { + if (value->data.integer >= 0) + threshold = value->data.integer; + } + } else if (!g_ascii_strcasecmp(name, "doubleclicktime")) { + if (value->type != TOKEN_INTEGER) + yyerror("invalid value"); + else { + if (value->data.integer >= 0) + dclicktime = value->data.integer; + } + } else + yyerror("invalid option"); + parse_free_token(value); +} + void plugin_setup_config() { - config_def_set(config_def_new("mouse.dragThreshold", Config_Integer, - "Drag Threshold", - "The drag threshold in pixels before a Drag " - "event starts.")); - config_def_set(config_def_new("mouse.doubleClickTime", Config_Integer, - "Double Click Interval", - "The amount of time (in milliseconds) in " - "which two clicks must occur to cause a " - "DoubleClick event.")); - - parse_reg_section("mouse", mouseparse); + threshold = 3; + dclicktime = 200; + parse_reg_section("mouse", mouseparse, parse_assign); } /* Array of GSList*s of PointerBinding*s. */ @@ -66,7 +79,7 @@ static void grab_for_client(Client *client, gboolean grab) static void grab_all_clients(gboolean grab) { - GSList *it; + GList *it; for (it = client_list; it != NULL; it = it->next) grab_for_client(it->data, grab); @@ -163,7 +176,8 @@ static gboolean fire_motion(MouseAction a, Context context, Client *c, break; } b->action[a]->data.resize.final = final; - } + } else + g_assert_not_reached(); b->action[a]->func(&b->action[a]->data); return TRUE; } @@ -189,20 +203,13 @@ static void event(ObEvent *e, void *foo) { static Time ltime; static int px, py, cx, cy, cw, ch, dx, dy; - static guint button = 0, lbutton = 0; + static guint button = 0, state = 0, lbutton = 0; static gboolean drag = FALSE, drag_used = FALSE; static Corner corner = Corner_TopLeft; - ConfigValue doubleclicktime; - ConfigValue dragthreshold; gboolean click = FALSE; gboolean dclick = FALSE; Context context; - if (!config_get("mouse.dragThreshold", Config_Integer, &dragthreshold)) - dragthreshold.integer = 3; /* default */ - if (!config_get("mouse.doubleClickTime", Config_Integer, &doubleclicktime)) - doubleclicktime.integer = 200; /* default */ - switch (e->type) { case Event_Client_Mapped: grab_for_client(e->data.c.client, TRUE); @@ -231,9 +238,10 @@ static void event(ObEvent *e, void *foo) corner = pick_corner(px, py, cx, cy, cw, ch); } button = e->data.x.e->xbutton.button; + state = e->data.x.e->xbutton.state; } - context = engine_get_context(e->data.x.client, - e->data.x.e->xbutton.window); + context = frame_context(e->data.x.client->frame, + e->data.x.e->xbutton.window); fire_button(MouseAction_Press, context, e->data.x.client, e->data.x.e->xbutton.state, @@ -247,14 +255,13 @@ static void event(ObEvent *e, void *foo) break; case Event_X_ButtonRelease: - context = engine_get_context(e->data.x.client, - e->data.x.e->xbutton.window); + context = frame_context(e->data.x.client->frame, + e->data.x.e->xbutton.window); if (e->data.x.e->xbutton.button == button) { /* end drags */ if (drag_used) { fire_motion(MouseAction_Motion, context, - e->data.x.client, e->data.x.e->xbutton.state, - e->data.x.e->xbutton.button, + e->data.x.client, state, button, cx, cy, cw, ch, dx, dy, TRUE, corner); drag = drag_used = FALSE; @@ -273,8 +280,7 @@ static void event(ObEvent *e, void *foo) click = TRUE; /* double clicks happen if there were 2 in a row! */ if (lbutton == button && - e->data.x.e->xbutton.time - doubleclicktime.integer <= - ltime) { + e->data.x.e->xbutton.time - dclicktime <= ltime) { dclick = TRUE; lbutton = 0; } else @@ -284,6 +290,7 @@ static void event(ObEvent *e, void *foo) } button = 0; + state = 0; ltime = e->data.x.e->xbutton.time; } fire_button(MouseAction_Release, context, @@ -304,16 +311,14 @@ static void event(ObEvent *e, void *foo) dx = e->data.x.e->xmotion.x_root - px; dy = e->data.x.e->xmotion.y_root - py; if (!drag && - (ABS(dx) >= dragthreshold.integer || - ABS(dy) >= dragthreshold.integer)) + (ABS(dx) >= threshold || ABS(dy) >= threshold)) drag = TRUE; if (drag) { - context = engine_get_context(e->data.x.client, - e->data.x.e->xbutton.window); + context = frame_context(e->data.x.client->frame, + e->data.x.e->xbutton.window); drag_used = fire_motion(MouseAction_Motion, context, e->data.x.client, - e->data.x.e->xmotion.state, - button, cx, cy, cw, ch, dx, dy, + state, button, cx, cy, cw, ch, dx, dy, FALSE, corner); } }