Fix key handling

I had forgotten to compare configured key values against lowered pressed
key values.
Integrated keypress() into winevent().
This commit is contained in:
Quentin Rameau 2015-11-22 17:44:40 +01:00
parent 971856a579
commit 00f9dcdf43

58
surf.c
View file

@ -105,7 +105,6 @@ static void sigchld(int unused);
static char *buildfile(const char *path); static char *buildfile(const char *path);
static char *buildpath(const char *path); static char *buildpath(const char *path);
static Client *newclient(Client *c); static Client *newclient(Client *c);
static void addaccelgroup(Client *c);
static void loaduri(Client *c, const Arg *a); static void loaduri(Client *c, const Arg *a);
static const char *geturi(Client *c); static const char *geturi(Client *c);
static void setatom(Client *c, int a, const char *v); static void setatom(Client *c, int a, const char *v);
@ -131,8 +130,6 @@ static WebKitWebView *newview(Client *c, WebKitWebView *rv);
static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a, static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a,
Client *c); Client *c);
static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c); static gboolean buttonreleased(GtkWidget *w, GdkEvent *e, Client *c);
static gboolean keypress(GtkAccelGroup *group, GObject *obj, guint key,
GdkModifierType mods, Client *c);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
gpointer d); gpointer d);
static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c); static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c);
@ -343,21 +340,6 @@ newclient(Client *rc)
return c; return c;
} }
void
addaccelgroup(Client *c)
{
int i;
GtkAccelGroup *group = gtk_accel_group_new();
GClosure *closure;
for (i = 0; i < LENGTH(keys); i++) {
closure = g_cclosure_new(G_CALLBACK(keypress), c, NULL);
gtk_accel_group_connect(group, keys[i].keyval, keys[i].mod, 0,
closure);
}
gtk_window_add_accel_group(GTK_WINDOW(c->win), group);
}
void void
loaduri(Client *c, const Arg *a) loaduri(Client *c, const Arg *a)
{ {
@ -828,28 +810,6 @@ buttonreleased(GtkWidget *w, GdkEvent *e, Client *c)
return FALSE; return FALSE;
} }
gboolean
keypress(GtkAccelGroup *group, GObject *obj, guint key, GdkModifierType mods,
Client *c)
{
guint i;
gboolean processed = FALSE;
mods = CLEANMASK(mods);
key = gdk_keyval_to_lower(key);
updatewinid(c);
for (i = 0; i < LENGTH(keys); i++) {
if (key == keys[i].keyval
&& mods == keys[i].mod
&& keys[i].func) {
keys[i].func(c, &(keys[i].arg));
processed = TRUE;
}
}
return processed;
}
GdkFilterReturn GdkFilterReturn
processx(GdkXEvent *e, GdkEvent *event, gpointer d) processx(GdkXEvent *e, GdkEvent *event, gpointer d)
{ {
@ -878,11 +838,26 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d)
gboolean gboolean
winevent(GtkWidget *w, GdkEvent *e, Client *c) winevent(GtkWidget *w, GdkEvent *e, Client *c)
{ {
int i;
switch (e->type) { switch (e->type) {
case GDK_ENTER_NOTIFY: case GDK_ENTER_NOTIFY:
c->overtitle = c->targeturi; c->overtitle = c->targeturi;
updatetitle(c); updatetitle(c);
break; break;
case GDK_KEY_PRESS:
if (!kioskmode) {
for (i = 0; i < LENGTH(keys); ++i) {
if (gdk_keyval_to_lower(e->key.keyval) ==
keys[i].keyval &&
CLEANMASK(e->key.state) == keys[i].mod &&
keys[i].func) {
updatewinid(c);
keys[i].func(c, &(keys[i].arg));
return TRUE;
}
}
}
case GDK_LEAVE_NOTIFY: case GDK_LEAVE_NOTIFY:
c->overtitle = NULL; c->overtitle = NULL;
updatetitle(c); updatetitle(c);
@ -928,7 +903,6 @@ showview(WebKitWebView *v, Client *c)
webkit_web_view_set_background_color(c->view, &bgcolor); webkit_web_view_set_background_color(c->view, &bgcolor);
if (!kioskmode) { if (!kioskmode) {
addaccelgroup(c);
gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK); gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
gdk_window_add_filter(gwin, processx, c); gdk_window_add_filter(gwin, processx, c);
} }
@ -970,6 +944,8 @@ createwindow(Client *c)
G_CALLBACK(destroywin), c); G_CALLBACK(destroywin), c);
g_signal_connect(G_OBJECT(w), "enter-notify-event", g_signal_connect(G_OBJECT(w), "enter-notify-event",
G_CALLBACK(winevent), c); G_CALLBACK(winevent), c);
g_signal_connect(G_OBJECT(w), "key-press-event",
G_CALLBACK(winevent), c);
g_signal_connect(G_OBJECT(w), "leave-notify-event", g_signal_connect(G_OBJECT(w), "leave-notify-event",
G_CALLBACK(winevent), c); G_CALLBACK(winevent), c);
g_signal_connect(G_OBJECT(w), "window-state-event", g_signal_connect(G_OBJECT(w), "window-state-event",