Harinlen / cuberok

Automatically exported from code.google.com/p/cuberok
GNU General Public License v3.0
0 stars 1 forks source link

feature: global shortcuts #84

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Feature request:
Allow global shortcut configuration.

(Thanks for the amazing software!)

Original issue reported on code.google.com by mats.ahl...@gmail.com on 27 Jan 2010 at 9:15

GoogleCodeExporter commented 8 years ago
What OS do you use? 

In windows it is possible to make global shortcuts to run specific programs. 
You can
run cuberok with commandline parameters, like this (screenshot in attach)
You can see full list of commandline parameters by typing "cuberok --help" in 
console.

For linux (KDE and Gnome) it is possible to make the same shortcuts, I hope :-)

Maybe for next versions these shortcuts will be out of the box.

Original comment by drmoriar...@gmail.com on 28 Jan 2010 at 6:55

Attachments:

GoogleCodeExporter commented 8 years ago
Hello!

Thanks very much for the reply. Yes, I'm using Linux. It is indeed possible to 
make 
such shortcuts, using a variety of third-party programs. The command line 
arguments 
are indeed a nice scripting feature!

Regarding how to get the shortcuts running "out of the box": In both KDE (which 
I 
use) and Gnome, normally the program exports/registers a list of shortcuts with 
KDE/Gnome/Qt4/GTK/somelibrary (I'm unsure what exactly), and everything is 
magically 
taken care of. The result looks like this:

http://liquidat.files.wordpress.com/2007/10/shortcuts.png
(not sure how similar Gnome is)

I grepped through the code and found that in src/main.cpp, there is imperative 
code 
like this:

    for(int i = 1; i < argc; i++) {
            if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
                    usage();
                    return;
            } else
            if(!strcmp(argv[i], "-n") || !strcmp(argv[i], "--new")) {
                    //if(list.size() && list.back().size())
                    list << QString("");
                    continue;
            } else
            if(!strcmp(argv[i], "-u") || !strcmp(argv[i], "--url")) {
                    url = true;
                    continue;
            } else
            if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--volume")) {
                    volume = true;
                    continue;
            } else
            if(!strcmp(argv[i], "-x") || !strcmp(argv[i], "--next")) {
                    list << "#next";
                    continue;
            } else
    // . . .

As well as duplicated code, like this:

    #ifdef WIN32
    #include <windows.h>
    void GlobalWinKeys(WId hwnd)
    {
        RegisterHotKey(hwnd, 100, MOD_SHIFT | MOD_ALT, 'Z');
        RegisterHotKey(hwnd, 200, MOD_SHIFT | MOD_ALT, 'X');
        RegisterHotKey(hwnd, 300, MOD_SHIFT | MOD_ALT, 'C');
        RegisterHotKey(hwnd, 400, MOD_SHIFT | MOD_ALT, 'V');
        RegisterHotKey(hwnd, 500, MOD_SHIFT | MOD_ALT, 'B');
    }

    void UnregisterWinKeys(WId hwnd)
    {
        UnregisterHotKey(hwnd, 100);
        UnregisterHotKey(hwnd, 200);
        UnregisterHotKey(hwnd, 300);
        UnregisterHotKey(hwnd, 400);
        UnregisterHotKey(hwnd, 500);
    }
    // . . . 

I might suggest refactoring the code to reify shortcuts, so you'd have an 
easier time 
adding them. I sketch out code for cross-platform shortcuts below in 
python-like 
pseudocode. Sorry, I'd actually submit a patch if I was more comfortable with 
C. =\

    // Some possible pseudocode
    // e.g. shortcuts.cpp

    // Logical combo-key prefixes
    // Note: we avoid alt-?? since it may conflict with menu hints (e.g. alt-F 
for File menu))
    common = ' ctrl ' if not Mac else ' cmd/applekey '
    uncommon = ' ctrl shift '
    rare = ' ctrl alt shift '
    global = ' meta ' if not Mac else ' ctrl alt '
    global_uncommon = ' meta shift '

    SHORTCUT_DEFAULTS = [
        Playback = [
            {
                name = 'Previous track'
                symbol = 'prev'

                combo = common + 'z'
                alternate = 'PrevTrack' // on Linux, special keys 
like this called "XF86Play"
                         // not exactly sure how to deal with this
                global = global + 'z'
            }
            {
                name = 'Play/pause track'
                symbol = 'play'

                combo = common + 'x'
                alternate = 'Pause'
                global = global + 'x'
            }
            {
                name = 'Play/restart track'
                symbol = 'replay'

                combo = uncommon + 'x'
                alternate = 'Play'
                global = global_uncommon + 'x'
            }
            {
                name = 'Next track'
                symbol = 'next'

                combo = 'ctrl-c'
                alternate = 'NextTrack'
                global = global+'c'
            }

            {
                name = 'Jog forward'
                symbol = 'jog_forward'

                combo = 'Right'
                global = global+'c'
            }
            {
                name = 'Jog backward'
                symbol = 'jog_backward'

                combo = 'Left'
                global = global+'c'
            }
        ]
        Volume = [
            ...
        ]
        GUI = [
            {
                name = 'Show Cuberok main window' //focus on current 
desktop

                // since this is missing keys
                // 'combo' and 'alternate', there 
                // is no shortcut within the app
                global = 'a' //
            }
        ]

    function flatView(shortcuts) =
        for shortcutFamily in shortcuts:
            for shortcut in shortcutFamily:
                yield shortcut

    // ---------------------------------------
    // Platform-specific stuff:

    // Now when you add a shortcut, you can just edit the above and not worry 
about the platform
    // Though, changing a shortcut may require prompting the user

    // Windows
    function exportShortcuts_Windows:
        counter = 0
        for shortcut in flatView(shortcuts):
            RegisterHotKey(hwnd, ...
            counter++

    // Mac
    function exportShortcuts_Mac:
        // ...

    // Linux
    function exportShortcuts_Linux:
        // I really have no idea how to do this...
        // Might be able to take code from Amarok project, which does this

        for registeredShortcut in 
DesktopEnvironment.whatAreShortcuts('Cuberok'):
            correspondingDefaultShortcut = 
SHORTCUT_DEFAULTS[registeredShortcut.key]
            if !correspondingDefaultShortcut or 
correspondingDefaultShortcut<registeredShortcut:

DesktopEnvironment.addShortcut(correspondingDefaultShortcut, 'Cuberok')

    // Command line
    function exportShortcuts_CommandLine:
        function parser(argv):
            // "cuberok --cmd"    -returns->    "#cmd"
            for shortcut in shortcuts:
                if '--'+shortcut.symbol in argv
                return '#'+shortcut.symbol
        return parser

    function printCommandLineShortcutFlags(shortcuts):
        // Used by cuberok --help
        for s in flatView(shortcuts):
            print s.name + '\t'*(20-len(s.name)) + s.symbol + '\n'

    // ---------------------------------------

    register function userPressedShortcutKey():
        dispatch(shortcut.symbol)

Original comment by mats.ahl...@gmail.com on 28 Jan 2010 at 4:56

GoogleCodeExporter commented 8 years ago
Addendum:

I noticed ctrl-D queues a song like in Amarok. =)

Ideally the user should be able to figure out such shortcuts. Rather than 
create a new 
Issue I thought I'd mention that here, since the problem would disappear with a 
unified shortcut management dialog (like Amarok).

Original comment by mats.ahl...@gmail.com on 28 Jan 2010 at 5:05

GoogleCodeExporter commented 8 years ago
Thanks for help. I'll do shortcuts management soon.

Original comment by drmoriar...@gmail.com on 29 Jan 2010 at 6:09