Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package xkb-switch for openSUSE:Factory 
checked in at 2021-03-18 22:54:52
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/xkb-switch (Old)
 and      /work/SRC/openSUSE:Factory/.xkb-switch.new.2401 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "xkb-switch"

Thu Mar 18 22:54:52 2021 rev:2 rq:879752 version:1.8.5

Changes:
--------
--- /work/SRC/openSUSE:Factory/xkb-switch/xkb-switch.changes    2020-12-02 
13:59:26.833878643 +0100
+++ /work/SRC/openSUSE:Factory/.xkb-switch.new.2401/xkb-switch.changes  
2021-03-18 22:54:53.467527632 +0100
@@ -1,0 +2,37 @@
+Wed Mar 17 02:20:30 UTC 2021 - Martin Rey <m...@suse.com>
+
+- Adapt spec file to corrctly rename man file
+
+- Update to version 1.8.5 
+  * Fix a potential int/char error
+
+- Changes from version 1.8.4
+  * Use optarg for arguments
+  * Fix longopt of -s
+
+- Changes from version 1.8.3
+  * Can process tightly coupled one letter flags
+  * Rewrote option parsing using getopt 
+
+- Changes from version 1.8.2
+  * Minor fix for CMakeLists.tx
+  * Use gzip as a manpage compression
+  * Adjust CMakeLists style
+  * Replace vimtest.sh with more powerful test.sh 
+  * Fix and update test.sh
+
+- Changes from version 1.8.1
+  * Better header names
+
+- Changes from version 1.8.0
+  * Change error messages
+
+- Changes from version 1.7.1
+  * Change default man compression tool to gz
+
+- Changes from version 1.7.0
+  * Add -d|--debug flag
+  * Print version in verbose mode
+  * Enhance debug printing
+
+-------------------------------------------------------------------

Old:
----
  1.6.0.tar.gz

New:
----
  1.8.5.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ xkb-switch.spec ++++++
--- /var/tmp/diff_new_pack.95Lo2P/_old  2021-03-18 22:54:54.003528211 +0100
+++ /var/tmp/diff_new_pack.95Lo2P/_new  2021-03-18 22:54:54.007528215 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package xkb-switch
 #
-# Copyright (c) 2020 SUSE LLC
+# Copyright (c) 2021 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -17,7 +17,7 @@
 
 
 Name:           xkb-switch
-Version:        1.6.0
+Version:        1.8.5
 Release:        0
 Summary:        Switch X keyboard layouts from the command line
 License:        GPL-3.0-only
@@ -45,6 +45,7 @@
   mv %{buildroot}%{_prefix}/lib/ %{buildroot}%{_libdir}
 fi
 rm -f %{buildroot}%{_libdir}/libxkbswitch.so
+mv %{buildroot}%{_mandir}/man1/xkb-switch.1.gzip 
%{buildroot}%{_mandir}/man1/xkb-switch.1.gz
 
 %post -p /sbin/ldconfig
 

++++++ 1.6.0.tar.gz -> 1.8.5.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/CMakeLists.txt 
new/xkb-switch-1.8.5/CMakeLists.txt
--- old/xkb-switch-1.6.0/CMakeLists.txt 2019-07-22 20:03:43.000000000 +0200
+++ new/xkb-switch-1.8.5/CMakeLists.txt 2021-02-03 00:50:00.000000000 +0100
@@ -2,18 +2,20 @@
 
 PROJECT( XKB-SWITCH )
 SET(MAJOR_VERSION 1)
-SET(MINOR_VERSION 6)
-SET(RELEASE_VERSION 0)
+SET(MINOR_VERSION 8)
+SET(RELEASE_VERSION 5)
 SET(XKBSWITCH_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${RELEASE_VERSION})
 ADD_DEFINITIONS(-DXKBSWITCH_VERSION="${XKBSWITCH_VERSION}")
 
 # Check presence of development libraries required for build
 FIND_PACKAGE(X11 REQUIRED)
 if(NOT X11_FOUND)
-    message(FATAL_ERROR "Not found development files of 'libx11' required for 
build. (Install libx11-dev or libx11-devel package.) CMake will exit.")
+    MESSAGE(FATAL_ERROR "Not found development files of 'libx11' required for 
build. (Install libx11-dev or libx11-devel package.) CMake will exit.")
 elseif(NOT X11_Xkbfile_FOUND)
-    message(FATAL_ERROR "Not found development files of 'libxkbfile' required 
for build. (Install libxkbfile-dev or libxkbfile-devel package.) CMake will 
exit.")
+    MESSAGE(FATAL_ERROR "Not found development files of 'libxkbfile' required 
for build. (Install libxkbfile-dev or libxkbfile-devel package.) CMake will 
exit.")
 endif()
+INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR})
+LINK_DIRECTORIES(${X11_LIBRARY_DIR})
 
 # Compile and link program
 OPTION(BUILD_XKBSWITCH_LIB
@@ -36,19 +38,16 @@
     LIBRARY DESTINATION lib OPTIONAL
 )
 
+SET(MAN_COMPRESSION "gzip" CACHE STRING "Manpages compression tool")
+SET(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE STRING "Manpages 
installation path")
+
 # Function to compress and install man page
 # Gets file name and type number
 function(install_man man_filename man_type)
     # check what compression tool is available
-    SET(MAN_COMPRESSION xz)
-    FIND_PROGRAM(COMPRESS_EXECUTABLE NAMES xz)
+    FIND_PROGRAM(COMPRESS_EXECUTABLE NAMES ${MAN_COMPRESSION})
     if(NOT COMPRESS_EXECUTABLE)
-        FIND_PROGRAM(COMPRESS_EXECUTABLE NAMES gzip)
-        if(COMPRESS_EXECUTABLE)
-            SET(MAN_COMPRESSION gz)
-        else()
-            SET(MAN_COMPRESSION NO)
-        endif()
+      SET(MAN_COMPRESSION NO)
     endif()
     # set input an output file names
     SET(raw_man man/${man_filename}.${man_type})
@@ -63,7 +62,7 @@
         )
     # elsewise just copy
     else()
-        MESSAGE(WARNING "There is no compression tool for man pages (xz or 
gzip). Not compressed copy of man file will be used.")
+        MESSAGE(WARNING "There is no compression tool for man pages (gzip). 
Not compressed copy of man file will be used.")
         SET(compressed_man ${CMAKE_BINARY_DIR}/${man_filename}.${man_type})
         ADD_CUSTOM_COMMAND(OUTPUT ${compressed_man}
             COMMAND cp ${raw_man} ${CMAKE_BINARY_DIR}
@@ -75,7 +74,7 @@
     # add actions
     ADD_CUSTOM_TARGET(man_${man_filename}_${man_type} ALL DEPENDS 
${compressed_man})
     INSTALL(FILES ${compressed_man}
-        DESTINATION share/man/man${man_type}
+        DESTINATION ${MANDIR}/man${man_type}
     )
 endfunction()
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/README.md 
new/xkb-switch-1.8.5/README.md
--- old/xkb-switch-1.6.0/README.md      2019-07-22 20:03:43.000000000 +0200
+++ new/xkb-switch-1.8.5/README.md      2021-02-03 00:50:00.000000000 +0100
@@ -18,49 +18,56 @@
 Installing
 ----------
 
-Make sure you have package *libxkbfile-dev* (or *libxkbfile-devel* for Fedora)
-installed. _CMake Hacker wanted: please help me to express this dependency in
-CMakeLists.txt_.
+Package *libxkbfile-dev* (or *libxkbfile-devel* for Fedora) needs to be
+installed to build the program.
 
 To build the program manually, unpack the tarball and cd to source directory.
 [Nix](http://nixos.org/nix) users may use `nix-shell` to enter the minimally
 sufficient development shell or `nix-build` to build the sources. Other
-distributions typically require the following commands to build in install the
+distributions typically require the following commands to build and install the
 program:
 
+```sh
+$ mkdir build && cd build
+$ cmake ..
+$ make
 ```
-    $ mkdir build && cd build
-    $ cmake ..
-    $ make
+
+Optionally, test the basic functions by running `./test.sh` script. The script
+should print OK in the last line and return exit code of zero.
+
+```sh
+$ ../test.sh 2>&1 | tee test.log
+$ tail -n 1 test.log | grep OK || echo "Test failed!"
 ```
 
 In order to install, use your system's package manager or default to the 
following:
 
-```
-    $ sudo make install
+```sh
+$ sudo make install
 ```
 
 On some distributions, you may need to update the program cache if it's the
 first time you're installing this program
 
-```
-    $ sudo ldconfig
+```sh
+$ sudo ldconfig
 ```
 
 Usage
 -----
 
 ```
-    $ xkb-switch --help
+$ xkb-switch --help
 
-    Usage: xkb-switch -s ARG            Sets current layout group to ARG
-           xkb-switch -l|--list         Displays all layout groups
-           xkb-switch -h|--help         Displays this message
-           xkb-switch -v|--version      Shows version number
-           xkb-switch -w|--wait [-p]    Waits for group change and exits
-           xkb-switch -W                Infinitely waits for group change
-           xkb-switch -n|--next         Switch to the next layout group
-           xkb-switch [-p]              Displays current layout group
+Usage: xkb-switch -s ARG            Sets current layout group to ARG
+       xkb-switch -l|--list         Displays all layout groups
+       xkb-switch -h|--help         Displays this message
+       xkb-switch -v|--version      Shows version number
+       xkb-switch -w|--wait [-p]    Waits for group change and exits
+       xkb-switch -W                Infinitely waits for group change
+       xkb-switch -n|--next         Switch to the next layout group
+       xkb-switch [-p]              Displays current layout group
 ```
 
 *A note on `xkb-switch -x`*
@@ -73,10 +80,10 @@
 Xkb-switch goes with a library libxkbswitch.so which can be called from
 within Vim scripts like this:
 
-```
-    let g:XkbSwitchLib = "/path/to/libxkbswitch.so"
-    echo libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '')
-    call libcall(g:XkbSwitchLib, 'Xkb_Switch_setXkbLayout', 'us')
+```vim
+let g:XkbSwitchLib = "/path/to/libxkbswitch.so"
+echo libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '')
+call libcall(g:XkbSwitchLib, 'Xkb_Switch_setXkbLayout', 'us')
 ```
 
 See also [article in 
Russian](http://lin-techdet.blogspot.ru/2012/12/vim-xkb-switch-libcall.html)
@@ -89,17 +96,17 @@
 input at it's stdin every time you want to trigger layouts from primary to
 secondary and back. For example:
 
-```
-    $ xkb-group.sh us ru
-    switch # switch from us to ru or from current layout to us
-    switch # switch from ru to us or from us to ru
-
-    (from other terminal)
-    $ xkb-switch -s de # switch to 'de' layout, change secondary layout to 'de'
-
-    (back to terminal running xkb-group.sh)
-    switch # switch from de to us
-    switch # switch from us to de
+```sh
+$ xkb-group.sh us ru
+switch # switch from us to ru or from current layout to us
+switch # switch from ru to us or from us to ru
+
+# from another terminal
+$ xkb-switch -s de # switch to 'de' layout, change secondary layout to 'de'
+
+# back to terminal running `xkb-group.sh'
+switch # switch from de to us
+switch # switch from us to de
 ```
 
 Bugs or Problems
@@ -108,6 +115,15 @@
 Admittedly, I only tested with a few different layouts that I used. If you find
 any bugs let me know by submitting an issue or via grr...@gmail.com.
 
+References:
+
+* <https://www.x.org/releases/X11R7.5/doc/input/XKB-Config.html>
+  - XKB configuration
+* <https://www.x.org/releases/current/doc/xorg-docs/input/XKB-Enhancing.html>
+  - How to further enhance XKB configuration
+* <https://0x64616c.livejournal.com/914.html>
+  - Old LJ post by Mitya describing minimalistic X11 kb test application
+
 Regards,
 Sergey.
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/src/Utils.hpp 
new/xkb-switch-1.8.5/src/Utils.hpp
--- old/xkb-switch-1.6.0/src/Utils.hpp  1970-01-01 01:00:00.000000000 +0100
+++ new/xkb-switch-1.8.5/src/Utils.hpp  2021-02-03 00:50:00.000000000 +0100
@@ -0,0 +1,49 @@
+/*
+ * C++ exceptions that wraps X11 errors.
+ *
+ * Copyright (C) 2008 by Jay Bromley <jbrom...@gmail.com>
+ *
+ * This file is part of Xkb-switch.
+ * Xkb-switch is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Xkb-switch is distributed in the hope that it will be useful,
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xkb-switch. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef XKBSWITCH_HPP
+#define XKBSWITCH_HPP
+
+#include <exception>
+#include <stdexcept>
+
+#define THROW_MSG(verbose, msg) do { \
+  std::ostringstream oss; \
+  if (verbose >= 2) { \
+    oss << __FILE__ << ":" << __LINE__ << ": "; \
+  } \
+  oss << msg; \
+  throw std::runtime_error(oss.str()); \
+} while(0)
+
+#define CHECK_MSG(verbose, x, msg) do { \
+  if(!(x)) { \
+    std::ostringstream oss; \
+    if (verbose >= 2) { \
+      oss << __FILE__ << ":" << __LINE__ << ": Condition " << #x << " failed. 
"; \
+    } \
+    oss << msg; \
+    throw std::runtime_error(oss.str()); \
+  } \
+} while(0)
+
+#define CHECK(verbose, x) CHECK_MSG(verbose, x, "")
+
+#endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/src/XKbSwitch.cpp 
new/xkb-switch-1.8.5/src/XKbSwitch.cpp
--- old/xkb-switch-1.6.0/src/XKbSwitch.cpp      2019-07-22 20:03:43.000000000 
+0200
+++ new/xkb-switch-1.8.5/src/XKbSwitch.cpp      2021-02-03 00:50:00.000000000 
+0100
@@ -22,9 +22,10 @@
 #include <iostream>
 #include <algorithm>
 #include <sstream>
+#include <getopt.h>
 
-#include "XKeyboard.h"
-#include "XKbSwitch.hpp"
+#include "XKeyboard.hpp"
+#include "Utils.hpp"
 
 using namespace std;
 using namespace kb;
@@ -38,6 +39,7 @@
   cerr << "       xkb-switch -w|--wait [-p]    Waits for group change" << endl;
   cerr << "       xkb-switch -W                Infinitely waits for group 
change, prints group names to stdout" << endl;
   cerr << "       xkb-switch -n|--next         Switch to the next layout 
group" << endl;
+  cerr << "       xkb-switch -d|--debug        Print debug information" << 
endl;
   cerr << "       xkb-switch [-p]              Displays current layout group" 
<< endl;
 }
 
@@ -58,9 +60,10 @@
 
 int main( int argc, char* argv[] )
 {
-       string_vector syms;
+  size_t verbose = 1;
+  string_vector syms;
+  bool syms_collected = false;
 
-       using namespace std;
   try {
     int m_cnt = 0;
     int m_wait = 0;
@@ -68,56 +71,82 @@
     int m_print = 0;
     int m_next = 0;
     int m_list = 0;
+    int opt;
+    int option_index = 0;
     string newgrp;
 
-    for(int i=1; i<argc; i) {
-      string arg(argv[i++]);
-      if(arg == "-s") {
-        CHECK_MSG(i<argc, "Argument expected");
-        newgrp=argv[i++];
+    static struct option long_options[] = {
+            {"set", required_argument, NULL, 's'},
+            {"list", no_argument, NULL, 'l'},
+            {"version", no_argument, NULL, 'v'},
+            {"wait", no_argument, NULL, 'w'},
+            {"longwait", no_argument, NULL, 'W'},
+            {"print", no_argument, NULL, 'p'},
+            {"next", no_argument, NULL, 'n'},
+            {"help", no_argument, NULL, 'h'},
+            {"debug", no_argument, NULL, 'd'},
+            {NULL, 0, NULL, 0},
+    };
+    while ((opt = getopt_long(argc, argv, "s:lvwWpnhd",
+                              long_options, &option_index))!=-1) {
+      switch (opt) {
+      case 's':
+        if (!optarg || string(optarg).empty())
+          CHECK_MSG(verbose, 0, "Argument expected");
+        newgrp=optarg;
         m_cnt++;
-      }
-      else if(arg == "-l" || arg == "--list") {
+        break;
+      case 'l':
         m_list = 1;
         m_cnt++;
-      }
-      else if(arg == "-v" || arg=="--version") {
+        break;
+      case 'v':
         cerr << "xkb-switch " << XKBSWITCH_VERSION << endl;
-        return 0;
-      }
-      else if(arg == "-w" || arg == "--wait") {
+        break;
+      case 'w':
         m_wait = 1;
         m_cnt++;
-      }
-      else if(arg == "-W" || arg == "--longwait") {
+        break;
+      case 'W':
         m_lwait = 1;
         m_cnt++;
-      }
-      else if(arg == "-p" || arg == "--print") {
+        break;
+      case 'p':
         m_print = 1;
         m_cnt++;
-      }
-      else if(arg == "-n" || arg == "--next") {
+        break;
+      case 'n':
         m_next = 1;
         m_cnt++;
-      }
-      else if(arg == "-h" || arg == "--help") {
+        break;
+      case 'h':
         usage();
-        return 1;
-      }
-      else {
-        THROW_MSG("Invalid argument: '" << arg << "'. Check --help.");
+        break;
+      case 'd':
+        verbose++;
+        break;
+      case '?':
+        THROW_MSG(verbose, "Invalid arguments. Check --help.");
+        break;
+      default:
+        THROW_MSG(verbose, "Invalid argument: '" << (char)opt << "'. Check 
--help.");
+        break;
       }
     }
 
-    if(m_list || m_lwait || !newgrp.empty())
-      CHECK_MSG(m_cnt==1, "Invalid flag combination. Try --help.");
+    if (verbose > 1) {
+      cerr << "[DEBUG] xkb-switch version " << XKBSWITCH_VERSION << endl;
+    }
+
+    if(m_list || m_lwait || !newgrp.empty()) {
+      CHECK_MSG(verbose, m_cnt==1, "Invalid flag combination. Try --help.");
+    }
 
     // Default action
     if(m_cnt==0)
       m_print = 1;
 
-    XKeyboard xkb;
+    XKeyboard xkb(verbose);
     xkb.open_display();
 
     if(m_wait) {
@@ -128,25 +157,29 @@
       while(true) {
         xkb.wait_event();
         xkb.build_layout(syms);
+        syms_collected = true;
         cout << syms.at(xkb.get_group()) << endl;
       }
     }
 
-    if (m_lwait)
-      syms.clear();
-
-    xkb.build_layout(syms);
+    layout_variant_strings lv = xkb.get_layout_variant();
+    if(verbose >= 2) {
+      cerr << "[DEBUG] layout: " << (lv.first.length() > 0 ? lv.first : 
"<empty>") << endl;
+      cerr << "[DEBUG] variant: " << (lv.second.length() > 0 ? lv.second : 
"<empty>") << endl;
+    }
+    xkb.build_layout_from(syms, lv);
+    syms_collected = true;
 
     if (m_next) {
-      CHECK_MSG(!syms.empty(), "No layout groups configured");
+      CHECK_MSG(verbose, !syms.empty(), "No layout groups configured");
       const string nextgrp = syms.at(xkb.get_group());
       string_vector::iterator i = find(syms.begin(), syms.end(), nextgrp);
-      if (++i == syms.end()) i = syms.begin();
+      if (++i == syms.end())i = syms.begin();
       xkb.set_group(i - syms.begin());
     }
     else if(!newgrp.empty()) {
       string_vector::iterator i = find(syms.begin(), syms.end(), newgrp);
-      CHECK_MSG(i!=syms.end(),
+      CHECK_MSG(verbose, i!=syms.end(),
         "Group '" << newgrp << "' is not supported by current layout. Try 
xkb-switch -l.");
       xkb.set_group(i-syms.begin());
     }
@@ -163,9 +196,15 @@
     return 0;
   }
   catch(std::exception & err) {
-    cerr << "xkb-switch: " << err.what() << endl;
-    // TODO: don't print syms if they are not yet collected
-    cerr << "xkb-switch: layouts: " << print_layouts(syms) << endl;
+    if ( verbose >= 2) {
+      cerr << "xkb-switch: ";
+    }
+    cerr << err.what() << endl;
+    if (verbose >= 2) {
+      if (syms_collected) {
+        cerr << "xkb-switch: layouts: " << print_layouts(syms) << endl;
+      }
+    }
     return 2;
   }
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/src/XKbSwitch.hpp 
new/xkb-switch-1.8.5/src/XKbSwitch.hpp
--- old/xkb-switch-1.6.0/src/XKbSwitch.hpp      2019-07-22 20:03:43.000000000 
+0200
+++ new/xkb-switch-1.8.5/src/XKbSwitch.hpp      1970-01-01 01:00:00.000000000 
+0100
@@ -1,43 +0,0 @@
-/*
- * C++ exceptions that wraps X11 errors.
- *
- * Copyright (C) 2008 by Jay Bromley <jbrom...@gmail.com>
- *
- * This file is part of Xkb-switch.
- * Xkb-switch is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Xkb-switch is distributed in the hope that it will be useful,
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xkb-switch. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef XKBSWITCH_HPP
-#define XKBSWITCH_HPP
-
-#include <exception>
-#include <stdexcept>
-
-#define THROW_MSG(msg) do{ \
-  std::ostringstream oss; \
-  oss << __FILE__ << ":" << __LINE__ << ":" << msg; \
-  throw std::runtime_error(oss.str()); \
-} while(0)
-
-#define CHECK_MSG(x,msg) do{ \
-  if(!(x)) { \
-    std::ostringstream oss; \
-    oss << __FILE__ << ":" << __LINE__ << ": Condition " << #x << " failed. " 
<< msg; \
-    throw std::runtime_error(oss.str()); \
-  } \
-} while(0)
-
-#define CHECK(x) CHECK_MSG(x,"")
-
-#endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/src/XKbSwitchApi.cpp 
new/xkb-switch-1.8.5/src/XKbSwitchApi.cpp
--- old/xkb-switch-1.6.0/src/XKbSwitchApi.cpp   2019-07-22 20:03:43.000000000 
+0200
+++ new/xkb-switch-1.8.5/src/XKbSwitchApi.cpp   2021-02-03 00:50:00.000000000 
+0100
@@ -10,7 +10,7 @@
  */
 
 #include <algorithm>
-#include "XKeyboard.h"
+#include "XKeyboard.hpp"
 
 using namespace std;
 using namespace kb;
@@ -38,7 +38,7 @@
 
                 try
                 {
-                    xkb = new XKeyboard();
+                    xkb = new XKeyboard((size_t)(-1));
                     xkb->open_display();
                 }
                 catch( ... )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/src/XKeyboard.cpp 
new/xkb-switch-1.8.5/src/XKeyboard.cpp
--- old/xkb-switch-1.6.0/src/XKeyboard.cpp      2019-07-22 20:03:43.000000000 
+0200
+++ new/xkb-switch-1.8.5/src/XKeyboard.cpp      2021-02-03 00:50:00.000000000 
+0100
@@ -21,13 +21,15 @@
 #include <X11/XKBlib.h>
 #include <X11/extensions/XKBrules.h>
 
-#include "XKeyboard.h"
-#include "XKbSwitch.hpp"
+#include "XKeyboard.hpp"
+#include "Utils.hpp"
+
+using namespace std;
 
 namespace kb {
 
-XKeyboard::XKeyboard()
-  : _display(0), _deviceId(XkbUseCoreKbd), _kbdDescPtr(0)
+XKeyboard::XKeyboard(size_t verbose)
+  : _display(0), _deviceId(XkbUseCoreKbd), _kbdDescPtr(0), _verbose(verbose)
 {
 }
 
@@ -48,16 +50,16 @@
   free(displayName);
   switch (reasonReturn) {
     case XkbOD_Success:           break;
-    case XkbOD_BadLibraryVersion: THROW_MSG("Bad XKB library version.");
-    case XkbOD_ConnectionRefused: THROW_MSG("Connection to X server refused.");
-    case XkbOD_BadServerVersion:  THROW_MSG("Bad X11 server version.");
-    case XkbOD_NonXkbServer:      THROW_MSG("XKB not present.");
-    default:                      THROW_MSG("XKB refused to open the display 
with reason '" << reasonReturn << "'.");
+    case XkbOD_BadLibraryVersion: THROW_MSG(_verbose, "Bad XKB library 
version.");
+    case XkbOD_ConnectionRefused: THROW_MSG(_verbose, "Connection to X server 
refused.");
+    case XkbOD_BadServerVersion:  THROW_MSG(_verbose, "Bad X11 server 
version.");
+    case XkbOD_NonXkbServer:      THROW_MSG(_verbose, "XKB not present.");
+    default:                      THROW_MSG(_verbose, "XKB refused to open the 
display with reason '" << reasonReturn << "'.");
   }
 
   _kbdDescPtr = XkbAllocKeyboard();
   if (_kbdDescPtr == NULL) {
-    THROW_MSG("Failed to get keyboard description.");
+    THROW_MSG(_verbose, "Failed to get keyboard description.");
   }
 
   _kbdDescPtr->dpy = _display;
@@ -95,8 +97,7 @@
   }
 };
 
-
-void XKeyboard::build_layout(string_vector& out)
+layout_variant_strings XKeyboard::get_layout_variant()
 {
   XkbRF_VarDefsRec_wrapper vdr;
   char* tmp = NULL;
@@ -104,10 +105,16 @@
 
   bret = XkbRF_GetNamesProp(_display, &tmp, &vdr._it);
   free(tmp);  // return memory allocated by XkbRF_GetNamesProp
-  CHECK_MSG(bret==True, "Failed to get keyboard properties");
+  CHECK_MSG(_verbose, bret==True, "Failed to get keyboard properties");
 
-  std::istringstream layout(vdr._it.layout ? vdr._it.layout : "us");
-  std::istringstream variant(vdr._it.variant ? vdr._it.variant : "");
+  return make_pair(string(vdr._it.layout ? vdr._it.layout : "us"),
+                   string(vdr._it.variant ? vdr._it.variant : ""));
+}
+
+void XKeyboard::build_layout_from(string_vector& out, const 
layout_variant_strings& lv)
+{
+  std::istringstream layout(lv.first);
+  std::istringstream variant(lv.second);
 
   while(true) {
     string l,v;
@@ -126,23 +133,30 @@
   }
 }
 
+
+void XKeyboard::build_layout(string_vector& out)
+{
+  layout_variant_strings lv=this->get_layout_variant();
+  build_layout_from(out, lv);
+}
+
 void XKeyboard::wait_event()
 {
-  CHECK(_display != 0);
+  CHECK(_verbose, _display != 0);
 
   Bool bret = XkbSelectEventDetails(_display, XkbUseCoreKbd,
       XkbStateNotify, XkbAllStateComponentsMask, XkbGroupStateMask);
-  CHECK_MSG(bret==True, "XkbSelectEventDetails failed");
+  CHECK_MSG(_verbose, bret==True, "XkbSelectEventDetails failed");
 
   XEvent event;
   int iret = XNextEvent(_display, &event);
-  CHECK_MSG(iret==0, "XNextEvent failed with " << iret);
+  CHECK_MSG(_verbose, iret==0, "XNextEvent failed with " << iret);
 }
 
 void XKeyboard::set_group(int groupNum)
 {
   Bool result = XkbLockGroup(_display, _deviceId, groupNum);
-  CHECK(result == True);
+  CHECK(_verbose, result == True);
   XFlush(_display);
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/src/XKeyboard.h 
new/xkb-switch-1.8.5/src/XKeyboard.h
--- old/xkb-switch-1.6.0/src/XKeyboard.h        2019-07-22 20:03:43.000000000 
+0200
+++ new/xkb-switch-1.8.5/src/XKeyboard.h        1970-01-01 01:00:00.000000000 
+0100
@@ -1,73 +0,0 @@
-/*
- * Interface for a class to get keyboard layout information and change layouts
- *
- * Copyright (C) 2008 by Jay Bromley <jbrom...@gmail.com>
- *
- * This file is part of Xkb-switch.
- * Xkb-switch is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Xkb-switch is distributed in the hope that it will be useful,
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xkb-switch. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef XKEYBOARD_H
-#define XKEYBOARD_H
-
-#include <vector>
-#include <string>
-#include <iostream>
-#include <sstream>
-#include <X11/Xlib.h>
-#include <X11/XKBlib.h>
-#include <map>
-#include <string>
-
-using std::string;
-
-namespace kb {
-
-typedef std::vector<std::string> string_vector;
-
-
-class XKeyboard
-{
-public:
-
-       Display* _display;
-       int _deviceId;
-       XkbDescRec* _kbdDescPtr;
-
-       XKeyboard();
-       ~XKeyboard();
-
-  // Opens display (or throw std::runtime_error)
-  void open_display(void);
-
-       // Gets the current layout
-       int get_group() const;
-
-       // Sets the layout
-       void set_group(int num);
-
-       // Returns keyboard layout string
-       void build_layout(string_vector& vec);
-
-       // Waits for kb event
-       void wait_event();
-
-private:
-
-};
-
-}
-
-#endif
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/src/XKeyboard.hpp 
new/xkb-switch-1.8.5/src/XKeyboard.hpp
--- old/xkb-switch-1.6.0/src/XKeyboard.hpp      1970-01-01 01:00:00.000000000 
+0100
+++ new/xkb-switch-1.8.5/src/XKeyboard.hpp      2021-02-03 00:50:00.000000000 
+0100
@@ -0,0 +1,73 @@
+/*
+ * Interface for a class to get keyboard layout information and change layouts
+ *
+ * Copyright (C) 2008 by Jay Bromley <jbrom...@gmail.com>
+ *
+ * This file is part of Xkb-switch.
+ * Xkb-switch is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Xkb-switch is distributed in the hope that it will be useful,
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xkb-switch. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef XKEYBOARD_HPP
+#define XKEYBOARD_HPP
+
+#include <vector>
+#include <string>
+#include <iostream>
+#include <sstream>
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include <map>
+#include <string>
+
+namespace kb {
+
+typedef std::vector<std::string> string_vector;
+typedef std::pair<std::string,std::string> layout_variant_strings;
+
+class XKeyboard
+{
+public:
+
+  Display* _display;
+  int _deviceId;
+  XkbDescRec* _kbdDescPtr;
+  size_t _verbose;
+
+  XKeyboard(size_t verbose);
+  ~XKeyboard();
+
+  // Opens display (or throw std::runtime_error)
+  void open_display(void);
+
+  // Gets the current layout
+  int get_group() const;
+
+  // Sets the layout
+  void set_group(int num);
+
+  // Return layout/variant strings
+  layout_variant_strings get_layout_variant();
+
+  // Returns keyboard layout string
+  void build_layout_from(string_vector& vec, const layout_variant_strings& lv);
+  void build_layout(string_vector& vec);
+
+  // Waits for kb event
+  void wait_event();
+};
+
+}
+
+#endif
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/test.sh new/xkb-switch-1.8.5/test.sh
--- old/xkb-switch-1.6.0/test.sh        1970-01-01 01:00:00.000000000 +0100
+++ new/xkb-switch-1.8.5/test.sh        2021-02-03 00:50:00.000000000 +0100
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+set -e -x
+
+LIB=./libxkbswitch.so
+X=./xkb-switch
+
+if ! test -f "$LIB" ; then
+  echo "$LIB not found. Did you run ./test.sh from the build directory?" >&2
+  exit 1
+fi
+
+if ! test -f "$X" ; then
+  echo "$X not found. Did you run ./test.sh from the build directory?" >&2
+  exit 1
+fi
+
+if ! which gcc ; then
+  echo "GCC not found, check your environment" >&2
+  exit 1
+fi
+
+if ! which vim; then
+  echo "VIM is required for this test, check your environment" >&2
+  exit 1
+fi
+
+if test -z "$DISPLAY" ; then
+  echo "This test requires X-server connection" >&2
+  exit 1
+fi
+
+if which git; then
+  git status -vv
+fi
+setxkbmap -query
+"$X" --version
+"$X" --version 2>&1 | grep -q xkb-switch
+"$X" --help 2>&1 | grep -q 'xkb-switch -s ARG'
+test "$($X --help)" = "$($X -h)"
+test "$($X --list)" = "$($X -l)"
+for l in $($X --list) ; do
+  "$X" -s "$l"
+  "$X" -ds "$l"
+  "$X" --set="$l"
+  test "$($X -p)" = "$l"
+done
+"$X" -n
+"$X" --next
+! test "$X" -s fooooo
+
+cat >/tmp/vimxkbswitch <<EOF
+let g:XkbSwitchLib = "$LIB"
+echo libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '')
+call libcall(g:XkbSwitchLib, 'Xkb_Switch_setXkbLayout', 'us')
+quit
+EOF
+
+STDLIB=$(gcc --print-file-name=libstdc++.so)
+LD_LIBRARY_PATH="`dirname $STDLIB`:$LD_LIBRARY_PATH" \
+  vim -S /tmp/vimxkbswitch
+
+echo OK
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/xkb-switch-1.6.0/vimtest.sh 
new/xkb-switch-1.8.5/vimtest.sh
--- old/xkb-switch-1.6.0/vimtest.sh     2019-07-22 20:03:43.000000000 +0200
+++ new/xkb-switch-1.8.5/vimtest.sh     1970-01-01 01:00:00.000000000 +0100
@@ -1,26 +0,0 @@
-#!/bin/sh
-
-LIB=`dirname $0`/build/libxkbswitch.so
-
-if ! test -f "$LIB" ; then
-        echo "$LIB not found. Try building it first" >&2
-        exit 1
-fi
-
-if ! which gcc ; then
-        echo "GCC not found" >&2
-        exit 1
-fi
-
-STDLIB=$(gcc --print-file-name=libstdc++.so)
-export LD_LIBRARY_PATH="`dirname $STDLIB`:$LD_LIBRARY_PATH"
-
-cat >/tmp/vimxkbswitch <<EOF
-let g:XkbSwitchLib = "$LIB"
-echo libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '')
-call libcall(g:XkbSwitchLib, 'Xkb_Switch_setXkbLayout', 'us')
-quit
-EOF
-
-vim -S /tmp/vimxkbswitch && echo OK
-

Reply via email to