Guest User

slock dynamic psword input indicator

a guest
Sep 5th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.73 KB | Source Code | 0 0
  1. config:
  2. ```
  3. // Date display settings
  4. static const char *pswind_font = "Liberation Sans Mono:style=Regular:size=16";
  5. static const char *pswind_color = "#ffffff";
  6. static const int pswind_y_off = 0; // pixels relative to center
  7. ```
  8. readpw() part:
  9. ```
  10.             // if len > 0 -> password input, if resetcolor -> media keys || escape pressed, else -> failed passwored input
  11.             color = len ? INPUT : resetcolor ? INIT : ((failure || failonclear) ? FAILED : INIT);
  12.             if (resetcolor) { --resetcolor; };
  13.             if (running) {
  14.                 pthread_mutex_lock(&mutex);
  15.                 for (screen = 0; screen < nscreens; screen++) {
  16.                     if (oldc != color){
  17.                         XSetWindowBackground(dpy,
  18.                                              locks[screen]->win,
  19.                                              locks[screen]->colors[color]);
  20.                         XClearWindow(dpy, locks[screen]->win);
  21.                         /* Redraw time  and date after screen cleared */
  22.                         draw_time(dpy, locks[screen]);
  23.                         draw_date(dpy, locks[screen]);
  24.                     };
  25.                     draw_pswind(dpy, locks[screen], failure);
  26.                 }
  27.                 if (failure) { --failure; };
  28.                 pthread_mutex_unlock(&mutex);
  29.                 oldc = color;
  30.             }
  31. ```
  32. draw_pswind():
  33. ```
  34. static unsigned long prrnum = 0;
  35. static void draw_pswind(Display *dpy, struct lock *lock, int failure) {
  36.     char pswindstr[25];
  37.     if (failure) {
  38.         snprintf(pswindstr, sizeof(pswindstr), "✕✕✕✕✕✕✕✕");
  39.     } else {
  40.         unsigned long rnum;
  41.         if (getrandom(&rnum,sizeof(rnum),0) != sizeof(rnum)){
  42.             srandom(time(NULL));
  43.             rnum = random();
  44.         };
  45.         rnum &= 0xFF;
  46.  
  47.         if (prrnum == rnum) {
  48.             ++rnum;
  49.         };
  50.         prrnum = rnum;
  51.  
  52.         char *sym[] = {"●", "⚫"}; // {"▪", "■"};
  53.         snprintf(pswindstr, sizeof(pswindstr), "%s%s%s%s%s%s%s%s",
  54.                  sym[(rnum >> 0) & 1], sym[(rnum >> 1) & 1],
  55.                  sym[(rnum >> 2) & 1], sym[(rnum >> 3) & 1],
  56.                  sym[(rnum >> 4) & 1], sym[(rnum >> 5) & 1],
  57.                  sym[(rnum >> 6) & 1], sym[(rnum >> 7) & 1]);
  58.     };
  59.  
  60.     XGlyphInfo ext;
  61.     XftTextExtentsUtf8(dpy, pswindfont, (FcChar8*)pswindstr, strlen(pswindstr), &ext);
  62.     int pswind_x = (lock->w - ext.xOff) / 2;
  63.     int pswind_y = ((lock->h/6) * 5) + pswind_y_off;
  64.     XClearArea(dpy, lock->win, pswind_x, pswind_y - pswindfont->ascent, ext.xOff,
  65.                pswindfont->ascent + pswindfont->descent, False);
  66.     XftDrawStringUtf8(lock->xftdraw, &lock->picol, pswindfont, pswind_x, pswind_y,
  67.                       (FcChar8*)pswindstr, strlen(pswindstr));
  68.     XFlush(dpy);
  69. }
  70. ```
Tags: slock pswind
Advertisement
Add Comment
Please, Sign In to add comment