File: gtkkeyboard.c

package info (click to toggle)
fuse-emulator 1.0.0.1a%2Bdfsg1-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 9,568 kB
  • sloc: ansic: 67,895; sh: 10,265; perl: 3,386; makefile: 787; yacc: 227; lex: 139
file content (106 lines) | stat: -rw-r--r-- 3,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* gtkkeyboard.c: GTK+ routines for dealing with the keyboard
   Copyright (c) 2000-2008 Philip Kendall, Russell Marks

   $Id: gtkkeyboard.c 4176 2010-10-06 10:56:05Z fredm $

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program 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 General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

   Author contact information:

   E-mail: philip-fuse@shadowmagic.org.uk

*/

#include <config.h>

#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "compat.h"
#include "gtkinternals.h"
#include "input.h"
#include "keyboard.h"
#include "ui/ui.h"

/* Given a hardware keycode, return the keyval which would have been returned if
   the key were unshifted */
static guint
unshift_keysym( guint keycode, gint group )
{
  GdkKeymapKey *maps;
  guint *keyvals, i, r = GDK_VoidSymbol, r2 = GDK_VoidSymbol;
  gint count;

  gdk_keymap_get_entries_for_keycode( NULL, keycode, &maps, &keyvals, &count );

  for( i = 0; i < count; i++ ) {
    if( maps[i].group == group && maps[i].level == 0 ) {
      r = keyvals[i];
      break;
    }
    if( maps[i].group == 0 && maps[i].level == 0 ) {
      r2 = keyvals[i];
    }
  }
  if (i == count)
	  r = r2;

  g_free( keyvals ); g_free( maps );

  return r;
}

static void
get_keysyms( input_event_t *event, guint keycode, guint keysym, gint group )
{
  guint unshifted;

  /* The GTK+ UI doesn't actually use the native keysym for anything,
     but we may as well set it up anyway as we've got it */
  event->types.key.native_key = keysyms_remap( keysym );

  unshifted = unshift_keysym( keycode, group );
  event->types.key.spectrum_key = keysyms_remap( unshifted );
}

int
gtkkeyboard_keypress( GtkWidget *widget GCC_UNUSED, GdkEvent *event,
		      gpointer data GCC_UNUSED )
{
  input_event_t fuse_event;

  if( event->key.keyval == GDK_F1 && event->key.state == 0 )
    ui_mouse_suspend();

  fuse_event.type = INPUT_EVENT_KEYPRESS;
  get_keysyms( &fuse_event, event->key.hardware_keycode, event->key.keyval, event->key.group );

  return input_event( &fuse_event );

  /* FIXME: handle F1 to deal with the pop-up menu */
}

int
gtkkeyboard_keyrelease( GtkWidget *widget GCC_UNUSED, GdkEvent *event,
			gpointer data GCC_UNUSED )
{
  input_event_t fuse_event;

  fuse_event.type = INPUT_EVENT_KEYRELEASE;
  get_keysyms( &fuse_event, event->key.hardware_keycode, event->key.keyval, event->key.group );

  return input_event( &fuse_event );
}