mirror of
https://github.com/0intro/wmii
synced 2024-11-24 22:59:45 +03:00
3acb239918
GCC switched default from -fcommon to -fno-common, leading to the following compilation errors: multiple definition of `argv0' multiple definition of `display' multiple definition of `scr' multiple definition of `font' multiple definition of `cnorm' multiple definition of `csel' multiple definition of `debugflag' multiple definition of `debugfile' multiple definition of `cursor' multiple definition of `framehandler' multiple definition of `NM'
83 lines
1.3 KiB
C
83 lines
1.3 KiB
C
/* Copyright ©2010 Kris Maglione <maglione.k at Gmail>
|
|
* See LICENSE file for license details.
|
|
*/
|
|
#include <stuff/util.h>
|
|
#include <stuff/x.h>
|
|
#include <fmt.h>
|
|
#include <locale.h>
|
|
#include <unistd.h>
|
|
|
|
char *argv0;
|
|
Display *display;
|
|
Screen scr;
|
|
|
|
static const char version[] = "wikeyname-"VERSION", "COPYRIGHT"\n";
|
|
|
|
static Handlers handlers;
|
|
static char* keyname;
|
|
static int nkeys;
|
|
|
|
static void
|
|
usage(void) {
|
|
lprint(2, "usage: wikeyname\n");
|
|
exit(1);
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[]) {
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
ARGBEGIN{
|
|
case 'v':
|
|
lprint(2, version);
|
|
return 0;
|
|
default: usage();
|
|
}ARGEND;
|
|
|
|
if(argc)
|
|
usage();
|
|
|
|
fmtinstall('K', fmtkey);
|
|
initdisplay();
|
|
|
|
selectinput(&scr.root, KeyPressMask|KeyReleaseMask);
|
|
sethandler(&scr.root, &handlers);
|
|
if(!grabkeyboard(&scr.root))
|
|
fatal("can't grab keyboard\n");
|
|
|
|
if(isatty(1))
|
|
lprint(2, "Please press a key...\n");
|
|
event_loop();
|
|
lprint(1, "%s\n", keyname);
|
|
|
|
XCloseDisplay(display);
|
|
return 0;
|
|
}
|
|
|
|
static bool
|
|
kdown_event(Window *w, void *aux, XKeyEvent *ev) {
|
|
|
|
USED(w, aux);
|
|
nkeys++;
|
|
free(keyname);
|
|
keyname = smprint("%K", ev);
|
|
return false;
|
|
}
|
|
|
|
static bool
|
|
kup_event(Window *w, void *aux, XKeyEvent *ev) {
|
|
|
|
USED(w, aux, ev);
|
|
if(keyname != nil && --nkeys <= 0)
|
|
event_looprunning = false;
|
|
return false;
|
|
}
|
|
|
|
|
|
static Handlers handlers = {
|
|
.kup = kup_event,
|
|
.kdown = kdown_event,
|
|
};
|
|
|