]> Dogcows Code - chaz/openbox/blob - openbox/focus.c
d9ed80bcbbfdbcb267fc344b0959658aff63f100
[chaz/openbox] / openbox / focus.c
1 #include "event.h"
2 #include "openbox.h"
3 #include "client.h"
4 #include "screen.h"
5 #include "prop.h"
6 #include "dispatch.h"
7 #include "focus.h"
8
9 #include <X11/Xlib.h>
10 #include <glib.h>
11
12 Client *focus_client = NULL;
13 GList **focus_order = NULL; /* these lists are created when screen_startup
14 sets the number of desktops */
15
16 Window focus_backup = None;
17
18 void focus_startup()
19 {
20 /* create the window which gets focus when no clients get it. Have to
21 make it override-redirect so we don't try manage it, since it is
22 mapped. */
23 XSetWindowAttributes attrib;
24
25 focus_client = NULL;
26
27 attrib.override_redirect = TRUE;
28 focus_backup = XCreateWindow(ob_display, ob_root,
29 -100, -100, 1, 1, 0, 0, InputOnly,
30 CopyFromParent, CWOverrideRedirect, &attrib);
31 XMapRaised(ob_display, focus_backup);
32
33 /* start with nothing focused */
34 focus_set_client(NULL);
35 }
36
37 void focus_shutdown()
38 {
39 guint i;
40
41 for (i = 0; i < screen_num_desktops; ++i)
42 g_list_free(focus_order[i]);
43 g_free(focus_order);
44 focus_order = NULL;
45
46 XDestroyWindow(ob_display, focus_backup);
47
48 /* reset focus to root */
49 XSetInputFocus(ob_display, PointerRoot, RevertToNone, event_lasttime);
50 }
51
52 void focus_set_client(Client *client)
53 {
54 Window active;
55 Client *old;
56 guint desktop;
57
58 /* uninstall the old colormap, and install the new one */
59 screen_install_colormap(focus_client, FALSE);
60 screen_install_colormap(client, TRUE);
61
62
63 if (client == NULL) {
64 /* when nothing will be focused, send focus to the backup target */
65 XSetInputFocus(ob_display, focus_backup, RevertToNone,
66 event_unfocustime);
67 }
68
69 old = focus_client;
70 focus_client = client;
71
72 /* move to the top of the list */
73 if (client != NULL) {
74 desktop = client->desktop;
75 if (desktop == DESKTOP_ALL) desktop = screen_desktop;
76 focus_order[desktop] = g_list_remove(focus_order[desktop], client);
77 focus_order[desktop] = g_list_prepend(focus_order[desktop], client);
78 }
79
80 /* set the NET_ACTIVE_WINDOW hint */
81 active = client ? client->window : None;
82 PROP_SET32(ob_root, net_active_window, window, active);
83
84 if (focus_client != NULL)
85 dispatch_client(Event_Client_Focus, focus_client, 0, 0);
86 if (old != NULL)
87 dispatch_client(Event_Client_Unfocus, old, 0, 0);
88 }
This page took 0.034542 seconds and 3 git commands to generate.