This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[Patch] Hide/Show menu with "Alt" key

Tags: None
(comma "," separated)
Elv13
Registered Member
Posts
23
Karma
0
OS

[Patch] Hide/Show menu with "Alt" key

Sat Aug 22, 2009 10:39 pm
Hi, here is a patch a add to every KDE apps the ability to show and hide menubar with the "Alt" key. It will not be added to KDE as is break some HIG rules.

This behavior can be foundin applications like Internet Explorer and Firefox (with hidemenu extension) and make sense because the menubar is useless 99.95% of time, you only need it when you want to use it.

With menu:
http://img29.imageshack.us/img29/1701/snapshot53.png

Without:
http://img265.imageshack.us/img265/9730/snapshot52.png

Just add this code:
Code: Select all
    case QEvent::KeyPress:
   {
     if (((QKeyEvent*) ev)->key() == Qt::Key_Alt) {
       if ((hasMenuBar()) && (menuBar()))
       menuBar()->setHidden(!(menuBar()->isHidden()));
     }
   }
        break;


Under this bunch of line:
Code: Select all
    K_D(KMainWindow);
    switch( ev->type() ) {
#ifdef Q_WS_WIN
    case QEvent::Move:
#endif
    case QEvent::Resize:
        d->setSizeDirty();
        break;
    case QEvent::Polish:
        d->polish(this);
        break;


In kdelibs/kdeui/widgets/kmainwindow.cpp

It will look like:
Code: Select all
    case QEvent::Resize:
        d->setSizeDirty();
        break;
    case QEvent::Polish:
        d->polish(this);
        break;
    case QEvent::KeyPress:
   {
     if (((QKeyEvent*) ev)->key() == Qt::Key_Alt) {
       if ((hasMenuBar()) && (menuBar()))
       menuBar()->setHidden(!(menuBar()->isHidden()));
     }
   }
        break;
    case QEvent::ChildPolished:
        {
            QChildEvent *event = static_cast<QChildEvent*>(ev);
            QDockWidget *dock = qobject_cast<QDockWidget*>(event->child());
            KToolBar *tool

In KDE 4.4, it may differ a little in earlier versions (it is why I pasted the code and not a patch).

It lack features such as always showing the menubar when alt is pressed and configuration, but it work fine for me. I hope at least one other member of the community will enjoy this patch.


Elv13, proud KDE user since KDE 2.2.
User avatar
GoolerES
Registered Member
Posts
10
Karma
0
OS
There are already some wishes https://bugs.kde.org/show_bug.cgi?id=168070 and at least one brainstorm entry for this brainstorm.php#idea63895 , so you are not alone ;D, but it has an important problem with bringing back the menu. Most applications "solve" it by adding an entry to the context menu, others don't like the feature at all and don't want to offer it.

I think that a feature like this should be available systemwide, so please, comment your patch in the links i've given you. Anyway, why use Alt instead of the standard Ctrl+M?

Maybe a good compromise between new users and experienced users would be adding this as an option in system settings, appareance, style, fine tunning: safer new users, happier old users ;)
Elv13
Registered Member
Posts
23
Karma
0
OS
Simply because Alt is used by IE and one of my favorite Firefox extension and I like that. Alt is (in theory) used to work with menu anyway (alt+f = file and so on) so it make some sense after all.

Ctrl+m can't be used. Some apps, like kolourpaint, use it for something else. I just can't submit a patch that break so many apps, KDE4 is in API freeze after all. An application that work with 4.1 need to work with 4.4 with little or no modifications.

Ctrl+Alt+M may be the best solution because it refer to global shortcut. I discussed about this patch a lot on IRC and this could be achieved using ctrl+alt+m. Even there, this patch can't be used. In intercept event a a really unusual way (because KDE does not support 1 key shortcut so I had to add the support for it). Of course, I can edit the patch to work with ctrl+alt+m, but this would be stupid, it is not the right way to setup shortcut, it was just the only one for "alt" alone. But the concept would work with all KDE applications with no problem, it is quite easy to hide the menu.

About the menu entry to bring it back, you are wrong, even applications that does not support hiding menu will have the entry, it is already a global KDE function, however applications are not forced to use it. Take a look, Dolphin does not support hiding menu, but if I do, I see that: http://img41.imageshack.us/img41/8489/snapshot54.png

As you can see, it does appear in the menu by itself, without any modification.

The option would not belong in fine tuning, but global shortcut by the way, but as you, I also proposed to add it there too, but it was rejected.


Elv13, proud KDE user since KDE 2.2.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]