Exemplo n.º 1
0
Arquivo: focus.c Projeto: fvwmorg/fvwm
static void __focus_grab_buttons(FvwmWindow *fw, Bool client_entered)
{
	int i;
	Bool do_grab_window = False;
	int grab_buttons;

	if (fw == NULL || IS_SCHEDULED_FOR_DESTROY(fw) || !IS_MAPPED(fw))
	{
		/* It is pointless to grab buttons on dieing windows.  Buttons
		 * can not be grabbed when the window is unmapped. */
		return;
	}
	grab_buttons = Scr.buttons2grab;
	do_grab_window = focus_query_grab_buttons(fw, client_entered);
	if (do_grab_window == True)
	{
		grab_buttons |= FP_USE_MOUSE_BUTTONS(FW_FOCUS_POLICY(fw));
	}
	if (grab_buttons != fw->grabbed_buttons)
	{
		MyXGrabServer(dpy);
		for (i = 0; i < NUMBER_OF_EXTENDED_MOUSE_BUTTONS; i++)
		{
			__focus_grab_one_button(fw, i, grab_buttons);
		}
		MyXUngrabServer (dpy);
	}

	return;
}
Exemplo n.º 2
0
/********************************************************************
 *
 * Sets the input focus to the indicated window.
 *
 **********************************************************************/
static void DoSetFocus(Window w, FvwmWindow *Fw, Bool FocusByMouse, Bool NoWarp)
{
  extern Time lastTimestamp;
  FvwmWindow *sf;

  if (Fw && WM_TAKES_FOCUS(Fw))
  {
    send_clientmessage(dpy, w, _XA_WM_TAKE_FOCUS, lastTimestamp);
  }
  if (Fw && HAS_NEVER_FOCUS(Fw))
  {
    if (WM_TAKES_FOCUS(Fw))
    {
      /* give it a chance to take the focus itself */
      XSync(dpy, 0);
    }
    else
    {
      /* make sure the window is not hilighted */
      DrawDecorations(Fw, DRAW_ALL, False, False, None);
    }
    return;
  }
  if (Fw && !IS_LENIENT(Fw) &&
      Fw->wmhints && (Fw->wmhints->flags & InputHint) && !Fw->wmhints->input &&
      (sf = get_focus_window()) && sf->Desk == Scr.CurrentDesk)
  {
    return;
  }
  /* ClickToFocus focus queue manipulation - only performed for
   * Focus-by-mouse type focus events */
  /* Watch out: Fw may not be on the windowlist and the windowlist may be
   * empty */
  if (Fw && Fw != get_focus_window() && Fw != &Scr.FvwmRoot &&
      !IS_SCHEDULED_FOR_DESTROY(Fw))
  {
    if (FocusByMouse) /* pluck window from list and deposit at top */
    {
      /* remove Fw from list */
      if (Fw->prev)
	Fw->prev->next = Fw->next;
      if (Fw->next)
	Fw->next->prev = Fw->prev;

      /* insert Fw at start */
      Fw->next = Scr.FvwmRoot.next;
      if (Scr.FvwmRoot.next)
	Scr.FvwmRoot.next->prev = Fw;
      Scr.FvwmRoot.next = Fw;
      Fw->prev = &Scr.FvwmRoot;
    }
    else
    {
      /* move the windowlist around so that Fw is at the top */
      FvwmWindow *tmp_win;

      /* find the window on the windowlist */
      tmp_win = &Scr.FvwmRoot;
      while (tmp_win && tmp_win != Fw)
        tmp_win = tmp_win->next;

      if (tmp_win) /* the window is on the (non-zero length) windowlist */
      {
        /* make tmp_win point to the last window on the list */
        while (tmp_win->next)
          tmp_win = tmp_win->next;

        /* close the ends of the windowlist */
        tmp_win->next = Scr.FvwmRoot.next;
        Scr.FvwmRoot.next->prev = tmp_win;

        /* make Fw the new start of the list */
        Scr.FvwmRoot.next = Fw;
        /* open the closed loop windowlist */
        Fw->prev->next = NULL;
        Fw->prev = &Scr.FvwmRoot;
      }
    }
  }
  lastFocusType = FocusByMouse;

  if (!Fw && !Scr.flags.is_pointer_on_this_screen)
  {
    focus_grab_buttons(Scr.Ungrabbed, False);
    set_focus_window(NULL);
    /* DV (25-Nov-2000): Don't give the Scr.NoFocusWin the focus here. This
     * would steal the focus from the other screen's root window again. */
    /* FOCUS_SET(Scr.NoFocusWin); */
    return;
  }

  if (Fw && !NoWarp)
  {
    if (IS_ICONIFIED(Fw))
    {
      rectangle r;

      r.x = Fw->icon_g.x;
      r.y = Fw->icon_g.y;
      r.width = Fw->icon_g.width;
      r.height = Fw->icon_p_height + Fw->icon_g.height;
      if (!IsRectangleOnThisPage(&r, Fw->Desk))
      {
        Fw = NULL;
        w = Scr.NoFocusWin;
      }
    }
    else if (!IsRectangleOnThisPage(&(Fw->frame_g),Fw->Desk))
    {
      Fw = NULL;
      w = Scr.NoFocusWin;
    }
  }

  /*
      RBW - 1999/12/08 - we have to re-grab the unfocused window here for the
      MouseFocusClickRaises case also, but we can't ungrab the newly focused
      window here, or we'll never catch the raise click. For this special case,
      the newly-focused window is ungrabbed in events.c (HandleButtonPress).
  */
  if (Scr.Ungrabbed != Fw)
  {
    /* need to grab all buttons for window that we are about to unfocus */
    focus_grab_buttons(Scr.Ungrabbed, False);
  }
  /* if we do click to focus, remove the grab on mouse events that
   * was made to detect the focus change */
  if (Fw && HAS_CLICK_FOCUS(Fw))
  {
    focus_grab_buttons(Fw, True);
  }
  /* RBW - allow focus to go to a NoIconTitle icon window so
   * auto-raise will work on it... */
  if (Fw && IS_ICONIFIED(Fw))
  {
    Bool is_window_selected = False;

    if (Fw->icon_w)
    {
      w = Fw->icon_w;
      is_window_selected = True;
    }
    if ((!is_window_selected || WAS_ICON_HINT_PROVIDED(Fw)) &&
	Fw->icon_pixmap_w)
    {
      w = Fw->icon_pixmap_w;
    }
  }

  if (Fw && IS_LENIENT(Fw))
  {
    FOCUS_SET(w);
    set_focus_window(Fw);
    SET_FOCUS_CHANGE_BROADCAST_PENDING(Fw, 1);
    Scr.UnknownWinFocused = None;
  }
  else if (!Fw || !(Fw->wmhints) || !(Fw->wmhints->flags & InputHint) ||
           Fw->wmhints->input != False)
  {
    /* Window will accept input focus */
    FOCUS_SET(w);
    set_focus_window(Fw);
    if (Fw)
    {
      SET_FOCUS_CHANGE_BROADCAST_PENDING(Fw, 1);
    }
    Scr.UnknownWinFocused = None;
  }
  else if ((sf = get_focus_window()) && sf->Desk == Scr.CurrentDesk)
  {
    /* Window doesn't want focus. Leave focus alone */
    /* FOCUS_SET(Scr.Hilite->w);*/
  }
  else
  {
    FOCUS_SET(Scr.NoFocusWin);
    set_focus_window(NULL);
  }
  XSync(dpy,0);

  return;
}
Exemplo n.º 3
0
void focus_grab_buttons(FvwmWindow *tmp_win, Bool is_focused)
{
  int i;
  Bool accepts_input_focus;
  Bool do_grab_window = False;
  unsigned char grab_buttons = Scr.buttons2grab;

  if (!tmp_win || IS_SCHEDULED_FOR_DESTROY(tmp_win))
  {
    /* It's pointless to grab buttons on dying windows */
    return;
  }
  accepts_input_focus = do_accept_input_focus(tmp_win);
  if (HAS_SLOPPY_FOCUS(tmp_win) || HAS_MOUSE_FOCUS(tmp_win) ||
       HAS_NEVER_FOCUS(tmp_win))
  {
    if (DO_RAISE_MOUSE_FOCUS_CLICK(tmp_win) &&
        (!is_focused || !is_on_top_of_layer(tmp_win)))
    {
      grab_buttons = ((1 << NUMBER_OF_MOUSE_BUTTONS) - 1);
      do_grab_window = True;
    }
  }
  else if (HAS_CLICK_FOCUS(tmp_win))
  {
    if (is_focused && !is_on_top_of_layer(tmp_win) &&
        DO_NOT_RAISE_CLICK_FOCUS_CLICK(tmp_win) && accepts_input_focus)
    {
      /* don't grab */
    }
    else if ((!is_focused || !is_on_top_of_layer(tmp_win)) &&
             (!DO_NOT_RAISE_CLICK_FOCUS_CLICK(tmp_win) || accepts_input_focus))
    {
      grab_buttons = ((1 << NUMBER_OF_MOUSE_BUTTONS) - 1);
      do_grab_window = True;
    }
  }

#if 0
  /*
      RBW - If we've come here to grab and all buttons are already grabbed,
      or to ungrab and none is grabbed, then we've nothing to do.
  */
  if ((!is_focused && grab_buttons == tmp_win->grabbed_buttons) ||
     (is_focused && ((tmp_win->grabbed_buttons & grab_buttons) == 0)))
  {
    return;
  }
#else
  if (grab_buttons != tmp_win->grabbed_buttons)
#endif
  {
    Bool do_grab;

    MyXGrabServer(dpy);
    Scr.Ungrabbed = (do_grab_window) ? NULL : tmp_win;
    for (i = 0; i < NUMBER_OF_MOUSE_BUTTONS; i++)
    {
#if 0
      /*  RBW - Set flag for grab or ungrab according to how we were called. */
      if (!is_focused||1)
      {
        do_grab = !!(grab_buttons & (1 << i));
      }
      else
      {
        do_grab = !(grab_buttons & (1 << i));
      }
#else
      if ((grab_buttons & (1 << i)) == (tmp_win->grabbed_buttons & (1 << i)))
	continue;
      do_grab = !!(grab_buttons & (1 << i));
#endif

      {
	register unsigned int mods;
	register unsigned int max = GetUnusedModifiers();
	register unsigned int living_modifiers = ~max;

	/* handle all bindings for the dead modifiers */
	for (mods = 0; mods <= max; mods++)
	{
	  /* Since mods starts with 1 we don't need to test if mods
	   * contains a dead modifier. Otherwise both, dead and living
	   * modifiers would be zero ==> mods == 0 */
	  if (!(mods & living_modifiers))
	  {
	    if (do_grab)
	    {
	      XGrabButton(
		dpy, i + 1, mods, tmp_win->Parent, True, ButtonPressMask,
		GrabModeSync, GrabModeAsync, None, None);
              /*  Set each FvwmWindow flag accordingly, as we grab or ungrab. */
              tmp_win->grabbed_buttons |= (1<<i);
	    }
	    else
	    {
	      XUngrabButton(dpy, (i+1), mods, tmp_win->Parent);
              tmp_win->grabbed_buttons &= ~(1<<i);
	    }
	  }
	} /* for */
      }
    } /* for */
    MyXUngrabServer (dpy);

  }

  return;
}
Exemplo n.º 4
0
Arquivo: focus.c Projeto: fvwmorg/fvwm
static void __update_windowlist(
	FvwmWindow *fw, fpol_set_focus_by_t set_by,
	int is_focus_by_flip_focus_cmd)
{
	lastFocusType = (is_focus_by_flip_focus_cmd) ? True : False;
	if (fw == NULL || focus_is_focused(fw) || fw == &Scr.FvwmRoot ||
	    IS_SCHEDULED_FOR_DESTROY(fw))
	{
		return;
	}
	/* Watch out: fw may not be on the windowlist and the windowlist may be
	 * empty */
	if (!is_focus_by_flip_focus_cmd &&
	    (FP_DO_SORT_WINDOWLIST_BY(FW_FOCUS_POLICY(fw)) ==
	     FPOL_SORT_WL_BY_OPEN ||
	     set_by == FOCUS_SET_BY_FUNCTION))
	{
		/* move the windowlist around so that fw is at the top */
		FvwmWindow *fw2;

		/* find the window on the windowlist */
		for (fw2 = &Scr.FvwmRoot; fw2 && fw2 != fw; fw2 = fw2->next)
		{
			/* nothing */
		}
		if (fw2)
		{
			/* the window is on the (non-zero length) windowlist */
			/* make fw2 point to the last window on the list */
			while (fw2->next)
			{
				fw2 = fw2->next;
			}

			/* close the ends of the windowlist */
			fw2->next = Scr.FvwmRoot.next;
			Scr.FvwmRoot.next->prev = fw2;

			/* make fw the new start of the list */
			Scr.FvwmRoot.next = fw;
			/* open the closed loop windowlist */
			fw->prev->next = NULL;
			fw->prev = &Scr.FvwmRoot;
		}
	}
	else
	{
		/* pluck window from list and deposit at top */
		/* remove fw from list */
		if (fw->prev)
		{
			fw->prev->next = fw->next;
		}
		if (fw->next)
		{
			fw->next->prev = fw->prev;
		}
		/* insert fw at start */
		fw->next = Scr.FvwmRoot.next;
		if (Scr.FvwmRoot.next)
		{
			Scr.FvwmRoot.next->prev = fw;
		}
		Scr.FvwmRoot.next = fw;
		fw->prev = &Scr.FvwmRoot;
	}

	return;
}