# HG changeset patch # User nkeynes # Date 1201660797 0 # Node ID 3ade50e8603ce330bef65e7ff393a2a6220378d2 # Parent 476a717a54f3cc50e2131c64187e2285b37b4078 Embed gdk_display_warp_pointer for GTK 2.6 implementations that lack in (mainly for OSX) Perform real modifier mapping to get CTRL+ALT for screen ungrab rather than assuming the keysyms. --- a/src/gtkui/gtkui.c Tue Jan 29 10:39:56 2008 +0000 +++ b/src/gtkui/gtkui.c Wed Jan 30 02:39:57 2008 +0000 @@ -20,6 +20,7 @@ #include #include #include +#include #include "dreamcast.h" #include "display.h" #include "gdrom/gdrom.h" @@ -491,3 +492,69 @@ return keyval; } +/************* X11-specificness **********/ +#include + +guint gdk_keycode_to_modifier( GdkDisplay *display, guint keycode ) +{ + int i; + int result = 0; + Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); + XModifierKeymap *keymap = XGetModifierMapping( xdisplay ); + for( i=0; i<8*keymap->max_keypermod; i++ ) { + if( keymap->modifiermap[i] == keycode ) { + result = 1 << (i/keymap->max_keypermod); + break; + } + } + XFreeModifiermap(keymap); + return result; +} + +#if !(GTK_CHECK_VERSION(2,8,0)) +/* gdk_display_warp_pointer was added in GTK 2.8. If we're using an earlier + * version, include the code here. (Can't just set the dependency on 2.8 as + * it still hasn't been ported to OSX...) Original copyright statement belo + */ + +/* GDK - The GIMP Drawing Kit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ +void gdk_display_warp_pointer (GdkDisplay *display, + GdkScreen *screen, + gint x, + gint y) +{ + Display *xdisplay; + Window dest; + + xdisplay = GDK_DISPLAY_XDISPLAY (display); + dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen)); + + XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y); +} + +#endif + --- a/src/gtkui/gtkui.h Tue Jan 29 10:39:56 2008 +0000 +++ b/src/gtkui/gtkui.h Wed Jan 30 02:39:57 2008 +0000 @@ -92,6 +92,15 @@ uint16_t gtk_get_unmodified_keyval( GdkEventKey *event ); /** + * Map a hardware keycode (not keyval) to a modifier state mask. + * @param display The display (containing the modifier map) + * @param keycde The hardware keycode to map + * @return The modifier mask (eg GDK_CONTROL_MASK) or 0 if the keycode + * is not recognized as a modifier key. + */ +guint gdk_keycode_to_modifier( GdkDisplay *display, guint keycode ); + +/** * Construct a new pixbuf that takes ownership of the frame buffer */ GdkPixbuf *gdk_pixbuf_new_from_frame_buffer( frame_buffer_t buffer ); --- a/src/gtkui/main_win.c Tue Jan 29 10:39:56 2008 +0000 +++ b/src/gtkui/main_win.c Wed Jan 30 02:39:57 2008 +0000 @@ -168,11 +168,10 @@ * Only check Ctrl/Shift/Alt for state - don't want to check numlock/capslock/ * mouse buttons/etc */ - int state = event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_MOD1_MASK); - if( (state == GDK_CONTROL_MASK && - (event->keyval == GDK_Alt_L || event->keyval == GDK_Alt_R)) || - (state == GDK_MOD1_MASK && - (event->keyval == GDK_Control_L || event->keyval == GDK_Control_R)) ) { + int mod = gdk_keycode_to_modifier(gtk_widget_get_display(widget), event->hardware_keycode); + int state = event->state & gtk_accelerator_get_default_mod_mask(); + if( (state == GDK_CONTROL_MASK && mod == GDK_MOD1_MASK) || + (state == GDK_MOD1_MASK && mod == GDK_CONTROL_MASK) ) { video_window_ungrab_display(win); // Consume the keypress, DC doesn't get it. return TRUE; @@ -190,13 +189,6 @@ return TRUE; } -static gboolean on_video_window_grab_broken( GtkWidget *widget, GdkEventGrabBroken *event, - gpointer user_data ) -{ - main_window_t win = (main_window_t)user_data; - fprintf( stderr, "Grab broken\n" ); -} - static gboolean on_video_window_focus_changed( GtkWidget *widget, GdkEventFocus *event, gpointer user_data ) { @@ -293,8 +285,6 @@ g_signal_connect( win->window, "window-state-event", G_CALLBACK(on_main_window_state_changed), win ); - g_signal_connect( win->video, "grab-broken-event", - G_CALLBACK(on_video_window_grab_broken), win ); g_signal_connect( win->video, "key-press-event", G_CALLBACK(on_video_window_key_pressed), win ); g_signal_connect( win->video, "key-release-event",