1 /* Skippy - Seduces Kids Into Perversion
2 *
3 * Copyright (C) 2004 Hyriand <hyriand@thegraveyard.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #ifndef SKIPPY_FOCUS_H
21 #define SKIPPY_FOCUS_H
22
23 /**
24 * @brief Focus the mini window of a client window.
25 */
26 static inline void
focus_miniw_adv(session_t * ps,ClientWin * cw,bool move_ptr)27 focus_miniw_adv(session_t *ps, ClientWin *cw, bool move_ptr) {
28 if (unlikely(!cw))
29 return;
30 assert(cw->mini.window);
31 if (move_ptr)
32 XWarpPointer(ps->dpy, None, cw->mini.window, 0, 0, 0, 0, cw->mini.width / 2, cw->mini.height / 2);
33 XSetInputFocus(ps->dpy, cw->mini.window, RevertToParent, CurrentTime);
34 XFlush(ps->dpy);
35 }
36
37 static inline void
focus_miniw(session_t * ps,ClientWin * cw)38 focus_miniw(session_t *ps, ClientWin *cw) {
39 focus_miniw_adv(ps, cw, ps->o.movePointerOnSelect);
40 }
41
42 /**
43 * @brief Focus the mini window of next client window in list.
44 */
45 static inline void
focus_miniw_next(session_t * ps,ClientWin * cw)46 focus_miniw_next(session_t *ps, ClientWin *cw) {
47 dlist *e = dlist_find_data(cw->mainwin->cod, cw);
48 if (!e) {
49 printfef("(%#010lx): Client window not found in list.", cw->src.window);
50 return;
51 }
52 if (e->next)
53 focus_miniw(ps, e->next->data);
54 else
55 focus_miniw(ps, dlist_first(e)->data);
56 }
57
58 /**
59 * @brief Focus the mini window of previous client window in list.
60 */
61 static inline void
focus_miniw_prev(session_t * ps,ClientWin * cw)62 focus_miniw_prev(session_t *ps, ClientWin *cw) {
63 dlist *cwlist = dlist_first(cw->mainwin->cod);
64 dlist *tgt = NULL;
65
66 if (cw == cwlist->data)
67 tgt = dlist_last(cwlist);
68 else
69 foreach_dlist (cwlist) {
70 if (iter->next && cw == iter->next->data) {
71 tgt = iter;
72 break;
73 }
74 }
75
76 if (!tgt) {
77 printfef("(%#010lx): Client window not found in list.", cw->src.window);
78 return;
79 }
80
81 focus_miniw(ps, (ClientWin *) tgt->data);
82 }
83
84 void focus_up(ClientWin *cw);
85 void focus_down(ClientWin *cw);
86 void focus_left(ClientWin *cw);
87 void focus_right(ClientWin *cw);
88
89 #endif /* SKIPPY_FOCUS_H */
90