Skip to content

Commit

Permalink
1.01: First public release
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Jun 1, 2019
1 parent eaf2922 commit 01d8fb3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
34 changes: 18 additions & 16 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,42 @@
This is free software under GNU GPLv3.

Installation

Unpack archive and copy the s1kls file to the any location that is suitable for programs.

Command line


Unpack archive and copy as root the s1kls file to the any location that is suitable for programs, /usr/bin/ for instance
It is recommended to run this program with root privileges for better poll accuracy. For do this set after installation SUID flag:
chmod u+s /usr/bin/s1kls

Command line

xkbs1kls keycode1 keycode2 ...

The key with keycode 'keycode1' sets the layout 1,
the key with keycode 'keycode2' sets the layout 2 ...

Features

Only LockGroup switch type supported (each key select the own layout). No layout indicator supported.
Key codes you can find out by calling this program in the terminal without parameters.

Backgrownd
Standard X11 layout switcher is activated immediately by pressing the keys and therefore conflicts with the application shortcuts.

Standard X11 layout switcher is activated immediately by pressing the keys and therefore conflicts with the application shortcuts.
This switcher is activated by releasing the keys, but only under the condition that no other key is pressed. For example, You were asked to switch to the layout 2 by RCtrl. Then if You press and release RCtrl, the layout will be switched. But if You pressed in a text editor RCtrl-Right, then the editor performs jump forward a word and layout will not be switched.

If You need a layout indicator, You can use a standard X11 LED indicator or any tray indicator as xxkb.

Example

I use 3 layouts: (us,ru,ua), LED "ScrollLock" as indicator and keys following: RShift sets "us", RCtrl sets "ru" and RWin sets "ua". On the pc105 keyboard these keys have the keycodes 62, 105 and 134.

In the X11 keyboard config (in my ArchLinux it is the file /etc/X11/xorg.conf.d/01-keyboard-layout.conf) I define:

Option "XkbLayout" "us, ru, ua"
Option "XkbOptions" "grp_led:scroll"

In the autostart I call this program:

xkbs1kls 62 105 134 &


https://sourceforge.net/projects/s1kls/
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gcc -lX11 s1kls.c -O2 -o xkbs1kls
gcc -lX11 -pthread s1kls.c -O2 -o xkbs1kls
17 changes: 14 additions & 3 deletions s1kls.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ but only yf no other key(s) has been pressed.
Developed by Alexey Korop, 2014
Compile:
gcc -lX11 s1kls.c -o xkbs1kls
gcc -lX11 -pthread s1kls.c -o xkbs1kls
This program is free software, under the GNU General Public License
version 3.
Expand All @@ -20,10 +20,11 @@ but only yf no other key(s) has been pressed.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <pthread.h>

//#define TRACE

Expand All @@ -41,6 +42,14 @@ static int switcher[16];

typedef unsigned char bool;

/* set realtime priority if possible */
void set_rt_prio(void){
struct sched_param param;

param.__sched_priority = 1;
pthread_setschedparam(pthread_self(), SCHED_FIFO, &param); // do not check success
}

int main(int argc, char *argv[]) {
Display *display;
char keys_cur[32], keys_prev[32];
Expand All @@ -63,15 +72,17 @@ int main(int argc, char *argv[]) {
}
if (n < 2){
help:
printf("Simple X11 1-key Keyboard layout switcher. Version 1.00.\n");
printf("Simple X11 1-key Keyboard layout switcher. Version 1.01.\n");
printf("(c) Alexey Korop, 2014. Free software under GNU GPLv3\n\n");
printf("It is recommended to run this program with root privileges for better poll accuracy\n");
printf("Command line: s1kls keycode1 keycode2 ...\n\n");
printf("The key with keycode 'keycode1' sets the layout 1, \n");
printf("the key with keycode 'keycode2' sets the layout 2 ... \n\n");
printf("Now You may press the desired keys and see their keycodes.\n");
view_codes = 1;
}

set_rt_prio();
display = XOpenDisplay(NULL);
if (display == NULL){
fprintf(stderr, "XOpenDisplay error \n");
Expand Down

0 comments on commit 01d8fb3

Please sign in to comment.