From ee1d021a7f66262d7d15d079931c2435e08e4b69 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 6 Jan 2012 16:45:33 +0000 Subject: [PATCH] Added snooper, a tool to test the gtk_key_snooper_install() function --- Makefile | 1 + tools/.cvsignore | 1 + tools/Makefile | 14 ++++++++-- tools/project.conf | 6 +++- tools/snooper.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 tools/snooper.c diff --git a/Makefile b/Makefile index 47e6415..d45ca2a 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ dist: $(PACKAGE)-$(VERSION)/src/layout.h \ $(PACKAGE)-$(VERSION)/src/project.conf \ $(PACKAGE)-$(VERSION)/tools/plug.c \ + $(PACKAGE)-$(VERSION)/tools/snooper.c \ $(PACKAGE)-$(VERSION)/tools/xkey.c \ $(PACKAGE)-$(VERSION)/tools/Makefile \ $(PACKAGE)-$(VERSION)/tools/project.conf \ diff --git a/tools/.cvsignore b/tools/.cvsignore index fc62e49..643f57b 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -1,2 +1,3 @@ plug +snooper xkey diff --git a/tools/Makefile b/tools/Makefile index 830ee26..ba0a19a 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,4 +1,4 @@ -TARGETS = plug xkey +TARGETS = plug snooper xkey PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -23,6 +23,13 @@ plug_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) plug: $(plug_OBJS) $(CC) -o plug $(plug_OBJS) $(plug_LDFLAGS) +snooper_OBJS = snooper.o +snooper_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +snooper_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +snooper: $(snooper_OBJS) + $(CC) -o snooper $(snooper_OBJS) $(snooper_LDFLAGS) + xkey_OBJS = xkey.o xkey_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) xkey_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -lXtst @@ -33,11 +40,14 @@ xkey: $(xkey_OBJS) plug.o: plug.c $(CC) $(plug_CFLAGS) -c plug.c +snooper.o: snooper.c + $(CC) $(snooper_CFLAGS) -c snooper.c + xkey.o: xkey.c $(CC) $(xkey_CFLAGS) -c xkey.c clean: - $(RM) -- $(plug_OBJS) $(xkey_OBJS) + $(RM) -- $(plug_OBJS) $(snooper_OBJS) $(xkey_OBJS) distclean: clean $(RM) -- $(TARGETS) diff --git a/tools/project.conf b/tools/project.conf index e6e29e6..c99e344 100644 --- a/tools/project.conf +++ b/tools/project.conf @@ -1,4 +1,4 @@ -targets=plug,xkey +targets=plug,snooper,xkey cflags_force=-W `pkg-config --cflags gtk+-2.0` cflags=-Wall -g -O2 ldflags_force=`pkg-config --libs gtk+-2.0` @@ -8,6 +8,10 @@ dist=Makefile type=binary sources=plug.c +[snooper] +type=binary +sources=snooper.c + [xkey] type=binary sources=xkey.c diff --git a/tools/snooper.c b/tools/snooper.c new file mode 100644 index 0000000..5ce2190 --- /dev/null +++ b/tools/snooper.c @@ -0,0 +1,70 @@ +/* $Id$ */ +/* Copyright (c) 2012 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Keyboard */ +/* 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, version 3 of the License. + * + * 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, see . */ + + + +#include +#include +#include +#include + + +/* prototypes */ +/* callbacks */ +static gint _snooper_on_key_snoop(GtkWidget * grab, GdkEventKey * event, + gpointer data); + + +/* functions */ +/* callbacks */ +/* snooper_on_key_snoop */ +static gint _snooper_on_key_snoop(GtkWidget * grab, GdkEventKey * event, + gpointer data) +{ +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s()\n", __func__); +#endif + return TRUE; +} + + +/* usage */ +static int _usage(void) +{ + fputs("Usage: snooper\n", stderr); + return 1; +} + + +/* main */ +int main(int argc, char * argv[]) +{ + int o; + guint id; + + gtk_init(&argc, &argv); + while((o = getopt(argc, argv, "")) != -1) + switch(o) + { + default: + return _usage(); + } + if(optind != argc) + return _usage(); + id = gtk_key_snooper_install(_snooper_on_key_snoop, NULL); + gtk_main(); + gtk_key_snooper_remove(id); + return 0; +}