static Bool
addPassiveButtonGrab (CompScreen        *s,
		      CompButtonBinding *button)
{
    CompButtonGrab *buttonGrab;
    unsigned int   modifiers, mask;
    int            i;

    modifiers = button->modifiers & ~(CompPressMask | CompReleaseMask);
    if (modifiers == button->modifiers)
	return TRUE;

    for (i = 0; i < s->nButtonGrab; i++)
    {
	if (button->button  == s->buttonGrab[i].button &&
	    modifiers       == s->buttonGrab[i].modifiers)
	{
	    s->buttonGrab[i].count++;
	    return TRUE;
	}
    }

    buttonGrab = realloc (s->buttonGrab,
			  sizeof (CompButtonGrab) * (s->nButtonGrab + 1));
    if (!buttonGrab)
	return FALSE;

    s->buttonGrab = buttonGrab;

    mask = virtualToRealModMask (s->display, modifiers);
    if (!(mask & CompNoMask))
    {
	compCheckForError ();

	XGrabButton (s->display->display,
		     button->button,
		     mask,
		     s->root,
		     TRUE,
		     POINTER_GRAB_MASK,
		     GrabModeAsync,
		     GrabModeAsync,
		     None,
		     None);

	XSync (s->display->display, FALSE);

	if (compCheckForError ())
	{

#ifdef DEBUG
	    fprintf (stderr, "XGrabButton failed: %s 0x%x\n",
		     button->button, modifiers);
#endif

	return FALSE;
	}
    }

    s->buttonGrab[s->nButtonGrab].button    = button->button;
    s->buttonGrab[s->nButtonGrab].modifiers = modifiers;
    s->buttonGrab[s->nButtonGrab].count     = 1;

    s->nButtonGrab++;

    return TRUE;
}
예제 #2
0
static void
decorCheckForDmOnScreen (CompScreen *s,
			 Bool	    updateWindows)
{
    CompDisplay   *d = s->display;
    Atom	  actual;
    int		  result, format;
    unsigned long n, left;
    unsigned char *data;
    Window	  dmWin = None;

    DECOR_DISPLAY (s->display);
    DECOR_SCREEN (s);

    result = XGetWindowProperty (d->display, s->root,
				 dd->supportingDmCheckAtom, 0L, 1L, FALSE,
				 XA_WINDOW, &actual, &format,
				 &n, &left, &data);

    if (result == Success && data)
    {
	if (n)
	{
	    XWindowAttributes attr;

	    memcpy (&dmWin, data, sizeof (Window));

	    compCheckForError (d->display);

	    XGetWindowAttributes (d->display, dmWin, &attr);

	    if (compCheckForError (d->display))
		dmWin = None;
	}

	XFree (data);
    }

    if (dmWin != ds->dmWin)
    {
	CompWindow *w;
	int	   i;

	if (dmWin)
	{
	    for (i = 0; i < DECOR_NUM; i++)
		ds->decor[i] =
		    decorCreateDecoration (s, s->root, dd->decorAtom[i]);
	}
	else
	{
	    for (i = 0; i < DECOR_NUM; i++)
	    {
		if (ds->decor[i])
		{
		    decorReleaseDecoration (s, ds->decor[i]);
		    ds->decor[i] = 0;
		}
	    }

	    for (w = s->windows; w; w = w->next)
	    {
		DECOR_WINDOW (w);

		if (dw->decor)
		{
		    decorReleaseDecoration (s, dw->decor);
		    dw->decor = 0;
		}
	    }
	}

	ds->dmWin = dmWin;

	if (updateWindows)
	{
	    for (w = s->windows; w; w = w->next)
		decorWindowUpdate (w, TRUE);
	}
    }
}
static Bool
addPassiveKeyGrab (CompScreen	  *s,
		   CompKeyBinding *key)
{
    CompKeyGrab  *keyGrab;
    unsigned int modifiers, mask;
    int          i;

    modifiers = key->modifiers & ~(CompPressMask | CompReleaseMask);
    if (modifiers == key->modifiers)
	return TRUE;

    for (i = 0; i < s->nKeyGrab; i++)
    {
	if (key->keycode == s->keyGrab[i].keycode &&
	    modifiers    == s->keyGrab[i].modifiers)
	{
	    s->keyGrab[i].count++;
	    return TRUE;
	}
    }

    keyGrab = realloc (s->keyGrab, sizeof (CompKeyGrab) * (s->nKeyGrab + 1));
    if (!keyGrab)
	return FALSE;

    s->keyGrab = keyGrab;

    mask = virtualToRealModMask (s->display, modifiers);
    if (!(mask & CompNoMask))
    {
	compCheckForError ();

	XGrabKey (s->display->display,
		  key->keycode,
		  mask,
		  s->root,
		  TRUE,
		  GrabModeAsync,
		  GrabModeAsync);

	XSync (s->display->display, FALSE);

	if (compCheckForError ())
	{

#ifdef DEBUG
	    KeySym keysym;
	    char   *keyname;

	    keysym = XKeycodeToKeysym (s->display->display,
				       key->keycode,
				       0);
	    keyname = XKeysymToString (keysym);

	    fprintf (stderr, "XGrabKey failed: %s 0x%x\n",
		     keyname, modifiers);
#endif

	    return FALSE;
	}
    }

    s->keyGrab[s->nKeyGrab].keycode   = key->keycode;
    s->keyGrab[s->nKeyGrab].modifiers = modifiers;
    s->keyGrab[s->nKeyGrab].count     = 1;

    s->nKeyGrab++;

    return TRUE;
}