[hackers] [dmenu] added ^K, optimisations || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Sat, 19 Jun 2010 23:44:42 +0000 (UTC)

changeset: 310:f9ec28c3da4c
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sun Jun 20 00:44:26 2010 +0100
files: dmenu.c
description:
added ^K, optimisations

diff -r 0e9b70a8f134 -r f9ec28c3da4c dmenu.c
--- a/dmenu.c Sat Jun 19 21:44:32 2010 +0100
+++ b/dmenu.c Sun Jun 20 00:44:26 2010 +0100
@@ -79,9 +79,9 @@
 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 cursor = 0;
 static unsigned int numlockmask = 0;
 static Bool running = True;
 static Display *dpy;
@@ -338,8 +338,8 @@
 void
 kpress(XKeyEvent * e) {
         char buf[sizeof text];
- int i, num;
- unsigned int len;
+ int num;
+ unsigned int i, len;
         KeySym ksym;
 
         len = strlen(text);
@@ -381,6 +381,10 @@
                 case XK_J:
                         ksym = XK_Return;
                         break;
+ case XK_k:
+ case XK_K:
+ text[cursor] = '\0';
+ break;
                 case XK_u:
                 case XK_U:
                         memmove(text, text + cursor, sizeof text - cursor + 1);
@@ -450,12 +454,12 @@
                 }
                 break;
         case XK_BackSpace:
- if(cursor > 0) {
- for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++);
- memmove(text + cursor - i, text + cursor, sizeof text - cursor + i);
- cursor -= i;
- match(text);
- }
+ if(cursor == 0)
+ return;
+ for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++);
+ memmove(text + cursor - i, text + cursor, sizeof text - cursor + i);
+ cursor -= i;
+ match(text);
                 break;
         case XK_Delete:
                 for(i = 1; cursor + i < len && !IS_UTF8_1ST_CHAR(text[cursor + i]); i++);
@@ -477,7 +481,7 @@
         case XK_Escape:
                 ret = 1;
                 running = False;
- break;
+ return;
         case XK_Home:
                 if(sel == item) {
                         cursor = 0;
@@ -519,7 +523,7 @@
                         fprintf(stdout, "%s", sel->text);
                 fflush(stdout);
                 running = False;
- break;
+ return;
         case XK_Right:
         case XK_Down:
                 if(cursor < len)
Received on Sat Jun 19 2010 - 23:44:42 UTC

This archive was generated by hypermail 2.2.0 : Sat Jun 19 2010 - 23:48:04 UTC