forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfocus.c
136 lines (114 loc) · 2.96 KB
/
focus.c
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
/*
* focus.c - focus management
*
* Copyright © 2007 Julien Danjou <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "util.h"
#include "tag.h"
#include "layout.h"
#include "focus.h"
extern AwesomeConf globalconf;
static FocusList *
focus_get_node_by_client(Client *c)
{
FocusList *fh;
for(fh = globalconf.focus; fh; fh = fh->prev)
if(fh->client == c)
return fh;
return NULL;
}
static FocusList *
focus_detach_node(FocusList *fl)
{
FocusList *tmp;
if(globalconf.focus == fl)
globalconf.focus = fl->prev;
else
{
for(tmp = globalconf.focus; tmp && tmp->prev != fl; tmp = tmp->prev);
tmp->prev = fl->prev;
}
return fl;
}
static FocusList *
focus_attach_node(FocusList *fl)
{
FocusList *old_head;
old_head = globalconf.focus;
globalconf.focus = fl;
fl->prev = old_head;
return fl;
}
void
focus_add_client(Client *c)
{
FocusList *new_fh;
/* if we don't find this node, create a new one */
if(!(new_fh = focus_get_node_by_client(c)))
{
new_fh = p_new(FocusList, 1);
new_fh->client = c;
}
else /* if we've got a node, detach it */
focus_detach_node(new_fh);
focus_attach_node(new_fh);
}
void
focus_delete_client(Client *c)
{
FocusList *fc = focus_get_node_by_client(c), *target;
if (fc)
{
target = focus_detach_node(fc);
p_delete(&target);
}
}
Client *
focus_get_latest_client_for_tag(int screen, Tag *t)
{
FocusList *fl;
for(fl = globalconf.focus; fl; fl = fl->prev)
if(is_client_tagged(fl->client, t, screen))
return fl->client;
return NULL;
}
/** Jump in focus history stack
* \param screen Screen ID
* \param arg Integer argument
* \ingroup ui_callback
*/
void
uicb_focus_history(int screen, char *arg)
{
int i;
FocusList *fl = globalconf.focus;
Tag *curtag = get_current_tag(screen);
if(arg)
{
i = atoi(arg);
if(i < 0)
{
for(; fl && i < 0; fl = fl->prev)
if(is_client_tagged(fl->client, curtag, screen))
i++;
if(fl)
focus(fl->client, True, screen);
}
}
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80