gtk: Replace some X11 input event handling

This regresses because IMs aren't used anymore. GTK+ has its own
IM implementations we should use instead, but for now event->string
is simpler.
Günther Brammer 2012-04-09 01:10:21 +02:00
parent 5f93869978
commit dc41afded5
3 changed files with 7 additions and 72 deletions

View File

@ -140,9 +140,6 @@ bool C4AbstractApp::Init(int argc, char * argv[])
// So a repeated keypress-event is not preceded with a keyrelease.
XkbSetDetectableAutoRepeat(dpy, True, &Priv->detectable_autorepeat_supported);
XSetLocaleModifiers("");
Priv->xim = XOpenIM(dpy, 0, 0, 0);
if (!Priv->xim) Log("Failed to open input method.");
#if USE_CONSOLE && HAVE_LIBREADLINE
@ -222,44 +219,6 @@ void C4AbstractApp::HandleXMessage()
case EnterNotify:
KeyMask = event.xcrossing.state;
break;
case KeyPress:
// Needed for input methods
if (!filtered)
{
char c[10] = "";
if (Priv->xic)
{
Status lsret;
Xutf8LookupString(Priv->xic, &event.xkey, c, 10, 0, &lsret);
if (lsret == XLookupKeySym) fprintf(stderr, "FIXME: XmbLookupString returned XLookupKeySym\n");
if (lsret == XBufferOverflow) fprintf(stderr, "FIXME: XmbLookupString returned XBufferOverflow\n");
}
else
{
static XComposeStatus state;
XLookupString(&event.xkey, c, 10, 0, &state);
}
if (c[0])
{
C4Window * pWindow = Priv->GetWindow(event.xany.window);
if (pWindow)
{
pWindow->CharIn(c);
}
}
// Fallthrough
}
case KeyRelease:
KeyMask = KeyMaskFromKeyEvent(dpy, &event.xkey);
Priv->LastEventTime = event.xkey.time;
break;
case ButtonPress:
// We can take this directly since there are no key presses
// involved. TODO: We probably need to correct button state
// here though.
KeyMask = event.xbutton.state;
Priv->LastEventTime = event.xbutton.time;
break;
case ClientMessage:
if (!strcmp(XGetAtomName(dpy, event.xclient.message_type), "WM_PROTOCOLS"))
{
@ -291,12 +250,6 @@ void C4AbstractApp::HandleXMessage()
Priv->SetWindow(event.xany.window, 0);
break;
}
case FocusIn:
if (Priv->xic) XSetICFocus(Priv->xic);
break;
case FocusOut:
if (Priv->xic) XUnsetICFocus(Priv->xic);
break;
case ConfigureNotify:
if (pWindow && event.xany.window == pWindow->wnd)
{

View File

@ -54,6 +54,7 @@ static gboolean OnKeyPress(GtkWidget* widget, GdkEventKey* event, gpointer data)
C4Window* wnd = static_cast<C4Window*>(data);
DWORD key = XKeycodeToKeysym(GDK_WINDOW_XDISPLAY(event->window), event->hardware_keycode, 0);
Game.DoKeyboardInput(key, KEYEV_Down, !!(event->state & GDK_MOD1_MASK), !!(event->state & GDK_CONTROL_MASK), !!(event->state & GDK_SHIFT_MASK), false, NULL);
wnd->CharIn(event->string); // FIXME: Use GtkIMContext somehow
return true;
}
@ -64,6 +65,11 @@ static gboolean OnKeyRelease(GtkWidget* widget, GdkEventKey* event, gpointer use
return true;
}
static gboolean OnButtonPress(GtkWidget *widget, GdkEventButton * event, C4AbstractApp * pApp)
{
pApp->KeyMask = event->state;
return false;
}
static void OnDragDataReceivedStatic(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer user_data)
{
if (!Console.Editing) { Console.Message(LoadResStr("IDS_CNS_NONETEDIT")); return; }
@ -555,6 +561,7 @@ C4Window* C4GtkWindow::Init(WindowKind windowKind, C4AbstractApp * pApp, const c
gtk_window_set_wmclass(GTK_WINDOW(window), C4ENGINENAME, C4ENGINENAME);
handlerDestroy = g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(OnDestroyStatic), this);
g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(OnButtonPress), pApp);
g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(OnUpdateKeyMask), pApp);
g_signal_connect(G_OBJECT(window), "key-release-event", G_CALLBACK(OnUpdateKeyMask), pApp);

View File

@ -305,31 +305,6 @@ C4Window * C4Window::Init(C4Window::WindowKind windowKind, C4AbstractApp * pApp,
return NULL;
}
if (pApp->Priv->xim && !pApp->Priv->xic)
{
pApp->Priv->xic = XCreateIC(pApp->Priv->xim,
XNClientWindow, wnd,
XNFocusWindow, wnd,
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNResourceName, C4ENGINENAME,
XNResourceClass, C4ENGINENAME,
NULL);
if(pApp->Priv->xic)
{
long ic_event_mask;
if (XGetICValues(pApp->Priv->xic, XNFilterEvents, &ic_event_mask, NULL) == NULL)
attr.event_mask |= ic_event_mask;
XSelectInput(dpy, wnd, attr.event_mask);
XSetICFocus(pApp->Priv->xic);
}
else
{
Log("Failed to create input context.");
XCloseIM(pApp->Priv->xim);
pApp->Priv->xim=0;
}
}
#if 0
// Set _NET_WM_STATE
if(n_net_wm_state_atoms)