commit d5b19e9731c7df1670bbc028d8508e7cd71880a7
parent 857030f02c45e5618a52fc256d6c477e10a46cef
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Tue, 4 Jul 2006 17:31:37 +0200
implemented dblclick selection for input widget, and C-u, C-w, C-a, C-e handling
Diffstat:
3 files changed, 87 insertions(+), 7 deletions(-)
diff --git a/cmd/wm/event.c b/cmd/wm/event.c
@@ -78,7 +78,7 @@ handle_buttonrelease(XEvent *e)
ev->button, b->name);
}
else if((f = frame_of_win(ev->window))) {
- if(blitz_brelease_input(&f->tagbar, ev->x, ev->y))
+ if(blitz_brelease_input(&f->tagbar, ev->x, ev->y, ev->time))
draw_frame(f);
write_event("ClientClick %d %d\n", idx_of_client(f->client), ev->button);
}
@@ -261,7 +261,7 @@ static void
handle_keypress(XEvent *e)
{
XKeyEvent *ev = &e->xkey;
- KeySym k;
+ KeySym k = 0;
char buf[32];
int n;
static Frame *f;
@@ -276,7 +276,7 @@ handle_keypress(XEvent *e)
return;
buf[n] = 0;
- if(blitz_kpress_input(&f->tagbar, k, buf))
+ if(blitz_kpress_input(&f->tagbar, ev->state, k, buf))
draw_frame(f);
}
else
diff --git a/liblitz/blitz.h b/liblitz/blitz.h
@@ -68,6 +68,7 @@ struct BlitzInput {
char *curend;
unsigned int size;
unsigned int len;
+ unsigned long tdbclk;
Bool drag;
Drawable drawable;
Window win;
@@ -99,8 +100,8 @@ void blitz_loadfont(Blitz *blitz, BlitzFont *font);
void blitz_draw_input(BlitzInput *i);
/* blitz_b* functions return True on expose */
Bool blitz_bpress_input(BlitzInput *i, int x, int y);
-Bool blitz_brelease_input(BlitzInput *i, int x, int y);
+Bool blitz_brelease_input(BlitzInput *i, int x, int y, unsigned long time);
Bool blitz_bmotion_input(BlitzInput *i, int x, int y);
Bool blitz_ispointinrect(int x, int y, XRectangle * r);
void blitz_setinput(BlitzInput *i, char *text);
-Bool blitz_kpress_input(BlitzInput *i, KeySym k, char *ks);
+Bool blitz_kpress_input(BlitzInput *i, unsigned long mod, KeySym k, char *ks);
diff --git a/liblitz/input.c b/liblitz/input.c
@@ -182,8 +182,40 @@ blitz_bpress_input(BlitzInput *i, int x, int y)
return (i->curstart == ostart) && (i->curend == oend);
}
+static void
+mark_word(BlitzInput *i, int x, int y)
+{
+ char *start, *end, *ps, *pe, *p;
+
+ start = curstart(i);
+ end = curend(i);
+
+ if(!start)
+ return;
+
+ if(start != end) {
+ i->curstart = i->curend = charof(i, x, y);
+ return;
+ }
+
+ for(ps = start; (ps > i->text) && (*ps == ' '); ps--);
+ for(pe = start; *pe && (*pe == ' '); pe++);
+
+ if(start - ps > pe - start)
+ p = pe;
+ else
+ p = ps;
+
+ while((p > i->text) && (*(p - 1) != ' '))
+ *p--;
+ i->curstart = p;
+ while(*p && (*p != ' '))
+ p++;
+ i->curend = p;
+}
+
Bool
-blitz_brelease_input(BlitzInput *i, int x, int y)
+blitz_brelease_input(BlitzInput *i, int x, int y, unsigned long time)
{
char *oend;
@@ -192,8 +224,17 @@ blitz_brelease_input(BlitzInput *i, int x, int y)
XSetInputFocus(i->blitz->dpy, i->win,
RevertToPointerRoot, CurrentTime);
oend = i->curend;
+
+ if(time - i->tdbclk < 1000) {
+ mark_word(i, x, y);
+ i->drag = False;
+ i->tdbclk = 0;
+ return True;
+ }
i->curend = charof(i, x, y);
+ i->tdbclk = time;
i->drag = False;
+
return i->curend == oend;
}
@@ -217,7 +258,7 @@ blitz_bmotion_input(BlitzInput *i, int x, int y)
}
Bool
-blitz_kpress_input(BlitzInput *i, KeySym k, char *ks)
+blitz_kpress_input(BlitzInput *i, unsigned long mod, KeySym k, char *ks)
{
char *start, *end;
unsigned int len;
@@ -225,8 +266,45 @@ blitz_kpress_input(BlitzInput *i, KeySym k, char *ks)
start = curstart(i);
end = curend(i);
+ if(mod & ControlMask) {
+ switch (k) {
+ case XK_A:
+ case XK_a:
+ k = XK_Begin;
+ break;
+ case XK_E:
+ case XK_e:
+ k = XK_End;
+ break;
+ case XK_H:
+ case XK_h:
+ k = XK_BackSpace;
+ break;
+ case XK_U:
+ case XK_u:
+ k = XK_BackSpace;
+ start = i->text;
+ break;
+ case XK_W:
+ case XK_w:
+ k = XK_BackSpace;
+ while(start > i->text && (*(--start) == ' '));
+ while(start > i->text && (*(start - 1) != ' '))
+ --start;
+ break;
+ default: /* ignore other control sequences */
+ return False;
+ }
+ }
+
if(IsCursorKey(k)) {
switch(k) {
+ case XK_Begin:
+ i->curstart = i->curend = i->text;
+ return True;
+ case XK_End:
+ i->curstart = i->curend = i->text + i->len;
+ return True;
case XK_Left:
if(start != end)
i->curstart = i->curend = start;
@@ -262,6 +340,7 @@ blitz_kpress_input(BlitzInput *i, KeySym k, char *ks)
}
i->text[i->len] = 0;
return True;
+
default:
len = strlen(ks);
if(!start) {