forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfocus.c
More file actions
152 lines (131 loc) · 3.69 KB
/
Copy pathfocus.c
File metadata and controls
152 lines (131 loc) · 3.69 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
/*
* focus.c - focus management
*
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
*
* 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 "tag.h"
#include "focus.h"
#include "client.h"
extern AwesomeConf globalconf;
static client_node_t *
focus_get_node_by_client(Client *c)
{
client_node_t *node;
for(node = globalconf.focus; node; node = node->next)
if(node->client == c)
return node;
return NULL;
}
void
focus_add_client(Client *c)
{
client_node_t *node;
/* if we don't find this node, create a new one */
if(!(node = focus_get_node_by_client(c)))
{
node = p_new(client_node_t, 1);
node->client = c;
}
else /* if we've got a node, detach it */
client_node_list_detach(&globalconf.focus, node);
client_node_list_push(&globalconf.focus, node);
}
void
focus_delete_client(Client *c)
{
client_node_t *node = focus_get_node_by_client(c);
if(node)
{
client_node_list_detach(&globalconf.focus, node);
p_delete(&node);
}
}
static Client *
focus_get_latest_client_for_tags(Tag **t, int nindex)
{
client_node_t *node;
Tag **tags;
int i = 0;
for(node = globalconf.focus; node; node = node->next)
if(node->client && ((!node->client->skip
&& node->client != globalconf.scratch.client)
|| globalconf.scratch.isvisible))
for(tags = t; *tags; tags++)
if(is_client_tagged(node->client, *tags))
{
if(i == nindex)
return node->client;
else
i--;
}
return NULL;
}
Client *
focus_get_current_client(int screen)
{
Tag **curtags = tags_get_current(screen);
Client *sel = focus_get_latest_client_for_tags(curtags, 0);
p_delete(&curtags);
return sel;
}
/** Jump back in the focus history stack.
* Set arg to 0 for previous, -1 for previous of previous, etc.
* \param screen Screen ID
* \param arg Integer argument
* \ingroup ui_callback
*/
void
uicb_focus_history(int screen, char *arg)
{
int i;
Tag **curtags;
Client *c;
if(arg)
{
i = atoi(arg);
if(i < 0)
{
curtags = tags_get_current(screen);
c = focus_get_latest_client_for_tags(curtags, i);
p_delete(&curtags);
if(c)
client_focus(c, screen, True);
}
}
}
/** Focus one of the visible clients by its name.
* \param screen screen id
* \param arg client's name
* \ingroup ui_callback
*/
void
uicb_focus_client_byname(int screen, char *arg)
{
Client *c;
Tag **curtags, **tag;
if(arg)
{
curtags = tags_get_current(screen);
if((c = client_get_byname(globalconf.clients, arg)))
for(tag = curtags; *tag; tag++)
if(is_client_tagged(c, *tag))
client_focus(c, screen, True);
p_delete(&curtags);
}
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80