[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#267076: xtrlock: [patch] could use different colors to show status



Package: xtrlock
Version: 2.0-8
Severity: wishlist


It is confusing to use xtrlock because there is no information of the
status of the user's input. With this patch the cursor changes its color
to green if a password is being typed, and changes it again to red for a
second if a bad try is done.

In addition to this:
- xtrlock don't do annoying beeps if the display is color capable
  because the colors provide enough information by themselves.
- The no-type pause after a bad try is constant. This makes xtrlock
  more comfortable to use.
- Some minor changes to ensure compatibility with gcc 3.4.

This increases the executable size by only 264 bytes.



-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-1-686
Locale: LANG=es_ES, LC_CTYPE=es_ES

Versions of packages xtrlock depends on:
ii  libc6                     2.3.2.ds1-16   GNU C Library: Shared libraries an
ii  libx11-6                  4.3.0.dfsg.1-6 X Window System protocol client li
ii  xlibs                     4.3.0.dfsg.1-6 X Window System client libraries m

-- no debconf information
--- xtrlock-2.0_original/xtrlock.c	2002-09-01 06:46:29.000000000 +0200
+++ xtrlock-2.0/xtrlock.c	2004-08-20 16:16:17.000000000 +0200
@@ -14,6 +14,14 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
+ *
+ *
+ * Javier Donaire Segarra <jyuyu@fraguel.org>  Fri, 20 Aug 2004 16:12:44 +0200
+ *   - Color of cursor changes to report the user input's status
+ *   - Beeps replaced by color information if the display is color capable
+ *   - Constant retry timeout of 1 sec to be more intuitive
+ *   - Minor changes to ensure compatibility with new versions of gcc
+ *
  */
 
 #include <X11/X.h>
@@ -48,10 +56,6 @@
 Display *display;
 Window window, root;
 
-#define TIMEOUTPERATTEMPT 30000
-#define MAXGOODWILL  (TIMEOUTPERATTEMPT*5)
-#define INITIALGOODWILL MAXGOODWILL
-#define GOODWILLPORTION 0.3
 
 struct passwd *pw;
 int passwordok(const char *s) {
@@ -71,17 +75,66 @@
 #endif
 }
 
+
+Cursor create_cursor (Pixmap *csr_source, Pixmap *csr_mask,
+		      char *bg_color, char *fg_color,
+		      int *color_capable)
+{
+  XColor csr_fg, csr_bg, dummy;
+
+  if (color_capable) *color_capable = 1;
+  if ( ! XAllocNamedColor (display,
+			   DefaultColormap (display, DefaultScreen (display)),
+			   bg_color,
+			   &dummy, &csr_bg) ) {
+    XAllocNamedColor (display,
+		      DefaultColormap (display, DefaultScreen (display)),
+		      "black",
+		      &dummy, &csr_bg);
+    if (color_capable) *color_capable = 0;
+  }
+
+  if ( ! XAllocNamedColor (display,
+			   DefaultColormap (display, DefaultScreen (display)),
+			   fg_color,
+			   &dummy, &csr_fg) ) {
+    XAllocNamedColor (display,
+		      DefaultColormap (display, DefaultScreen (display)),
+		      "white",
+		      &dummy, &csr_bg);
+    if (color_capable) *color_capable = 0;
+  }
+
+  return XCreatePixmapCursor (display, *csr_source, *csr_mask,
+			      &csr_fg, &csr_bg, lock_x_hot,lock_y_hot);
+}
+
+
+void set_cursor (Cursor cursor)
+{
+  static Cursor current_cursor;
+
+  if (current_cursor != cursor) {
+    if (XGrabPointer (display, window, False, (KeyPressMask|KeyReleaseMask) &0,
+		      GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime)
+	!= GrabSuccess) {
+      XUngrabKeyboard (display, CurrentTime);
+      exit (1);
+    }
+    current_cursor = cursor;
+  }
+}
+
+
 int main(int argc, char **argv){
   XEvent ev;
   KeySym ks;
   char cbuf[10], rbuf[128]; /* shadow appears to suggest 127 a good value here */
-  int clen, rlen=0;
-  long goodwill= INITIALGOODWILL, timeout= 0;
+  int clen, rlen=0, use_colors;
+  long timeout= 0;
   XSetWindowAttributes attrib;
-  Cursor cursor;
+  Cursor cursor_noinput, cursor_input, cursor_failed;
   Pixmap csr_source,csr_mask;
-  XColor csr_fg, csr_bg, dummy;
-  int ret;
 #ifdef SHADOW_PWD
   struct spwd *sp;
 #endif
@@ -130,48 +183,29 @@
   csr_source= XCreateBitmapFromData(display,window,lock_bits,lock_width,lock_height);
   csr_mask= XCreateBitmapFromData(display,window,mask_bits,mask_width,mask_height);
 
-  ret = XAllocNamedColor(display,
-                        DefaultColormap(display, DefaultScreen(display)),
-                        "steelblue3",
-                        &dummy, &csr_bg);
-  if (ret==0)
-    XAllocNamedColor(display,
-                    DefaultColormap(display, DefaultScreen(display)),
-                    "black",
-                    &dummy, &csr_bg);
-
-  ret = XAllocNamedColor(display,
-                        DefaultColormap(display,DefaultScreen(display)),
-                        "grey25",
-                        &dummy, &csr_fg);
-  if (ret==0)
-    XAllocNamedColor(display,
-                    DefaultColormap(display, DefaultScreen(display)),
-                    "white",
-                    &dummy, &csr_bg);
-
-
-
-  cursor= XCreatePixmapCursor(display,csr_source,csr_mask,&csr_fg,&csr_bg,
-                              lock_x_hot,lock_y_hot);
+  cursor_noinput = create_cursor (&csr_source, &csr_mask,
+				  "steelblue3", "grey25", &use_colors);
+  if (use_colors) {
+    cursor_input   = create_cursor (&csr_source, &csr_mask,
+				    "SpringGreen2", "grey25", NULL);
+    cursor_failed  = create_cursor (&csr_source, &csr_mask,
+				    "firebrick1", "grey25", NULL);
+  }
+  else
+    cursor_input = cursor_failed = cursor_noinput;  /* skip warnings */
 
   XMapWindow(display,window);
   if (XGrabKeyboard(display,window,False,GrabModeAsync,GrabModeAsync,
 		    CurrentTime)!=GrabSuccess) {
     exit(1);
   }
-  if (XGrabPointer(display,window,False,(KeyPressMask|KeyReleaseMask)&0,
-               GrabModeAsync,GrabModeAsync,None,
-               cursor,CurrentTime)!=GrabSuccess) {
-    XUngrabKeyboard(display,CurrentTime);
-    exit(1);
-  }
+  set_cursor (cursor_noinput);
 
   for (;;) {
     XNextEvent(display,&ev);
     switch (ev.type) {
     case KeyPress:
-      if (ev.xkey.time < timeout) { XBell(display,0); break; }
+      if (ev.xkey.time < timeout) break;
       clen= XLookupString(&ev.xkey,cbuf,9,&ks,0);
       switch (ks) {
       case XK_Escape: case XK_Clear:
@@ -182,18 +216,15 @@
       case XK_Linefeed: case XK_Return:
         if (rlen==0) break;
         rbuf[rlen]=0;
-        if (passwordok(rbuf)) goto loop_x;
-        XBell(display,0);
+        if (passwordok(rbuf))
+	  exit (0);
+	if (use_colors)
+	  set_cursor (cursor_failed);
+	else
+	  XBell(display,0);
         rlen= 0;
-        if (timeout) {
-          goodwill+= ev.xkey.time - timeout;
-          if (goodwill > MAXGOODWILL) {
-            goodwill= MAXGOODWILL;
-          }
-        }
-        timeout= -goodwill*GOODWILLPORTION;
-        goodwill+= timeout;
-        timeout+= ev.xkey.time + TIMEOUTPERATTEMPT;
+	timeout = ev.xkey.time + 1000;  /* 1sec */
+	sleep (1);
         break;
       default:
         if (clen != 1) break;
@@ -202,10 +233,9 @@
         rlen++;
         break;
       }
+      if (use_colors)
+	set_cursor (rlen ? cursor_input : cursor_noinput);
       break;
-    default:
     }
   }
- loop_x:
-  exit(0);
 }

Reply to: