]> git.sur5r.net Git - i3/i3/blobdiff - src/main.c
Clicking the root window should try to focus the relevant workspace.
[i3/i3] / src / main.c
index 7936e75889bb15946251104f7b8e4515becbdc79..65db1711c40845710233535463ab8a465c9cc5ae 100644 (file)
@@ -232,13 +232,15 @@ static void i3_exit(void) {
  * Unlinks the SHM log and re-raises the signal.
  *
  */
-static void handle_signal(int sig, siginfo_t *info, void *data) {
+static void handle_signal(struct ev_loop *loop, ev_signal *w, int revents) {
+    int sig = w->signum;
     fprintf(stderr, "Received signal %d, terminating\n", sig);
     if (*shmlogname != '\0') {
         fprintf(stderr, "Closing SHM log \"%s\"\n", shmlogname);
         shm_unlink(shmlogname);
     }
     fflush(stderr);
+    ev_signal_stop(loop, w);
     raise(sig);
 }
 
@@ -391,7 +393,8 @@ int main(int argc, char *argv[]) {
                 fprintf(stderr, "\t--force-xinerama\n"
                                 "\tUse Xinerama instead of RandR.\n"
                                 "\tThis option should only be used if you are stuck with the\n"
-                                "\tnvidia closed source driver which does not support RandR.\n");
+                                "\told nVidia closed source driver (older than 302.17), which does\n"
+                                "\tnot support RandR.\n");
                 fprintf(stderr, "\n");
                 fprintf(stderr, "\t--get-socketpath\n"
                                 "\tRetrieve the i3 IPC socket path from X11, print it, then exit.\n");
@@ -541,6 +544,7 @@ int main(int argc, char *argv[]) {
 
     uint32_t mask = XCB_CW_EVENT_MASK;
     uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
+                          XCB_EVENT_MASK_BUTTON_PRESS |
                           XCB_EVENT_MASK_STRUCTURE_NOTIFY |         /* when the user adds a screen (e.g. video
                                                                            projector), the root window gets a
                                                                            ConfigureNotify */
@@ -779,31 +783,32 @@ int main(int argc, char *argv[]) {
     }
     xcb_ungrab_server(conn);
 
-    struct sigaction action;
 
-    action.sa_sigaction = handle_signal;
-    action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
-    sigemptyset(&action.sa_mask);
+#define HANDLE_SIGNAL_EV(signum) \
+    do { \
+        struct ev_signal *signal_watcher = scalloc(sizeof(struct ev_signal)); \
+        ev_signal_init(signal_watcher, handle_signal, signum); \
+        ev_signal_start(main_loop, signal_watcher); \
+    } while (0)
 
     if (!disable_signalhandler)
         setup_signal_handler();
     else {
         /* Catch all signals with default action "Core", see signal(7) */
-        if (sigaction(SIGQUIT, &action, NULL) == -1 ||
-            sigaction(SIGILL, &action, NULL) == -1 ||
-            sigaction(SIGABRT, &action, NULL) == -1 ||
-            sigaction(SIGFPE, &action, NULL) == -1 ||
-            sigaction(SIGSEGV, &action, NULL) == -1)
-            ELOG("Could not setup signal handler");
+        HANDLE_SIGNAL_EV(SIGQUIT);
+        HANDLE_SIGNAL_EV(SIGILL);
+        HANDLE_SIGNAL_EV(SIGABRT);
+        HANDLE_SIGNAL_EV(SIGFPE);
+        HANDLE_SIGNAL_EV(SIGSEGV);
     }
 
     /* Catch all signals with default action "Term", see signal(7) */
-    if (sigaction(SIGHUP, &action, NULL) == -1 ||
-        sigaction(SIGINT, &action, NULL) == -1 ||
-        sigaction(SIGALRM, &action, NULL) == -1 ||
-        sigaction(SIGUSR1, &action, NULL) == -1 ||
-        sigaction(SIGUSR2, &action, NULL) == -1)
-        ELOG("Could not setup signal handler");
+    HANDLE_SIGNAL_EV(SIGHUP);
+    HANDLE_SIGNAL_EV(SIGINT);
+    HANDLE_SIGNAL_EV(SIGALRM);
+    HANDLE_SIGNAL_EV(SIGTERM);
+    HANDLE_SIGNAL_EV(SIGUSR1);
+    HANDLE_SIGNAL_EV(SIGUSR2);
 
     /* Ignore SIGPIPE to survive errors when an IPC client disconnects
      * while we are sending him a message */