1999-10-04 15:06:00 -07:00
|
|
|
/*
|
2004-01-19 14:30:35 -08:00
|
|
|
* Copyright (C) 2000-2004 Carsten Haitzler, Geoff Harrison and various contributors
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
1999-08-17 15:56:46 -07:00
|
|
|
#include "E.h"
|
|
|
|
|
2003-06-11 13:05:59 -07:00
|
|
|
static int new_desk_focus_nesting = 0;
|
|
|
|
|
2004-02-24 15:19:03 -08:00
|
|
|
/*
|
|
|
|
* Return !0 if it is OK to focus ewin.
|
2004-07-17 01:55:34 -07:00
|
|
|
* on_screen: Require window to be on-screen now
|
2004-02-24 15:19:03 -08:00
|
|
|
*/
|
|
|
|
static int
|
2004-07-17 01:55:34 -07:00
|
|
|
FocusEwinValid(EWin * ewin, int on_screen)
|
2004-02-24 15:19:03 -08:00
|
|
|
{
|
2004-07-17 01:55:34 -07:00
|
|
|
if (!ewin)
|
|
|
|
return 0;
|
|
|
|
|
2004-07-17 03:11:31 -07:00
|
|
|
if (ewin->neverfocus || ewin->iconified)
|
2004-07-17 01:55:34 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!ewin->client.need_input)
|
2004-02-24 15:19:03 -08:00
|
|
|
return 0;
|
|
|
|
|
2004-07-15 16:31:02 -07:00
|
|
|
if (!EwinIsMapped(ewin))
|
2004-02-26 11:33:21 -08:00
|
|
|
return 0;
|
|
|
|
|
2004-07-17 01:55:34 -07:00
|
|
|
return !on_screen || EwinIsOnScreen(ewin);
|
2004-02-24 15:19:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-02-26 11:33:21 -08:00
|
|
|
* Return the ewin to focus after entering area or losing focused window.
|
2004-02-24 15:19:03 -08:00
|
|
|
*/
|
|
|
|
static EWin *
|
|
|
|
FocusEwinSelect(void)
|
|
|
|
{
|
2004-04-01 14:41:22 -08:00
|
|
|
EWin *const *lst, *ewin = NULL;
|
2004-02-24 15:19:03 -08:00
|
|
|
int num, i;
|
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
switch (Conf.focus.mode)
|
2004-02-24 15:19:03 -08:00
|
|
|
{
|
2004-02-26 11:33:21 -08:00
|
|
|
default:
|
|
|
|
case MODE_FOCUS_POINTER:
|
|
|
|
ewin = GetEwinPointerInClient();
|
|
|
|
break;
|
2004-07-17 01:55:34 -07:00
|
|
|
case MODE_FOCUS_SLOPPY:
|
|
|
|
ewin = GetEwinPointerInClient();
|
|
|
|
if (ewin)
|
|
|
|
break;
|
|
|
|
/* If pointer not in window - fall thru and select other */
|
2004-02-26 11:33:21 -08:00
|
|
|
case MODE_FOCUS_CLICK:
|
2004-12-28 15:46:49 -08:00
|
|
|
lst = EwinListFocusGet(&num);
|
2004-02-26 11:33:21 -08:00
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-07-17 07:58:16 -07:00
|
|
|
if (!FocusEwinValid(lst[i], 1) || lst[i]->skipfocus)
|
2004-02-26 11:33:21 -08:00
|
|
|
continue;
|
|
|
|
ewin = lst[i];
|
|
|
|
break;
|
|
|
|
}
|
2004-02-24 15:19:03 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ewin;
|
|
|
|
}
|
|
|
|
|
1999-09-21 19:13:51 -07:00
|
|
|
static void
|
2004-04-01 14:41:22 -08:00
|
|
|
AutoraiseTimeout(int val, void *data __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-01-28 12:09:07 -08:00
|
|
|
EWin *ewin;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
if (Conf.focus.mode == MODE_FOCUS_CLICK)
|
1999-08-17 15:56:46 -07:00
|
|
|
return;
|
2004-01-28 12:09:07 -08:00
|
|
|
|
|
|
|
ewin = FindItem("", val, LIST_FINDBY_ID, LIST_TYPE_EWIN);
|
|
|
|
if (ewin)
|
|
|
|
RaiseEwin(ewin);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
1999-09-21 19:13:51 -07:00
|
|
|
static void
|
2004-04-01 14:41:22 -08:00
|
|
|
ReverseTimeout(int val, void *data __UNUSED__)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
EWin *ewin;
|
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
ewin = FindItem("", val, LIST_FINDBY_ID, LIST_TYPE_EWIN);
|
1999-08-17 15:56:46 -07:00
|
|
|
if (ewin)
|
2004-12-28 15:46:49 -08:00
|
|
|
EwinListFocusRaise(ewin);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2004-07-23 13:05:50 -07:00
|
|
|
void
|
|
|
|
FocusGetNextEwin(void)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-07-23 13:05:50 -07:00
|
|
|
EWin *const *lst;
|
|
|
|
EWin *ewin;
|
|
|
|
int i, num;
|
2004-01-21 15:32:45 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
lst = EwinListFocusGet(&num);
|
2004-07-23 13:05:50 -07:00
|
|
|
if (num <= 1)
|
|
|
|
return;
|
2004-01-21 15:32:45 -08:00
|
|
|
|
2004-07-23 13:05:50 -07:00
|
|
|
ewin = NULL;
|
|
|
|
for (i = num - 1; i >= 0; i--)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-07-23 13:05:50 -07:00
|
|
|
if (lst[i]->skipfocus || !FocusEwinValid(lst[i], 1))
|
|
|
|
continue;
|
|
|
|
ewin = lst[i];
|
|
|
|
break;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-01-21 15:32:45 -08:00
|
|
|
|
2004-07-23 13:05:50 -07:00
|
|
|
if (ewin)
|
|
|
|
FocusToEWin(ewin, FOCUS_NEXT);
|
2004-01-21 15:32:45 -08:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-01-21 15:32:45 -08:00
|
|
|
void
|
|
|
|
FocusGetPrevEwin(void)
|
|
|
|
{
|
2004-07-23 13:05:50 -07:00
|
|
|
EWin *const *lst;
|
|
|
|
EWin *ewin;
|
|
|
|
int i, num;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
lst = EwinListFocusGet(&num);
|
2004-07-23 13:05:50 -07:00
|
|
|
if (num <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ewin = NULL;
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if (lst[i]->skipfocus || !FocusEwinValid(lst[i], 1))
|
|
|
|
continue;
|
|
|
|
ewin = lst[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ewin)
|
|
|
|
FocusToEWin(ewin, FOCUS_PREV);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
void
|
|
|
|
FocusEwinSetGrabs(EWin * ewin)
|
|
|
|
{
|
2004-03-20 07:49:05 -08:00
|
|
|
if ((Conf.focus.mode != MODE_FOCUS_CLICK &&
|
2004-12-28 15:46:49 -08:00
|
|
|
ewin->active && Conf.focus.clickraises &&
|
|
|
|
ewin != EwinListStackGetTop()) ||
|
2004-03-20 07:49:05 -08:00
|
|
|
(Conf.focus.mode == MODE_FOCUS_CLICK && !ewin->active))
|
2004-02-01 03:28:06 -08:00
|
|
|
{
|
2004-08-14 08:06:26 -07:00
|
|
|
GrabButtonSet(AnyButton, AnyModifier, ewin->win_container,
|
|
|
|
ButtonPressMask, ECSR_PGRAB, 1);
|
2004-08-13 17:47:17 -07:00
|
|
|
#if 0
|
|
|
|
Eprintf("FocusEwinSetGrabs: %#lx grab %s\n", ewin->client.win,
|
2005-01-09 14:36:01 -08:00
|
|
|
EwinGetName(ewin));
|
2004-08-13 17:47:17 -07:00
|
|
|
#endif
|
2004-02-01 03:28:06 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-14 08:06:26 -07:00
|
|
|
GrabButtonRelease(AnyButton, AnyModifier, ewin->win_container);
|
2004-08-13 17:47:17 -07:00
|
|
|
#if 0
|
|
|
|
Eprintf("FocusEwinSetGrabs: %#lx ungrab %s\n", ewin->client.win,
|
2005-01-09 14:36:01 -08:00
|
|
|
EwinGetName(ewin));
|
2004-08-13 17:47:17 -07:00
|
|
|
#endif
|
2004-02-01 03:28:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
static void
|
|
|
|
FocusEwinSetActive(EWin * ewin, int active)
|
|
|
|
{
|
|
|
|
ewin->active = active;
|
2004-06-07 09:46:08 -07:00
|
|
|
EwinBorderUpdateState(ewin);
|
2004-04-01 14:41:22 -08:00
|
|
|
|
|
|
|
FocusEwinSetGrabs(ewin);
|
|
|
|
}
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
void
|
2004-01-21 15:32:45 -08:00
|
|
|
FocusFix(void)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-03-26 13:21:47 -08:00
|
|
|
EWin *const *lst, *ewin;
|
1999-08-17 15:56:46 -07:00
|
|
|
int i, num;
|
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
lst = EwinListGetAll(&num);
|
2004-02-01 03:28:06 -08:00
|
|
|
for (i = 0; i < num; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-02-01 03:28:06 -08:00
|
|
|
ewin = lst[i];
|
2004-08-14 08:06:26 -07:00
|
|
|
GrabButtonRelease(AnyButton, AnyModifier, ewin->win_container);
|
2004-02-01 03:28:06 -08:00
|
|
|
FocusEwinSetGrabs(ewin);
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-01-21 15:32:45 -08:00
|
|
|
FocusToEWin(EWin * ewin, int why)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-02-08 14:51:50 -08:00
|
|
|
int do_follow = 0;
|
2004-07-23 13:05:50 -07:00
|
|
|
int do_raise = 0, do_warp = 0;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-03-22 08:36:03 -08:00
|
|
|
if (EventDebug(EDBUG_TYPE_FOCUS))
|
2004-02-17 15:15:54 -08:00
|
|
|
{
|
|
|
|
if (ewin)
|
2004-04-08 05:54:46 -07:00
|
|
|
Eprintf("FocusToEWin %#lx %s why=%d\n", ewin->client.win,
|
2005-01-09 14:36:01 -08:00
|
|
|
EwinGetName(ewin), why);
|
2004-02-17 15:15:54 -08:00
|
|
|
else
|
2004-04-08 05:54:46 -07:00
|
|
|
Eprintf("FocusToEWin None why=%d\n", why);
|
2004-02-17 15:15:54 -08:00
|
|
|
}
|
1999-10-03 09:02:09 -07:00
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
switch (why)
|
|
|
|
{
|
2004-07-23 13:05:50 -07:00
|
|
|
case FOCUS_NEXT:
|
|
|
|
case FOCUS_PREV:
|
|
|
|
if (Conf.focus.raise_on_next)
|
|
|
|
do_raise = 1;
|
|
|
|
if (Conf.focus.warp_on_next)
|
|
|
|
do_warp = 1;
|
|
|
|
/* Fall thru */
|
2004-02-01 03:28:06 -08:00
|
|
|
default:
|
2004-07-17 01:55:34 -07:00
|
|
|
case FOCUS_SET:
|
|
|
|
case FOCUS_ENTER:
|
|
|
|
case FOCUS_LEAVE: /* Unused */
|
|
|
|
case FOCUS_CLICK:
|
|
|
|
if (ewin == Mode.focuswin)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-07-17 01:55:34 -07:00
|
|
|
if (ewin == NULL) /* Unfocus */
|
|
|
|
break;
|
|
|
|
if (!FocusEwinValid(ewin, 1))
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-07-17 01:55:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FOCUS_DESK_ENTER:
|
|
|
|
ewin = FocusEwinSelect();
|
|
|
|
if (!ewin)
|
2004-12-28 15:46:49 -08:00
|
|
|
goto done;
|
2004-07-17 01:55:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FOCUS_NONE:
|
|
|
|
case FOCUS_DESK_LEAVE:
|
|
|
|
ewin = NULL;
|
2004-03-20 07:49:05 -08:00
|
|
|
if (ewin == Mode.focuswin)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-02-01 03:28:06 -08:00
|
|
|
break;
|
1999-10-03 09:02:09 -07:00
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
case FOCUS_EWIN_GONE:
|
2004-03-20 07:49:05 -08:00
|
|
|
if (ewin != Mode.focuswin)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-07-17 01:55:34 -07:00
|
|
|
ewin = FocusEwinSelect();
|
|
|
|
if (ewin == Mode.focuswin)
|
2004-04-08 08:51:26 -07:00
|
|
|
ewin = NULL;
|
2004-02-26 11:33:21 -08:00
|
|
|
break;
|
1999-10-03 09:02:09 -07:00
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
case FOCUS_EWIN_NEW:
|
2004-07-12 16:24:36 -07:00
|
|
|
/* Don't chase around after the windows at startup */
|
2004-12-28 15:46:49 -08:00
|
|
|
if (Mode.wm.startup || Mode.doingslide)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-07-12 16:24:36 -07:00
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
if (Conf.focus.all_new_windows_get_focus)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-02-08 14:51:50 -08:00
|
|
|
do_follow = 2;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
2004-03-20 07:49:05 -08:00
|
|
|
else if (Conf.focus.new_transients_get_focus)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-02-01 03:28:06 -08:00
|
|
|
if (ewin->client.transient)
|
2004-02-08 14:51:50 -08:00
|
|
|
do_follow = 2;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
2004-03-20 07:49:05 -08:00
|
|
|
else if (Conf.focus.new_transients_get_focus_if_group_focused)
|
2004-02-01 03:28:06 -08:00
|
|
|
{
|
|
|
|
EWin *ewin2;
|
|
|
|
|
|
|
|
ewin2 = FindItem(NULL, ewin->client.transient_for,
|
|
|
|
LIST_FINDBY_ID, LIST_TYPE_EWIN);
|
2004-03-20 07:49:05 -08:00
|
|
|
if ((ewin2) && (Mode.focuswin == ewin2))
|
2004-02-08 14:51:50 -08:00
|
|
|
do_follow = 2;
|
2004-02-01 03:28:06 -08:00
|
|
|
}
|
2004-03-20 07:49:05 -08:00
|
|
|
else if (Mode.place)
|
2004-02-01 03:28:06 -08:00
|
|
|
{
|
2004-02-08 14:51:50 -08:00
|
|
|
do_follow = 1;
|
2004-02-01 03:28:06 -08:00
|
|
|
}
|
|
|
|
|
2004-02-08 14:51:50 -08:00
|
|
|
if (!do_follow)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-07-17 01:55:34 -07:00
|
|
|
if (ewin == Mode.focuswin)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-07-17 01:55:34 -07:00
|
|
|
if (!FocusEwinValid(ewin, 0))
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-02-01 03:28:06 -08:00
|
|
|
break;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-02-01 03:28:06 -08:00
|
|
|
|
2004-07-17 01:55:34 -07:00
|
|
|
if (ewin == Mode.focuswin)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2004-07-15 16:31:02 -07:00
|
|
|
|
2004-07-17 01:55:34 -07:00
|
|
|
/* Check if ewin is a valid focus window target */
|
2004-02-01 03:28:06 -08:00
|
|
|
|
2004-07-17 01:55:34 -07:00
|
|
|
if (!ewin)
|
|
|
|
goto done;
|
2004-02-01 03:28:06 -08:00
|
|
|
|
2004-07-17 01:55:34 -07:00
|
|
|
/* NB! ewin != NULL */
|
2004-02-01 03:28:06 -08:00
|
|
|
|
2004-04-28 15:31:37 -07:00
|
|
|
if (do_follow)
|
2005-02-26 08:40:36 -08:00
|
|
|
DeskGotoByEwin(ewin);
|
2004-02-08 14:51:50 -08:00
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
if (Conf.autoraise.enable)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-02-01 03:28:06 -08:00
|
|
|
RemoveTimerEvent("AUTORAISE_TIMEOUT");
|
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
if (Conf.focus.mode != MODE_FOCUS_CLICK)
|
2004-12-28 15:46:49 -08:00
|
|
|
DoIn("AUTORAISE_TIMEOUT", 0.001 * Conf.autoraise.delay,
|
|
|
|
AutoraiseTimeout, ewin->client.win, NULL);
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-02-01 03:28:06 -08:00
|
|
|
|
2004-07-23 13:05:50 -07:00
|
|
|
if (do_raise)
|
2004-02-01 03:28:06 -08:00
|
|
|
RaiseEwin(ewin);
|
|
|
|
|
2004-07-23 13:05:50 -07:00
|
|
|
if (do_warp && ewin != Mode.mouse_over_ewin)
|
2004-12-28 15:46:49 -08:00
|
|
|
XWarpPointer(disp, None, EoGetWin(ewin), 0, 0, 0, 0, EoGetW(ewin) / 2,
|
|
|
|
EoGetH(ewin) / 2);
|
2004-02-01 03:28:06 -08:00
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
RemoveTimerEvent("REVERSE_FOCUS_TIMEOUT");
|
2004-07-23 13:05:50 -07:00
|
|
|
switch (why)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case FOCUS_PREV:
|
|
|
|
DoIn("REVERSE_FOCUS_TIMEOUT", 0.5, ReverseTimeout, ewin->client.win,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case FOCUS_DESK_ENTER:
|
|
|
|
break;
|
|
|
|
case FOCUS_NEXT:
|
2004-12-28 15:46:49 -08:00
|
|
|
EwinListFocusRaise(ewin);
|
2004-07-23 13:05:50 -07:00
|
|
|
break;
|
|
|
|
}
|
2004-02-01 03:28:06 -08:00
|
|
|
|
|
|
|
SoundPlay("SOUND_FOCUS_SET");
|
2004-03-20 07:49:05 -08:00
|
|
|
done:
|
2005-01-10 15:34:46 -08:00
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
/* Unset old focus window (if any) highlighting */
|
|
|
|
if (Mode.focuswin)
|
|
|
|
FocusEwinSetActive(Mode.focuswin, 0);
|
2004-02-01 03:28:06 -08:00
|
|
|
ICCCM_Cmap(ewin);
|
2005-01-13 16:03:50 -08:00
|
|
|
|
|
|
|
/* Quit if pointer is not on our screen */
|
|
|
|
if (!PointerAt(NULL, NULL))
|
|
|
|
{
|
|
|
|
Mode.focuswin = NULL;
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2005-01-13 16:03:50 -08:00
|
|
|
}
|
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
/* Set new focus window (if any) highlighting */
|
2005-01-13 16:03:50 -08:00
|
|
|
Mode.focuswin = ewin;
|
2004-04-01 14:41:22 -08:00
|
|
|
if (Mode.focuswin)
|
|
|
|
FocusEwinSetActive(Mode.focuswin, 1);
|
2004-12-28 15:46:49 -08:00
|
|
|
if (why != FOCUS_DESK_LEAVE)
|
|
|
|
ICCCM_Focus(ewin);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-01-21 15:32:45 -08:00
|
|
|
FocusNewDeskBegin(void)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2003-06-11 13:05:59 -07:00
|
|
|
if (new_desk_focus_nesting++)
|
|
|
|
return;
|
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
FocusToEWin(NULL, FOCUS_DESK_LEAVE);
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
/* we are about to flip desktops or areas - disable enter and leave events
|
2003-06-11 13:05:59 -07:00
|
|
|
* temporarily */
|
2004-12-28 15:46:49 -08:00
|
|
|
EwinsEventsConfigure(0);
|
2005-02-26 08:40:36 -08:00
|
|
|
DesksEventsConfigure(0);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2005-01-10 15:34:46 -08:00
|
|
|
static void
|
|
|
|
FocusInit(void)
|
|
|
|
{
|
|
|
|
EWin *ewin;
|
|
|
|
|
|
|
|
/* Set the mouse-over window */
|
|
|
|
ewin = GetEwinByCurrentPointer();
|
|
|
|
Mode.mouse_over_ewin = ewin;
|
|
|
|
|
|
|
|
FocusToEWin(NULL, FOCUS_DESK_ENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FocusExit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
void
|
2004-01-21 15:32:45 -08:00
|
|
|
FocusNewDesk(void)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-04-12 06:57:43 -07:00
|
|
|
EWin *ewin;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2003-06-11 13:05:59 -07:00
|
|
|
if (--new_desk_focus_nesting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* we flipped - re-enable enter and leave events */
|
2004-12-28 15:46:49 -08:00
|
|
|
EwinsEventsConfigure(1);
|
2005-02-26 08:40:36 -08:00
|
|
|
DesksEventsConfigure(1);
|
2003-06-11 13:05:59 -07:00
|
|
|
|
2004-04-04 14:32:37 -07:00
|
|
|
/* Set the mouse-over window */
|
|
|
|
ewin = GetEwinByCurrentPointer();
|
2004-06-28 16:37:55 -07:00
|
|
|
Mode.mouse_over_ewin = ewin;
|
2004-04-04 14:32:37 -07:00
|
|
|
|
2004-07-17 01:55:34 -07:00
|
|
|
FocusToEWin(NULL, FOCUS_DESK_ENTER);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
/*
|
|
|
|
* Focus event handlers
|
|
|
|
*/
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
void
|
2004-12-28 15:46:49 -08:00
|
|
|
FocusHandleEnter(EWin * ewin, XEvent * ev)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-04-01 14:41:22 -08:00
|
|
|
Window win = ev->xcrossing.window;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
Mode.mouse_over_ewin = ewin;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if (!ewin)
|
2004-04-01 14:41:22 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
/* Entering root may mean entering this screen */
|
|
|
|
if (win == VRoot.win &&
|
|
|
|
(ev->xcrossing.mode == NotifyNormal &&
|
|
|
|
ev->xcrossing.detail != NotifyInferior))
|
|
|
|
{
|
|
|
|
FocusToEWin(NULL, FOCUS_DESK_ENTER);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-01 14:41:22 -08:00
|
|
|
}
|
|
|
|
|
2004-06-28 16:37:55 -07:00
|
|
|
Mode.mouse_over_ewin = ewin;
|
2004-01-28 12:09:07 -08:00
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
switch (Conf.focus.mode)
|
2004-01-28 12:09:07 -08:00
|
|
|
{
|
2004-02-01 03:28:06 -08:00
|
|
|
default:
|
|
|
|
case MODE_FOCUS_CLICK:
|
|
|
|
break;
|
|
|
|
case MODE_FOCUS_SLOPPY:
|
|
|
|
if (!ewin || ewin->focusclick)
|
|
|
|
break;
|
|
|
|
FocusToEWin(ewin, FOCUS_ENTER);
|
|
|
|
break;
|
|
|
|
case MODE_FOCUS_POINTER:
|
|
|
|
if (ewin && ewin->focusclick)
|
|
|
|
break;
|
|
|
|
FocusToEWin(ewin, FOCUS_ENTER);
|
|
|
|
break;
|
2004-01-28 12:09:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-12-28 15:46:49 -08:00
|
|
|
FocusHandleLeave(EWin * ewin __UNUSED__, XEvent * ev)
|
2004-01-28 12:09:07 -08:00
|
|
|
{
|
2004-02-06 16:30:23 -08:00
|
|
|
Window win = ev->xcrossing.window;
|
|
|
|
|
2004-02-16 14:58:21 -08:00
|
|
|
/* Leaving root may mean entering other screen */
|
2004-05-04 12:04:42 -07:00
|
|
|
if (win == VRoot.win &&
|
2004-02-16 14:58:21 -08:00
|
|
|
(ev->xcrossing.mode == NotifyNormal &&
|
|
|
|
ev->xcrossing.detail != NotifyInferior))
|
2004-12-28 15:46:49 -08:00
|
|
|
FocusToEWin(NULL, FOCUS_DESK_LEAVE);
|
2004-01-28 12:09:07 -08:00
|
|
|
}
|
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
void
|
2004-12-28 15:46:49 -08:00
|
|
|
FocusHandleClick(EWin * ewin, Window win)
|
2004-02-01 03:28:06 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
#if 0
|
2004-02-01 03:28:06 -08:00
|
|
|
EWin *ewin;
|
|
|
|
|
2004-08-14 11:50:27 -07:00
|
|
|
ewin = FindEwinByChildren(win);
|
|
|
|
if (!ewin)
|
|
|
|
ewin = FindEwinByBase(win);
|
2004-02-01 03:28:06 -08:00
|
|
|
if (!ewin)
|
|
|
|
return;
|
2004-12-28 15:46:49 -08:00
|
|
|
#endif
|
2004-02-01 03:28:06 -08:00
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
if ((Conf.focus.clickraises) || (Conf.focus.mode == MODE_FOCUS_CLICK))
|
2004-02-01 03:28:06 -08:00
|
|
|
{
|
|
|
|
RaiseEwin(ewin);
|
|
|
|
FocusToEWin(ewin, FOCUS_CLICK);
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
/* Remove grabs if on top of stacking list */
|
|
|
|
FocusEwinSetGrabs(ewin);
|
|
|
|
|
2004-02-01 03:28:06 -08:00
|
|
|
/* allow click to pass thorugh */
|
2004-11-27 05:29:39 -08:00
|
|
|
if (EventDebug(EDBUG_TYPE_GRABS))
|
|
|
|
Eprintf("FocusHandleClick %#lx %#lx\n", win, ewin->win_container);
|
2004-02-01 03:28:06 -08:00
|
|
|
if (win == ewin->win_container)
|
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
ecore_x_sync();
|
2004-02-01 03:28:06 -08:00
|
|
|
XAllowEvents(disp, ReplayPointer, CurrentTime);
|
2004-12-28 15:46:49 -08:00
|
|
|
ecore_x_sync();
|
2004-02-01 03:28:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ewin->focusclick)
|
|
|
|
{
|
|
|
|
FocusToEWin(ewin, FOCUS_CLICK);
|
|
|
|
}
|
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2005-01-10 15:34:46 -08:00
|
|
|
/*
|
|
|
|
* Focus Module
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
FocusSighan(int sig, void *prm __UNUSED__)
|
|
|
|
{
|
|
|
|
switch (sig)
|
|
|
|
{
|
|
|
|
case ESIGNAL_START:
|
|
|
|
FocusInit();
|
|
|
|
break;
|
|
|
|
case ESIGNAL_EXIT:
|
|
|
|
FocusExit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
FocusIpc(const char *params, Client * c __UNUSED__)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
char cmd[128], prm[4096];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
cmd[0] = prm[0] = '\0';
|
|
|
|
p = params;
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
sscanf(p, "%100s %4000s %n", cmd, prm, &len);
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p || cmd[0] == '?')
|
|
|
|
{
|
|
|
|
EWin *ewin;
|
|
|
|
|
|
|
|
ewin = GetFocusEwin();
|
|
|
|
if (ewin)
|
|
|
|
IpcPrintf("Focused: %#lx\n", ewin->client.win);
|
|
|
|
else
|
|
|
|
IpcPrintf("Focused: none\n");
|
|
|
|
}
|
|
|
|
else if (!strcmp(cmd, "cfg"))
|
|
|
|
{
|
|
|
|
SettingsFocus();
|
|
|
|
}
|
|
|
|
else if (!strncmp(cmd, "mode", 2))
|
|
|
|
{
|
|
|
|
int mode = Conf.focus.mode;
|
|
|
|
|
|
|
|
if (!strcmp(prm, "click"))
|
|
|
|
{
|
|
|
|
mode = MODE_FOCUS_CLICK;
|
|
|
|
Mode.grabs.pointer_grab_active = 1;
|
|
|
|
}
|
|
|
|
else if (!strcmp(prm, "clicknograb"))
|
|
|
|
{
|
|
|
|
mode = MODE_FOCUS_CLICK;
|
|
|
|
Mode.grabs.pointer_grab_active = 0;
|
|
|
|
}
|
|
|
|
else if (!strcmp(prm, "pointer"))
|
|
|
|
{
|
|
|
|
mode = MODE_FOCUS_POINTER;
|
|
|
|
}
|
|
|
|
else if (!strcmp(prm, "sloppy"))
|
|
|
|
{
|
|
|
|
mode = MODE_FOCUS_SLOPPY;
|
|
|
|
}
|
|
|
|
else if (!strcmp(prm, "?"))
|
|
|
|
{
|
|
|
|
if (Conf.focus.mode == MODE_FOCUS_CLICK)
|
|
|
|
{
|
|
|
|
if (Mode.grabs.pointer_grab_active)
|
|
|
|
p = "click";
|
|
|
|
else
|
|
|
|
p = "clicknograb";
|
|
|
|
}
|
|
|
|
else if (Conf.focus.mode == MODE_FOCUS_SLOPPY)
|
|
|
|
p = "sloppy";
|
|
|
|
else if (Conf.focus.mode == MODE_FOCUS_POINTER)
|
|
|
|
p = "pointer";
|
|
|
|
else
|
|
|
|
p = "unknown";
|
|
|
|
IpcPrintf("Focus Mode: %s\n", p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IpcPrintf("Error: unknown focus type\n");
|
|
|
|
}
|
|
|
|
if (Conf.focus.mode != mode)
|
|
|
|
{
|
|
|
|
Conf.focus.mode = mode;
|
|
|
|
FocusFix();
|
|
|
|
autosave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strncmp(cmd, "next", 2))
|
|
|
|
{
|
|
|
|
if (Conf.warplist.enable)
|
|
|
|
WarpFocus(1);
|
|
|
|
else
|
|
|
|
FocusGetNextEwin();
|
|
|
|
}
|
|
|
|
else if (!strncmp(cmd, "prev", 2))
|
|
|
|
{
|
|
|
|
FocusGetPrevEwin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IpcItem FocusIpcArray[] = {
|
|
|
|
{
|
|
|
|
FocusIpc,
|
|
|
|
"focus", "sf",
|
|
|
|
"Focus functions",
|
|
|
|
" focus ? Show focus info\n"
|
|
|
|
" focus mode Set focus mode. Modes:\n"
|
|
|
|
" click: The traditional click-to-focus mode.\n"
|
|
|
|
" clicknograb: A similar focus mode, but without the grabbing of the click\n"
|
|
|
|
" (you cannot click anywhere in a window to focus it)\n"
|
|
|
|
" pointer: The focus will follow the mouse pointer\n"
|
|
|
|
" sloppy: The focus follows the mouse, but when over the desktop background\n"
|
|
|
|
" the last window does not lose the focus\n"}
|
|
|
|
,
|
|
|
|
};
|
|
|
|
#define N_IPC_FUNCS (sizeof(FocusIpcArray)/sizeof(IpcItem))
|
|
|
|
|
|
|
|
static const CfgItem FocusCfgItems[] = {
|
|
|
|
CFG_ITEM_INT(Conf.focus, mode, MODE_FOCUS_SLOPPY),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, clickraises, 0),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, transientsfollowleader, 1),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, switchfortransientmap, 1),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, all_new_windows_get_focus, 0),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, new_transients_get_focus, 0),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, new_transients_get_focus_if_group_focused, 1),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, raise_on_next, 1),
|
|
|
|
CFG_ITEM_BOOL(Conf.focus, warp_on_next, 0),
|
|
|
|
|
|
|
|
CFG_ITEM_BOOL(Conf, autoraise.enable, 0),
|
|
|
|
CFG_ITEM_INT(Conf, autoraise.delay, 500),
|
|
|
|
};
|
|
|
|
#define N_CFG_ITEMS (sizeof(FocusCfgItems)/sizeof(CfgItem))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module descriptor
|
|
|
|
*/
|
|
|
|
EModule ModFocus = {
|
|
|
|
"focus", NULL,
|
2005-01-10 15:34:46 -08:00
|
|
|
FocusSighan,
|
2004-12-28 15:46:49 -08:00
|
|
|
{N_IPC_FUNCS, FocusIpcArray},
|
|
|
|
{N_CFG_ITEMS, FocusCfgItems}
|
|
|
|
};
|