sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3512621f352c5f9a4c79a6618942dfb2a909660a
parent a0d7f886c726782d17d367b2206383c2cf59b3aa
Author: Enno Boland (tox) <tox@s01.de>
Date:   Sun,  8 Nov 2009 12:59:57 +0100

adding cursor patch to dmenu
Diffstat:
Atools.suckless.org/dmenu/dmenu-tip-cursor.diff | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/cursor.md | 9+++++++++
Atools.suckless.org/dmenu/patches/dmenu-tip-cursor.diff | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 310 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/dmenu-tip-cursor.diff b/tools.suckless.org/dmenu/dmenu-tip-cursor.diff @@ -0,0 +1,159 @@ +diff -r 9b203c5c180d dmenu.c +--- a/dmenu.c Sat Apr 18 12:50:12 2009 +0100 ++++ b/dmenu.c Sun Nov 08 12:58:13 2009 +0100 +@@ -18,6 +18,7 @@ + #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) + #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) + #define MIN(a, b) ((a) < (b) ? (a) : (b)) ++#define MAX(a, b) ((a) > (b) ? (a) : (b)) + + /* enums */ + enum { ColFG, ColBG, ColLast }; +@@ -73,6 +74,7 @@ + static int cmdw = 0; + static int promptw = 0; + static int ret = 0; ++static int cursor = 0; + static int screen; + static unsigned int mw, mh; + static unsigned int numlockmask = 0; +@@ -171,6 +173,16 @@ + } + + void ++drawcursor(void) { ++ XRectangle r = { dc.x, dc.y + 2, 1, dc.h - 4 }; ++ ++ r.x += textnw(text, cursor) + dc.font.height / 2; ++ ++ XSetForeground(dpy, dc.gc, dc.norm[ColFG]); ++ XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); ++} ++ ++void + drawmenu(void) { + Item *i; + +@@ -190,6 +202,7 @@ + if(cmdw && item) + dc.w = cmdw; + drawtext(text[0] ? text : NULL, dc.norm); ++ drawcursor(); + dc.x += cmdw; + if(curr) { + dc.w = spaceitem; +@@ -331,8 +344,6 @@ + /* first check if a control mask is omitted */ + if(e->state & ControlMask) { + switch (ksym) { +- default: /* ignore other control sequences */ +- return; + case XK_bracketleft: + ksym = XK_Escape; + break; +@@ -353,7 +364,7 @@ + text[0] = 0; + match(text); + drawmenu(); +- return; ++ break; + case XK_w: + case XK_W: + if(len) { +@@ -365,12 +376,11 @@ + match(text); + drawmenu(); + } +- return; ++ break; + } + } + if(CLEANMASK(e->state) & Mod1Mask) { + switch(ksym) { +- default: return; + case XK_h: + ksym = XK_Left; + break; +@@ -393,15 +403,17 @@ + } + switch(ksym) { + default: +- if(num && !iscntrl((int) buf[0])) { +- buf[num] = 0; +- strncpy(text + len, buf, sizeof text - len); ++ if(num && !iscntrl((int) buf[0]) && num + strlen(text) < sizeof text) { ++ memmove(text + cursor + num, text + cursor, sizeof text - cursor); ++ memcpy(text + cursor, buf, num); ++ cursor+=num; + match(text); + } + break; + case XK_BackSpace: +- if(len) { +- text[--len] = 0; ++ if(cursor > 0) { ++ memmove(text + cursor + -1, text + cursor, sizeof text - cursor); ++ cursor--; + match(text); + } + break; +@@ -426,13 +438,17 @@ + calcoffsets(); + break; + case XK_Left: +- if(!(sel && sel->left)) ++ if(sel && sel->left){ ++ sel=sel->left; ++ if(sel->right == curr) { ++ curr = prev; ++ calcoffsets(); ++ } ++ } ++ else if(cursor > 0) ++ cursor--; ++ else + return; +- sel=sel->left; +- if(sel->right == curr) { +- curr = prev; +- calcoffsets(); +- } + break; + case XK_Next: + if(!next) +@@ -457,21 +473,29 @@ + running = False; + break; + case XK_Right: +- if(!(sel && sel->right)) ++ if(cursor < len) ++ cursor++; ++ else if(sel && sel->right) { ++ sel=sel->right; ++ if(sel == next) { ++ curr = next; ++ calcoffsets(); ++ } ++ } ++ else + return; +- sel=sel->right; +- if(sel == next) { +- curr = next; +- calcoffsets(); +- } + break; + case XK_Tab: + if(!sel) + return; + strncpy(text, sel->text, sizeof text); ++ cursor = strlen(text); + match(text); + break; + } ++ len = strlen(text); ++ cursor = MIN(cursor, len); ++ cursor = MAX(cursor, 0); + drawmenu(); + } + diff --git a/tools.suckless.org/dmenu/patches/cursor.md b/tools.suckless.org/dmenu/patches/cursor.md @@ -0,0 +1,9 @@ +CURSOR HANDLING +=============== + +This patch allows to use extended text editing. + +Download +-------- + +* [dmenu-tip-cursor.diff](dmenu-tip-cursor.diff) diff --git a/tools.suckless.org/dmenu/patches/dmenu-tip-cursor.diff b/tools.suckless.org/dmenu/patches/dmenu-tip-cursor.diff @@ -0,0 +1,142 @@ +diff -r 9b203c5c180d dmenu.c +--- a/dmenu.c Sat Apr 18 12:50:12 2009 +0100 ++++ b/dmenu.c Sun Nov 08 12:48:53 2009 +0100 +@@ -18,6 +18,7 @@ + #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) + #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) + #define MIN(a, b) ((a) < (b) ? (a) : (b)) ++#define MAX(a, b) ((a) > (b) ? (a) : (b)) + + /* enums */ + enum { ColFG, ColBG, ColLast }; +@@ -73,6 +74,7 @@ + static int cmdw = 0; + static int promptw = 0; + static int ret = 0; ++static int cursor = 0; + static int screen; + static unsigned int mw, mh; + static unsigned int numlockmask = 0; +@@ -171,6 +173,16 @@ + } + + void ++drawcursor(void) { ++ XRectangle r = { dc.x, dc.y + 2, 1, dc.h - 4 }; ++ ++ r.x += textnw(text, cursor) + dc.font.height / 2; ++ ++ XSetForeground(dpy, dc.gc, dc.norm[ColFG]); ++ XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); ++} ++ ++void + drawmenu(void) { + Item *i; + +@@ -190,6 +202,7 @@ + if(cmdw && item) + dc.w = cmdw; + drawtext(text[0] ? text : NULL, dc.norm); ++ drawcursor(); + dc.x += cmdw; + if(curr) { + dc.w = spaceitem; +@@ -353,7 +366,7 @@ + text[0] = 0; + match(text); + drawmenu(); +- return; ++ break; + case XK_w: + case XK_W: + if(len) { +@@ -365,7 +378,7 @@ + match(text); + drawmenu(); + } +- return; ++ break; + } + } + if(CLEANMASK(e->state) & Mod1Mask) { +@@ -395,13 +408,16 @@ + default: + if(num && !iscntrl((int) buf[0])) { + buf[num] = 0; +- strncpy(text + len, buf, sizeof text - len); ++ memmove(text + cursor + num, text + cursor, sizeof text - cursor); ++ strncpy(text + cursor, buf, sizeof text - cursor); ++ cursor+=num; + match(text); + } + break; + case XK_BackSpace: +- if(len) { +- text[--len] = 0; ++ if(cursor > 0) { ++ memmove(text + cursor + -1, text + cursor, sizeof text - cursor); ++ cursor--; + match(text); + } + break; +@@ -426,13 +442,17 @@ + calcoffsets(); + break; + case XK_Left: +- if(!(sel && sel->left)) ++ if(sel && sel->left){ ++ sel=sel->left; ++ if(sel->right == curr) { ++ curr = prev; ++ calcoffsets(); ++ } ++ } ++ else if(cursor > 0) ++ cursor--; ++ else + return; +- sel=sel->left; +- if(sel->right == curr) { +- curr = prev; +- calcoffsets(); +- } + break; + case XK_Next: + if(!next) +@@ -457,21 +477,29 @@ + running = False; + break; + case XK_Right: +- if(!(sel && sel->right)) ++ if(cursor < len) ++ cursor++; ++ else if(sel && sel->right) { ++ sel=sel->right; ++ if(sel == next) { ++ curr = next; ++ calcoffsets(); ++ } ++ } ++ else + return; +- sel=sel->right; +- if(sel == next) { +- curr = next; +- calcoffsets(); +- } + break; + case XK_Tab: + if(!sel) + return; + strncpy(text, sel->text, sizeof text); ++ cursor = strlen(text); + match(text); + break; + } ++ len = strlen(text); ++ cursor = MIN(cursor, len); ++ cursor = MAX(cursor, 0); + drawmenu(); + } +