Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/kraxel/tags/pull-ui-20170614-1'…
Browse files Browse the repository at this point in the history
… into staging

ui: prefer gtk3 and sdl2, various fixes.

# gpg: Signature made Wed 14 Jun 2017 08:54:22 BST
# gpg:                using RSA key 0x4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/pull-ui-20170614-1:
  spice: don't enter opengl mode in case another UI provides opengl support
  sdl: prefer sdl2 over sdl1
  gtk: prefer gtk3 over gtk2
  spice: Use proper enum type for kbd led state
  Improve Cocoa modifier key handling

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Jun 19, 2017
2 parents cef8fd6 + fe5c44f commit 30ff7d1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 26 deletions.
24 changes: 12 additions & 12 deletions configure
Expand Up @@ -2301,14 +2301,14 @@ fi
# GTK probe

if test "$gtkabi" = ""; then
# The GTK ABI was not specified explicitly, so try whether 2.0 is available.
# Use 3.0 as a fallback if that is available.
if $pkg_config --exists "gtk+-2.0 >= 2.18.0"; then
gtkabi=2.0
elif $pkg_config --exists "gtk+-3.0 >= 3.0.0"; then
# The GTK ABI was not specified explicitly, so try whether 3.0 is available.
# Use 2.0 as a fallback if that is available.
if $pkg_config --exists "gtk+-3.0 >= 3.0.0"; then
gtkabi=3.0
else
elif $pkg_config --exists "gtk+-2.0 >= 2.18.0"; then
gtkabi=2.0
else
gtkabi=3.0
fi
fi

Expand All @@ -2331,7 +2331,7 @@ if test "$gtk" != "no"; then
libs_softmmu="$gtk_libs $libs_softmmu"
gtk="yes"
elif test "$gtk" = "yes"; then
feature_not_found "gtk" "Install gtk2 or gtk3 devel"
feature_not_found "gtk" "Install gtk3-devel"
else
gtk="no"
fi
Expand Down Expand Up @@ -2598,12 +2598,12 @@ fi
# sdl-config even without cross prefix, and favour pkg-config over sdl-config.

if test "$sdlabi" = ""; then
if $pkg_config --exists "sdl"; then
sdlabi=1.2
elif $pkg_config --exists "sdl2"; then
if $pkg_config --exists "sdl2"; then
sdlabi=2.0
else
elif $pkg_config --exists "sdl"; then
sdlabi=1.2
else
sdlabi=2.0
fi
fi

Expand All @@ -2630,7 +2630,7 @@ elif has ${sdl_config}; then
sdlversion=$($sdlconfig --version)
else
if test "$sdl" = "yes" ; then
feature_not_found "sdl" "Install SDL devel"
feature_not_found "sdl" "Install SDL2-devel"
fi
sdl=no
fi
Expand Down
2 changes: 2 additions & 0 deletions include/ui/spice-display.h
Expand Up @@ -140,6 +140,8 @@ struct SimpleSpiceCursor {
QXLCursor cursor;
};

extern bool spice_opengl;

int qemu_spice_rect_is_empty(const QXLRect* r);
void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);

Expand Down
60 changes: 48 additions & 12 deletions ui/cocoa.m
Expand Up @@ -52,6 +52,8 @@
/* macOS 10.12 deprecated many constants, #define the new names for older SDKs */
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
#define NSEventMaskAny NSAnyEventMask
#define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
#define NSEventModifierFlagShift NSShiftKeyMask
#define NSEventModifierFlagCommand NSCommandKeyMask
#define NSEventModifierFlagControl NSControlKeyMask
#define NSEventModifierFlagOption NSAlternateKeyMask
Expand Down Expand Up @@ -268,7 +270,7 @@ @interface QemuCocoaView : NSView
NSWindow *fullScreenWindow;
float cx,cy,cw,ch,cdx,cdy;
CGDataProviderRef dataProviderRef;
int modifiers_state[256];
BOOL modifiers_state[256];
BOOL isMouseGrabbed;
BOOL isFullscreen;
BOOL isAbsoluteEnabled;
Expand Down Expand Up @@ -536,18 +538,59 @@ - (void) toggleFullScreen:(id)sender
}
}

- (void) toggleModifier: (int)keycode {
// Toggle the stored state.
modifiers_state[keycode] = !modifiers_state[keycode];
// Send a keyup or keydown depending on the state.
qemu_input_event_send_key_qcode(dcl->con, keycode, modifiers_state[keycode]);
}

- (void) toggleStatefulModifier: (int)keycode {
// Toggle the stored state.
modifiers_state[keycode] = !modifiers_state[keycode];
// Generate keydown and keyup.
qemu_input_event_send_key_qcode(dcl->con, keycode, true);
qemu_input_event_send_key_qcode(dcl->con, keycode, false);
}

- (void) handleEvent:(NSEvent *)event
{
COCOA_DEBUG("QemuCocoaView: handleEvent\n");

int buttons = 0;
int keycode;
int keycode = 0;
bool mouse_event = false;
NSPoint p = [event locationInWindow];

switch ([event type]) {
case NSEventTypeFlagsChanged:
keycode = cocoa_keycode_to_qemu([event keyCode]);
if ([event keyCode] == 0) {
// When the Cocoa keyCode is zero that means keys should be
// synthesized based on the values in in the eventModifiers
// bitmask.

if (qemu_console_is_graphic(NULL)) {
NSEventModifierFlags modifiers = [event modifierFlags];

if (!!(modifiers & NSEventModifierFlagCapsLock) != !!modifiers_state[Q_KEY_CODE_CAPS_LOCK]) {
[self toggleStatefulModifier:Q_KEY_CODE_CAPS_LOCK];
}
if (!!(modifiers & NSEventModifierFlagShift) != !!modifiers_state[Q_KEY_CODE_SHIFT]) {
[self toggleModifier:Q_KEY_CODE_SHIFT];
}
if (!!(modifiers & NSEventModifierFlagControl) != !!modifiers_state[Q_KEY_CODE_CTRL]) {
[self toggleModifier:Q_KEY_CODE_CTRL];
}
if (!!(modifiers & NSEventModifierFlagOption) != !!modifiers_state[Q_KEY_CODE_ALT]) {
[self toggleModifier:Q_KEY_CODE_ALT];
}
if (!!(modifiers & NSEventModifierFlagCommand) != !!modifiers_state[Q_KEY_CODE_META_L]) {
[self toggleModifier:Q_KEY_CODE_META_L];
}
}
} else {
keycode = cocoa_keycode_to_qemu([event keyCode]);
}

if ((keycode == Q_KEY_CODE_META_L || keycode == Q_KEY_CODE_META_R)
&& !isMouseGrabbed) {
Expand All @@ -559,16 +602,9 @@ - (void) handleEvent:(NSEvent *)event
// emulate caps lock and num lock keydown and keyup
if (keycode == Q_KEY_CODE_CAPS_LOCK ||
keycode == Q_KEY_CODE_NUM_LOCK) {
qemu_input_event_send_key_qcode(dcl->con, keycode, true);
qemu_input_event_send_key_qcode(dcl->con, keycode, false);
[self toggleStatefulModifier:keycode];
} else if (qemu_console_is_graphic(NULL)) {
if (modifiers_state[keycode] == 0) { // keydown
qemu_input_event_send_key_qcode(dcl->con, keycode, true);
modifiers_state[keycode] = 1;
} else { // keyup
qemu_input_event_send_key_qcode(dcl->con, keycode, false);
modifiers_state[keycode] = 0;
}
[self toggleModifier:keycode];
}
}

Expand Down
1 change: 1 addition & 0 deletions ui/spice-core.c
Expand Up @@ -847,6 +847,7 @@ void qemu_spice_init(void)
exit(1);
}
display_opengl = 1;
spice_opengl = 1;
}
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion ui/spice-display.c
Expand Up @@ -27,6 +27,7 @@
#include "ui/spice-display.h"

static int debug = 0;
bool spice_opengl;

static void GCC_FMT_ATTR(2, 3) dprint(int level, const char *fmt, ...)
{
Expand Down Expand Up @@ -1013,7 +1014,7 @@ static void qemu_spice_display_init_one(QemuConsole *con)

ssd->dcl.ops = &display_listener_ops;
#ifdef HAVE_SPICE_GL
if (display_opengl) {
if (spice_opengl) {
ssd->dcl.ops = &display_listener_gl_ops;
ssd->gl_unblock_bh = qemu_bh_new(qemu_spice_gl_unblock_bh, ssd);
ssd->gl_unblock_timer = timer_new_ms(QEMU_CLOCK_REALTIME,
Expand Down
2 changes: 1 addition & 1 deletion ui/spice-input.c
Expand Up @@ -87,7 +87,7 @@ static void kbd_leds(void *opaque, int ledstate)
if (ledstate & QEMU_CAPS_LOCK_LED) {
kbd->ledstate |= SPICE_KEYBOARD_MODIFIER_FLAGS_CAPS_LOCK;
}
spice_server_kbd_leds(&kbd->sin, ledstate);
spice_server_kbd_leds(&kbd->sin, kbd->ledstate);
}

/* mouse bits */
Expand Down

0 comments on commit 30ff7d1

Please sign in to comment.