Re: XUngrabKeyboard problem ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

Again, I think you should grab the seperate keys instead of the whole
keyboard.

Anyway, a good thing to avoid a lockout due to the keyboard being grabbed
is to use XNest. Test your application in a Xnested session. If your
keyboard is "grabbed" so you can't do anything you an just kill the
XNest-session from your "main" session.

/h
> Yessss it's working !
>
> Thanks you very much for your help, i will be able to continue my work
> :)
>
> Romain
>
>
> On Thu, 2004-04-22 at 00:49, Henrik Sandklef wrote:
>> Hmmm.... If you flush the X buffer after the ungrab call. Just add
>>
>> 	XFlush(disp);
>>
>> That should do it... I hope :)
>>
>> BTW, I would have grabbed the keys insted of the whole keyboard.
>>
>> /hesa
>> On Tue, 2004-04-20 at 20:28, Romain wrote:
>> > Humm nobody know where i can find help ?
>> >
>> > On Mon, 2004-04-19 at 01:39, Romain wrote:
>> > > Hello,
>> > >
>> > > I try to make a little program based on xlib and xosd, it's a daemon
>> > > listening on the keyboard made for example to increase volume level
>> or
>> > > other things.
>> > >
>> > > But i have a problem to Ungrab the keyboard, i made a sample of what
>> i
>> > > would like to do, if someone see where is the problem
>> > >
>> > > Thanks ! :)
>> > >
>> > > Romain
>> > >
>> > > (gcc devxosd.c -o devxosd -lxosd)
>> > >
>> > > /*
>> > >  * XOSD TEST
>> > >  */
>> > >
>> > > #include <stdio.h>
>> > > #include <stdlib.h>
>> > > #include <unistd.h>
>> > > #include <fcntl.h>
>> > > #include <sys/ioctl.h>
>> > > #include <errno.h>
>> > > #include <linux/types.h>
>> > >
>> > > #include <xosd.h>
>> > > #include <X11/Xlib.h>
>> > > #include <X11/keysym.h>
>> > > #include <X11/Xutil.h>
>> > >
>> > > #include <sys/soundcard.h>
>> > >
>> > >
>> > > int getSound (void)
>> > > {
>> > >      int fd_mixer, vol;
>> > >
>> > >      if ((fd_mixer = open ("/dev/mixer", O_RDWR)) < 0) {
>> > >           perror ("/dev/mixer");
>> > >           return -1;
>> > >      }
>> > >
>> > >      if (ioctl (fd_mixer, SOUND_MIXER_READ_VOLUME, &vol) == -1) {
>> > >           perror ("ioctl");
>> > >           return -1;
>> > >      }
>> > >
>> > >      if (close(fd_mixer) == -1) {
>> > >           perror("close");
>> > >           return -1;
>> > >      }
>> > >
>> > >      return vol&255;
>> > > }
>> > >
>> > > int setSound (int v)
>> > > {
>> > >      int fd_mixer, vol;
>> > >
>> > >      if ((fd_mixer = open ("/dev/mixer", O_RDWR)) < 0) {
>> > >           perror ("/dev/mixer");
>> > >           return -1;
>> > >      }
>> > >
>> > >      vol = (v << 8) | v ;
>> > >
>> > >      if (ioctl (fd_mixer, SOUND_MIXER_WRITE_VOLUME, &vol) == -1) {
>> > >           perror ("ioctl");
>> > >           return -1;
>> > >      }
>> > >
>> > >      if (close(fd_mixer) == -1) {
>> > >           perror("close");
>> > >           return -1;
>> > >      }
>> > >
>> > >      return 0;
>> > > }
>> > >
>> > > int volume (int level)
>> > > {
>> > >      Display *disp = NULL;
>> > >      Window root;
>> > >
>> > >      disp = XOpenDisplay(NULL);
>> > >      if (!disp) {
>> > >           fprintf(stderr, "Failed to open display\n");
>> > >           return -1;
>> > >      }
>> > >
>> > >      root = DefaultRootWindow(disp);
>> > >
>> > >
>> > >      /* Xlib */
>> > >      int nbre;
>> > >      char chaine[2];
>> > >      KeySym touche;
>> > >
>> > >      /* Xosd */
>> > >      xosd *osd = NULL;
>> > >      char *font =
>> > > "-adobe-helvetica-bold-r-normal-*-*-240-*-*-p-*-iso8859-1";
>> > >      char *title = "Volume";
>> > >
>> > >      int isUp = 1;
>> > >
>> > >      osd = xosd_create (2);
>> > >      if (osd == NULL) {
>> > >           perror ("Could not create \"osd\"");
>> > >           return -1;
>> > >      }
>> > >
>> > >      if (xosd_set_font (osd, font)) {
>> > >           printf ("Cound not set font\n");
>> > >           return -1;
>> > >      }
>> > >
>> > >      xosd_set_shadow_offset (osd, 2);
>> > >      xosd_set_colour (osd, "white");
>> > >
>> > >      /* Position */
>> > >      xosd_set_pos (osd, XOSD_bottom);
>> > >      xosd_set_vertical_offset (osd, 20);
>> > >      xosd_set_align (osd, XOSD_center);
>> > >      xosd_set_horizontal_offset (osd, 0);
>> > >      xosd_set_bar_length(osd, 20);
>> > >
>> > >      xosd_display (osd, 0, XOSD_string, title);
>> > >      xosd_display (osd, 1, XOSD_percentage, level);
>> > >
>> > >      XGrabKeyboard (disp, root, True, GrabModeAsync, GrabModeAsync,
>> > > CurrentTime);
>> > >
>> > >      while (isUp) {
>> > >           XEvent ev;
>> > >
>> > >           XNextEvent (disp, &ev);
>> > >           if (ev.type == KeyPress) {
>> > >
>> > >                nbre = XLookupString (&ev.xkey, chaine, 2, &touche,
>> 0);
>> > >                chaine[nbre] = 0;
>> > >
>> > >                switch (touche) {
>> > >
>> > >                case XK_q:
>> > >                case XK_Q:
>> > >                case XK_Escape:
>> > >                     isUp = 0;
>> > >                     break;
>> > >
>> > >                case XK_Right:
>> > >                     level = (level > 95 ? 100 : level + 5 );
>> > >                     setSound(level);
>> > >                     xosd_display (osd, 1, XOSD_percentage, level);
>> > >                     break;
>> > >
>> > >                case XK_Left:
>> > >                     level = (level < 5 ? 0 : level - 5 );
>> > >                     setSound(level);
>> > >                     xosd_display (osd, 1, XOSD_percentage, level);
>> > >                     break;
>> > >
>> > >                default:
>> > >                     break;
>> > >                }
>> > >           }
>> > >      }
>> > >
>> > >      XUngrabKeyboard (disp, CurrentTime);
>> > >      xosd_destroy (osd);
>> > >      return 0;
>> > > }
>> > >
>> > >
>> > > int main (int argc, char *argv[])
>> > > {
>> > >      volume (getSound());
>> > >      printf ("I want the keyboard back !\n");
>> > >      sleep (20);
>> > >      return 1;
>> > > }
>>
>> _______________________________________________
>> XFree86 mailing list
>> XFree86@xxxxxxxxxxx
>> http://XFree86.Org/mailman/listinfo/xfree86
> --
> Romain <buchu@xxxxxxxxxxxx>
> _______________________________________________
> XFree86 mailing list
> XFree86@xxxxxxxxxxx
> http://XFree86.Org/mailman/listinfo/xfree86
>


-- 
Though we rush ahead to save our time
We are only what we feel

 -- Neil Young / On the Way Home --
_______________________________________________
XFree86 mailing list
XFree86@xxxxxxxxxxx
http://XFree86.Org/mailman/listinfo/xfree86

[Index of Archives]     [X Forum]     [Xorg]     [XFree86 Newbie]     [IETF Announce]     [Security]     [Font Config]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux Kernel]

  Powered by Linux