OSDN Git Service

Add support for scroll lock
authora <a@b.c>
Tue, 3 Apr 2018 14:38:22 +0000 (16:38 +0200)
committera <a@b.c>
Tue, 3 Apr 2018 14:38:22 +0000 (16:38 +0200)
README.md
src/options.c
src/prototypes/x11.h
src/x11.c

index ec6f487..5c05d4c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -99,6 +99,7 @@ The order of supplied options will dictate how, where and what system informatio
 |              | --mouse     | Query xorg and get the mouse speed in percentage                   |
 |              | --numlock   | Query xorg to get the current state of numlock                     |
 |              | --capslock  | Query xorg to get the current state of capslock                    |
+|              | --scrolllock | Query xorg to get the current state of scroll lock                |
 |              | --gmail     | Query gmail and show all unread emails                             |
 |              | --perl      | Extend pinkybar with your scripts written in perl, learn more from the Opt-in section.     |
 |              | --python    | Extend pinkybar with your scripts written in python, learn more from the Opt-in section.     |
@@ -209,7 +210,7 @@ It's up to you to decide which features suit you best.
 | --with-mpd     | --without-mpd       | To see the currently played song name (if any).                                            |
 | --with-keyboard | --without-keyboard | Query xorg and show the currently used keyboard layout                                     |
 | --with-mouse   | --without-mouse     | Query xorg and get the mouse speed in percentage                                           |
-| --with-numcapslock | --without-numcapslock | Query xorg to get the current state of numlock and capslock                          |
+| --with-numcapslock | --without-numcapslock | Query xorg to get the current state of numlock, capslock and scroll lock             |
 | --with-mail    | --without-mail      | Query gmail and show all unread emails, must be combined with the variables **gmail_account** and **gmail_password**  |
 | --with-ip      | --without-ip        | Return your external ip address (ipv4).                                                    |
 | gmail\_account=foo  |                     | Your gmail account goes here, must be combined **--with-mail**                        |
index 5fbe5ab..5db2c55 100644 (file)
@@ -61,6 +61,7 @@ enum {
   MOUSE,
   NUMLOCK,
   CAPSLOCK,
+  SCROLLLOCK,
   BULLSHIFT
 };
 const char *argp_program_version = PACKAGE_STRING;
@@ -192,8 +193,9 @@ static const struct argp_option options[] = {
 #endif /* WITH_MOUSE && HAVE_X11_XLIB_H */
 
 #if WITH_NUMLOCK == 1 && defined(HAVE_X11_XLIB_H)
-  { .name = "numlock",      .key = NUMLOCK,        .doc = "Query xorg to get the current state of numlock."              },
-  { .name = "capslock",     .key = CAPSLOCK,       .doc = "Query xorg to get the current state of capslock."             },
+  { .name = "numlock",      .key = NUMLOCK,            .doc = "Query xorg to get the current state of numlock."          },
+  { .name = "capslock",     .key = CAPSLOCK,           .doc = "Query xorg to get the current state of capslock."         },
+  { .name = "scrolllock",   .key = SCROLLLOCK,         .doc = "Query xorg to get the current state of capslock."         },
 #endif /* WITH_MOUSE && HAVE_X11_XLIB_H */
 
 #if !defined(__OpenBSD__)
@@ -419,6 +421,8 @@ parse_opt(int key, char *arg, struct argp_state *state) {
     NEW_LABEL(NUMLOCK, char numlock[VLA], numlock, FMT_KERN);
 
     NEW_LABEL(CAPSLOCK, char capslock[VLA], capslock, FMT_KERN);
+
+    NEW_LABEL(SCROLLLOCK, char scrolllock[VLA], scrolllock, FMT_KERN);
 #endif /* WITH_KEYBOARD && HAVE_X11_XLIB_H */
 
 
index 320c3e5..fb76753 100644 (file)
@@ -35,6 +35,7 @@ void get_mouse(char *);
 #if WITH_NUMLOCK == 1 && defined(HAVE_X11_XLIB_H)
 void get_numlock(char *);
 void get_capslock(char *);
+void get_scrolllock(char *);
 #endif /* WITH_NUMLOCK && HAVE_X11_XLIB_H */
 
 #endif /* X11_H_ */
index f267d86..77c3e2b 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -128,6 +128,21 @@ get_capslock(char *str1) {
 
   FILL_ARR(str1, "Caps %s", (x.led_mask & 1 ? "On" : "Off"));
 }
+
+void
+get_scrolllock(char *str1) {
+  Display *display = XOpenDisplay(NULL);
+  XKeyboardState x;
+
+  if (NULL == display) {
+    exit_with_err(CANNOT_OPEN, "X server");
+  }
+
+  XGetKeyboardControl(display, &x);
+  XCloseDisplay(display);
+
+  FILL_ARR(str1, "Scroll %s", (x.led_mask & 4 ? "On" : "Off"));
+}
 #endif /* WITH_NUMLOCK && HAVE_X11_XLIB_H */
 
 #else