]> git.sur5r.net Git - i3/i3/blobdiff - src/main.c
Make default shmlog_size a const int
[i3/i3] / src / main.c
index 8bae9957db894e3fac02363b37e857ef49f9ad4f..0912d48ebcaa5c63d59ac81e1f39863410d95ba5 100644 (file)
@@ -4,7 +4,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * main.c: Initialization, main loop
  *
@@ -19,6 +19,7 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include "all.h"
+#include "shmlog.h"
 
 #include "sd-daemon.h"
 
@@ -67,6 +68,9 @@ xcb_key_symbols_t *keysyms;
 /* Those are our connections to X11 for use with libXcursor and XKB */
 Display *xlibdpy, *xkbdpy;
 
+/* Default shmlog size if not set by user. */
+const int default_shmlog_size = 25 * 1024 * 1024;
+
 /* The list of key bindings */
 struct bindings_head *bindings;
 
@@ -233,12 +237,9 @@ static void i3_exit(void) {
  *
  */
 static void handle_signal(int sig, siginfo_t *info, void *data) {
-    fprintf(stderr, "Received signal %d, terminating\n", sig);
     if (*shmlogname != '\0') {
-        fprintf(stderr, "Closing SHM log \"%s\"\n", shmlogname);
         shm_unlink(shmlogname);
     }
-    fflush(stderr);
     raise(sig);
 }
 
@@ -272,6 +273,7 @@ int main(int argc, char *argv[]) {
         {"get_socketpath", no_argument, 0, 0},
         {"fake_outputs", required_argument, 0, 0},
         {"fake-outputs", required_argument, 0, 0},
+        {"force-old-config-parser-v4.4-only", no_argument, 0, 0},
         {0, 0, 0, 0}
     };
     int option_index = 0, opt;
@@ -293,7 +295,7 @@ int main(int argc, char *argv[]) {
     init_logging();
 
     /* On non-release builds, disable SHM logging by default. */
-    shmlog_size = (is_debug_build() ? 25 * 1024 * 1024 : 0);
+    shmlog_size = (is_debug_build() ? default_shmlog_size : 0);
 
     start_argv = argv;
 
@@ -317,11 +319,11 @@ int main(int argc, char *argv[]) {
                 only_check_config = true;
                 break;
             case 'v':
-                printf("i3 version " I3_VERSION " © 2009-2012 Michael Stapelberg and contributors\n");
+                printf("i3 version " I3_VERSION " © 2009-2013 Michael Stapelberg and contributors\n");
                 exit(EXIT_SUCCESS);
                 break;
             case 'm':
-                printf("Binary i3 version:  " I3_VERSION " © 2009-2012 Michael Stapelberg and contributors\n");
+                printf("Binary i3 version:  " I3_VERSION " © 2009-2013 Michael Stapelberg and contributors\n");
                 display_running_version();
                 exit(EXIT_SUCCESS);
                 break;
@@ -375,6 +377,9 @@ int main(int argc, char *argv[]) {
                     LOG("Initializing fake outputs: %s\n", optarg);
                     fake_outputs = sstrdup(optarg);
                     break;
+                } else if (strcmp(long_options[option_index].name, "force-old-config-parser-v4.4-only") == 0) {
+                    ELOG("You are passing --force-old-config-parser-v4.4-only, but that flag was removed by now.\n");
+                    break;
                 }
                 /* fall-through */
             default:
@@ -459,14 +464,16 @@ int main(int argc, char *argv[]) {
             err(EXIT_FAILURE, "IPC: write()");
 
         uint32_t reply_length;
+        uint32_t reply_type;
         uint8_t *reply;
         int ret;
-        if ((ret = ipc_recv_message(sockfd, I3_IPC_MESSAGE_TYPE_COMMAND,
-                                    &reply_length, &reply)) != 0) {
+        if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
             if (ret == -1)
                 err(EXIT_FAILURE, "IPC: read()");
             return 1;
         }
+        if (reply_type != I3_IPC_MESSAGE_TYPE_COMMAND)
+            errx(EXIT_FAILURE, "IPC: received reply of type %d but expected %d (COMMAND)", reply_type, I3_IPC_MESSAGE_TYPE_COMMAND);
         printf("%.*s\n", reply_length, reply);
         return 0;
     }
@@ -540,16 +547,8 @@ int main(int argc, char *argv[]) {
             config.ipc_socket_path = sstrdup(config.ipc_socket_path);
     }
 
-    uint32_t mask = XCB_CW_EVENT_MASK;
-    uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
-                          XCB_EVENT_MASK_STRUCTURE_NOTIFY |         /* when the user adds a screen (e.g. video
-                                                                           projector), the root window gets a
-                                                                           ConfigureNotify */
-                          XCB_EVENT_MASK_POINTER_MOTION |
-                          XCB_EVENT_MASK_PROPERTY_CHANGE |
-                          XCB_EVENT_MASK_ENTER_WINDOW };
     xcb_void_cookie_t cookie;
-    cookie = xcb_change_window_attributes_checked(conn, root, mask, values);
+    cookie = xcb_change_window_attributes_checked(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ ROOT_EVENT_MASK });
     check_error(conn, cookie, "Another window manager seems to be running");
 
     xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(conn, gcookie, NULL);
@@ -600,13 +599,13 @@ int main(int argc, char *argv[]) {
         int i1;
         if (!XkbQueryExtension(xkbdpy,&i1,&xkb_event_base,&errBase,&major,&minor)) {
             fprintf(stderr, "XKB not supported by X-server\n");
-            return 1;
+           xkb_supported = false;
         }
         /* end of ugliness */
 
-        if (!XkbSelectEvents(xkbdpy, XkbUseCoreKbd,
-                             XkbMapNotifyMask | XkbStateNotifyMask,
-                             XkbMapNotifyMask | XkbStateNotifyMask)) {
+        if (xkb_supported && !XkbSelectEvents(xkbdpy, XkbUseCoreKbd,
+                                              XkbMapNotifyMask | XkbStateNotifyMask,
+                                              XkbMapNotifyMask | XkbStateNotifyMask)) {
             fprintf(stderr, "Could not set XKB event mask\n");
             return 1;
         }
@@ -774,6 +773,20 @@ int main(int argc, char *argv[]) {
         xcb_aux_sync(conn);
         xcb_generic_event_t *event;
         while ((event = xcb_poll_for_event(conn)) != NULL) {
+            if (event->response_type == 0) {
+                free(event);
+                continue;
+            }
+
+            /* Strip off the highest bit (set if the event is generated) */
+            int type = (event->response_type & 0x7F);
+
+            /* We still need to handle MapRequests which are sent in the
+             * timespan starting from when we register as a window manager and
+             * this piece of code which drops events. */
+            if (type == XCB_MAP_REQUEST)
+                handle_event(type, event);
+
             free(event);
         }
         manage_existing_windows(root);