Xref: utzoo comp.windows.news:2264 alt.sys.sun:1115 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!sun-barr!newstop!sun!booga.Eng.Sun.COM!siegel From: siegel@booga.Eng.Sun.COM (Josh Siegel) Newsgroups: comp.windows.news,alt.sys.sun Subject: Re: Why does X-programs running under XView/NeWS not respond to key-press Message-ID: <139540@sun.Eng.Sun.COM> Date: 25 Jul 90 03:36:09 GMT References: <1990Jul23.202347.6625@resam.dk> Sender: news@sun.Eng.Sun.COM Organization: Sun Microsystems, Mt. View, Ca. Lines: 120 In article <1990Jul23.202347.6625@resam.dk> andrew@resam.dk (Leif Andrew Rump) writes: >I have several program written for X which runs perfect under NeWS >except for keyinput - it end in the shell that started the program! >Why? > OpenWindows requires window manager hints to be sent to the window manager in order to get keyboard events. Below is a sample program that "should" compile under OpenWindows 2.0 that gives a example of keyboard events. Hope this helps --josh siegel --- /* A side note... * * For keyboard input, you MUST give the XSetWMHints() call BEFORE * you map the window. If you do it after, it has no effect. */ #include #include #include main(argc, argv) int argc; char *argv[]; { GC gc; KeySym key; XEvent event; Window window; Display *display; XSizeHints shints; XWMHints wmhints; XGCValues values; char temp; int num, screen; unsigned long mask, foreground, background; if (!(display = XOpenDisplay(""))) { (void) fprintf(stderr,"Can't open display....\n"); exit(1); } screen = DefaultScreen(display); foreground = WhitePixel(display, screen); background = BlackPixel(display, screen); shints.x = shints.y = 250; shints.width = shints.height = 350; shints.flags = PPosition | PSize; window = XCreateSimpleWindow(display, DefaultRootWindow(display), shints.x, shints.y, shints.width, shints.height, 2, foreground, background); mask = GCForeground | GCBackground;; values.foreground = foreground; values.background = background; gc = XCreateGC(display, window, mask, &values); wmhints.input = True; wmhints.flags = InputHint; XSetWMHints(display, window, &wmhints); mask = KeyPressMask | ExposureMask ; XSelectInput(display, window, mask); XSetStandardProperties(display, window, "Hello Demo", "Hello Icon", None, argv, &argc, &shints); XMapRaised(display, window); XFlush(display); XSync(display,False); while (1) { XWindowEvent(display,window, mask, &event); switch (event.type) { case Expose: if (event.xexpose.count == 0) XClearWindow(display, window); break; case MappingNotify: XRefreshKeyboardMapping(&event); break; case KeyPress: printf("KeyPress\n"); num = XLookupString(&event, &temp, 1, &key, 0); if (num == 1 && (temp == 'q' || temp == 'Q')) { XFreeGC(display, gc); XDestroyWindow(display, window); XCloseDisplay(display); exit(0); } break; } XFlush(display); } }