[go: up one dir, main page]

Menu

[a6a015]: / src / focus.c  Maximize  Restore  History

Download this file

154 lines (133 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/****************************************************************************
* This module is all original code
* by Rob Nation
* Copyright 1993, Robert Nation
* You may use this code for any purpose, as long as the original
* copyright remains in the source code and all documentation
****************************************************************************/
/***********************************************************************
*
* scwm focus-setting code
*
***********************************************************************/
#include "../configure.h"
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include "scwm.h"
#include "menus.h"
#include "misc.h"
#include "parse.h"
#include "screen.h"
#include "module.h"
/********************************************************************
*
* Sets the input focus to the indicated window.
*
**********************************************************************/
void SetFocus(Window w, ScwmWindow *Fw, Bool FocusByMouse)
{
int i;
extern Time lastTimestamp;
/* ClickToFocus focus queue manipulation - only performed for
* Focus-by-mouse type focus events */
if ((FocusByMouse)&&(Fw && Fw != Scr.Focus && Fw != &Scr.ScwmRoot))
{
ScwmWindow *tmp_win1, *tmp_win2;
tmp_win1 = Fw->prev;
tmp_win2 = Fw->next;
if (tmp_win1) tmp_win1->next = tmp_win2;
if (tmp_win2) tmp_win2->prev = tmp_win1;
Fw->next = Scr.ScwmRoot.next;
if(Scr.ScwmRoot.next)Scr.ScwmRoot.next->prev = Fw;
Scr.ScwmRoot.next = Fw;
Fw->prev = &Scr.ScwmRoot;
}
if(Scr.NumberOfScreens > 1)
{
XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,
&JunkX, &JunkY, &JunkX, &JunkY, &JunkMask);
if(JunkRoot != Scr.Root)
{
if((Scr.Ungrabbed != NULL)&&(Scr.Ungrabbed->flags & ClickToFocus))
{
/* Need to grab buttons for focus window */
XSync(dpy,0);
for(i=0;i<3;i++)
if(Scr.buttons2grab & (1<<i))
{
XGrabButton(dpy,(i+1),0,Scr.Ungrabbed->frame,True,
ButtonPressMask, GrabModeSync,GrabModeAsync,
None,Scr.ScwmCursors[SYS]);
XGrabButton(dpy,(i+1),LockMask,Scr.Ungrabbed->frame,True,
ButtonPressMask, GrabModeSync,GrabModeAsync,
None,Scr.ScwmCursors[SYS]);
}
Scr.Focus = NULL;
Scr.Ungrabbed = NULL;
XSetInputFocus(dpy, Scr.NoFocusWin,RevertToParent,lastTimestamp);
}
return;
}
}
if((Fw != NULL)&&(Fw->Desk != Scr.CurrentDesk))
{
Fw = NULL;
w = Scr.NoFocusWin;
}
if((Scr.Ungrabbed != NULL)&&
(Scr.Ungrabbed->flags & ClickToFocus)
&& (Scr.Ungrabbed != Fw))
{
/* need to grab all buttons for window that we are about to
* unfocus */
XSync(dpy,0);
for(i=0;i<3;i++)
if(Scr.buttons2grab & (1<<i))
XGrabButton(dpy,(i+1),0,Scr.Ungrabbed->frame,True,
ButtonPressMask, GrabModeSync,GrabModeAsync,None,
Scr.ScwmCursors[SYS]);
Scr.Ungrabbed = NULL;
}
/* if we do click to focus, remove the grab on mouse events that
* was made to detect the focus change */
if((Fw != NULL)&&(Fw->flags&ClickToFocus))
{
for(i=0;i<3;i++)
if(Scr.buttons2grab & (1<<i))
{
XUngrabButton(dpy,(i+1),0,Fw->frame);
XUngrabButton(dpy,(i+1),LockMask,Fw->frame);
}
Scr.Ungrabbed = Fw;
}
if((Fw)&&(Fw->flags & ICONIFIED)&&(Fw->icon_w))
w= Fw->icon_w;
if((Fw)&&(Fw->flags & Lenience))
{
XSetInputFocus (dpy, w, RevertToParent, lastTimestamp);
Scr.Focus = Fw;
Scr.UnknownWinFocused = None;
}
else if(!((Fw)&&(Fw->wmhints)&&(Fw->wmhints->flags & InputHint)&&
(Fw->wmhints->input == False)))
{
/* Window will accept input focus */
XSetInputFocus (dpy, w, RevertToParent, lastTimestamp);
Scr.Focus = Fw;
Scr.UnknownWinFocused = None;
}
else if ((Scr.Focus)&&(Scr.Focus->Desk == Scr.CurrentDesk))
{
/* Window doesn't want focus. Leave focus alone */
/* XSetInputFocus (dpy,Scr.Hilite->w , RevertToParent, lastTimestamp);*/
}
else
{
XSetInputFocus (dpy, Scr.NoFocusWin, RevertToParent, lastTimestamp);
Scr.Focus = NULL;
}
if ((Fw)&&(Fw->flags & DoesWmTakeFocus))
send_clientmessage (dpy, w, _XA_WM_TAKE_FOCUS, lastTimestamp);
XSync(dpy,0);
}