Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't seem to work on Elementary OS #5

Closed
BenoitDuffez opened this issue Aug 9, 2019 · 17 comments
Closed

Doesn't seem to work on Elementary OS #5

BenoitDuffez opened this issue Aug 9, 2019 · 17 comments
Labels
bug Something isn't working

Comments

@BenoitDuffez
Copy link

I have Elementary OS (latest, up to date) and two Logitech K750 keyboards. One is windows layout, the other is mac. I used to use the windows one at work for linux, and the other one at home with my mac and my linux when working from home. I just had to create a new layout to swap @ and <, which for some reason were swapped.

I installed your script but it failed:



                      K!nt◎
            - F!x the dɑmn kɐyb◎ɑrd. - 

Press Enter to begin...

What type of system are you using?
    1) Windows
    2) Chromebook
    3) Mac
3

Would you like to swap Command back to Super/Win and Ctrl key back to Ctrl when using terminal applications? (y/n)
Note: For a more mac like experience & less issues with terminal based interactions y is recommended.
y

Looking for keyboards...

Internal Keyboard
Name: AT Translated Set 2 keyboard
ID: 17


USB Keyboard
Name: Microsoft_Microsoft_Nano_Transceiver_1.1
ID: 14
14
14

Setting up mac keyswap as a service.
You can disable and remove the service by using the following commands.
systemctl --user stop keyswap
systemctl --user disable keyswap
rm -rf ~/.config/autostart/keyswap.sh
rm -rf ~/.config/xactive.sh
/bin/bash -c "./keyswap_service.sh 1 0 mac 17 14
14
14 0"
+ swapbehavior=1
+ noswapcmd=0
+ systemtype=mac
+ internalid=17
+ usbid=14
+ chromeswap=
+ [[ 1 == \1 ]]
++ whoami
+ swapcmd='\/bin\/bash\ \/home\/bdu\/.config\/xactive.sh\ mac\ 17\ 14\ '
+ mkdir -p /home/bdu/.config/systemd/user
+ cp ./system-config/keyswap.service /home/bdu/.config/systemd/user/keyswap.service
+ cp ./system-config/keyswap.sh /home/bdu/.config/autostart/keyswap.sh
+ cp ./system-config/xactive.sh /home/bdu/.config/xactive.sh
++ whoami
+ sed -i 's/{username}/bdu/g' /home/bdu/.config/systemd/user/keyswap.service
+ sed -i 's/ExecStart=/ExecStart=\/bin\/bash\ \/home\/bdu\/.config\/xactive.sh\ mac\ 17\ 14\ /g' /home/bdu/.config/systemd/user/keyswap.service
+ systemctl --user enable keyswap
+ systemctl --user start keyswap
/bin/bash: line 1: 14: command not found
/bin/bash: line 2: 14: command not found
Traceback (most recent call last):
  File "./install.py", line 162, in <module>
    keyboard_detect()
  File "./install.py", line 82, in keyboard_detect
    subprocess.check_output(keyswapcmd, shell=True).decode('utf-8')
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '/bin/bash -c "./keyswap_service.sh 1 0 mac 17 14
14
14 0"' returned non-zero exit status 127.

I tried to read the install script, the keyswap service script (I just added set -x to see what it does), but nothing worked. The keys were not swapped.

@rbreaves
Copy link
Owner

rbreaves commented Aug 9, 2019

It's having difficulty parsing your keyboard info. I need to change that part of the installer, in most cases I really don't even need the id's of either an internal or external keyboard.

The issue

/bin/bash -c "./keyswap_service.sh 1 0 mac 17 14
14
14 0"

Quick work around

Use vi or nano, or editor of choice and update this file

~/.config/systemd/user/keyswap.service

It should say 17 14 0, but an carriage return is being inserted after 14, breaking the install and I think that's the only thing broken.

ExecStart=/bin/bash /home/ryanreaves/.config/xactive.sh mac 17 14 0

If you need to stop and start the keyswap service

systemctl --user stop keyswap
systemctl --user start keyswap

If you can run these 2 commands though I will review the output and update the installer to improve the parsing.

xinput list
udevadm info -e

rbreaves added a commit that referenced this issue Aug 9, 2019
…ards, only chromebooks will make use of device id's for external keyboards. Closes #5
@rbreaves
Copy link
Owner

rbreaves commented Aug 9, 2019

This issue has now been resolved. And an improvement to the parsing has been made for chromebook users that may need device id's of external keyboards. Further improvements to the parser may be made if the output of the above commands are shared.

@rbreaves rbreaves closed this as completed Aug 9, 2019
@rbreaves
Copy link
Owner

I just had to create a new layout to swap @ and <, which for some reason were swapped.

Could you provide me with the new layout you created? I believe I have another user that is German that experienced something similar, and if the keyswaps I am doing are not cross-compatible with US, French and German keyboards then I would like to fix it during the install if possible.

@BenoitDuffez
Copy link
Author

BenoitDuffez commented Oct 7, 2019

Hi @rbreaves I wish I had replied to you because some system upgrade erased what I did in /usr/share/X11/xkb and now my layout doesn't work anymore.

In fact I didn't use the mac keyboard anymore since I had access to a windows/linux keyboard every day. My son went by and broke my left control key, so now it's like I'm crippled in the terminal. I now use the mac keyboard, and this is how I noticed my keyboard layout was gone...

So what I did to fix it today seems hackish, instead of creating a new layout (this is what I needed at that time when I had the mac and windows/linux keyboards alternatively every week), I modified /usr/share/X11/xkb/symbols/fr and I swapped the TLDE and LSGT.

Here's my edit:

$ grep -nB1 was: /usr/share/X11/xkb/symbols/fr
862-    key <LSGT> {    [          at, numbersign, periodcentered,  Ydiaeresis  ]       }; // MISSING: Ydiaeresis; eherlent : ok in Latin9
863://was: key <TLDE> { [          at, numbersign, periodcentered,  Ydiaeresis  ]       }; // MISSING: Ydiaeresis; eherlent : ok in Latin9
--
904-    key <TLDE> {    [      less, greater, VoidSymbol, VoidSymbol    ]       };
905://was: key <LSGT> { [      less, greater, VoidSymbol, VoidSymbol    ]       };

The //was: line is a backup, and the line preceding it is my edit. Basically I just swapped the two keys and now @/< behave like my windows/linux keyboard. I just need to train my muscle memory because the right alt key is not physically the same size as before.

@rbreaves
Copy link
Owner

rbreaves commented Oct 9, 2019

Thank you, that could be useful to know.

Looks like I should be able to modify the layout easily enough in the users home directory and not touch the system level files.

setxkbmap -print > ~/.xkb/keymap/kbd.mac.gui
setxkbmap -print > ~/.xkb/keymap/kbd.mac.term

After printing the default layout info into those directories my script then adds in the proper custom layouts and I can add another inside the gui and term based symbol files for various languages as needed. More ideally though I'd just like to create an actual app for the system tray and a gui that can make remapping things like this a simple affair. Linux has a decent underlying xkb setup, but it feels like very few have taken the time to simplify it on the same level as karabiner on macos.

https://github.com/rbreaves/kinto/blob/master/.xkb/symbols/mac_gui
https://github.com/rbreaves/kinto/blob/master/.xkb/symbols/mac_term

@rbreaves
Copy link
Owner

@BenoitDuffez
Kinto has undergone a lot of changes since this ticket was last updated. I'd encourage you to try it out, but you may need to bring over your symbols or types modifications. Just make sure you backup your ~/.xkb working directory before updating as the setup will overwrite that directory.

@rbreaves rbreaves added the bug Something isn't working label Feb 20, 2020
@BenoitDuffez
Copy link
Author

Indeed, 187 commits! I tried again and it seems very nice. I'll have to see how my muscle memory will work out.
My problem is that I work 1/3 of my time on my laptop (windows keyboard since it's sold as a windows PC), and 2/3 of my time on an USB Keyboard (K750 for mac). So the layout on laptop is windows, and on the keyboard it's mac.
I don't know if it would be easy to handle both at a time? Or switch?

@rbreaves
Copy link
Owner

As long as the mac keyboard is an official Apple keyboard (macbook laptop) or Apple keyboard the linux hid driver should kick in and the setup will configure it to have the same layout as a Windows keyboard at that point.

So what I am saying is yes, you should be able to use both keyboards and at the same time as long as you select #2 and then #1 in the setup. I did that very purposefully so that I could switch myself without having to go back through the setup.

@BenoitDuffez
Copy link
Author

I got confused by the question the setup asked about that specifically. It's not an Apple branded keyboard it's Logitech. I have no idea what driver is used and if it's Linux hid. I just know that the two layouts are physically different and don't behave the same way. I'll run the setup again with these options and see how this works.

@rbreaves
Copy link
Owner

rbreaves commented Feb 22, 2020

Ah, I see then I am honestly not sure what’ll work best. If it has the command key in the right place then I’d pick “Mac Only” it specifies it’s for VMs & non-official Apple keyboards in the title now. (In the latest master)

If it’s laid out Windows style though then pick Windows. (Although a person with a Windows could select Mac w/ hid driver & it ought to still work.. it’d just set driver settings that won’t matter.)

@BenoitDuffez
Copy link
Author

It doesn't seem to do what I have on my mac.

Bottom left layout of my keyboards: (❖ means windows key)

  • macbook air: fn
  • logitech K750:
  • HP laptop: ctrl fn alt

My mac with either the Logitech K750 or the laptop keyboard have the exact same behavior. My Elementary with choices 2-1 doesn't work, as I don't have the /sys/module/hid_apple. So I chose 2-2 which works, but then I have this behavior (compared to my mac):

Keys pressed Behavior on Mac Behavior on Elementary + Kinto "2-2" in setup
⌘C copy copy
⌘tab change app change tab 👎
⌃tab change tab nothing 👎
⌥arrow move to next word nothing 👎
⌃C in terminal SIGINT SIGINT
⌘C in terminal copy SIGINT 👎

I guess it's simply not possible and I'll keep using my Linux without Kinto and the default "Mac" layout on Elementary. This is what I have and I can cope with:

Desired behavior Keys on Mac Keys on Elementary default "Mac" layout + K750 Keys on Elementary default "Mac" layout + internal HP keyboard
copy ⌘C ⌃C ctrl-C
change app ⌘tab ⌥tab alt-tab
change tab ⌃tab ⌃tab ctrl-tab
change workspace ⌃arrow ⌘arrow ❖arrow
move to next word ⌥arrow ⌃arrow ctrl-arrow
SIGINT ⌃C ⌃C ctrl-C

The only difference between HP keyboard and K750 keyboard is that meta and alt are swapped: alt vs .

The perfect world for me would be to use the same shortcuts for both mac and Linux on that second table.

Also, I don't need to copy the terminal, as I use tmux and selection actually copies to clipboard. I paste with shift-inser most of the time, sometimes with mouse wheel, or sometimes with ⌃⇧V (depending on what clipboard I want to paste from). Also I remapped ⇪ (caps lock) to actually behave like control (both on mac and linux) as my shortcut for tmux is ⌃Q and on my azerty keyboard, Q is in front of ⇪.

@rbreaves
Copy link
Owner

rbreaves commented Feb 23, 2020

The logitech keyboard with the mac key layout should be following the 2-2 layout, assuming linux will not use the hid driver.

The HP laptop however with a windows key layout should be using the 1-1 layout for Windows. The keyboard type only references your keyboard type, not the style it'll be mapping to.

Kinto probably should remap Ctrl+Tab to Alt+Tab, as that does seem to be the universal hotkey btwn distros to switch apps and would bring it into alignment with macOS. The question then is where to relocate Ctrl+Tab, to the Alt+Tab or the Super+Tab position. I am leaning towards placing Ctrl+Tab on the Super+Tab position for the sake of sublime text in particular as that would place it back into the normal position to change tabs in Sublime and browsers. And then also place Super+Tab on the Alt+Tab position.

Behavior Elementary/Ubuntu Default Mac Keymap Fix
change app Alt + Tab Cmd + Tab Ctrl+Tab -> Alt + Tab
change tab in app Ctrl + Tab Ctrl + Tab Super + Tab -> Ctrl + Tab
change workspaces Super + Arrow/Tab Ctrl + Left/Right Super + Left/Right -> Ctrl + Left/Right

A little funky, but I think that would get the job done in a manner that makes the most sense. If there are some apps that don't like it then exceptions can be made for those apps easily enough.

I am still not sure if there is a wordwise problem though, I can't seem to duplicate one, so I am wondering if for your HP keyboard if you had selected the Windows keyboard or not as that should sort out the keys to where wordwise would work (but I would have thought the same for 2-1 as well). Again 2-2 is the one that should work for the logitech, unless it did work with the apple driver then it'd be 2-1.

@rbreaves
Copy link
Owner

This really falls into the Translation Table project I bulleted out in another Ticket - because I am not into making one off changes that may not carry over to a majority of other distros.

I will begin work on the Translation Table between ElementaryOS and others. Anyone is welcome to make whatever one off changes they want to the xkb files or create new xbindkeys files, but Kinto, as an app, needs to focus on what I can comfortably confirm will be the same across distros or DE's shortcut wise.

Extra logic can be added to the setup file though to use specific keymaps in various situations - but that just speaks to the care that needs to take place before making assumptions about shortcut keys from one distro or DE to the next.

@rbreaves
Copy link
Owner

With this ticket being closed if you want to continue the discussion about shortcut keys we can do so in this open ticket. #44 @BenoitDuffez but I do hear you, app switching is pretty basic and needs to be aligned at the very least.

@rbreaves
Copy link
Owner

rbreaves commented Feb 24, 2020

@BenoitDuffez In this commit in Dev the in app tab switching should be fixed and the App Tab Switching is too with an exception.. You will have to update your DE, Gnome, KDE or whatever it is to use Ctrl + \ as the hotkey for app switching. I wish I could have done it differently, but with every attempt I tried it just appeared to fail to pickup properly. I think the xkb remap for some reason doesn't pass the held down modifier properly to the app switcher, but by keeping the hotkey on Ctrl it fixes that.

9b97bd9

Also the reason the App Switcher can't just be mapped from Alt+Tab or Super+Tab to Ctrl+Tab is that most in app tab switching occurs on Ctrl+Tab, so I have to avoid that conflict or we'd lose in app tab switching when you press the physical Ctrl+Tab (which is Super+Tab but maps to Ctrl+Tab in actuality so other apps don't need remapping, if I have to remap the DE vs individual apps I will pick the DE).

Before making this an official release I will add a builtin tweak to remap Gnome, KDE, or XFCE properly so users don't have to setup Ctrl + \.

@BenoitDuffez
Copy link
Author

I'll try that tomorrow. Meanwhile I have a question: what layout should I choose on the os settings? By default it would be french, which uses the same layout as the windows layout printed on the hp keyboard. However I have switched that to French (Mac) which changes some keys (like @ or ! or $).

Before running kinto setup should I put Mac or default (windows) layout? I'm not talking about meta/alt/control.

@rbreaves
Copy link
Owner

rbreaves commented Feb 24, 2020

I am not sure, I am guessing you are talking about what comes back you type in?

$ setxkbmap -query
rules:      evdev
model:      pc105
layout:     us,us
variant:    ,

I have never needed to change my keyboard from the English after the distro setup/install and have never specified Mac for even my official mac keyboard, but you can certainly try it either way. It should not impact the setup process at all, so you can change it after the fact just fine.

One thing you may want to be aware of though is that I often reset the keyboard back to their defaults by running this command.

setxkbmap -option

I don't really know how that impacts users that installed linux under a different language from US. I assume it defaults to their own language just fine, but you can replace that command in the defaults.json and/or user_config.json before or after the install.

If you modify it after the install then it is just ~/.config/kinto/user_config.json. You can easily try other variations such as

setxkbmap -layout fr -variant mac

If you need to do so, and please let me know if that helps any, because I simply do not know atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants