[wiki] [sites] wiki updated

From: <hg_AT_suckless.org>
Date: Sun, 8 Nov 2009 11:59:53 +0000 (UTC)

changeset: 369:fa238261838b
tag: tip
user: Enno Boland (tox) <tox_AT_s01.de>
date: Sun Nov 08 12:59:57 2009 +0100
files: tools.suckless.org/dmenu/dmenu-tip-cursor.diff tools.suckless.org/dmenu/patches/cursor.md tools.suckless.org/dmenu/patches/dmenu-tip-cursor.diff
description:
adding cursor patch to dmenu


diff -r b93b2daecbfa -r fa238261838b tools.suckless.org/dmenu/dmenu-tip-cursor.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools.suckless.org/dmenu/dmenu-tip-cursor.diff Sun Nov 08 12:59:57 2009 +0100
_AT_@ -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
+_AT_@ -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 };
+_AT_@ -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;
+_AT_@ -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;
+
+_AT_@ -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;
+_AT_@ -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;
+_AT_@ -353,7 +364,7 @@
+ text[0] = 0;
+ match(text);
+ drawmenu();
+- return;
++ break;
+ case XK_w:
+ case XK_W:
+ if(len) {
+_AT_@ -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;
+_AT_@ -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;
+_AT_@ -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)
+_AT_@ -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 -r b93b2daecbfa -r fa238261838b tools.suckless.org/dmenu/patches/cursor.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools.suckless.org/dmenu/patches/cursor.md Sun Nov 08 12:59:57 2009 +0100
_AT_@ -0,0 +1,9 @@
+CURSOR HANDLING
+===============
+
+This patch allows to use extended text editing.
+
+Download
+--------
+
+* [dmenu-tip-cursor.diff](dmenu-tip-cursor.diff)
diff -r b93b2daecbfa -r fa238261838b tools.suckless.org/dmenu/patches/dmenu-tip-cursor.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools.suckless.org/dmenu/patches/dmenu-tip-cursor.diff Sun Nov 08 12:59:57 2009 +0100
_AT_@ -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
+_AT_@ -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 };
+_AT_@ -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;
+_AT_@ -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;
+
+_AT_@ -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;
+_AT_@ -353,7 +366,7 @@
+ text[0] = 0;
+ match(text);
+ drawmenu();
+- return;
++ break;
+ case XK_w:
+ case XK_W:
+ if(len) {
+_AT_@ -365,7 +378,7 @@
+ match(text);
+ drawmenu();
+ }
+- return;
++ break;
+ }
+ }
+ if(CLEANMASK(e->state) & Mod1Mask) {
+_AT_@ -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;
+_AT_@ -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)
+_AT_@ -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();
+ }
+
Received on Sun Nov 08 2009 - 12:59:53 CET

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 19:31:00 CEST