]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/focus.c
add the ebox style
[mikachu/openbox.git] / openbox / focus.c
1 #include "openbox.h"
2 #include "client.h"
3 #include "screen.h"
4 #include "prop.h"
5 #include "dispatch.h"
6
7 #include <X11/Xlib.h>
8 #include <glib.h>
9
10 Client *focus_client = NULL;
11 GList **focus_order = NULL; /* these lists are created when screen_startup
12                                sets the number of desktops */
13
14 Window focus_backup = None;
15
16 void focus_set_client(Client *client);
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
45     XDestroyWindow(ob_display, focus_backup);
46
47     /* reset focus to root */
48     XSetInputFocus(ob_display, PointerRoot, RevertToNone, CurrentTime);
49 }
50
51 void focus_set_client(Client *client)
52 {
53     Window active;
54     Client *old;
55     guint desktop;
56
57     /* uninstall the old colormap, and install the new one */
58     screen_install_colormap(focus_client, FALSE);
59     screen_install_colormap(client, TRUE);
60
61
62     if (client == NULL) {
63         /* when nothing will be focused, send focus to the backup target */
64         XSetInputFocus(ob_display, focus_backup, RevertToNone, CurrentTime);
65     }
66
67     old = focus_client;
68     focus_client = client;
69
70     /* move to the top of the list */
71     if (client != NULL) {
72         desktop = client->desktop;
73         if (desktop == DESKTOP_ALL) desktop = screen_desktop;
74         focus_order[desktop] = g_list_remove(focus_order[desktop], client);
75         focus_order[desktop] = g_list_prepend(focus_order[desktop], client);
76     }
77
78     /* set the NET_ACTIVE_WINDOW hint */
79     active = client ? client->window : None;
80     PROP_SET32(ob_root, net_active_window, window, active);
81
82     if (focus_client != NULL)
83         dispatch_client(Event_Client_Focus, focus_client, 0, 0);
84     if (old != NULL)
85         dispatch_client(Event_Client_Unfocus, old, 0, 0);
86 }