0

Chrome - hardcoding new keyboard shortcuts

Wed, 16 Dec 2015 (tags:linux, chrome, features)

What

On Thinkpads there are 2 nice keys near cursor keys, by default they are configured to be multimedia keys, back/forward. In chrome this default configuration can be annoying, filling form and in middle of it one accidental press and you are back. If you don't have extensions like lazarus you might lose your form content which can be frustrating. For me most pleasing approach was to change the keys to F14 and F15 with xmod and allowed me easier shortcuts in eclipse and other applications. Now I often bind these keys to swap between the tabs, move them and to iterate search results and other tasks. Now these key are absolutely essential for my UI pleasure :)

To utilize these keys in chrome I had hotkeys extension which is bit dodgy and still doesn't do everything I want. Then I very often duplicate tabs and hate doing it with mouse, so I run separate  extension called surprisingly Duplicate Tab Shortcut. The Alt+ for duplication was introduced just recently and is not pleasant on laptops, so I like mine approach anyway (plus this approach can be applied to older versions too).

But I got fed up with it and decided to hardcode my shortcuts, will save bits of resources (i don't like having bloated browser with dozens of plugins).

TL;DR - Downloads

If you trust strangers with binaries, here are compiled packages:

Version 52 and newer are linked in this article.

Features

Without modifiers you select next / previous tabs.

With Shift+Ctrl you can move selected tab.

With Shift you can get next/prev search result when you use Ctrl+F find (the next shortcut is similar to enter, but i like it this way)

With CTRL you can bookmark one page, or all tabs. This is handy because CTRL+W will close the tab, so you can quickly go through tabs, decide which one to bookmark and close very quickly.

With ALT you can duplicate tab and reload tab with clean cache (other shortcuts just ignore cache, this one clears cache first and then calls the regular ignore cache, it's more aggressive. See file chromium-browser-47.0.2526.73/chrome/browser/ui/browser_command_controller.cc)

 

How

I downloaded source and compiled it as descried in my previous blog post. I don't know how google managed to do, but for this huge source base the chromium source is rather pleasant to browse and to find parts of code you want to modify.

And I modified file: chromium-browser-47.0.2526.73/chrome/browser/ui/views/accelerator_table.cc
For more commands look at file chromium-browser-47.0.2526.73/chrome/browser/ui/browser_command_controller.cc

 

// For many commands, the Mac equivalent uses Cmd instead of Ctrl. We only need
// to list the ones that do not have a key equivalent in the main menu, i.e.
// only the ones in global_keyboard_shortcuts_mac.mm.
// TODO(jackhou): If-def out the accelerators that should not be on Mac.
#if defined(OS_MACOSX)
const ui::EventFlags kPlatformModifier = ui::EF_COMMAND_DOWN;
#else
const ui::EventFlags kPlatformModifier = ui::EF_CONTROL_DOWN;
#endif
 
// NOTE: Keep this list in the same (mostly-alphabetical) order as
// the Windows accelerators in ../../app/chrome_dll.rc.
// Do not use Ctrl-Alt as a shortcut modifier, as it is used by i18n keyboards:
// http://blogs.msdn.com/b/oldnewthing/archive/2004/03/29/101121.aspx
const AcceleratorMapping kAcceleratorMap[] = {
//Anton-begin Thinkpad custom shortcuts
  { ui::VKEY_F15, ui::EF_NONE, IDC_SELECT_NEXT_TAB },
  { ui::VKEY_F14, ui::EF_NONE, IDC_SELECT_PREVIOUS_TAB },
 
  { ui::VKEY_F15, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, IDC_MOVE_TAB_NEXT },
  { ui::VKEY_F14, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, IDC_MOVE_TAB_PREVIOUS },
 
  { ui::VKEY_F15, ui::EF_CONTROL_DOWN, IDC_BOOKMARK_PAGE },
  { ui::VKEY_F14, ui::EF_CONTROL_DOWN, IDC_BOOKMARK_ALL_TABS },
 
  { ui::VKEY_F15, ui::EF_SHIFT_DOWN, IDC_FIND_NEXT },
  { ui::VKEY_F14, ui::EF_SHIFT_DOWN, IDC_FIND_PREVIOUS },
 
  { ui::VKEY_F15, ui::EF_ALT_DOWN, IDC_DUPLICATE_TAB },
  { ui::VKEY_F14, ui::EF_ALT_DOWN, IDC_RELOAD_CLEARING_CACHE },
 
//  { ui::VKEY_F15, ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN, IDC_RELOAD_CLEARING_CACHE },
//  { ui::VKEY_F14, ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN, IDC_DUPLICATE_TAB },
 
// CTRL+SHIFT+D for duplicate as well, but it conflicts bookmark shortcuts
//  { ui::VKEY_D, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, IDC_DUPLICATE_TAB },
//Anton-end
  { ui::VKEY_LEFT, ui::EF_ALT_DOWN, IDC_BACK },
  { ui::VKEY_BACK, ui::EF_NONE, IDC_BACK },
  { ui::VKEY_D, ui::EF_CONTROL_DOWN, IDC_BOOKMARK_PAGE },
  { ui::VKEY_D, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
    IDC_BOOKMARK_ALL_TABS },
  { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_TAB },
 
Pasting these changes added my desired shortcuts, I could get rid of the extensions.

0 Responses so far.