Search
lxdream.org :: lxdream/src/drivers/video_gtk.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_gtk.c
changeset 608:4f588e52bce0
prev586:2a3ba82cf243
next609:41b61a0d5f1a
author nkeynes
date Sat Jan 26 02:45:27 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Bug #50: Implement mouse and keyboard
file annotate diff log raw
1.1 --- a/src/drivers/video_gtk.c Tue Jan 15 20:50:23 2008 +0000
1.2 +++ b/src/drivers/video_gtk.c Sat Jan 26 02:45:27 2008 +0000
1.3 @@ -22,6 +22,7 @@
1.4 #include <stdint.h>
1.5 #include "dream.h"
1.6 #include "display.h"
1.7 +#include "dckeysyms.h"
1.8 #include "drivers/video_glx.h"
1.9 #include "drivers/gl_common.h"
1.10 #include "pvr2/pvr2.h"
1.11 @@ -35,44 +36,14 @@
1.12 void video_gtk_shutdown();
1.13 gboolean video_gtk_display_blank( uint32_t colour );
1.14 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
1.15 +uint16_t video_gtk_keycode_to_dckeysym(uint32_t keycode);
1.16
1.17 struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
1.18 video_gtk_resolve_keysym,
1.19 + video_gtk_keycode_to_dckeysym,
1.20 NULL, NULL, NULL, NULL, NULL,
1.21 video_gtk_display_blank, NULL };
1.22
1.23 -/**
1.24 - * Extract the keyval of the key event if no modifier keys were pressed -
1.25 - * in other words get the keyval of the key by itself. The other way around
1.26 - * would be to use the hardware keysyms directly rather than the keyvals,
1.27 - * but the mapping looks to be messier.
1.28 - */
1.29 -uint16_t video_gtk_unmodified_keyval( GdkEventKey *event )
1.30 -{
1.31 - GdkKeymap *keymap = gdk_keymap_get_default();
1.32 - guint keyval;
1.33 -
1.34 - gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval,
1.35 - NULL, NULL, NULL );
1.36 - return keyval;
1.37 -}
1.38 -
1.39 -gboolean video_gtk_keydown_callback(GtkWidget *widget,
1.40 - GdkEventKey *event,
1.41 - gpointer user_data)
1.42 -{
1.43 - input_event_keydown( video_gtk_unmodified_keyval(event) );
1.44 - return TRUE;
1.45 -}
1.46 -
1.47 -gboolean video_gtk_keyup_callback(GtkWidget *widget,
1.48 - GdkEventKey *event,
1.49 - gpointer user_data)
1.50 -{
1.51 - input_event_keyup( video_gtk_unmodified_keyval(event) );
1.52 - return TRUE;
1.53 -}
1.54 -
1.55 uint16_t video_gtk_resolve_keysym( const gchar *keysym )
1.56 {
1.57 int val = gdk_keyval_from_name( keysym );
1.58 @@ -100,6 +71,85 @@
1.59 return TRUE;
1.60 }
1.61
1.62 +uint16_t video_gtk_keycode_to_dckeysym(uint32_t keycode)
1.63 +{
1.64 + if( keycode >= 'a' && keycode <= 'z' ) {
1.65 + return (keycode - 'a') + DCKB_A;
1.66 + } else if( keycode >= '1' && keycode <= '9' ) {
1.67 + return (keycode - '1') + DCKB_1;
1.68 + }
1.69 + switch(keycode) {
1.70 + case XK_0: return DCKB_0;
1.71 + case XK_Return: return DCKB_ENTER;
1.72 + case XK_Escape: return DCKB_ESCAPE;
1.73 + case XK_BackSpace: return DCKB_BACKSPACE;
1.74 + case XK_Tab: return DCKB_TAB;
1.75 + case XK_space: return DCKB_SPACE;
1.76 + case XK_minus: return DCKB_MINUS;
1.77 + case XK_equal: return DCKB_EQUAL;
1.78 + case XK_bracketleft: return DCKB_LBRACKET;
1.79 + case XK_bracketright: return DCKB_RBRACKET;
1.80 + case XK_semicolon: return DCKB_SEMICOLON;
1.81 + case XK_apostrophe:return DCKB_QUOTE;
1.82 + case XK_grave : return DCKB_BACKQUOTE;
1.83 + case XK_comma: return DCKB_COMMA;
1.84 + case XK_period: return DCKB_PERIOD;
1.85 + case XK_slash: return DCKB_SLASH;
1.86 + case XK_Caps_Lock: return DCKB_CAPSLOCK;
1.87 + case XK_F1: return DCKB_F1;
1.88 + case XK_F2: return DCKB_F2;
1.89 + case XK_F3: return DCKB_F3;
1.90 + case XK_F4: return DCKB_F4;
1.91 + case XK_F5: return DCKB_F5;
1.92 + case XK_F6: return DCKB_F6;
1.93 + case XK_F7: return DCKB_F7;
1.94 + case XK_F8: return DCKB_F8;
1.95 + case XK_F9: return DCKB_F9;
1.96 + case XK_F10: return DCKB_F10;
1.97 + case XK_F11: return DCKB_F11;
1.98 + case XK_F12: return DCKB_F12;
1.99 + case XK_Scroll_Lock: return DCKB_SCROLLLOCK;
1.100 + case XK_Pause: return DCKB_PAUSE;
1.101 + case XK_Insert: return DCKB_INSERT;
1.102 + case XK_Home: return DCKB_HOME;
1.103 + case XK_Page_Up: return DCKB_PAGEUP;
1.104 + case XK_Delete: return DCKB_DELETE;
1.105 + case XK_End: return DCKB_END;
1.106 + case XK_Page_Down: return DCKB_PAGEDOWN;
1.107 + case XK_Right: return DCKB_RIGHT;
1.108 + case XK_Left: return DCKB_LEFT;
1.109 + case XK_Down: return DCKB_DOWN;
1.110 + case XK_Up: return DCKB_UP;
1.111 + case XK_Num_Lock: return DCKB_NUMLOCK;
1.112 + case XK_KP_Divide: return DCKB_KP_SLASH;
1.113 + case XK_KP_Multiply: return DCKB_KP_STAR;
1.114 + case XK_KP_Subtract: return DCKB_KP_MINUS;
1.115 + case XK_KP_Add: return DCKB_KP_PLUS;
1.116 + case XK_KP_Enter: return DCKB_KP_ENTER;
1.117 + case XK_KP_1: return DCKB_KP_1;
1.118 + case XK_KP_2: return DCKB_KP_2;
1.119 + case XK_KP_3: return DCKB_KP_3;
1.120 + case XK_KP_4: return DCKB_KP_4;
1.121 + case XK_KP_5: return DCKB_KP_5;
1.122 + case XK_KP_6: return DCKB_KP_6;
1.123 + case XK_KP_7: return DCKB_KP_7;
1.124 + case XK_KP_8: return DCKB_KP_8;
1.125 + case XK_KP_9: return DCKB_KP_9;
1.126 + case XK_KP_0: return DCKB_KP_0;
1.127 + case XK_KP_Decimal:return DCKB_KP_PERIOD;
1.128 + case XK_backslash: return DCKB_BACKSLASH;
1.129 + case XK_Control_L: return DCKB_CONTROL_L;
1.130 + case XK_Shift_L: return DCKB_SHIFT_L;
1.131 + case XK_Alt_L: return DCKB_ALT_L;
1.132 + case XK_Meta_L: return DCKB_S1;
1.133 + case XK_Control_R: return DCKB_CONTROL_R;
1.134 + case XK_Shift_R: return DCKB_SHIFT_R;
1.135 + case XK_Alt_R: return DCKB_ALT_R;
1.136 + case XK_Meta_R: return DCKB_S2;
1.137 + }
1.138 + return DCKB_NONE;
1.139 +}
1.140 +
1.141 gboolean video_gtk_init()
1.142 {
1.143
1.144 @@ -108,18 +158,10 @@
1.145 return FALSE;
1.146 }
1.147
1.148 - g_signal_connect( video_win, "key_press_event",
1.149 - G_CALLBACK(video_gtk_keydown_callback), NULL );
1.150 - g_signal_connect( video_win, "key_release_event",
1.151 - G_CALLBACK(video_gtk_keyup_callback), NULL );
1.152 g_signal_connect( video_win, "expose_event",
1.153 G_CALLBACK(video_gtk_expose_callback), NULL );
1.154 g_signal_connect( video_win, "configure_event",
1.155 G_CALLBACK(video_gtk_resize_callback), NULL );
1.156 - gtk_widget_add_events( video_win,
1.157 - GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
1.158 - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
1.159 - gtk_widget_set_double_buffered( video_win, FALSE );
1.160 video_width = video_win->allocation.width;
1.161 video_height = video_win->allocation.height;
1.162 Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win)));
.