stop using python internally. add an event dispatcher
[dana/openbox.git] / openbox / focus.c
1 #include "openbox.h"
2 #include "client.h"
3 #include "screen.h"
4 #include "prop.h"
5
6 #include <X11/Xlib.h>
7
8 Client *focus_client = NULL;
9
10 Window focus_backup = None;
11
12 void focus_set_client(Client *client);
13
14 void focus_startup()
15 {
16     /* create the window which gets focus when no clients get it. Have to
17        make it override-redirect so we don't try manage it, since it is
18        mapped. */
19     XSetWindowAttributes attrib;
20
21     attrib.override_redirect = TRUE;
22     focus_backup = XCreateWindow(ob_display, ob_root,
23                                  -100, -100, 1, 1, 0, 0, InputOnly,
24                                  CopyFromParent, CWOverrideRedirect, &attrib);
25     XMapRaised(ob_display, focus_backup);
26
27     /* start with nothing focused */
28     focus_set_client(NULL);
29 }
30
31 void focus_set_client(Client *client)
32 {
33     Window active;
34      
35     /* sometimes this is called with the already-focused window, this is
36        important for the python scripts to work (eg, c = 0 twice). don't just
37        return if _focused_client == c */
38
39     /* uninstall the old colormap, and install the new one */
40     screen_install_colormap(focus_client, FALSE);
41     screen_install_colormap(client, TRUE);
42
43
44     if (client == NULL) {
45         /* when nothing will be focused, send focus to the backup target */
46         XSetInputFocus(ob_display, focus_backup, RevertToNone, CurrentTime);
47     }
48
49     focus_client = client;
50
51     /* set the NET_ACTIVE_WINDOW hint */
52     active = client ? client->window : None;
53     PROP_SET32(ob_root, net_active_window, window, active);
54
55     /*HOOKFIRECLIENT(focused, client);XXX*/
56 }