From 7cb14dfbf32e91561ccd0c87213df3b652d4333c Mon Sep 17 00:00:00 2001 From: Ryan Reaves Date: Sat, 29 Feb 2020 23:37:56 -0600 Subject: [PATCH] - Added proper shortcuts for browser tab and app switching, updated installer. Chromebook related, galliumOS, xfce. --- .xkb/symbols/mac_gui | 123 +++++++++++++++++++++++++++++++--- setup.py | 156 +++++++++++++++++++++++++------------------ 2 files changed, 205 insertions(+), 74 deletions(-) diff --git a/.xkb/symbols/mac_gui b/.xkb/symbols/mac_gui index b9f2530..4d13ea5 100644 --- a/.xkb/symbols/mac_gui +++ b/.xkb/symbols/mac_gui @@ -294,27 +294,29 @@ default partial xkb_symbols "mac_levelssym" { }; partial xkb_symbols "mac_appcycle_chromebook" { // Cycle App and In App Tab Switching - key { [ F13 ] }; - key { [ F14 ] }; replace key { - type[Group1]= "ONE_LEVEL_CMD", + type[Group1]= "ONE_LEVEL_CTRL", symbols[Group1]= [ Tab, Tab, - F14, - F13, + Tab, + Tab, + backslash, + backslash, NoSymbol, NoSymbol ], actions[Group1]= [ + NoAction(), + NoAction(), // Alt Redirect(key=,mods=Control,clearmods=Mod1), // Alt + Shift Redirect(key=,mods=Control,clearmods=Mod1), // Control - Redirect(key=), - // Control + Shift - Redirect(key=), + Redirect(key=), + // Control+Shift + Redirect(key=), // Super NoAction(), // Super + Shift @@ -337,9 +339,9 @@ partial xkb_symbols "mac_appcycle" { NoSymbol ], actions[Group1]= [ - // Alt + // Base NoAction(), - // Alt + Shift + // Shift NoAction(), // Control Redirect(key=), @@ -352,6 +354,102 @@ partial xkb_symbols "mac_appcycle" { ] }; }; +partial xkb_symbols "mac_browsers_chromebook" { + // Cycle App and In App Tab Switching + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ + Tab, + Tab, + NoSymbol, + NoSymbol, + backslash, + backslash, + NoSymbol, + NoSymbol + ], + actions[Group1]= [ + NoAction(), + NoAction(), + // Alt + Redirect(key=,mods=Control,clearmods=Mod1), + // Alt + Shift + Redirect(key=,mods=Control,clearmods=Mod1+Shift), + // Control + Redirect(key=), + // Control+Shift + Redirect(key=), + // Super + NoAction(), + // Super + Shift + NoAction() + ] + }; + //Up to Mac Home + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ + Up, + Up, + Up, + Up, + NoSymbol, + NoSymbol, + Up + ], + actions[Group1]= [ + NoAction(), + NoAction(), + // Wordwise + RedirectKey(key=,clearmods=Mod1), + RedirectKey(key=,clearmods=Mod1), + RedirectKey(key=), + RedirectKey(key=), + // Wordwise - Sublime? + RedirectKey(key=,clearmods=Super), + RedirectKey(key=,modifiers=Mod1,clearmods=Super) + ] + }; + // Down to Mac End + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ + Down, + Down, + Down, + Down, + NoSymbol, + NoSymbol, + Down + ], + actions[Group1]= [ + NoAction(), + NoAction(), + // Wordwise + RedirectKey(key=,clearmods=Mod1), + RedirectKey(key=,clearmods=Mod1), + RedirectKey(key=), + RedirectKey(key=), + // Wordwise - Sublime? + RedirectKey(key=,clearmods=Super), + RedirectKey(key=,modifiers=Mod1,clearmods=Super) + ] + }; + // Alt BKSP to DELETE + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ + BackSpace, + BackSpace, + BackSpace + ], + actions[Group1]= [ + NoAction(), + NoAction(), + RedirectKey(key=,clearmods=Mod1) + ] + }; +}; partial xkb_symbols "mac_browsers" { // Cycle App and In App Tab Switching key { [ F13 ] }; @@ -452,10 +550,15 @@ partial xkb_symbols "mac_chrome" { Left ], actions[Group1]= [ + // Base NoAction(), + // Shift NoAction(), + // Alt RedirectKey(key=), + // Alt RedirectKey(key=), + // Control RedirectKey(key=,modifiers=Mod1,clearmods=Control) ] }; diff --git a/setup.py b/setup.py index a4ac404..6756a30 100755 --- a/setup.py +++ b/setup.py @@ -33,8 +33,88 @@ def install_ibus(): input("IBus has been set as the default Input Method.\nPress any key to exit and re-run after logoff & logon...") sys.exit() +def setShortcuts(): + distro = cmdline("awk -F= '$1==\"NAME\" { print $2 ;}' /etc/os-release").replace('"','').strip() + distroVersion = cmdline("awk -F= '$1==\"VERSION_ID\" { print $2 ;}' /etc/os-release").replace('"','').strip() + dename = cmdline("./system-config/dename.sh").replace('"','').strip().split(" ")[0] + + print("\nIf Kinto is already running it will be stopped...") + print("If you cancel the installer you can re-run Kinto via\n systemctl --user start keyswap") + + cmdline("systemctl --user stop keyswap") + print("\nDetected " + distro + " " + distroVersion.strip() + " DE: " + dename + "\n") + addhotkeys = yn_choice("\nDo you want to apply system level shortcuts?") + if(addhotkeys): + distro = distro.lower() + if dename == "gnome": + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-applications \"['F13','F13','Tab']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-applications-backward \"['F14','F14','Tab']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") + if distro == "ubuntu" and dename == "gnome": + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left \"['Left','Left']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right \"['Right','Right']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") + elif distro == "pop!_os" and dename == "gnome": + cmdline("gsettings set org.gnome.desktop.wm.keybindings close \"['F4','w']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings toggle-maximized \"['F10','Up']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-up \"['Up','Left']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-down \"['Down','Right']\"") + elif distro == "elementaryos" and dename == "gnome": + cmdline("gsettings set org.gnome.desktop.wm.keybindings show-desktop \"['d','Down']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings toggle-maximized \"['F10','Up']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") + elif distro == "galliumos" and dename == "xfce": + print("Applying GalliumOS (xfce) shortcuts...") + # Reset Show desktop + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/d" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/d" --create --type string --set "show_desktop_key"') + # Reset App Cycle + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Tab" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Tab" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/backslash" --create --type string --set "cycle_windows_key"') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/backslash" --create --type string --set "cycle_reverse_windows_key"') + # cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/h" --create --type string --set "hide_window_key"') + # Don't need to undo other maps for menu + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/commands/custom/space" --create --type string --set "xfce4-popup-whiskermenu"') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/commands/custom/space" --create --type string --set "xfce4-popup-whiskermenu"') + # Reset move to desktop shortcuts + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Home" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/End" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Left" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Right" --reset') + os.system('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Left" --create --type string --set "move_window_prev_workspace_key"') + os.system('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Right" --create --type string --set "move_window_next_workspace_key"') + # Reset Change Workspace + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Left" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Right" --reset') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Left" --create --type string --set "left_workspace_key"') + cmdline('xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Right" --create --type string --set "right_workspace_key"') + print("\nYou may need to run these commands manually to make sure they are set, if you want to move windows between desktops.\n") + print(' xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Left" --create --type string --set "move_window_prev_workspace_key"') + print(' xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/Right" --create --type string --set "move_window_next_workspace_key"\n') + elif distro == "fedora" and dename == "gnome": + cmdline("gsettings set org.gnome.desktop.wm.keybindings show-desktop \"['d']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left \"['Left','Left']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right \"['Right','Right']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") + cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") + elif distro == "manjaro linux" and dename == "kde": + cmdline('kwriteconfig5 --file "$HOME/.config/kglobalshortcutsrc" --group "kwin" --key "Maximize Window" "Alt+F10,Meta+PgUp,Maximize Window"') + cmdline('kwriteconfig5 --file "$HOME/.config/kglobalshortcutsrc" --group "kwin" --key "Minimize Window" "Meta+h,Meta+PgDown,Minimize Window"') + cmdline('kwriteconfig5 --file "$HOME/.config/kglobalshortcutsrc" --group "kwin" --key "Switch to Next Desktop" "Meta+Right,Meta+Right,Switch to Next Desktop"') + cmdline('kwriteconfig5 --file "$HOME/.config/kglobalshortcutsrc" --group "kwin" --key "Switch to Previous Desktop" "Meta+Left,Meta+Left,Switch to Previous Desktop"') + cmdline('kquitapp5 kglobalaccel && sleep 2s && kglobalaccel5 &') + else: + print("A supported OS and DE was not found, you may not have full system level shortcuts installed.") + # check_x11 = cmdline("env | grep -i x11").strip() -check_x11 = cmdline("env | grep -i x11 || loginctl show-session \"$XDG_SESSION_ID\" -p Type | awk -F= '{print $2}'").strip() +check_x11 = cmdline("(env | grep -i x11 || loginctl show-session \"$XDG_SESSION_ID\" -p Type) | awk -F= '{print $2}'").strip() if len(check_x11) == 0: print("You are not using x11, please logout and back in using x11/Xorg") @@ -79,66 +159,6 @@ if len(check_xdotool) == 0: if runpkg != 0: requirements(pkgm) -distro = cmdline("awk -F= '$1==\"NAME\" { print $2 ;}' /etc/os-release").replace('"','').strip() -distroVersion = cmdline("awk -F= '$1==\"VERSION_ID\" { print $2 ;}' /etc/os-release").replace('"','').strip() -dename = cmdline("./system-config/dename.sh").replace('"','').strip() - -print("\nIf Kinto is already running it will be stopped...") -print("If you cancel the installer you can re-run Kinto via\n systemctl --user start keyswap") - -cmdline("systemctl --user stop keyswap") -addhotkeys = yn_choice("\nDo you want to apply system level shortcuts?") -if(addhotkeys): - print("\nDetected " + distro + " " + distroVersion.strip() + " DE: " + dename) - distro = distro.lower() - if dename == "gnome": - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-applications \"['F13','F13','Tab']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-applications-backward \"['F14','F14','Tab']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") - if distro == "ubuntu" and dename == "gnome": - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left \"['Left','Left']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right \"['Right','Right']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") - elif distro == "pop!_os" and dename == "gnome": - cmdline("gsettings set org.gnome.desktop.wm.keybindings close \"['F4','w']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings toggle-maximized \"['F10','Up']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-up \"['Up','Left']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-down \"['Down','Right']\"") - elif distro == "elementaryos" and dename == "gnome": - cmdline("gsettings set org.gnome.desktop.wm.keybindings show-desktop \"['d','Down']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings toggle-maximized \"['F10','Up']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") - elif distro == "galliumos" and dename == "xfce": - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/d\" --create --type string --set \"show_desktop_key\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/Tab\" --set \"cycle_reverse_windows_key\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/Tab\" --set \"cycle_windows_key\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/Tab\" --set \"cycle_windows_key\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/Tab\" --set \"cycle_reverse_windows_key\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/h\" --create --type string --set \"hide_window_key\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/commands/custom/space\" --create --type string --set \"xfce4-popup-whiskermenu\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/Left\" --create --type string --set \"move_window_prev_workspace_key\"") - cmdline("xfconf-query --channel xfce4-keyboard-shortcuts --property \"/xfwm4/custom/Right\" --create --type string --set \"move_window_next_workspace_key\"") - elif distro == "fedora" and dename == "gnome": - cmdline("gsettings set org.gnome.desktop.wm.keybindings show-desktop \"['d']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left \"['Left','Left']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right \"['Right','Right']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings minimize \"['h','F9']\"") - cmdline("gsettings set org.gnome.desktop.wm.keybindings panel-main-menu \"['Space','Space']\"") - elif distro == "manjaro linux" and dename == "kde": - cmdline("kwriteconfig5 --file \"$HOME/.config/kglobalshortcutsrc\" --group \"kwin\" --key \"Maximize Window\" \"Alt+F10,Meta+PgUp,Maximize Window\"") - cmdline("kwriteconfig5 --file \"$HOME/.config/kglobalshortcutsrc\" --group \"kwin\" --key \"Minimize Window\" \"Meta+h,Meta+PgDown,Minimize Window\"") - cmdline("kwriteconfig5 --file \"$HOME/.config/kglobalshortcutsrc\" --group \"kwin\" --key \"Switch to Next Desktop\" \"Meta+Right,Meta+Right,Switch to Next Desktop\"") - cmdline("kwriteconfig5 --file \"$HOME/.config/kglobalshortcutsrc\" --group \"kwin\" --key \"Switch to Previous Desktop\" \"Meta+Left,Meta+Left,Switch to Previous Desktop\"") - cmdline("kquitapp5 kglobalaccel && sleep 2s && kglobalaccel5 &") - else: - print("A supported OS and DE was not found, you may not have full system level shortcuts installed.") - if os.path.exists(homedir + '/.config/ibus/bus') and cmdline("ls ~/.config/ibus/bus -1rt") == "": install_ibus() @@ -205,6 +225,9 @@ print("") keyboardconfigs = [obj for obj in data['defaults'] if(obj['type'] == data['defaulttypes'][default-1])] + +setShortcuts() + # for k in keyboardconfigs: for index, k in enumerate(keyboardconfigs): print(color_arr[default-1] + bcolors.BOLD + str(index+1) + '. ' + k['name'] + bcolors.ENDC) @@ -243,8 +266,13 @@ cmdline('sed -i '' -e "' + types_line + 's/\\"/' + keyboardconfigs[defaultkb-1][ cmdline('sed -i '' -e "' + symbols_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_symbols_term'] + '\\"/2" ~/.xkb/keymap/kbd.mac.term') cmdline('sed -i '' -e "' + types_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_types_term'] + '\\"/2" ~/.xkb/keymap/kbd.mac.term') -cmdline('sed -i '' -e "' + symbols_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_symbols_gui'].replace("+mac_gui(mac_levelssym)+mac_gui(mac_appcycle)","+mac_gui(mac_levelssym)+mac_gui(mac_browsers)") + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.browsers') -cmdline('sed -i '' -e "' + symbols_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_symbols_gui'].replace("+mac_gui(mac_levelssym)+mac_gui(mac_appcycle)","+mac_gui(mac_browsers)+mac_gui(mac_chrome)") + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.chrome') +# Set chrome file accordingly for chromebooks or normal +if default != 3: + cmdline('sed -i '' -e "' + symbols_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_symbols_gui'].replace("+mac_gui(mac_levelssym)+mac_gui(mac_appcycle_chromebook)","+mac_gui(mac_levelssym)+mac_gui(mac_browsers)") + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.browsers') + cmdline('sed -i '' -e "' + symbols_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_symbols_gui'].replace("+mac_gui(mac_levelssym)+mac_gui(mac_appcycle_chromebook","+mac_gui(mac_browsers)+mac_gui(mac_chrome)") + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.chrome') +else: + cmdline('sed -i '' -e "' + symbols_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_symbols_gui'].replace("+mac_gui(mac_levelssym)+mac_gui(mac_appcycle_chromebook)","+mac_gui(mac_levelssym)+mac_gui(mac_browsers_chromebook)") + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.browsers') + cmdline('sed -i '' -e "' + symbols_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_symbols_gui'].replace("+mac_gui(mac_levelssym)+mac_gui(mac_appcycle_chromebook)","+mac_gui(mac_browsers_chromebook)+mac_gui(mac_chrome)") + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.chrome') cmdline('sed -i '' -e "' + types_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_types_gui'] + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.browsers') cmdline('sed -i '' -e "' + types_line + 's/\\"/' + keyboardconfigs[defaultkb-1]['xkb_types_gui'] + '\\"/2" ~/.xkb/keymap/kbd.mac.gui.chrome') @@ -253,7 +281,7 @@ user_file = homedir + '/.config/kinto/user_config.json' with open(user_file, 'r') as f: user_config = json.load(f) -onetime = yn_choice("One time initialization tweaks are available. Would you like to view them?") +onetime = yn_choice("\nOne time initialization tweaks are available. Would you like to view them?") print("") if(onetime): intents = [obj for obj in user_config['de'] if(obj['intent'] == "init")]