diff mbox

ui/cocoa.m: Give laptop users ability to scroll in monitor

Message ID 9D0D12D4-476B-4EF4-80EB-0A61F0BED115@gmail.com
State New
Headers show

Commit Message

Programmingkid March 13, 2015, 4:35 a.m. UTC
Laptop users usually have keyboards that are missing the page up and page down keys. This means they cannot scroll in the monitor. This patch gives laptop users the ability to scroll in the monitor by having the user push the Control + Up/Down arrow keys to scroll one line at a time. Use ALT/Option in place of Control to be able to scroll at 10 lines at a time. 

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

---
 ui/cocoa.m |   82 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 55 insertions(+), 27 deletions(-)

Comments

Peter Maydell March 13, 2015, 9:51 a.m. UTC | #1
On 13 March 2015 at 04:35, Programmingkid <programmingkidx@gmail.com> wrote:
> Laptop users usually have keyboards that are missing the page up and page down keys. This means they cannot scroll in the monitor. This patch gives laptop users the ability to scroll in the monitor by having the user push the Control + Up/Down arrow keys to scroll one line at a time. Use ALT/Option in place of Control to be able to scroll at 10 lines at a time.

Don't the standard OSX function+up/down for pageup/down work?
If they don't we should probably figure out why rather than
adding a non-standard key combo.

-- PMM
Programmingkid March 13, 2015, 2:48 p.m. UTC | #2
On Mar 13, 2015, at 5:51 AM, Peter Maydell wrote:

> On 13 March 2015 at 04:35, Programmingkid <programmingkidx@gmail.com> wrote:
>> Laptop users usually have keyboards that are missing the page up and page down keys. This means they cannot scroll in the monitor. This patch gives laptop users the ability to scroll in the monitor by having the user push the Control + Up/Down arrow keys to scroll one line at a time. Use ALT/Option in place of Control to be able to scroll at 10 lines at a time.
> 
> Don't the standard OSX function+up/down for pageup/down work?
> If they don't we should probably figure out why rather than
> adding a non-standard key combo.
> 
> -- PMM

On my MacBook Pro, this functionality is missing. There is no way to do a page up or page down key.
Paolo Bonzini March 13, 2015, 5:31 p.m. UTC | #3
On 13/03/2015 15:48, Programmingkid wrote:
> 
> On Mar 13, 2015, at 5:51 AM, Peter Maydell wrote:
> 
>> On 13 March 2015 at 04:35, Programmingkid <programmingkidx@gmail.com> wrote:
>>> Laptop users usually have keyboards that are missing the page up and page down keys. This means they cannot scroll in the monitor. This patch gives laptop users the ability to scroll in the monitor by having the user push the Control + Up/Down arrow keys to scroll one line at a time. Use ALT/Option in place of Control to be able to scroll at 10 lines at a time.
>>
>> Don't the standard OSX function+up/down for pageup/down work?
>> If they don't we should probably figure out why rather than
>> adding a non-standard key combo.
>>
>> -- PMM
> 
> On my MacBook Pro, this functionality is missing. There is no way to do a page up or page down key. 

How do you do that in a terminal?

Paolo
Programmingkid March 13, 2015, 8:43 p.m. UTC | #4
On Mar 13, 2015, at 1:31 PM, Paolo Bonzini wrote:

> 
> 
> On 13/03/2015 15:48, Programmingkid wrote:
>> 
>> On Mar 13, 2015, at 5:51 AM, Peter Maydell wrote:
>> 
>>> On 13 March 2015 at 04:35, Programmingkid <programmingkidx@gmail.com> wrote:
>>>> Laptop users usually have keyboards that are missing the page up and page down keys. This means they cannot scroll in the monitor. This patch gives laptop users the ability to scroll in the monitor by having the user push the Control + Up/Down arrow keys to scroll one line at a time. Use ALT/Option in place of Control to be able to scroll at 10 lines at a time.
>>> 
>>> Don't the standard OSX function+up/down for pageup/down work?
>>> If they don't we should probably figure out why rather than
>>> adding a non-standard key combo.
>>> 
>>> -- PMM
>> 
>> On my MacBook Pro, this functionality is missing. There is no way to do a page up or page down key. 
> 
> How do you do that in a terminal?
> 
> Paolo

I'm not sure what exactly you're asking. I will say past Apple laptop did have the ability to page up or down by using the function key + the up or down arrow keys. It looks like Apple removed that ability. I tried using function key + up, control key + up, option key + up, and command key + up. These do not cause the Monitor to scroll without the patch.
Paolo Bonzini March 16, 2015, 12:19 p.m. UTC | #5
On 13/03/2015 21:43, Programmingkid wrote:
>> How do you do that in a terminal?
> 
> I'm not sure what exactly you're asking. I will say past Apple laptop
> did have the ability to page up or down by using the function key +
> the up or down arrow keys. It looks like Apple removed that ability.
> I tried using function key + up, control key + up, option key + up,
> and command key + up. These do not cause the Monitor to scroll
> without the patch.

How do you scroll up and down in OS X's Terminal.app?

Paolo
Programmingkid March 16, 2015, 1:35 p.m. UTC | #6
On Mar 16, 2015, at 8:19 AM, Paolo Bonzini wrote:

> 
> 
> On 13/03/2015 21:43, Programmingkid wrote:
>>> How do you do that in a terminal?
>> 
>> I'm not sure what exactly you're asking. I will say past Apple laptop
>> did have the ability to page up or down by using the function key +
>> the up or down arrow keys. It looks like Apple removed that ability.
>> I tried using function key + up, control key + up, option key + up,
>> and command key + up. These do not cause the Monitor to scroll
>> without the patch.
> 
> How do you scroll up and down in OS X's Terminal.app?
> 
> Paolo

With the scrollbar.
Paolo Bonzini March 16, 2015, 1:36 p.m. UTC | #7
On 16/03/2015 14:35, Programmingkid wrote:
> On Mar 16, 2015, at 8:19 AM, Paolo Bonzini wrote:
>> On 13/03/2015 21:43, Programmingkid wrote:
>>>> How do you do that in a terminal?
>>>
>>> I'm not sure what exactly you're asking. I will say past Apple laptop
>>> did have the ability to page up or down by using the function key +
>>> the up or down arrow keys. It looks like Apple removed that ability.
>>> I tried using function key + up, control key + up, option key + up,
>>> and command key + up. These do not cause the Monitor to scroll
>>> without the patch.
>>
>> How do you scroll up and down in OS X's Terminal.app?
> 
> With the scrollbar. 

And then people complain about GNOME...

Paolo
Programmingkid March 16, 2015, 1:39 p.m. UTC | #8
On Mar 16, 2015, at 9:36 AM, Paolo Bonzini wrote:

> 
> 
> On 16/03/2015 14:35, Programmingkid wrote:
>> On Mar 16, 2015, at 8:19 AM, Paolo Bonzini wrote:
>>> On 13/03/2015 21:43, Programmingkid wrote:
>>>>> How do you do that in a terminal?
>>>> 
>>>> I'm not sure what exactly you're asking. I will say past Apple laptop
>>>> did have the ability to page up or down by using the function key +
>>>> the up or down arrow keys. It looks like Apple removed that ability.
>>>> I tried using function key + up, control key + up, option key + up,
>>>> and command key + up. These do not cause the Monitor to scroll
>>>> without the patch.
>>> 
>>> How do you scroll up and down in OS X's Terminal.app?
>> 
>> With the scrollbar. 
> 
> And then people complain about GNOME...

??
Daniel P. Berrangé March 16, 2015, 1:48 p.m. UTC | #9
On Fri, Mar 13, 2015 at 04:43:54PM -0400, Programmingkid wrote:
> 
> On Mar 13, 2015, at 1:31 PM, Paolo Bonzini wrote:
> 
> > 
> > 
> > On 13/03/2015 15:48, Programmingkid wrote:
> >> 
> >> On Mar 13, 2015, at 5:51 AM, Peter Maydell wrote:
> >> 
> >>> On 13 March 2015 at 04:35, Programmingkid <programmingkidx@gmail.com> wrote:
> >>>> Laptop users usually have keyboards that are missing the page up and page down keys. This means they cannot scroll in the monitor. This patch gives laptop users the ability to scroll in the monitor by having the user push the Control + Up/Down arrow keys to scroll one line at a time. Use ALT/Option in place of Control to be able to scroll at 10 lines at a time.
> >>> 
> >>> Don't the standard OSX function+up/down for pageup/down work?
> >>> If they don't we should probably figure out why rather than
> >>> adding a non-standard key combo.
> >>> 
> >>> -- PMM
> >> 
> >> On my MacBook Pro, this functionality is missing. There is no way to do a page up or page down key. 
> > 
> > How do you do that in a terminal?
> > 
> > Paolo
> 
> I'm not sure what exactly you're asking. I will say past Apple
> laptop did have the ability to page up or down by using the
> function key + the up or down arrow keys. It looks like Apple
> removed that ability. I tried using function key + up, control
> key + up, option key + up, and command key + up. These do not
> cause the Monitor to scroll without the patch.

The docs[1] still refer to fn+up/down as the way to achieve page up/down,
so perhaps your install has simply lost the shortcut mappings ?

Regards,
Daniel

[1] https://support.apple.com/en-gb/HT201236
Peter Maydell March 16, 2015, 2 p.m. UTC | #10
On 16 March 2015 at 13:48, Daniel P. Berrange <berrange@redhat.com> wrote:
> The docs[1] still refer to fn+up/down as the way to achieve page up/down,
> so perhaps your install has simply lost the shortcut mappings ?

Works for me on a 2011 MacBook Air running Mavericks, anyway.
(Terminal is not necessarily the best app to choose to demonstrate
this, because its behaviour is to pass the page-down/page-up through
to the application in the terminal.)

-- PMM
Programmingkid March 16, 2015, 2:33 p.m. UTC | #11
On Mar 16, 2015, at 9:48 AM, Daniel P. Berrange wrote:

> On Fri, Mar 13, 2015 at 04:43:54PM -0400, Programmingkid wrote:
>> 
>> On Mar 13, 2015, at 1:31 PM, Paolo Bonzini wrote:
>> 
>>> 
>>> 
>>> On 13/03/2015 15:48, Programmingkid wrote:
>>>> 
>>>> On Mar 13, 2015, at 5:51 AM, Peter Maydell wrote:
>>>> 
>>>>> On 13 March 2015 at 04:35, Programmingkid <programmingkidx@gmail.com> wrote:
>>>>>> Laptop users usually have keyboards that are missing the page up and page down keys. This means they cannot scroll in the monitor. This patch gives laptop users the ability to scroll in the monitor by having the user push the Control + Up/Down arrow keys to scroll one line at a time. Use ALT/Option in place of Control to be able to scroll at 10 lines at a time.
>>>>> 
>>>>> Don't the standard OSX function+up/down for pageup/down work?
>>>>> If they don't we should probably figure out why rather than
>>>>> adding a non-standard key combo.
>>>>> 
>>>>> -- PMM
>>>> 
>>>> On my MacBook Pro, this functionality is missing. There is no way to do a page up or page down key. 
>>> 
>>> How do you do that in a terminal?
>>> 
>>> Paolo
>> 
>> I'm not sure what exactly you're asking. I will say past Apple
>> laptop did have the ability to page up or down by using the
>> function key + the up or down arrow keys. It looks like Apple
>> removed that ability. I tried using function key + up, control
>> key + up, option key + up, and command key + up. These do not
>> cause the Monitor to scroll without the patch.
> 
> The docs[1] still refer to fn+up/down as the way to achieve page up/down,
> so perhaps your install has simply lost the shortcut mappings ?
> 
> Regards,
> Daniel
> 
> [1] https://support.apple.com/en-gb/HT201236
> -- 
> |: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
> |: http://libvirt.org              -o-             http://virt-manager.org :|
> |: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
> |: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

Your document does state that using fn+up/down arrow keys emulate the page up and down keys, but this isn't universally true for all Apple Laptops. My 2010 MacBook Pro is such an example of removed page up/down key emulation.
Programmingkid March 16, 2015, 2:38 p.m. UTC | #12
On Mar 16, 2015, at 10:00 AM, Peter Maydell wrote:

> On 16 March 2015 at 13:48, Daniel P. Berrange <berrange@redhat.com> wrote:
>> The docs[1] still refer to fn+up/down as the way to achieve page up/down,
>> so perhaps your install has simply lost the shortcut mappings ?
> 
> Works for me on a 2011 MacBook Air running Mavericks, anyway.
Are you saying you are able to scroll up and down in QEMU's monitor using your MacBook Air's keyboard?

If your computer does have built-in emulation for the page up/down keys, would it still be ok to help the people whose computer don't have this feature?

http://xahlee.info/kbd/laptop_keyboards.html
This document states that the page up and down keys (as well as several other keys) have been removed from several manufacturer's laptops.
Peter Maydell March 16, 2015, 2:43 p.m. UTC | #13
On 16 March 2015 at 14:38, Programmingkid <programmingkidx@gmail.com> wrote:
>
> On Mar 16, 2015, at 10:00 AM, Peter Maydell wrote:
>
>> On 16 March 2015 at 13:48, Daniel P. Berrange <berrange@redhat.com> wrote:
>>> The docs[1] still refer to fn+up/down as the way to achieve page up/down,
>>> so perhaps your install has simply lost the shortcut mappings ?
>>
>> Works for me on a 2011 MacBook Air running Mavericks, anyway.

> Are you saying you are able to scroll up and down in QEMU's monitor
> using your MacBook Air's keyboard?

I haven't attempted to use the monitor. I'm just saying that
on my OSX it does turn those keys into pageup/down.

-- PMM
Programmingkid March 16, 2015, 2:45 p.m. UTC | #14
On Mar 16, 2015, at 10:43 AM, Peter Maydell wrote:

> On 16 March 2015 at 14:38, Programmingkid <programmingkidx@gmail.com> wrote:
>> 
>> On Mar 16, 2015, at 10:00 AM, Peter Maydell wrote:
>> 
>>> On 16 March 2015 at 13:48, Daniel P. Berrange <berrange@redhat.com> wrote:
>>>> The docs[1] still refer to fn+up/down as the way to achieve page up/down,
>>>> so perhaps your install has simply lost the shortcut mappings ?
>>> 
>>> Works for me on a 2011 MacBook Air running Mavericks, anyway.
> 
>> Are you saying you are able to scroll up and down in QEMU's monitor
>> using your MacBook Air's keyboard?
> 
> I haven't attempted to use the monitor. I'm just saying that
> on my OSX it does turn those keys into pageup/down.

Please try scrolling in the Monitor. I don't think it will work due to missing functionality.
Paolo Bonzini March 16, 2015, 2:47 p.m. UTC | #15
On 16/03/2015 15:45, Programmingkid wrote:
> > > Are you saying you are able to scroll up and down in QEMU's monitor
> > > using your MacBook Air's keyboard?
> > 
> > I haven't attempted to use the monitor. I'm just saying that
> > on my OSX it does turn those keys into pageup/down.
> 
> Please try scrolling in the Monitor. I don't think it will work due to missing functionality.

Just to understand what's going on, can you try using the GTK+ interface
on Mac OS X?  You should be able to scroll the terminal, if you have
libvte installed, with Shift+PgUp/Shift+PgDn (i.e.
Shift+Fn+Up/Shift+Fn/Down).

Paolo
Programmingkid March 16, 2015, 2:49 p.m. UTC | #16
On Mar 16, 2015, at 10:47 AM, Paolo Bonzini wrote:

> 
> 
> On 16/03/2015 15:45, Programmingkid wrote:
>>>> Are you saying you are able to scroll up and down in QEMU's monitor
>>>> using your MacBook Air's keyboard?
>>> 
>>> I haven't attempted to use the monitor. I'm just saying that
>>> on my OSX it does turn those keys into pageup/down.
>> 
>> Please try scrolling in the Monitor. I don't think it will work due to missing functionality.
> 
> Just to understand what's going on, can you try using the GTK+ interface
> on Mac OS X?  You should be able to scroll the terminal, if you have
> libvte installed, with Shift+PgUp/Shift+PgDn (i.e.
> Shift+Fn+Up/Shift+Fn/Down).

Sorry but the GTK interface doesn't work on Mac OS X. We are all hoping this will change in the future.
Paolo Bonzini March 16, 2015, 2:52 p.m. UTC | #17
On 16/03/2015 15:49, Programmingkid wrote:
> 
> On Mar 16, 2015, at 10:47 AM, Paolo Bonzini wrote:
> 
>>
>>
>> On 16/03/2015 15:45, Programmingkid wrote:
>>>>> Are you saying you are able to scroll up and down in QEMU's monitor
>>>>> using your MacBook Air's keyboard?
>>>>
>>>> I haven't attempted to use the monitor. I'm just saying that
>>>> on my OSX it does turn those keys into pageup/down.
>>>
>>> Please try scrolling in the Monitor. I don't think it will work due to missing functionality.
>>
>> Just to understand what's going on, can you try using the GTK+ interface
>> on Mac OS X?  You should be able to scroll the terminal, if you have
>> libvte installed, with Shift+PgUp/Shift+PgDn (i.e.
>> Shift+Fn+Up/Shift+Fn/Down).
> 
> Sorry but the GTK interface doesn't work on Mac OS X. We are all hoping this will change in the future. 

What's the problem?  Was the bug reported?

Also, if you have dual booting, does Linux handle
Shift+Fn+Up/Shift+Fn+Down?  Fn is usually trapped and transformed in the
keyboard firmware.

Paolo
Peter Maydell March 16, 2015, 2:59 p.m. UTC | #18
On 16 March 2015 at 14:52, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 16/03/2015 15:49, Programmingkid wrote:
>> Sorry but the GTK interface doesn't work on Mac OS X. We are all hoping this will change in the future.
>
> What's the problem?  Was the bug reported?

Well known and longstanding -- the Cocoa UI assumes it
is the only thing present (and it hooks itself into
the startup sequence by overriding main() with its
own function). Yes, ideally we'd refactor it to work like
the other UIs, but in practice nobody really wants to
use anything other than the Cocoa UI on OSX so nobody's
got round to it.

-- PMM
Programmingkid March 16, 2015, 3:01 p.m. UTC | #19
On Mar 16, 2015, at 10:52 AM, Paolo Bonzini wrote:

> 
> 
> On 16/03/2015 15:49, Programmingkid wrote:
>> 
>> On Mar 16, 2015, at 10:47 AM, Paolo Bonzini wrote:
>> 
>>> 
>>> 
>>> On 16/03/2015 15:45, Programmingkid wrote:
>>>>>> Are you saying you are able to scroll up and down in QEMU's monitor
>>>>>> using your MacBook Air's keyboard?
>>>>> 
>>>>> I haven't attempted to use the monitor. I'm just saying that
>>>>> on my OSX it does turn those keys into pageup/down.
>>>> 
>>>> Please try scrolling in the Monitor. I don't think it will work due to missing functionality.
>>> 
>>> Just to understand what's going on, can you try using the GTK+ interface
>>> on Mac OS X?  You should be able to scroll the terminal, if you have
>>> libvte installed, with Shift+PgUp/Shift+PgDn (i.e.
>>> Shift+Fn+Up/Shift+Fn/Down).
>> 
>> Sorry but the GTK interface doesn't work on Mac OS X. We are all hoping this will change in the future. 
> 
> What's the problem?  Was the bug reported?
I think the main problem is there is no Mac OS X/GTK user on the QEMU list who could help. Maybe a few Mac OS X/GTK users exist in the wild, but not very much evidence of this. 

> Also, if you have dual booting, does Linux handle
> Shift+Fn+Up/Shift+Fn+Down?  Fn is usually trapped and transformed in the
> keyboard firmware.

I have Linux installed in VirtualBox, when I tried the shift+fn+up/down keys, nothing happened. When I tried CNTL+UP/DOWN, then it worked. It looks like someone implemented my idea on Linux already!
Programmingkid March 16, 2015, 3:06 p.m. UTC | #20
On Mar 16, 2015, at 10:59 AM, Peter Maydell wrote:

> On 16 March 2015 at 14:52, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> 
>> 
>> On 16/03/2015 15:49, Programmingkid wrote:
>>> Sorry but the GTK interface doesn't work on Mac OS X. We are all hoping this will change in the future.
>> 
>> What's the problem?  Was the bug reported?
> 
> Well known and longstanding -- the Cocoa UI assumes it
> is the only thing present (and it hooks itself into
> the startup sequence by overriding main() with its
> own function). Yes, ideally we'd refactor it to work like
> the other UIs, but in practice nobody really wants to
> use anything other than the Cocoa UI on OSX so nobody's
> got round to it.

That sounds about right. I would just like to add that nobody wants to have to install GTK and its dependencies after going thru the dependency nightmare that is QEMU.
Peter Maydell May 10, 2015, 10:34 p.m. UTC | #21
On 16 March 2015 at 14:45, Programmingkid <programmingkidx@gmail.com> wrote:
> On Mar 16, 2015, at 10:43 AM, Peter Maydell wrote:
>> On 16 March 2015 at 14:38, Programmingkid <programmingkidx@gmail.com> wrote:
>>> On Mar 16, 2015, at 10:00 AM, Peter Maydell wrote:
>>>> On 16 March 2015 at 13:48, Daniel P. Berrange <berrange@redhat.com> wrote:
>>>>> The docs[1] still refer to fn+up/down as the way to achieve page up/down,
>>>>> so perhaps your install has simply lost the shortcut mappings ?
>>>>
>>>> Works for me on a 2011 MacBook Air running Mavericks, anyway.
>>
>>> Are you saying you are able to scroll up and down in QEMU's monitor
>>> using your MacBook Air's keyboard?
>>
>> I haven't attempted to use the monitor. I'm just saying that
>> on my OSX it does turn those keys into pageup/down.
>
> Please try scrolling in the Monitor. I don't think it will work due
> to missing functionality.

I've now tested again with my not-just-the-laptop setup, and:

 * in the guest OS (I tested with a Linux guest), PageUp/Down
   work OK and work the same whether I use an external USB
   keyboard with a physical PgUp/Down key or the MacBook Air's
   keyboard with Fn+UpArrow/Fn+DownArrow as the chord to
   input pageup/down
 * in the monitor window, neither way of inputting PageUp/Down
   works: all you get is a ',' input into the monitor

So my conclusion is that we should fix the underlying
problem that the monitor isn't handling PgUp/PgDown
correctly (not sure exactly why that's not working yet).

If your particular OSX version really doesn't implement
the Fn+Up/Down == PageUp/Down chord then I think you should
address that at the OSX level, not in QEMU (there are
likely several OSX utilities that will do the job).

thanks
-- PMM
Peter Maydell May 10, 2015, 10:51 p.m. UTC | #22
On 10 May 2015 at 23:34, Peter Maydell <peter.maydell@linaro.org> wrote:
> I've now tested again with my not-just-the-laptop setup, and:
>
>  * in the guest OS (I tested with a Linux guest), PageUp/Down
>    work OK and work the same whether I use an external USB
>    keyboard with a physical PgUp/Down key or the MacBook Air's
>    keyboard with Fn+UpArrow/Fn+DownArrow as the chord to
>    input pageup/down
>  * in the monitor window, neither way of inputting PageUp/Down
>    works: all you get is a ',' input into the monitor
>
> So my conclusion is that we should fix the underlying
> problem that the monitor isn't handling PgUp/PgDown
> correctly (not sure exactly why that's not working yet).

So looking at the code in ui/console.c that implements our
virtual consoles, the scrolling is hooked up to the keycodes
QEMU_KEY_CTRL_{UP,DOWN,PAGEUP,PAGEDOWN}. These only seem
to be output by one of our UI frontends, SDL.

Gerd, how is this supposed to work? Shouldn't something
in the generic console code be handling converting the
Q_KEY_CODE_CTRL/CTRL_R + Q_KEY_CODE_PGUP/DOWN/etc into
what the vc layer expects, rather than having each of the
ui frontends doing it?

thanks
-- PMM
Gerd Hoffmann May 11, 2015, 6:53 a.m. UTC | #23
On So, 2015-05-10 at 23:51 +0100, Peter Maydell wrote:
> On 10 May 2015 at 23:34, Peter Maydell <peter.maydell@linaro.org> wrote:
> > I've now tested again with my not-just-the-laptop setup, and:
> >
> >  * in the guest OS (I tested with a Linux guest), PageUp/Down
> >    work OK and work the same whether I use an external USB
> >    keyboard with a physical PgUp/Down key or the MacBook Air's
> >    keyboard with Fn+UpArrow/Fn+DownArrow as the chord to
> >    input pageup/down
> >  * in the monitor window, neither way of inputting PageUp/Down
> >    works: all you get is a ',' input into the monitor
> >
> > So my conclusion is that we should fix the underlying
> > problem that the monitor isn't handling PgUp/PgDown
> > correctly (not sure exactly why that's not working yet).
> 
> So looking at the code in ui/console.c that implements our
> virtual consoles, the scrolling is hooked up to the keycodes
> QEMU_KEY_CTRL_{UP,DOWN,PAGEUP,PAGEDOWN}. These only seem
> to be output by one of our UI frontends, SDL.
> 
> Gerd, how is this supposed to work? Shouldn't something
> in the generic console code be handling converting the
> Q_KEY_CODE_CTRL/CTRL_R + Q_KEY_CODE_PGUP/DOWN/etc into
> what the vc layer expects, rather than having each of the
> ui frontends doing it?

Unfortunaly it isn't that easy as we have two very different modes of
operation here:  For vc's we need the keyboard input already mapped to
your local keyboard layout (i.e. the keysyms).  For guest input we need
the raw scancodes of the keys as the keyboard layout handling is done by
the guest.  The differences between the UIs (especially when it comes to
raw scancodes) are big enough that it is next to impossible to hide all
that in common code.

Specifically for the vc control keys there is a little helper function
though: kbd_put_qcode_console(), used by sdl2 and gtk, which might be
useful for cocoa too.

cheers,
  Gerd
Peter Maydell June 11, 2015, 2:23 p.m. UTC | #24
On 11 May 2015 at 07:53, Gerd Hoffmann <kraxel@redhat.com> wrote:
> On So, 2015-05-10 at 23:51 +0100, Peter Maydell wrote:
>> So looking at the code in ui/console.c that implements our
>> virtual consoles, the scrolling is hooked up to the keycodes
>> QEMU_KEY_CTRL_{UP,DOWN,PAGEUP,PAGEDOWN}. These only seem
>> to be output by one of our UI frontends, SDL.
>>
>> Gerd, how is this supposed to work? Shouldn't something
>> in the generic console code be handling converting the
>> Q_KEY_CODE_CTRL/CTRL_R + Q_KEY_CODE_PGUP/DOWN/etc into
>> what the vc layer expects, rather than having each of the
>> ui frontends doing it?
>
> Unfortunaly it isn't that easy as we have two very different modes of
> operation here:  For vc's we need the keyboard input already mapped to
> your local keyboard layout (i.e. the keysyms).  For guest input we need
> the raw scancodes of the keys as the keyboard layout handling is done by
> the guest.  The differences between the UIs (especially when it comes to
> raw scancodes) are big enough that it is next to impossible to hide all
> that in common code.
>
> Specifically for the vc control keys there is a little helper function
> though: kbd_put_qcode_console(), used by sdl2 and gtk, which might be
> useful for cocoa too.

I was just looking back at this, and I'm confused --
kbd_put_qcode_console() doesn't seem to do anything with the
QEMU_KEY_CTRL_* keycodes... And indeed ctrl-pageup/pagedown/up/down
don't work in the GTK UI, though they do work in the SDL1 UI.

-- PMM
diff mbox

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index d37c29b..3ac847f 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -593,35 +593,63 @@  QemuCocoaView *cocoaView;
             // handlekeys for Monitor
             } else {
                 int keysym = 0;
-                switch([event keyCode]) {
-                case 115:
-                    keysym = QEMU_KEY_HOME;
-                    break;
-                case 117:
-                    keysym = QEMU_KEY_DELETE;
-                    break;
-                case 119:
-                    keysym = QEMU_KEY_END;
-                    break;
-                case 123:
-                    keysym = QEMU_KEY_LEFT;
-                    break;
-                case 124:
-                    keysym = QEMU_KEY_RIGHT;
-                    break;
-                case 125:
-                    keysym = QEMU_KEY_DOWN;
-                    break;
-                case 126:
-                    keysym = QEMU_KEY_UP;
-                    break;
-                default:
-                    {
-                        NSString *ks = [event characters];
-                        if ([ks length] > 0)
-                            keysym = [ks characterAtIndex:0];
+
+                /*
+                Holding down the up or down arrow key with the Control key scrolls the console one line.
+                Using the ALT/Option key with the up or down key scrolls the console 10 lines.
+                Had to do this because laptops don't have page up or page down keys.
+                */
+
+                // if the CONTROL key is held down
+                if([event modifierFlags] & NSControlKeyMask) {
+                    if([event keyCode] == 126) {         // up arrow key
+                        keysym = QEMU_KEY_CTRL_UP;
+                    } else if([event keyCode] == 125) {  // down arrow key
+                        keysym = QEMU_KEY_CTRL_DOWN;
+                    }
+                }
+
+                // if the ALT/OPTION key is held down
+                else if ([event modifierFlags] & NSAlternateKeyMask) {
+                    if ([event keyCode] == 126) {         // up arrow key
+                        keysym = QEMU_KEY_CTRL_PAGEUP;
+                    } else if ([event keyCode] == 125) {  // down arrow key
+                        keysym = QEMU_KEY_CTRL_PAGEDOWN;
                     }
                 }
+
+                else {
+                    switch([event keyCode]) {
+                    case 115:
+                        keysym = QEMU_KEY_HOME;
+                        break;
+                    case 117:
+                        keysym = QEMU_KEY_DELETE;
+                        break;
+                    case 119:
+                        keysym = QEMU_KEY_END;
+                        break;
+                    case 123:
+                        keysym = QEMU_KEY_LEFT;
+                        break;
+                    case 124:
+                        keysym = QEMU_KEY_RIGHT;
+                        break;
+                    case 125:
+                        keysym = QEMU_KEY_DOWN;
+                        break;
+                    case 126:
+                        keysym = QEMU_KEY_UP;
+                        break;
+                    default:
+                        {
+                            NSString *ks = [event characters];
+                            if ([ks length] > 0)
+                                keysym = [ks characterAtIndex:0];
+                        }
+                    }
+                }
+
                 if (keysym)
                     kbd_put_keysym(keysym);
             }