hama-slide-mouse-control-1.0/0002755000175000017500000000000010637555356016015 5ustar richardrichardhama-slide-mouse-control-1.0/COPYING0000644000175000017500000004310310637521766017045 0ustar richardrichard GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. hama-slide-mouse-control-1.0/hama-slide-mouse-control.sgml0000644000175000017500000002706210637541676023516 0ustar richardrichard
richard atterer.net
RichardAtterer 2007Richard Atterer June 24, 2007
hama-slide-mouse-control 1 hama-slide-mouse-control Control settings of the Hama SLide S1 USB gaming mouse hama-slide-mouse-control idVendor:idProduct0-OR-MORE-COMMANDS Description This program controls the Hama SLide S1 USB gaming mouse: It allows changing the DPI settings and to switch between three different modes which influence the functionality of the two "thumb buttons". Note: To be able to access the USB mouse, the program must either be run as root, be installed suid root, or udev must have been configured to allow access for normal users. See the section "udev Setup" below. The option can be used to specify the USB device that the program should search for. The option argument is a string of the form "056e:001c" (this particular value is also the default), i.e. the USB vendor and product IDs in hexadecimal, separated by a colon. See the output of the lsusb command to find out the IDs of connected devices. Commands Zero or more commands can be specified on the command line. If no commands at all are present, the program can be used to check for the presence of a Hama SLide mouse on the machine via its exit status. Otherwise, the commands are executed in the supplied order. If more than one Hama SLide mouse is connected, all commands are executed on all mice. The mouse is a very simple device: You can only write settings to it, the current state of the settings cannot be read from it. Mode 1: Select DPI via Thumb Button 1 Command: scroll This is the default mode of the mouse, it is activated immediately after plugging in the device. In this mode, the scroll wheel selects the mouse DPI while thumb button 1 is pressed down. Clicks on thumb button 1 cannot be detected by the OS. Thumb button 2 acts like another right mouse button. The current DPI setting is left unchanged. Mode 2: Fixed DPI Setting Commands: 400 800 1200 1600 In this mode, the mouse resolution is set to one of four DPI values by specifying that value. Both thumb buttons are available to the OS - by default, they act like another middle and right mouse button. The colour of the scroll wheel indicates the DPI setting: blue (400 dpi), green (800 dpi), cyan (1200 dpi) or red (1600 dpi). Note: The program allows you to specify more than one command. You can use this to select a certain DPI value first, but switch to "scroll" mode again afterwards, e.g. with: hama-slide-mouse-control 400 scroll. A small, harmless hardware bug of the mouse exhibits itself in this case: When using the scroll wheel afterwards to select another resolution, the mouse orders the other DPI states as if the program-controlled DPI change had not taken place. MODE 3: Thumb Buttons Switch Between Two Fixed DPI Settings Commands: 400+800 400+1200 400+1600 800+1200 800+1600 1200+1600 When this mode is used, each of the two thumb buttons selects a certain DPI setting when clicked. Thumb button 1 always selects the lower, thumb button 2 the higher setting. This results in the different combinations above. The current DPI setting is left unchanged. Clicks on either thumb button cannot be detected by the OS in this mode. Return Codes The program returns 0 if all commands were successfully sent to the device. If no commands are given, it returns 0 if the mouse is plugged in. It returns 1 if no Hama SLide mouse (USB vendor 056e, product ID 001c) is connected to the computer. It returns 2 if there was an error sending commands to the mouse, either because the mouse returned an error in response to a command or because you do not have the access rights to change mouse settings. udev Setup under Linux Executing <command>hama-slide-mouse-control</command> when the mouse is plugged in If you have root access and you are the only user on your machine, use the following udev rule to set up the mouse. The given command will be executed whenever the mouse is plugged in or the computer boots or resumes. Simply create a file named /etc/udev/rules.d/60-hama-slide-mouse-control.rules with the following content. Of course, you can execute the program with parameters of your choice instead of "400": ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", RUN+="/root/bin/hama-slide-mouse-control 400" Execute udevcontrol reload_rules as root after any changes to the configuration file. Allowing users to set up the mouse on login If several users (possibly with differing wishes about the mouse setup) use the machine, it is possible give all users permission to set up the mouse, instead of only root. Put the following into /etc/udev/rules.d/60-hama-slide-mouse-control.rules: ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", MODE="666" Users can then run hama-slide-mouse-control from startup scripts when their Gnome or KDE desktop starts up. It should be noted that this setup will allow remotely logged-in users to annoy the local user by playing around with the settings and letting the mouse flash in all its colours! :-) Of course you can also add both the RUN and MODE keywords to the udev rule. Finally, you can restrict write access to users in a certain group, by using MODE="660", GROUP="hamamouse" or similar. Setting <command>hama-slide-mouse-control</command> suid root It is possible to set the suid bit on the hama-slide-mouse-control to allow ordinary users to change mouse settings even if they do not have access to the USB device. The program has been written with care, using it this way should be fairly safe. However, running hama-slide-mouse-control suid root is NOT recommended because suid binaries should be avoided in general! In this particular case, there is even less of a reason to do this, as udev provides a mechanism to allow all users to access the device. The option cannot be used if the program is run suid root. Assigning Actions to the Thumb Buttons With imwheel The author has been unable to get the thumb buttons to do anything other than act as "clones" of the middle and right mouse button, but at least one web page claims that it is possible to redefine the meaning of the buttons, so here is a short description of how to configure this with imwheel. Having installed imwheel, edit /etc/X11/imwheel/startup.conf: Set IMWHEEL_START=1 and IMWHEEL_PARAMS='-b "0 0 8 9"'. Next, check the Section "InputDevice" of your /etc/X11/xorg.conf file. It is recommended to use Option "Protocol" "evdev" and to comment out any ZAxisMapping and Buttons settings, as they can cause confusing behaviour with newer imwheel versions. Now configure mappings in your ~/.imwheelrc file. For example, two lines "^XMMS" and None, Thumb1, Return will define the (not very useful) action that in any window whose title starts with "XMMS", a click with "none" modifier keys (like Shift) on the Thumb1 button will simulate a keypress of the Return key. Restart X11 to have the new settings loaded. See Also lsusb8 , imwheel1 , xorg.conf5 , mouse4x , udev7 , udevcontrol8 About This Program This program and documentation was written by Richard Atterer. Copyright 2007 Richard Atterer, released under GPL v2. The USB commands that are sent to the device were obtained by reverse-engineering the protocol used by Hama's control program for Windows. This was done using usbsnoop/Snoopy by Benoit Papillault - many thanks!
hama-slide-mouse-control-1.0/Makefile0000644000175000017500000000221510637543410017437 0ustar richardrichard# Copyright 2007 Richard Atterer, GPLv2 # From "docbook-utils" package: DOCBOOK2MAN = schroot -c unstable -p -- docbook2man DOCBOOK2HTML = schroot -c unstable -p -- docbook2html #DEBUG = -DDEBUG .SUFFIXES: .1 .sgml .html .sgml.1: mkdir -p tmp && cp "$<" tmp \ && cd tmp && $(DOCBOOK2MAN) "`echo $< | sed 's%.*/%%'`" sed -e 's/ */ /g' <"`ls tmp/*.1`" >"$@" rm -rf tmp .sgml.html: rm -f "$@" $(DOCBOOK2HTML) "$<" --nochunks .PHONY: all doc maintainer-clean install all: hama-slide-mouse-control doc doc: hama-slide-mouse-control.1 hama-slide-mouse-control.html hama-slide-mouse-control: hama-slide-mouse-control.c Makefile $(CC) -lusb -Wall -W -O2 $(DEBUG) -o "$@" "$<" clean: rm -f *~ hama-slide-mouse-control maintainer-clean: clean rm -f hama-slide-mouse-control.html hama-slide-mouse-control.1 install: all install -d "$(DESTDIR)/usr/bin" install -s hama-slide-mouse-control "$(DESTDIR)/usr/bin" install -d "$(DESTDIR)/usr/share/man/man1" install -m 644 hama-slide-mouse-control.1 "$(DESTDIR)/usr/share/man/man1" install -d "$(DESTDIR)/etc/udev/rules.d" install -m 644 60-hama-slide-mouse-control.rules "$(DESTDIR)/etc/udev/rules.d" hama-slide-mouse-control-1.0/60-hama-slide-mouse-control.rules0000644000175000017500000000171610633353455024117 0ustar richardrichard# udev rules for hama-slide-mouse-control # Put this file in /etc/udev/rules.d and modify it to suit your needs. # Remember to execute "udevcontrol reload_rules" to make any changes active. # Uncomment an ACTION line: # Execute hama-slide-mouse-control whenever the device is detected. This example # appends the argument "400" to switch to fixed DPI mode, 400 DPI #ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", RUN+="/usr/bin/hama-slide-mouse-control 400" # Change access rights whenever the device is detected. All users can subsequently # execute hama-slide-mouse-control to control the mouse settings, not just root #ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", MODE="666" # As above, but only allow users in group 'hamamouse' to change mouse settings: #ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", MODE="660", GROUP="hamamouse" hama-slide-mouse-control-1.0/hama-slide-mouse-control.10000644000175000017500000002007510637543477022712 0ustar richardrichard.\" This manpage has been automatically generated by docbook2man .\" from a DocBook document. This tool can be found at: .\" .\" Please send any bug reports, improvements, comments, patches, .\" etc. to Steve Cheng . .TH "HAMA-SLIDE-MOUSE-CONTROL" "1" "24 June 2007" "" "" .SH NAME hama-slide-mouse-control \- Control settings of the Hama SLide S1 USB gaming mouse .SH SYNOPSIS \fBhama-slide-mouse-control\fR [ \fB [ -d \fIidVendor:idProduct\fB ] \fI0-OR-MORE-COMMANDS\fB\fI ...\fB \fR | \fB-h\fR | \fB--help\fR | \fB-v\fR | \fB--version\fR ] .SH "DESCRIPTION" .PP This program controls the Hama SLide S1 USB gaming mouse: It allows changing the DPI settings and to switch between three different modes which influence the functionality of the two "thumb buttons". .PP Note: To be able to access the USB mouse, the program must either be run as root, be installed suid root, or udev must have been configured to allow access for normal users. See the section "udev Setup" below. .PP The \fB-d\fR option can be used to specify the USB device that the program should search for. The option argument is a string of the form "056e:001c" (this particular value is also the default), i.e. the USB vendor and product IDs in hexadecimal, separated by a colon. See the output of the \fBlsusb\fR command to find out the IDs of connected devices. .SH "COMMANDS" .PP Zero or more commands can be specified on the command line. If no commands at all are present, the program can be used to check for the presence of a Hama SLide mouse on the machine via its exit status. Otherwise, the commands are executed in the supplied order. If more than one Hama SLide mouse is connected, all commands are executed on all mice. .PP The mouse is a very simple device: You can only write settings to it, the current state of the settings cannot be read from it. .SS "MODE 1: SELECT DPI VIA THUMB BUTTON 1" .PP Command: \fBscroll\fR .PP This is the default mode of the mouse, it is activated immediately after plugging in the device. In this mode, the scroll wheel selects the mouse DPI while thumb button 1 is pressed down. Clicks on thumb button 1 cannot be detected by the OS. Thumb button 2 acts like another right mouse button. The current DPI setting is left unchanged. .SS "MODE 2: FIXED DPI SETTING" .PP Commands: \fB400\fR \fB800\fR \fB1200\fR \fB1600\fR .PP In this mode, the mouse resolution is set to one of four DPI values by specifying that value. Both thumb buttons are available to the OS - by default, they act like another middle and right mouse button. The colour of the scroll wheel indicates the DPI setting: blue (400 dpi), green (800 dpi), cyan (1200 dpi) or red (1600 dpi). .PP Note: The program allows you to specify more than one command. You can use this to select a certain DPI value first, but switch to "scroll" mode again afterwards, e.g. with: \fBhama-slide-mouse-control 400 scroll\fR\&. A small, harmless hardware bug of the mouse exhibits itself in this case: When using the scroll wheel afterwards to select another resolution, the mouse orders the other DPI states as if the program-controlled DPI change had not taken place. .SS "MODE 3: THUMB BUTTONS SWITCH BETWEEN TWO FIXED DPI SETTINGS" .PP Commands: \fB400+800\fR \fB400+1200\fR \fB400+1600\fR \fB800+1200\fR \fB800+1600\fR \fB1200+1600\fR .PP When this mode is used, each of the two thumb buttons selects a certain DPI setting when clicked. Thumb button 1 always selects the lower, thumb button 2 the higher setting. This results in the different combinations above. The current DPI setting is left unchanged. Clicks on either thumb button cannot be detected by the OS in this mode. .SH "RETURN CODES" .PP The program returns 0 if all commands were successfully sent to the device. If no commands are given, it returns 0 if the mouse is plugged in. It returns 1 if no Hama SLide mouse (USB vendor 056e, product ID 001c) is connected to the computer. It returns 2 if there was an error sending commands to the mouse, either because the mouse returned an error in response to a command or because you do not have the access rights to change mouse settings. .SH "UDEV SETUP UNDER LINUX" .SS "EXECUTING HAMA-SLIDE-MOUSE-CONTROL WHEN THE MOUSE IS PLUGGED IN" .PP If you have root access and you are the only user on your machine, use the following udev rule to set up the mouse. The given command will be executed whenever the mouse is plugged in or the computer boots or resumes. Simply create a file named \fI/etc/udev/rules.d/60-hama-slide-mouse-control.rules\fR with the following content. Of course, you can execute the program with parameters of your choice instead of "400": .nf ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", RUN+="/root/bin/hama-slide-mouse-control 400" .fi .PP Execute \fBudevcontrol reload_rules\fR as root after any changes to the configuration file. .SS "ALLOWING USERS TO SET UP THE MOUSE ON LOGIN" .PP If several users (possibly with differing wishes about the mouse setup) use the machine, it is possible give all users permission to set up the mouse, instead of only root. Put the following into \fI/etc/udev/rules.d/60-hama-slide-mouse-control.rules\fR: .nf ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", MODE="666" .fi .PP Users can then run \fBhama-slide-mouse-control\fR from startup scripts when their Gnome or KDE desktop starts up. It should be noted that this setup will allow remotely logged-in users to annoy the local user by playing around with the settings and letting the mouse flash in all its colours! :-) Of course you can also add both the RUN and MODE keywords to the udev rule. Finally, you can restrict write access to users in a certain group, by using MODE="660", GROUP="hamamouse" or similar. .SH "SETTING HAMA-SLIDE-MOUSE-CONTROL SUID ROOT" .PP It is possible to set the suid bit on the \fBhama-slide-mouse-control\fR to allow ordinary users to change mouse settings even if they do not have access to the USB device. The program has been written with care, using it this way should be fairly safe. \fBHowever, running hama-slide-mouse-control suid root is NOT recommended\fR because suid binaries should be avoided in general! In this particular case, there is even less of a reason to do this, as udev provides a mechanism to allow all users to access the device. .PP The \fB-d\fR option cannot be used if the program is run suid root. .SH "ASSIGNING ACTIONS TO THE THUMB BUTTONS WITH IMWHEEL" .PP The author has been unable to get the thumb buttons to do anything other than act as "clones" of the middle and right mouse button, but at least one web page claims that it is possible to redefine the meaning of the buttons, so here is a short description of how to configure this with \fBimwheel\fR\&. .PP Having installed \fBimwheel\fR, edit \fI/etc/X11/imwheel/startup.conf\fR: Set IMWHEEL_START=1 and IMWHEEL_PARAMS='-b "0 0 8 9"'\&. Next, check the Section "InputDevice" of your \fI/etc/X11/xorg.conf\fR file. It is recommended to use Option "Protocol" "evdev" and to comment out any ZAxisMapping and Buttons settings, as they can cause confusing behaviour with newer imwheel versions. Now configure mappings in your \fI~/.imwheelrc\fR file. For example, two lines "^XMMS" and None, Thumb1, Return will define the (not very useful) action that in any window whose title starts with "XMMS", a click with "none" modifier keys (like Shift) on the Thumb1 button will simulate a keypress of the Return key. Restart X11 to have the new settings loaded. .SH "SEE ALSO" .PP \fBlsusb\fR(8), \fBimwheel\fR(1), \fBxorg.conf\fR(5), \fBmouse\fR(4x), \fBudev\fR(7), \fBudevcontrol\fR(8) .SH "ABOUT THIS PROGRAM" .PP This program and documentation was written by Richard Atterer \&. Copyright 2007 Richard Atterer, released under GPL v2. .PP The USB commands that are sent to the device were obtained by reverse-engineering the protocol used by Hama's control program for Windows. This was done using usbsnoop/Snoopy by Benoit Papillault - many thanks! hama-slide-mouse-control-1.0/hama-slide-mouse-control.html0000644000175000017500000002547210637543501023510 0ustar richardrichard hama-slide-mouse-control

hama-slide-mouse-control

Name

hama-slide-mouse-control -- Control settings of the Hama SLide S1 USB gaming mouse

Synopsis

hama-slide-mouse-control [ [-d idVendor:idProduct] {0-OR-MORE-COMMANDS...}
| -h | --help | -v | --version]

Description

This program controls the Hama SLide S1 USB gaming mouse: It allows changing the DPI settings and to switch between three different modes which influence the functionality of the two "thumb buttons".

Note: To be able to access the USB mouse, the program must either be run as root, be installed suid root, or udev must have been configured to allow access for normal users. See the section "udev Setup" below.

The -d option can be used to specify the USB device that the program should search for. The option argument is a string of the form "056e:001c" (this particular value is also the default), i.e. the USB vendor and product IDs in hexadecimal, separated by a colon. See the output of the lsusb command to find out the IDs of connected devices.

Commands

Zero or more commands can be specified on the command line. If no commands at all are present, the program can be used to check for the presence of a Hama SLide mouse on the machine via its exit status. Otherwise, the commands are executed in the supplied order. If more than one Hama SLide mouse is connected, all commands are executed on all mice.

The mouse is a very simple device: You can only write settings to it, the current state of the settings cannot be read from it.

Mode 1: Select DPI via Thumb Button 1

Command: scroll

This is the default mode of the mouse, it is activated immediately after plugging in the device. In this mode, the scroll wheel selects the mouse DPI while thumb button 1 is pressed down. Clicks on thumb button 1 cannot be detected by the OS. Thumb button 2 acts like another right mouse button. The current DPI setting is left unchanged.

Mode 2: Fixed DPI Setting

Commands: 400 800 1200 1600

In this mode, the mouse resolution is set to one of four DPI values by specifying that value. Both thumb buttons are available to the OS - by default, they act like another middle and right mouse button. The colour of the scroll wheel indicates the DPI setting: blue (400 dpi), green (800 dpi), cyan (1200 dpi) or red (1600 dpi).

Note: The program allows you to specify more than one command. You can use this to select a certain DPI value first, but switch to "scroll" mode again afterwards, e.g. with: hama-slide-mouse-control 400 scroll. A small, harmless hardware bug of the mouse exhibits itself in this case: When using the scroll wheel afterwards to select another resolution, the mouse orders the other DPI states as if the program-controlled DPI change had not taken place.

MODE 3: Thumb Buttons Switch Between Two Fixed DPI Settings

Commands: 400+800 400+1200 400+1600 800+1200 800+1600 1200+1600

When this mode is used, each of the two thumb buttons selects a certain DPI setting when clicked. Thumb button 1 always selects the lower, thumb button 2 the higher setting. This results in the different combinations above. The current DPI setting is left unchanged. Clicks on either thumb button cannot be detected by the OS in this mode.

Return Codes

The program returns 0 if all commands were successfully sent to the device. If no commands are given, it returns 0 if the mouse is plugged in. It returns 1 if no Hama SLide mouse (USB vendor 056e, product ID 001c) is connected to the computer. It returns 2 if there was an error sending commands to the mouse, either because the mouse returned an error in response to a command or because you do not have the access rights to change mouse settings.

udev Setup under Linux

Executing hama-slide-mouse-control when the mouse is plugged in

If you have root access and you are the only user on your machine, use the following udev rule to set up the mouse. The given command will be executed whenever the mouse is plugged in or the computer boots or resumes. Simply create a file named /etc/udev/rules.d/60-hama-slide-mouse-control.rules with the following content. Of course, you can execute the program with parameters of your choice instead of "400":

ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", RUN+="/root/bin/hama-slide-mouse-control 400"

Execute udevcontrol reload_rules as root after any changes to the configuration file.

Allowing users to set up the mouse on login

If several users (possibly with differing wishes about the mouse setup) use the machine, it is possible give all users permission to set up the mouse, instead of only root. Put the following into /etc/udev/rules.d/60-hama-slide-mouse-control.rules:

ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="056e", SYSFS{idProduct}=="001c", MODE="666"

Users can then run hama-slide-mouse-control from startup scripts when their Gnome or KDE desktop starts up. It should be noted that this setup will allow remotely logged-in users to annoy the local user by playing around with the settings and letting the mouse flash in all its colours! :-) Of course you can also add both the RUN and MODE keywords to the udev rule. Finally, you can restrict write access to users in a certain group, by using MODE="660", GROUP="hamamouse" or similar.

Setting hama-slide-mouse-control suid root

It is possible to set the suid bit on the hama-slide-mouse-control to allow ordinary users to change mouse settings even if they do not have access to the USB device. The program has been written with care, using it this way should be fairly safe. However, running hama-slide-mouse-control suid root is NOT recommended because suid binaries should be avoided in general! In this particular case, there is even less of a reason to do this, as udev provides a mechanism to allow all users to access the device.

The -d option cannot be used if the program is run suid root.

Assigning Actions to the Thumb Buttons With imwheel

The author has been unable to get the thumb buttons to do anything other than act as "clones" of the middle and right mouse button, but at least one web page claims that it is possible to redefine the meaning of the buttons, so here is a short description of how to configure this with imwheel.

Having installed imwheel, edit /etc/X11/imwheel/startup.conf: Set IMWHEEL_START=1 and IMWHEEL_PARAMS='-b "0 0 8 9"'. Next, check the Section "InputDevice" of your /etc/X11/xorg.conf file. It is recommended to use Option "Protocol" "evdev" and to comment out any ZAxisMapping and Buttons settings, as they can cause confusing behaviour with newer imwheel versions. Now configure mappings in your ~/.imwheelrc file. For example, two lines "^XMMS" and None, Thumb1, Return will define the (not very useful) action that in any window whose title starts with "XMMS", a click with "none" modifier keys (like Shift) on the Thumb1 button will simulate a keypress of the Return key. Restart X11 to have the new settings loaded.

See Also

lsusb(8), imwheel(1), xorg.conf(5), mouse(4x), udev(7), udevcontrol(8)

About This Program

This program and documentation was written by Richard Atterer. Copyright 2007 Richard Atterer, released under GPL v2.

The USB commands that are sent to the device were obtained by reverse-engineering the protocol used by Hama's control program for Windows. This was done using usbsnoop/Snoopy by Benoit Papillault - many thanks!

hama-slide-mouse-control-1.0/hama-slide-mouse-control.c0000644000175000017500000002245310637555030022762 0ustar richardrichard/* -*- C -*- __ _ |_) /| Copyright (C) 2007 | richard@ | \/¯| Richard Atterer | atterer.net ¯ '` ¯ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. See the file COPYING for details. */ #include #include #include #include #include #include /* #define DEBUG */ #define VERSION "1.0" /*______________________________________________________________________*/ # define BUFLEN 256 static char buf[BUFLEN]; /* Start control transfer to mouse, with given index. The answer of the mouse always appears to be the same 4 bytes for me: 4b 16 17 a0 - we ignore the answer. */ int myGetString(usb_dev_handle *dh, int index) { int bytes; # ifdef DEBUG fprintf(stderr, " Querying index %02x - ", index); # endif bytes = usb_get_string(dh, index, 0x409, buf, BUFLEN); if (bytes < 0) { fputs(usb_strerror(), stderr); fputc('\n', stderr); if (bytes == -1 && errno == EPERM) fputs("You either need to be root or configure udev " "to give you access to the device.\n", stderr); } else { # ifdef DEBUG int j; fprintf(stderr, "got %d bytes:", bytes); for (j = 0; j < bytes; ++j) fprintf(stderr, " %02x", (unsigned)(buf[j] & 0xff)); fputc('\n', stderr); # endif } return bytes; } /*______________________________________________________________________*/ /* Slide mouse found, send commands to it. Returns 0 if OK, -1 on error. */ int setupDevice(struct usb_device *dev, int argc, char* argv[]) { usb_dev_handle *dh; int i; # ifdef DEBUG fprintf(stderr, " Found Hama S1 Gaming Mouse!\n"); # endif dh = usb_open(dev); /* Reverse-engineered values of string indices: 0x51 UNKNOWN - is issued by Hama software when it starts up 0xb5 Change functionality of thumb button: Holding down button and using scroll wheel cycles through different resolutions (button creates no event when clicked, but scrolling creates button 4 events; 2nd thumb button creates button 3 events.) 0xb6 Change functionality of thumb button: Button is normal mouse button (1st thumb creates button 2, 2nd thumb creates button 3) 0x08 Switch resolution to 400 dpi, colour blue 0x0c Switch resolution to 800 dpi, colour green 0x11 Switch resolution to 1200 dpi, colour cyan 0x14 Switch resolution to 1600 dpi, colour red 0xb7 Change functionality of thumb buttons: 2 buttons switch to 2 different resolutions (1st thumb creates button 4, 2nd no events) 0x20 Two buttons, two resolutions: 400 / 800 dpi 0x22 Two buttons, two resolutions: 400 / 1200 dpi 0x24 Two buttons, two resolutions: 400 / 1600 dpi 0x2b Two buttons, two resolutions: 800 / 1200 dpi 0x2d Two buttons, two resolutions: 800 / 1600 dpi 0x32 Two buttons, two resolutions: 1200 / 1600 dpi Bugs: 1) In 0xb5, scroll wheel both cycles res AND generates "scroll up" events for OS. 2) (Also happens under Windows!) Previous setting is used as basis for cycling. If e.g. 1600dpi is set after plugging in, we do 0x0c to switch to 800, then cycle down by one resolution, the mouse will switch to 1200 dpi ("one down from 1600") instead of 400 ("one down from 800"). 3) Mouse remapping does not work, thumb buttons can only cause button 2/3 clicks. Kernel mouse driver hack probably needed for this. xmodmap -e "pointer = 1 2 3 4 5 6 7 8 9 10 11 12" */ for (i = 1; i < argc; ++i) { int ret; /* // Allow sending arbitrary hex indices: sscanf(argv[i], "%x", &index); ret = myGetString(dh, index);*/ // Scroll wheel changes DPI if (strcmp(argv[i], "scroll") == 0) { ret = myGetString(dh, 0xb5); // Fixed DPI } else if (strcmp(argv[i], "400") == 0) { ret = myGetString(dh, 0xb6); if (ret >= 0) ret = myGetString(dh, 0x08); } else if (strcmp(argv[i], "800") == 0) { ret = myGetString(dh, 0xb6); if (ret >= 0) ret = myGetString(dh, 0x0c); } else if (strcmp(argv[i], "1200") == 0) { ret = myGetString(dh, 0xb6); if (ret >= 0) ret = myGetString(dh, 0x11); } else if (strcmp(argv[i], "1600") == 0) { ret = myGetString(dh, 0xb6); if (ret >= 0) ret = myGetString(dh, 0x14); // Two different DPI values, switch via thumb buttons } else if (strcmp(argv[i], "400+800") == 0) { ret = myGetString(dh, 0xb7); if (ret >= 0) ret = myGetString(dh, 0x20); } else if (strcmp(argv[i], "400+1200") == 0) { ret = myGetString(dh, 0xb7); if (ret >= 0) ret = myGetString(dh, 0x22); } else if (strcmp(argv[i], "400+1600") == 0) { ret = myGetString(dh, 0xb7); if (ret >= 0) ret = myGetString(dh, 0x24); } else if (strcmp(argv[i], "800+1200") == 0) { ret = myGetString(dh, 0xb7); if (ret >= 0) ret = myGetString(dh, 0x2b); } else if (strcmp(argv[i], "800+1600") == 0) { ret = myGetString(dh, 0xb7); if (ret >= 0) ret = myGetString(dh, 0x2d); } else if (strcmp(argv[i], "1200+1600") == 0) { ret = myGetString(dh, 0xb7); if (ret >= 0) ret = myGetString(dh, 0x32); } else { fprintf(stderr, "Unknown command '%s'\n", argv[i]); ret = -EINVAL; } if (ret < 0) { usb_close(dh); return ret; } } if (usb_close(dh) < 0) { fprintf(stderr, "usb_close() failed\n"); return -1; } return 0; } /*______________________________________________________________________*/ /* Scan through all slide mice and attempt to send commands to them. Return 0 if at least one succeeds, 1 if none such mouse was found, 2 if there was an error sending commands. */ int scanAllDevices(uint16_t idVendor, uint16_t idProduct, int argc, char* argv[]) { struct usb_bus *busses; struct usb_bus *bus; int result = 2; int found = 0; busses = usb_get_busses(); // Scan busses for (bus = busses; bus; bus = bus->next) { struct usb_device *dev; # ifdef DEBUG fprintf(stderr, "Scanning bus %s\n", bus->dirname); # endif for (dev = bus->devices; dev; dev = dev->next) { # ifdef DEBUG fprintf(stderr, " Scanning device %04x:%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, dev->filename); # endif if (dev->descriptor.idVendor == idVendor && dev->descriptor.idProduct == idProduct) { // Mouse found! int ret = setupDevice(dev, argc, argv); ++found; if (ret == 0) result = 0; } } } if (found == 0) { fprintf(stderr, "No Hama SLide S1 USB mouse detected! " "(Looked for USB vendor/device %04x:%04x)\n", idVendor, idProduct); result = 1; } return result; } /*______________________________________________________________________*/ static const char* const helpMessage = "hama-slide-mouse-control version "VERSION"\n" "Copyright 2007 Richard Atterer, released under GPL v2.\n" "\n" "Syntax: hama-slide-mouse-control [-d :] [0 or more commands]\n" " -d :\n" " Specify USB device (default: -d 056e:001c) - see \"lsusb\" output\n" "Available commands:\n" " scroll Scroll wheel selects DPI while button 4 is pressed\n" " 400 Fixed value of 400 dpi (blue), buttons 4+5 act like 2+3\n" " 800 Fixed value of 800 dpi (green), buttons 4+5 act like 2+3\n" " 1200 Fixed value of 1200 dpi (cyan), buttons 4+5 act like 2+3\n" " 1600 Fixed value of 1600 dpi (red), buttons 4+5 act like 2+3\n" " 400+800 Buttons 4+5 select 400 dpi and 800 dpi\n" " 400+1200 Buttons 4+5 select 400 dpi and 1200 dpi\n" " 400+1600 Buttons 4+5 select 400 dpi and 1600 dpi\n" " 800+1200 Buttons 4+5 select 800 dpi and 1200 dpi\n" " 800+1600 Buttons 4+5 select 800 dpi and 1600 dpi\n" " 1200+1600 Buttons 4+5 select 1200 dpi and 1600 dpi\n" "You can supply several commands, e.g. '800 scroll'.\n" ; int main(int argc, char* argv[]) { if (argc >= 2) { if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { fputs(helpMessage, stdout); return 0; } else if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) { fputs(VERSION "\n", stdout); return 0; } } // Look for any -d option preceding the commands unsigned idVendor = 0x056e; unsigned idProduct = 0x001c; if (argc >= 2 && strcmp(argv[1], "-d") == 0) { // -d switch is only allowed if not running suid root if (getuid() != geteuid()) { fputs("Usage of -d is disallowed when this program is run suid root.\n", stderr); return 2; } if (argc == 2) { fputs("Missing argument to -d option.\n", stderr); return 2; } int len = -1; sscanf(argv[2], "%4x:%4x%n", &idVendor, &idProduct, &len); if (len != (int)strlen(argv[2]) || idVendor == 0) { fputs("Argument to -d option has wrong format. " "Use \"-d 056e:001c\" or similar - see the output of \"lsusb\".\n", stderr); return 2; } argc -= 2; argv += 2; } # ifdef DEBUG fprintf(stderr, "Device: %04x:%04x\n", idVendor, idProduct); # endif usb_init(); usb_find_busses(); usb_find_devices(); return scanAllDevices(idVendor, idProduct, argc, argv); }