Ejemplo n.º 1
0
void InitKeyboardFocus (void)
{
    ClientData *pCD;
    Boolean sameScreen;
    Boolean focusSet = False;
    int scr;
    int junk;
    Window junk_win, root_returned;
    int  currentX, currentY;


    /*
     * Set the keyboard focus based on the keyboard focus policy.
     */

    wmGD.keyboardFocus = NULL;
    wmGD.nextKeyboardFocus = NULL;

    for (scr = 0; scr < wmGD.numScreens; scr++)
    {
	if (wmGD.Screens[scr].managed)
	{
	    wmGD.Screens[scr].focusPriority = 0;

	    if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER)
	    {
		/*
		 * Set the keyboard focus to the window that 
		 * currently contains the pointer.
		 */

		pCD = GetClientUnderPointer (&sameScreen);

		if (wmGD.colormapFocusPolicy == CMAP_FOCUS_POINTER)
		{
		    /*
		     * Do some colormap installation that has been 
		     * deferred from the InitColormapFocus routine.
		     */

		    SetColormapFocus (ACTIVE_PSD, pCD);
		}

		if (pCD)
		{
		    Do_Focus_Key (pCD, GetTimestamp (), ALWAYS_SET_FOCUS);
		    focusSet = True;
		}
	    }
	    else
	    {
		ButtonSpec *buttonSpec;
		
		/*
		 * Prepare to do explicit selection button grabs.
		 */

		buttonSpec = wmGD.Screens[scr].buttonSpecs;
		while (buttonSpec)
		{
		    if ((buttonSpec->button == FOCUS_SELECT_BUTTON) &&
			(buttonSpec->context & F_CONTEXT_WINDOW) &&
			(buttonSpec->subContext & F_SUBCONTEXT_W_CLIENT))
		    {
			if (buttonSpec->state == 0)
			{
			    removeSelectGrab = False;
			}
		    }
		    buttonSpec = buttonSpec->nextButtonSpec;
		}
	    }
	}
    }


    if (!focusSet)
    {
        /*
         * This is keyboard focus policy is either "explicit" or it it 
	 * "pointer"
         * and there is no window under the pointer.  No window currently has
         * the keyboard input focus.  Set the keyboard focus to the window
         * manager default (non-client) OR to the last client with focus.
	 *
	 * In Mwm 1.1.4 and later, calling Do_Focus_Key with NULL will try
	 * to find a 'reasonable' window to put focus.  This means that on
	 * startup and restarts, a Mwm window will have focus!  Yeah!
         */

	/* 
	 * Set Active Screen First 
	 */
	if (XQueryPointer(DISPLAY, DefaultRootWindow(DISPLAY), 
			  &root_returned, &junk_win,
			  &currentX, &currentY, 
			  &junk, &junk, (unsigned int *)&junk))
	{
	    for (scr = 0; scr < wmGD.numScreens; scr++)
	    {
		if (wmGD.Screens[scr].managed && 
		    wmGD.Screens[scr].rootWindow == root_returned)
		{
		    SetActiveScreen(&(wmGD.Screens[scr]));
		    break;
		}
	    }
	}

        Do_Focus_Key ((ClientData *)NULL, CurrentTime, ALWAYS_SET_FOCUS);
    }

} /* END OF FUNCTION InitKeyboardFocus */
Ejemplo n.º 2
0
void TimeoutProc (caddr_t client_data, XtIntervalId *id)
{
    WmTimer *pPrevTimer;
    WmTimer *pWmTimer;

    
    /*
     * Find out if the timer still needs to be serviced.
     */

    pPrevTimer = NULL;
    pWmTimer = wmGD.wmTimers;
    while (pWmTimer)
    {
	if (pWmTimer->timerId == *id)
	{
	    break;
	}
	pPrevTimer = pWmTimer;
	pWmTimer = pWmTimer->nextWmTimer;
    }

    if (pWmTimer)
    {
	/*
	 * Do the timer related action.
	 */

	switch (pWmTimer->timerType)
	{
	    case TIMER_QUIT:
	    {
		XKillClient (DISPLAY, pWmTimer->timerCD->client);
		break;
	    }

	    case TIMER_RAISE:
	    {
		Boolean sameScreen;

		if ((wmGD.keyboardFocus == pWmTimer->timerCD) &&
		    (pWmTimer->timerCD->focusPriority == 
			(PSD_FOR_CLIENT(pWmTimer->timerCD))->focusPriority) &&
		    (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER) &&
		    (pWmTimer->timerCD == GetClientUnderPointer(&sameScreen)))
		{
		    Do_Raise (pWmTimer->timerCD, (ClientListEntry *)NULL, STACK_NORMAL);
		}
		break;
	    }
	}


	/*
	 * Remove the timer from the wm timer list.
	 */

	if (pPrevTimer)
	{
	    pPrevTimer->nextWmTimer = pWmTimer->nextWmTimer;
	}
	else
	{
	    wmGD.wmTimers = pWmTimer->nextWmTimer;
	}
	XtFree ((char *)pWmTimer);
    }

    /*
     * Free up the timer.
     */

    XtRemoveTimeOut (*id);


} /* END OF FUNCTION TimeoutProc */
Ejemplo n.º 3
0
void SetKeyboardFocus (ClientData *pCD, long focusFlags)
{
    ClientData *currentFocus;

    
    /*
     * Don't set the keyboard input focus if it is already set to
     * the client window.
     */

    if (wmGD.keyboardFocus == pCD)
    {
	return;
    }
    currentFocus = wmGD.keyboardFocus;
    ACTIVE_PSD->focusPriority++;


    /*
     * If the keyboard input focus policy is "explicit" then reset the
     * selection button event handling.
     */

    if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT)
    {
	/*
	 * Reset explicit focus selection event tracking on the last focus
	 * window (reset the passive grab on the focus button).
	 */

	if (currentFocus)
	{
	    ResetExplicitSelectHandling (currentFocus);
	    wmGD.keyboardFocus = NULL;
	}
	
	if (pCD && ((pCD->clientState == NORMAL_STATE) ||
		    (pCD->clientState == MAXIMIZED_STATE)))
	{
	    /*
	     * The focus is to be set to a client window (not the root).
	     * Stop explicit focus selection event tracking on the new focus
	     * window.
	     */

	    if (removeSelectGrab)
	    {
	        WmUngrabButton (DISPLAY, FOCUS_SELECT_BUTTON, 0,
		    pCD->clientBaseWin);
	    }
        }
    }
    
    wmGD.keyboardFocus = pCD;


    /*
     * Do focus auto raise if specified.
     */

    if (pCD && pCD->focusAutoRaise)
    {
	if (wmGD.autoRaiseDelay &&
	    (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER))
	{
	    AddWmTimer (TIMER_RAISE, (unsigned long)wmGD.autoRaiseDelay,
		pCD);
	}
	else
	{
	    Boolean sameScreen;

	    if (((wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT) &&
		 (!pCD->focusAutoRaiseDisabled)) ||
		((wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER) &&
		 (pCD == GetClientUnderPointer (&sameScreen))))
	    {
	        Do_Raise (pCD, (ClientListEntry *)NULL, STACK_NORMAL);
	    }
	}
    }


    /*
     * Clear the focus indication if it is set for a client window or icon.
     */

    if (currentFocus)
    {
	ClearFocusIndication (currentFocus,
	    ((focusFlags & REFRESH_LAST_FOCUS) ? True : False));
    }


    /*
     * Install the client window colormap if the colormap focus policy is
     * "keyboard".
     */

    if ((wmGD.colormapFocusPolicy == CMAP_FOCUS_KEYBOARD) &&
	(!(focusFlags & SCREEN_SWITCH_FOCUS)))
    {
	SetColormapFocus (ACTIVE_PSD, pCD);
    }


    /*
     * Set the focus window or icon visual indication.
     */

    if (pCD)
    {
	pCD->focusPriority = ACTIVE_PSD->focusPriority;
	SetFocusIndication (pCD);
    }

} /* END OF FUNCTION SetKeyboardFocus */