Search
lxdream.org :: lxdream :: r618:3ade50e8603c
lxdream 0.9.1
released Jun 29
Download Now
changeset618:3ade50e8603c
parent617:476a717a54f3
child619:0800a0137472
authornkeynes
dateWed Jan 30 02:39:57 2008 +0000 (15 years ago)
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.
src/gtkui/gtkui.c
src/gtkui/gtkui.h
src/gtkui/main_win.c
1.1 --- a/src/gtkui/gtkui.c Tue Jan 29 10:39:56 2008 +0000
1.2 +++ b/src/gtkui/gtkui.c Wed Jan 30 02:39:57 2008 +0000
1.3 @@ -20,6 +20,7 @@
1.4 #include <sys/time.h>
1.5 #include <time.h>
1.6 #include <glib/gi18n.h>
1.7 +#include <gtk/gtkversion.h>
1.8 #include "dreamcast.h"
1.9 #include "display.h"
1.10 #include "gdrom/gdrom.h"
1.11 @@ -491,3 +492,69 @@
1.12 return keyval;
1.13 }
1.14
1.15 +/************* X11-specificness **********/
1.16 +#include <gdk/gdkx.h>
1.17 +
1.18 +guint gdk_keycode_to_modifier( GdkDisplay *display, guint keycode )
1.19 +{
1.20 + int i;
1.21 + int result = 0;
1.22 + Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1.23 + XModifierKeymap *keymap = XGetModifierMapping( xdisplay );
1.24 + for( i=0; i<8*keymap->max_keypermod; i++ ) {
1.25 + if( keymap->modifiermap[i] == keycode ) {
1.26 + result = 1 << (i/keymap->max_keypermod);
1.27 + break;
1.28 + }
1.29 + }
1.30 + XFreeModifiermap(keymap);
1.31 + return result;
1.32 +}
1.33 +
1.34 +#if !(GTK_CHECK_VERSION(2,8,0))
1.35 +/* gdk_display_warp_pointer was added in GTK 2.8. If we're using an earlier
1.36 + * version, include the code here. (Can't just set the dependency on 2.8 as
1.37 + * it still hasn't been ported to OSX...) Original copyright statement belo
1.38 + */
1.39 +
1.40 +/* GDK - The GIMP Drawing Kit
1.41 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.42 + *
1.43 + * This library is free software; you can redistribute it and/or
1.44 + * modify it under the terms of the GNU Lesser General Public
1.45 + * License as published by the Free Software Foundation; either
1.46 + * version 2 of the License, or (at your option) any later version.
1.47 + *
1.48 + * This library is distributed in the hope that it will be useful,
1.49 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.50 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.51 + * Lesser General Public License for more details.
1.52 + *
1.53 + * You should have received a copy of the GNU Lesser General Public
1.54 + * License along with this library; if not, write to the
1.55 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.56 + * Boston, MA 02111-1307, USA.
1.57 + */
1.58 +
1.59 +/*
1.60 + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
1.61 + * file for a list of people on the GTK+ Team. See the ChangeLog
1.62 + * files for a list of changes. These files are distributed with
1.63 + * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
1.64 + */
1.65 +void gdk_display_warp_pointer (GdkDisplay *display,
1.66 + GdkScreen *screen,
1.67 + gint x,
1.68 + gint y)
1.69 +{
1.70 + Display *xdisplay;
1.71 + Window dest;
1.72 +
1.73 + xdisplay = GDK_DISPLAY_XDISPLAY (display);
1.74 + dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
1.75 +
1.76 + XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y);
1.77 +}
1.78 +
1.79 +#endif
1.80 +
2.1 --- a/src/gtkui/gtkui.h Tue Jan 29 10:39:56 2008 +0000
2.2 +++ b/src/gtkui/gtkui.h Wed Jan 30 02:39:57 2008 +0000
2.3 @@ -92,6 +92,15 @@
2.4 uint16_t gtk_get_unmodified_keyval( GdkEventKey *event );
2.5
2.6 /**
2.7 + * Map a hardware keycode (not keyval) to a modifier state mask.
2.8 + * @param display The display (containing the modifier map)
2.9 + * @param keycde The hardware keycode to map
2.10 + * @return The modifier mask (eg GDK_CONTROL_MASK) or 0 if the keycode
2.11 + * is not recognized as a modifier key.
2.12 + */
2.13 +guint gdk_keycode_to_modifier( GdkDisplay *display, guint keycode );
2.14 +
2.15 +/**
2.16 * Construct a new pixbuf that takes ownership of the frame buffer
2.17 */
2.18 GdkPixbuf *gdk_pixbuf_new_from_frame_buffer( frame_buffer_t buffer );
3.1 --- a/src/gtkui/main_win.c Tue Jan 29 10:39:56 2008 +0000
3.2 +++ b/src/gtkui/main_win.c Wed Jan 30 02:39:57 2008 +0000
3.3 @@ -168,11 +168,10 @@
3.4 * Only check Ctrl/Shift/Alt for state - don't want to check numlock/capslock/
3.5 * mouse buttons/etc
3.6 */
3.7 - int state = event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_MOD1_MASK);
3.8 - if( (state == GDK_CONTROL_MASK &&
3.9 - (event->keyval == GDK_Alt_L || event->keyval == GDK_Alt_R)) ||
3.10 - (state == GDK_MOD1_MASK &&
3.11 - (event->keyval == GDK_Control_L || event->keyval == GDK_Control_R)) ) {
3.12 + int mod = gdk_keycode_to_modifier(gtk_widget_get_display(widget), event->hardware_keycode);
3.13 + int state = event->state & gtk_accelerator_get_default_mod_mask();
3.14 + if( (state == GDK_CONTROL_MASK && mod == GDK_MOD1_MASK) ||
3.15 + (state == GDK_MOD1_MASK && mod == GDK_CONTROL_MASK) ) {
3.16 video_window_ungrab_display(win);
3.17 // Consume the keypress, DC doesn't get it.
3.18 return TRUE;
3.19 @@ -190,13 +189,6 @@
3.20 return TRUE;
3.21 }
3.22
3.23 -static gboolean on_video_window_grab_broken( GtkWidget *widget, GdkEventGrabBroken *event,
3.24 - gpointer user_data )
3.25 -{
3.26 - main_window_t win = (main_window_t)user_data;
3.27 - fprintf( stderr, "Grab broken\n" );
3.28 -}
3.29 -
3.30 static gboolean on_video_window_focus_changed( GtkWidget *widget, GdkEventFocus *event,
3.31 gpointer user_data )
3.32 {
3.33 @@ -293,8 +285,6 @@
3.34 g_signal_connect( win->window, "window-state-event",
3.35 G_CALLBACK(on_main_window_state_changed), win );
3.36
3.37 - g_signal_connect( win->video, "grab-broken-event",
3.38 - G_CALLBACK(on_video_window_grab_broken), win );
3.39 g_signal_connect( win->video, "key-press-event",
3.40 G_CALLBACK(on_video_window_key_pressed), win );
3.41 g_signal_connect( win->video, "key-release-event",
.