OSDN Git Service

Add support to obtain the current mouse speed
authora <a@b.c>
Mon, 2 Apr 2018 14:59:41 +0000 (16:59 +0200)
committera <a@b.c>
Mon, 2 Apr 2018 14:59:41 +0000 (16:59 +0200)
README.md
extra/Gentoo/app-admin/pinkybar/metadata.xml
extra/Gentoo/app-admin/pinkybar/pinkybar-9999.ebuild
extra/xbm_icons/mouse.xbm [new file with mode: 0755]
m4/x11.m4
src/common.c
src/include/non_x11_colours.h
src/include/options_constants.h
src/options.c
src/prototypes/common.h

index b9d9fac..a7524cd 100644 (file)
--- a/README.md
+++ b/README.md
@@ -96,6 +96,7 @@ The order of supplied options will dictate how, where and what system informatio
 | -u           | --kernarch  | The machine architecture                                           |
 | -k           | --kernel    | Combined kernel name and version                                   |
 |              | --keyboard  | Query xorg and show the currently used keyboard layout             |
+|              | --mouse     | Query xorg and get the mouse speed in percentage                   |
 |              | --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.     |
@@ -205,6 +206,7 @@ It's up to you to decide which features suit you best.
 | icons=/tmp     |                     | xbm icons that can be used by dzen2 for example. Discarded when **--with-dwm** is used     |
 | --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-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 91c90cd..3665e3a 100644 (file)
                <flag name="dvd">To get the cdrom or dvdrom vendor and model names.</flag>
                <flag name="dwm">Output the data to the root window. Enable it if you are
                        using dwm.</flag>
-               <flag name="ip">Fetch and display your current (ipv4) IP address.</flag>
+               <flag name="ip">Fetch and display your external (ipv4) IP address.</flag>
                <flag name="keyboard">Query xorg and show the currently used keyboard
                        layout.</flag>
                <flag name="libnl">Enable the wifi related options regarding chipsets
                        supporting the cfg80211,mac80211 modules</flag>
                <flag name="lisp">Extend pinkybar with your own crafted script written
                        in lisp, stored in /usr/share/pinkysc/pinky.lisp</flag>
+               <flag name="mouse">Query xorg and get the mouse speed in percentage.</flag>
                <flag name="mpd">To see the currently played song name, date, artist(s),
                        title.</flag>
                <flag name="ncurses">Output the data to the terminal using the ncurses
index 71b0368..22e75c4 100644 (file)
@@ -15,7 +15,7 @@ HOMEPAGE="https://github.com/su8/pinky-bar"
 LICENSE="GPL-3"
 SLOT="0"
 IUSE="+alsa colors drivetemp drivetemp-light dvd dwm ip keyboard libnl lisp lua
-       mpd ncurses +net +pci perl python2 r ruby sensors slang smartemp tcl weather"
+       mouse mpd ncurses +net +pci perl python2 r ruby sensors slang smartemp tcl weather"
 
 DEPEND="
        sys-devel/autoconf
@@ -35,6 +35,7 @@ RDEPEND="
        libnl? ( >=dev-libs/libnl-3.2.27 virtual/pkgconfig )
        lisp? ( dev-lisp/ecls )
        lua? ( dev-lang/lua )
+       mouse? ( x11-libs/libX11 )
        mpd? ( media-sound/mpd media-libs/libmpdclient )
        ncurses? ( sys-libs/ncurses )
        net? ( sys-apps/iproute2 )
@@ -78,6 +79,7 @@ src_configure() {
                $(use_with libnl)
                $(use_with lisp)
                $(use_with lua)
+               $(use_with mouse)
                $(use_with mpd)
                $(use_with ncurses)
                $(use_with net)
diff --git a/extra/xbm_icons/mouse.xbm b/extra/xbm_icons/mouse.xbm
new file mode 100755 (executable)
index 0000000..05e91b5
--- /dev/null
@@ -0,0 +1,4 @@
+#define mouse_01_width 8
+#define mouse_01_height 8
+static unsigned char mouse_01_bits[] = {
+ 0xEE, 0xEE, 0xEE, 0x82, 0xFE, 0xFE, 0xFE, 0x7C };
index 40bc5f2..a3d06e4 100644 (file)
--- a/m4/x11.m4
+++ b/m4/x11.m4
@@ -26,6 +26,7 @@ AC_DEFUN([TEST_X11],[
   WITH_COLOURS=0
   WITH_KEYBOARD=0
   WITH_DWM=0
+  WITH_MOUSE=0
 
   AC_ARG_WITH([dwm],
     AS_HELP_STRING([--with-dwm],
@@ -41,6 +42,13 @@ AC_DEFUN([TEST_X11],[
     [with_keyboard=no]
   )
 
+  AC_ARG_WITH([mouse],
+    AS_HELP_STRING([--with-mouse],
+      [X11 linker flag for mouse speed support]),
+    [],
+    [with_mouse=no]
+  )
+
   AC_ARG_WITH([colors],
     AS_HELP_STRING([--with-colors],
       [Colorize the output]),
@@ -54,7 +62,7 @@ AC_DEFUN([TEST_X11],[
     WITH_COLOURS=1
   ])
 
-  AS_IF([test "x$with_dwm" = "xyes" || test "x$with_keyboard" = "xyes"], [
+  AS_IF([test "x$with_dwm" = "xyes" || test "x$with_keyboard" = "xyes" || test "x$with_mouse" = "xyes"], [
     AC_CHECK_HEADERS([X11/Xlib.h X11/XKBlib.h], [
       X_LIBS="-lX11"
       ],[
@@ -85,6 +93,10 @@ AC_DEFUN([TEST_X11],[
     WITH_KEYBOARD=1
   ])
 
+  AS_IF([test "x$with_mouse" = "xyes"], [
+    WITH_MOUSE=1
+  ])
+
   AS_IF([test "x$with_dwm" = "xyes"], [
     WITH_DWM=1
   ])
@@ -92,9 +104,10 @@ AC_DEFUN([TEST_X11],[
   AC_SUBST(X_LIBS)
   AC_DEFINE_UNQUOTED([WITH_COLOURS],[$WITH_COLOURS],[Colorize the output])
   AC_DEFINE_UNQUOTED([WITH_KEYBOARD],[$WITH_KEYBOARD],[Query xorg to get the currently used kb layout])
+  AC_DEFINE_UNQUOTED([WITH_MOUSE],[$WITH_MOUSE],[Query xorg to get the current mouse speed])
   AC_DEFINE_UNQUOTED([WITH_DWM],[$WITH_DWM],[Output the data to the root window])
 
-  AS_IF([test "x$with_dwm" = "xyes" || test "x$with_keyboard" = "xyes"], [
+  AS_IF([test "x$with_dwm" = "xyes" || test "x$with_keyboard" = "xyes" || test "x$with_mouse" = "xyes"], [
     AC_LINK_IFELSE([
       AC_LANG_SOURCE([[
         #include <X11/Xlib.h>
index 627599e..eead8f6 100644 (file)
@@ -436,6 +436,25 @@ get_keyboard(char *str1) {
 #endif /* WITH_KEYBOARD && HAVE_X11_XKBLIB_H */
 
 
+/* Based on xset.c */
+#if WITH_MOUSE == 1 && defined(HAVE_X11_XLIB_H)
+void
+get_mouse(char *str1) {
+  Display *display = XOpenDisplay(NULL);
+  int acc_num = 0, acc_denom = 0, threshold = 0;
+
+  if (NULL == display) {
+    exit_with_err(CANNOT_OPEN, "X server");
+  }
+
+  XGetPointerControl(display, &acc_num, &acc_denom, &threshold);
+  FILL_ARR(str1, "%d", (110 - threshold));
+  XCloseDisplay(display);
+}
+
+#endif /* WITH_MOUSE && HAVE_X11_XLIB_H */
+
+
 #if !defined(HAVE_SENSORS_SENSORS_H) && !defined(__OpenBSD__)
 void 
 get_fans(char *str1) {
index 37cc905..dabf438 100644 (file)
@@ -49,6 +49,7 @@
 #define LOAD_STR   CPU_STR
 #define UP_STR     XBM_ICON("uptime.xbm")
 #define MAIL_STR   XBM_ICON("mail.xbm")
+#define MOUSE_STR  XBM_ICON("mouse.xbm")
 
 /* Only for the weather */
 #define OUT_STR    BLUE XBM_ICON("fox.xbm")" "
index 4c24232..83f7b8d 100644 (file)
@@ -59,6 +59,7 @@
 #define LOAD_STR   "Load/avg"
 #define OUT_STR    "Out "
 #define MAIL_STR   "Mail"
+#define MOUSE_STR  "Mouse"
 
 #endif /* HAVE_X11_XLIB_H || WITH_NCURSES || WITH_COLOURS */
 
index 0bf98c7..b2c1761 100644 (file)
@@ -57,6 +57,7 @@ enum {
   KEYBOARD,
   GMAIL,
   IP,
+  MOUSE,
   BULLSHIFT
 };
 const char *argp_program_version = PACKAGE_STRING;
@@ -183,6 +184,10 @@ static const struct argp_option options[] = {
   { .name = "keyboard",     .key = KEYBOARD,           .doc = "Query xorg and show the currently used keyboard layout."  },
 #endif /* WITH_KEYBOARD && HAVE_X11_XKBLIB_H */
 
+#if WITH_MOUSE == 1 && defined(HAVE_X11_XLIB_H)
+  { .name = "mouse",        .key = MOUSE,              .doc = "Query xorg to get the current mouse speed."               },
+#endif /* WITH_MOUSE && HAVE_X11_XLIB_H */
+
 #if !defined(__OpenBSD__)
   { .name = "ramshared",    .key = 'l',                .doc = "The shared ram."                                          },
   { .name = "rambuffer",    .key = 'o',                .doc = "The buffered ram."                                        },
@@ -391,10 +396,17 @@ parse_opt(int key, char *arg, struct argp_state *state) {
     NEW_MPD_LABEL('W', char song_track[VLA], song_track, 1, FMT_SONG);
 #endif /* HAVE_MPD_CLIENT_H */
 
+
 #if WITH_KEYBOARD == 1 && defined(HAVE_X11_XKBLIB_H)
     NEW_LABEL(KEYBOARD, char keyboard[VLA], keyboard, FMT_KERN);
 #endif /* WITH_KEYBOARD && HAVE_X11_XKBLIB_H */
 
+
+#if WITH_MOUSE == 1 && defined(HAVE_X11_XLIB_H)
+    NEW_LABEL(MOUSE, char mouse[VLA], mouse, FMT, MOUSE_STR);
+#endif /* WITH_MOUSE && HAVE_X11_XLIB_H */
+
+
 #if defined(HAVE_CDIO_CDIO_H) || defined(__linux__)
     NEW_LABEL('z', char dvd[VLA], dvd, FMT_KERN);
 #endif /* HAVE_CDIO_CDIO_H || __linux__ */
index 901e73f..527cae3 100644 (file)
@@ -47,7 +47,11 @@ void set_status(const char *);
 
 #if WITH_KEYBOARD == 1 && defined(HAVE_X11_XKBLIB_H)
 void get_keyboard(char *);
-#endif /* WITH_KEYBOARD */
+#endif /* WITH_KEYBOARD && HAVE_X11_XKBLIB_H */
+
+#if WITH_MOUSE == 1 && defined(HAVE_X11_XLIB_H)
+void get_mouse(char *);
+#endif /* WITH_MOUSE && HAVE_X11_XKBLIB_H */
 
 #if defined(HAVE_CDIO_CDIO_H) || defined(__linux__)
 void get_dvd(char *);