]> git.sur5r.net Git - i3/i3/blobdiff - src/nc.c
Re-implement support for the urgency hint, extend t/13-urgent.t
[i3/i3] / src / nc.c
index 7b2b126ac6c507ec7a066c6eb8d7f8f54207149e..a5769d170812b6f045ab2a3858fecc19567945fa 100644 (file)
--- a/src/nc.c
+++ b/src/nc.c
@@ -2,6 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  */
 #include <ev.h>
+#include <limits.h>
 #include "all.h"
 
 static int xkb_event_base;
@@ -62,110 +63,8 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
     }
 }
 
-int handle_map_request(void *unused, xcb_connection_t *conn, xcb_map_request_event_t *event) {
-    xcb_get_window_attributes_cookie_t cookie;
-
-    cookie = xcb_get_window_attributes_unchecked(conn, event->window);
-
-    LOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence);
-    //add_ignore_event(event->sequence);
-
-    manage_window(event->window, cookie, false);
-    return 1;
-}
-
-
-int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_notify_event_t *event) {
-    LOG("unmap event for 0x%08x\n", event->window);
-    Con *con = con_by_window_id(event->window);
-    if (con == NULL) {
-        LOG("Not a managed window, ignoring\n");
-        return 1;
-    }
-
-    tree_close(con);
-    tree_render();
-    return 1;
-}
-
-int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) {
-    Con *parent, *con;
-
-    /* event->count is the number of minimum remaining expose events for this window, so we
-       skip all events but the last one */
-    if (event->count != 0)
-            return 1;
-    LOG("expose-event, window = %08x\n", event->window);
-
-    if ((parent = con_by_frame_id(event->window)) == NULL) {
-        LOG("expose event for unknown window, ignoring\n");
-        return 1;
-    }
-
-    TAILQ_FOREACH(con, &(parent->nodes_head), nodes) {
-        LOG("expose for con %p / %s\n", con, con->name);
-        if (con->window)
-            x_draw_decoration(con);
-    }
-    xcb_flush(conn);
-
-    return 1;
-}
-
-
-
-void parse_command(const char *command) {
-    printf("received command: %s\n", command);
-
-    if (strcasecmp(command, "open") == 0)
-        tree_open_con(NULL);
-    else if (strcasecmp(command, "close") == 0)
-        tree_close_con();
-    else if (strcasecmp(command, "split h") == 0)
-        tree_split(focused, HORIZ);
-    else if (strcasecmp(command, "split v") == 0)
-        tree_split(focused, VERT);
-    else if (strcasecmp(command, "level up") == 0)
-        level_up();
-    else if (strcasecmp(command, "level down") == 0)
-        level_down();
-    else if (strcasecmp(command, "prev h") == 0)
-        tree_next('p', HORIZ);
-    else if (strcasecmp(command, "prev v") == 0)
-        tree_next('p', VERT);
-    else if (strcasecmp(command, "next h") == 0)
-        tree_next('n', HORIZ);
-    else if (strcasecmp(command, "next v") == 0)
-        tree_next('n', VERT);
-    else if (strncasecmp(command, "workspace ", strlen("workspace ")) == 0)
-        workspace_show(command + strlen("workspace "));
-
-    else if (strcasecmp(command, "move before h") == 0)
-        tree_move('p', HORIZ);
-    else if (strcasecmp(command, "move before v") == 0)
-        tree_move('p', VERT);
-    else if (strcasecmp(command, "move after h") == 0)
-        tree_move('n', HORIZ);
-    else if (strcasecmp(command, "move after v") == 0)
-        tree_move('n', VERT);
-    else if (strncasecmp(command, "restore", strlen("restore")) == 0)
-        tree_append_json(command + strlen("restore "));
-    else if (strncasecmp(command, "exec", strlen("exec")) == 0)
-        start_application(command + strlen("exec "));
-    else if (strcasecmp(command, "restart") == 0)
-        i3_restart();
-    else if (strcasecmp(command, "floating") == 0)
-        toggle_floating_mode(focused, false);
-
-    tree_render();
-
-#if 0
-    if (strcasecmp(command, "prev") == 0)
-        tree_prev(O_CURRENT);
-#endif
-}
-
 int main(int argc, char *argv[]) {
+    //parse_cmd("[ foo ] attach, attach ; focus");
     int screens;
     char *override_configpath = NULL;
     bool autostart = true;
@@ -308,10 +207,16 @@ int main(int argc, char *argv[]) {
     xcb_event_set_map_request_handler(&evenths, handle_map_request, NULL);
 
     xcb_event_set_unmap_notify_handler(&evenths, handle_unmap_notify_event, NULL);
-    //xcb_event_set_destroy_notify_handler(&evenths, handle_destroy_notify_event, NULL);
+    xcb_event_set_destroy_notify_handler(&evenths, handle_destroy_notify_event, NULL);
 
     xcb_event_set_expose_handler(&evenths, handle_expose_event, NULL);
 
+    /* Enter window = user moved his mouse over the window */
+    xcb_event_set_enter_notify_handler(&evenths, handle_enter_notify, NULL);
+
+    /* Client message are sent to the root window. The only interesting client message
+       for us is _NET_WM_STATE, we honour _NET_WM_STATE_FULLSCREEN */
+    xcb_event_set_client_message_handler(&evenths, handle_client_message, NULL);
 
     /* Setup NetWM atoms */
     #define GET_ATOM(name) \
@@ -347,8 +252,21 @@ int main(int argc, char *argv[]) {
     GET_ATOM(_NET_ACTIVE_WINDOW);
     GET_ATOM(_NET_WORKAREA);
 
+    /* Watch _NET_WM_NAME (title of the window encoded in UTF-8) */
     xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL);
 
+    /* Watch WM_HINTS (contains the urgent property) */
+    xcb_property_set_handler(&prophs, WM_HINTS, UINT_MAX, handle_hints, NULL);
+
+    /* Watch WM_NAME (title of the window encoded in COMPOUND_TEXT) */
+    xcb_watch_wm_name(&prophs, 128, handle_windowname_change_legacy, NULL);
+
+    /* Set up the atoms we support */
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTED], ATOM, 32, 7, atoms);
+    /* Set up the window manager’s name */
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTING_WM_CHECK], WINDOW, 32, 1, &root);
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_WM_NAME], atoms[UTF8_STRING], 8, strlen("i3"), "i3");
+
     keysyms = xcb_key_symbols_alloc(conn);
 
     xcb_get_numlock_mask(conn);