]> git.sur5r.net Git - i3/i3/commitdiff
Send WM_TAKE_FOCUS when setting focus (fixes java problems)
authorMichael Stapelberg <michael@stapelberg.de>
Thu, 17 Mar 2011 21:44:29 +0000 (22:44 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 17 Mar 2011 21:44:29 +0000 (22:44 +0100)
include/i3.h
include/util.h
include/xcb.h
src/mainx.c
src/manage.c
src/util.c

index bf9d4b814e6960e9c949cf72fbd0d3bc0497dedf..9b20e2a9812437bfab16e98c95fc8c1945aa1882 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef _I3_H
 #define _I3_H
 
-#define NUM_ATOMS 21
+#define NUM_ATOMS 22
 
 extern xcb_connection_t *global_conn;
 extern xcb_key_symbols_t *keysyms;
index d1384962b1fa3bfee0647a61faa20448eae42551..7d942766fe7e345a8dc9f4ee98af3cf95edbe9c1 100644 (file)
@@ -126,6 +126,12 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen);
 Client *get_last_focused_client(xcb_connection_t *conn, Container *container,
                                 Client *exclude);
 
+/**
+ * Sends WM_TAKE_FOCUS to the client
+ *
+ */
+void take_focus(xcb_connection_t *conn, Client *client);
+
 /**
  * Sets the given client as focused by updating the data structures correctly,
  * updating the X input focus and finally re-decorating both windows (to
index 78e1373a964cc86cf15645e0a29f55184ca63b7a..8d8675537fed52480ea017cef7672298c73b4a3d 100644 (file)
@@ -64,7 +64,8 @@ enum { _NET_SUPPORTED = 0,
         WM_CLIENT_LEADER,
         _NET_CURRENT_DESKTOP,
         _NET_ACTIVE_WINDOW,
-        _NET_WORKAREA
+        _NET_WORKAREA,
+        WM_TAKE_FOCUS
 };
 
 extern unsigned int xcb_numlock_mask;
index b0ae40b98ca47f2bc868ce62a5a621ee5b6dd1d6..be4713e654353cbb20ec170892af74720065adc4 100644 (file)
@@ -326,6 +326,7 @@ int main(int argc, char *argv[], char *env[]) {
         REQUEST_ATOM(_NET_CURRENT_DESKTOP);
         REQUEST_ATOM(_NET_ACTIVE_WINDOW);
         REQUEST_ATOM(_NET_WORKAREA);
+        REQUEST_ATOM(WM_TAKE_FOCUS);
 
         /* TODO: this has to be more beautiful somewhen */
         int major, minor, error;
@@ -491,6 +492,7 @@ int main(int argc, char *argv[], char *env[]) {
         GET_ATOM(_NET_CURRENT_DESKTOP);
         GET_ATOM(_NET_ACTIVE_WINDOW);
         GET_ATOM(_NET_WORKAREA);
+        GET_ATOM(WM_TAKE_FOCUS);
 
         xcb_property_set_handler(&prophs, atoms[_NET_WM_WINDOW_TYPE], UINT_MAX, handle_window_type, NULL);
         /* TODO: In order to comply with EWMH, we have to watch _NET_WM_STRUT_PARTIAL */
index 06f4e664338f736dceca5034a1486c64cea13951..089d62cbfa40057918216e25bcaca20306cf9eca 100644 (file)
@@ -512,6 +512,7 @@ map:
                         }
                         if (new->container == CUR_CELL || client_is_floating(new)) {
                                 xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, new->child, XCB_CURRENT_TIME);
+                                take_focus(conn, new);
                                 ewmh_update_active_window(new->child);
                         }
                 }
index cb37d30aa2619d56f6dbeb8052b6183c3e50328b..d119b35a532b0485d97c5c845ed37a4e164bb9c8 100644 (file)
@@ -222,6 +222,25 @@ Client *get_last_focused_client(xcb_connection_t *conn, Container *container, Cl
         return NULL;
 }
 
+/*
+ * Sends WM_TAKE_FOCUS to the client
+ *
+ */
+void take_focus(xcb_connection_t *conn, Client *client) {
+    xcb_client_message_event_t ev;
+
+    memset(&ev, 0, sizeof(xcb_client_message_event_t));
+
+    ev.response_type = XCB_CLIENT_MESSAGE;
+    ev.window = client->child;
+    ev.type = atoms[WM_PROTOCOLS];
+    ev.format = 32;
+    ev.data.data32[0] = atoms[WM_TAKE_FOCUS];
+    ev.data.data32[1] = XCB_CURRENT_TIME;
+
+    DLOG("Sending WM_TAKE_FOCUS to the client\n");
+    xcb_send_event(conn, false, client->child, XCB_EVENT_MASK_NO_EVENT, (char*)&ev);
+}
 
 /*
  * Sets the given client as focused by updating the data structures correctly,
@@ -261,6 +280,7 @@ void set_focus(xcb_connection_t *conn, Client *client, bool set_anyways) {
         CLIENT_LOG(client);
         /* Set focus to the entered window, and flush xcb buffer immediately */
         xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, client->child, XCB_CURRENT_TIME);
+        take_focus(conn, client);
         ewmh_update_active_window(client->child);
         //xcb_warp_pointer(conn, XCB_NONE, client->child, 0, 0, 0, 0, 10, 10);