]> git.sur5r.net Git - i3/i3/commitdiff
Merge branch 'master' into next
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 9 Aug 2011 07:47:10 +0000 (09:47 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 9 Aug 2011 07:47:10 +0000 (09:47 +0200)
14 files changed:
docs/ipc
i3-msg/main.c
include/config.h
include/i3/ipc.h
src/cfgparse.l
src/cfgparse.y
src/config.c
src/floating.c
src/ipc.c
src/load_layout.c
src/manage.c
src/workspace.c
testcases/t/73-get-marks.t [new file with mode: 0644]
testcases/t/74-border-config.t [new file with mode: 0644]

index 7e71326022606aa2b4d1abf93d4d77d3c448fe1a..4093ffce26e2233b7258c62bedc4e180b3c70fad 100644 (file)
--- a/docs/ipc
+++ b/docs/ipc
@@ -59,6 +59,10 @@ GET_TREE (4)::
        Gets the layout tree. i3 uses a tree as data structure which includes
        every container. The reply will be the JSON-encoded tree (see the reply
        section).
+GET_MARKS (5)::
+       Gets a list of marks (identifiers for containers to easily jump to them
+       later). The reply will be a JSON-encoded list of window marks (see
+       reply section).
 
 So, a typical message could look like this:
 --------------------------------------------------
@@ -110,6 +114,8 @@ GET_OUTPUTS (3)::
        Reply to the GET_OUTPUTS message.
 GET_TREE (4)::
        Reply to the GET_TREE message.
+GET_MARKS (5)::
+       Reply to the GET_MARKS message.
 
 === COMMAND reply
 
@@ -416,6 +422,16 @@ JSON dump:
    }
  ]
 }
+
+
+=== GET_MARKS reply
+
+The reply consists of a single array of strings for each container that has a
+mark. The order of that array is undefined. If more than one container has the
+same mark, it will be represented multiple times in the reply (the array
+contents are not unique).
+
+If no window has a mark the response will be the empty array [].
 ------------------------
 
 
index 630a345d63c6ce57dc611b19464d8a5b6da0f8cf..d8195e08c8df3ff7629148b9d97bad68e2e03886 100644 (file)
@@ -180,9 +180,11 @@ int main(int argc, char *argv[]) {
                 message_type = I3_IPC_MESSAGE_TYPE_GET_OUTPUTS;
             else if (strcasecmp(optarg, "get_tree") == 0)
                 message_type = I3_IPC_MESSAGE_TYPE_GET_TREE;
+            else if (strcasecmp(optarg, "get_marks") == 0)
+                message_type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
             else {
                 printf("Unknown message type\n");
-                printf("Known types: command, get_workspaces, get_outputs, get_tree\n");
+                printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks\n");
                 exit(EXIT_FAILURE);
             }
         } else if (o == 'q') {
index 1021a612e7a98917a211a61d037b688e255c6861..3234b91e5d5f658cae51ed548d047b5df05116e4 100644 (file)
@@ -126,6 +126,9 @@ struct Config {
         /** The default border style for new windows. */
         border_style_t default_border;
 
+        /** The default border style for new floating windows. */
+        border_style_t default_floating_border;
+
         /** The modifier which needs to be pressed in combination with your mouse
          * buttons to do things with floating windows (move, resize) */
         uint32_t floating_modifier;
index e81f9a155ad5e7254a631c1fb04d7a6a172e6a48..30b2d3044e353cdb4c202a571e6acfde6138326d 100644 (file)
@@ -38,6 +38,8 @@
 /** Requests the tree layout from i3 */
 #define I3_IPC_MESSAGE_TYPE_GET_TREE            4
 
+/** Request the current defined marks from i3 */
+#define I3_IPC_MESSAGE_TYPE_GET_MARKS           5
 
 /*
  * Messages from i3 to clients
@@ -59,6 +61,8 @@
 /** Tree reply type */
 #define I3_IPC_REPLY_TYPE_TREE                  4
 
+/** Marks reply type*/
+#define I3_IPC_REPLY_TYPE_MARKS                 5
 
 /*
  * Events from i3 to clients. Events have the first bit set high.
index 4cf1a1c3777a5fd1f7a115c7cf85b3123764e055..e29f6efc1466ec0438ea9d2f681b65c0a179de1f 100644 (file)
@@ -118,6 +118,7 @@ vertical                        { return TOK_VERT; }
 auto                            { return TOK_AUTO; }
 workspace_layout                { return TOK_WORKSPACE_LAYOUT; }
 new_window                      { return TOKNEWWINDOW; }
+new_float                       { return TOKNEWFLOAT; }
 normal                          { return TOK_NORMAL; }
 none                            { return TOK_NONE; }
 1pixel                          { return TOK_1PIXEL; }
index abbe4da0a40a90a8d0a3b856db6fe0e13a9f5a7d..4a4c26ca39eff116292942daa209aa8852e4e985 100644 (file)
@@ -310,6 +310,53 @@ void kill_configerror_nagbar(bool wait_for_it) {
     waitpid(configerror_pid, NULL, 0);
 }
 
+/*
+ * Checks for duplicate key bindings (the same keycode or keysym is configured
+ * more than once). If a duplicate binding is found, a message is printed to
+ * stderr and the has_errors variable is set to true, which will start
+ * i3-nagbar.
+ *
+ */
+static void check_for_duplicate_bindings(struct context *context) {
+    Binding *bind, *current;
+    TAILQ_FOREACH(current, bindings, bindings) {
+        TAILQ_FOREACH(bind, bindings, bindings) {
+            /* Abort when we reach the current keybinding, only check the
+             * bindings before */
+            if (bind == current)
+                break;
+
+            /* Check if one is using keysym while the other is using bindsym.
+             * If so, skip. */
+            /* XXX: It should be checked at a later place (when translating the
+             * keysym to keycodes) if there are any duplicates */
+            if ((bind->symbol == NULL && current->symbol != NULL) ||
+                (bind->symbol != NULL && current->symbol == NULL))
+                continue;
+
+            /* If bind is NULL, current has to be NULL, too (see above).
+             * If the keycodes differ, it can't be a duplicate. */
+            if (bind->symbol != NULL &&
+                strcasecmp(bind->symbol, current->symbol) != 0)
+                continue;
+
+            /* Check if the keycodes or modifiers are different. If so, they
+             * can't be duplicate */
+            if (bind->keycode != current->keycode ||
+                bind->mods != current->mods)
+                continue;
+            context->has_errors = true;
+            if (current->keycode != 0) {
+                ELOG("Duplicate keybinding in config file:\n  modmask %d with keycode %d, command \"%s\"\n",
+                     current->mods, current->keycode, current->command);
+            } else {
+                ELOG("Duplicate keybinding in config file:\n  modmask %d with keysym %s, command \"%s\"\n",
+                     current->mods, current->symbol, current->command);
+            }
+        }
+    }
+}
+
 void parse_file(const char *f) {
     SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
     int fd, ret, read_bytes = 0;
@@ -463,6 +510,8 @@ void parse_file(const char *f) {
         exit(1);
     }
 
+    check_for_duplicate_bindings(context);
+
     if (context->has_errors) {
         start_configerror_nagbar(f);
     }
@@ -530,6 +579,7 @@ void parse_file(const char *f) {
 %token                  TOK_AUTO                    "auto"
 %token                  TOK_WORKSPACE_LAYOUT        "workspace_layout"
 %token                  TOKNEWWINDOW                "new_window"
+%token                  TOKNEWFLOAT                 "new_float"
 %token                  TOK_NORMAL                  "normal"
 %token                  TOK_NONE                    "none"
 %token                  TOK_1PIXEL                  "1pixel"
@@ -561,6 +611,7 @@ void parse_file(const char *f) {
 %type   <number>        layout_mode
 %type   <number>        border_style
 %type   <number>        new_window
+%type   <number>        new_float
 %type   <number>        colorpixel
 %type   <number>        bool
 %type   <number>        popup_setting
@@ -585,6 +636,7 @@ line:
     | orientation
     | workspace_layout
     | new_window
+    | new_float
     | focus_follows_mouse
     | force_focus_wrapping
     | workspace_bar
@@ -875,6 +927,14 @@ new_window:
     }
     ;
 
+new_float:
+    TOKNEWFLOAT border_style
+    {
+       DLOG("new floating windows should start with border style %d\n", $2);
+       config.default_floating_border = $2;
+    }
+    ;
+
 border_style:
     TOK_NORMAL      { $$ = BS_NORMAL; }
     | TOK_NONE      { $$ = BS_NONE; }
index 14fc6e025922c924f9c11f8f0f80493e44b1ad37..b3a204420fa18d463be5716638b24c10f8f9283d 100644 (file)
@@ -333,6 +333,7 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
         INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff");
 
         config.default_border = BS_NORMAL;
+        config.default_floating_border = BS_NORMAL;
         /* Set default_orientation to NO_ORIENTATION for auto orientation. */
         config.default_orientation = NO_ORIENTATION;
 
index b394f3156780cc0fa0c22dcf543ffe86f9c376aa..2ba08330c3c218982bb3eb27dd27105cc896c945 100644 (file)
@@ -129,6 +129,10 @@ void floating_enable(Con *con, bool automatic) {
     con->percent = 1.0;
     con->floating = FLOATING_USER_ON;
 
+    /* 4: set the border style as specified with new_float */
+    if (automatic)
+        con->border_style = config.default_floating_border;
+
     /* Some clients (like GIMP’s color picker window) get mapped
      * to (0, 0), so we push them to a reasonable position
      * (centered over their leader) */
index d798ffa0a6bce3b5e401d28585629919a61cdb99..d7b5ac701a8414f7c94599872d3908e70e5bb12e 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -203,6 +203,11 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
     ystr("urgent");
     y(bool, con->urgent);
 
+    if (con->mark != NULL) {
+        ystr("mark");
+        ystr(con->mark);
+    }
+
     ystr("focused");
     y(bool, (con == focused));
 
@@ -333,6 +338,7 @@ IPC_HANDLER(tree) {
     y(free);
 }
 
+
 /*
  * Formats the reply message for a GET_WORKSPACES request and sends it to the
  * client
@@ -463,6 +469,34 @@ IPC_HANDLER(get_outputs) {
     y(free);
 }
 
+/*
+ * Formats the reply message for a GET_MARKS request and sends it to the
+ * client
+ *
+ */
+IPC_HANDLER(get_marks) {
+#if YAJL_MAJOR >= 2
+    yajl_gen gen = yajl_gen_alloc(NULL);
+#else
+    yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+#endif
+    y(array_open);
+
+    Con *con;
+    TAILQ_FOREACH(con, &all_cons, all_cons)
+        if (con->mark != NULL)
+            ystr(con->mark);
+
+    y(array_close);
+
+    const unsigned char *payload;
+    unsigned int length;
+    y(get_buf, &payload, &length);
+
+    ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_MARKS, length);
+    y(free);
+}
+
 /*
  * Callback for the YAJL parser (will be called when a string is parsed).
  *
@@ -550,12 +584,13 @@ IPC_HANDLER(subscribe) {
 
 /* The index of each callback function corresponds to the numeric
  * value of the message type (see include/i3/ipc.h) */
-handler_t handlers[5] = {
+handler_t handlers[6] = {
     handle_command,
     handle_get_workspaces,
     handle_subscribe,
     handle_get_outputs,
-    handle_tree
+    handle_tree,
+    handle_get_marks
 };
 
 /*
index b61a0e5c490210a72d30255ebef30ed576469c4c..37322c4ea3857f2b92e85f05c5ee843054f8e975 100644 (file)
@@ -146,6 +146,10 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
                 json_node->layout = L_OUTPUT;
             else LOG("Unhandled \"layout\": %s\n", buf);
             free(buf);
+        } else if (strcasecmp(last_key, "mark") == 0) {
+            char *buf = NULL;
+            asprintf(&buf, "%.*s", (int)len, val);
+            json_node->mark = buf;
         }
     }
     return 1;
index 68c91e72221904a66009d2fa26a42b52a8aebf2b..18e94dd21559b8a7daf65dcaa7280ec229d5fa2e 100644 (file)
@@ -321,7 +321,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
 
     if (want_floating) {
         DLOG("geometry = %d x %d\n", nc->geometry.width, nc->geometry.height);
-        floating_enable(nc, false);
+        floating_enable(nc, true);
     }
 
     /* to avoid getting an UnmapNotify event due to reparenting, we temporarily
index 2fe9630483029de25500239f1e6342f97b27efa0..d3d2a8e2e871d80cd1f0632f2fd4da7a809addec 100644 (file)
@@ -49,12 +49,11 @@ Con *workspace_get(const char *num, bool *created) {
         workspace->name = sstrdup(num);
         /* We set ->num to the number if this workspace’s name consists only of
          * a positive number. Otherwise it’s a named ws and num will be -1. */
-        char *end;
-        long parsed_num = strtol(num, &end, 10);
+
+        long parsed_num = strtol(num, NULL, 10);
         if (parsed_num == LONG_MIN ||
             parsed_num == LONG_MAX ||
-            parsed_num < 0 ||
-            (end && *end != '\0'))
+            parsed_num <= 0)
             workspace->num = -1;
         else workspace->num = parsed_num;
         LOG("num = %d\n", workspace->num);
diff --git a/testcases/t/73-get-marks.t b/testcases/t/73-get-marks.t
new file mode 100644 (file)
index 0000000..8648174
--- /dev/null
@@ -0,0 +1,63 @@
+#!perl
+# vim:ts=4:sw=4:expandtab
+#
+# checks if the IPC message type get_marks works correctly
+#
+use i3test;
+
+# TODO: this will be available in AnyEvent::I3 soon
+sub get_marks {
+    my $i3 = i3(get_socket_path());
+    $i3->connect->recv;
+    my $cv = AnyEvent->condvar;
+    my $msg = $i3->message(5);
+    my $t;
+    $msg->cb(sub {
+        my ($_cv) = @_;
+        $cv->send($_cv->recv);
+    });
+    $t = AnyEvent->timer(after => 2, cb => sub {
+        $cv->croak('timeout while waiting for the marks');
+    });
+    return $cv->recv;
+}
+
+##############################################################
+# 1: check that get_marks returns no marks yet
+##############################################################
+
+my $tmp = fresh_workspace;
+
+my $marks = get_marks();
+cmp_deeply($marks, [], 'no marks set so far');
+
+##############################################################
+# 2: check that setting a mark is reflected in the get_marks reply
+##############################################################
+
+cmd 'open';
+cmd 'mark foo';
+
+cmp_deeply(get_marks(), [ 'foo' ], 'mark foo set');
+
+##############################################################
+# 3: check that the mark is gone after killing the container
+##############################################################
+
+cmd 'kill';
+
+cmp_deeply(get_marks(), [ ], 'mark gone');
+
+##############################################################
+# 4: check that duplicate marks are included twice in the get_marks reply
+##############################################################
+
+cmd 'open';
+cmd 'mark bar';
+
+cmd 'open';
+cmd 'mark bar';
+
+cmp_deeply(get_marks(), [ 'bar', 'bar' ], 'duplicate mark found twice');
+
+done_testing;
diff --git a/testcases/t/74-border-config.t b/testcases/t/74-border-config.t
new file mode 100644 (file)
index 0000000..c8a4d73
--- /dev/null
@@ -0,0 +1,140 @@
+#!perl
+# vim:ts=4:sw=4:expandtab
+# !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
+#
+# Tests the new_window and new_float config option.
+#
+
+use i3test;
+use X11::XCB qw(:all);
+use X11::XCB::Connection;
+
+my $x = X11::XCB::Connection->new;
+
+#####################################################################
+# 1: check that new windows start with 'normal' border unless configured
+# otherwise
+#####################################################################
+
+my $config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+EOT
+
+my $process = launch_with_config($config);
+
+my $tmp = fresh_workspace;
+
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
+
+my $first = open_standard_window($x);
+
+my @content = @{get_ws_content($tmp)};
+ok(@content == 1, 'one container opened');
+is($content[0]->{border}, 'normal', 'border normal by default');
+
+exit_gracefully($process->pid);
+
+#####################################################################
+# 2: check that new tiling windows start with '1pixel' border when
+# configured
+#####################################################################
+
+$config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+
+new_window 1pixel
+EOT
+
+$process = launch_with_config($config);
+
+$tmp = fresh_workspace;
+
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
+
+$first = open_standard_window($x);
+
+@content = @{get_ws_content($tmp)};
+ok(@content == 1, 'one container opened');
+is($content[0]->{border}, '1pixel', 'border normal by default');
+
+exit_gracefully($process->pid);
+
+#####################################################################
+# 3: check that new floating windows start with 'normal' border unless
+# configured otherwise
+#####################################################################
+
+$config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+EOT
+
+$process = launch_with_config($config);
+
+$tmp = fresh_workspace;
+
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
+
+# Create a floating window which is smaller than the minimum enforced size of i3
+$first = $x->root->create_child(
+    class => WINDOW_CLASS_INPUT_OUTPUT,
+    rect => [ 0, 0, 30, 30],
+    background_color => '#C0C0C0',
+    # replace the type with 'utility' as soon as the coercion works again in X11::XCB
+    window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'),
+);
+
+$first->map;
+
+sleep 0.25;
+
+my $wscontent = get_ws($tmp);
+my @floating = @{$wscontent->{floating_nodes}};
+ok(@floating == 1, 'one floating container opened');
+my $floatingcon = $floating[0];
+is($floatingcon->{nodes}->[0]->{border}, 'normal', 'border normal by default');
+
+exit_gracefully($process->pid);
+
+#####################################################################
+# 4: check that new floating windows start with '1pixel' border when
+# configured
+#####################################################################
+
+$config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+
+new_float 1pixel
+EOT
+
+$process = launch_with_config($config);
+
+$tmp = fresh_workspace;
+
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
+
+# Create a floating window which is smaller than the minimum enforced size of i3
+$first = $x->root->create_child(
+    class => WINDOW_CLASS_INPUT_OUTPUT,
+    rect => [ 0, 0, 30, 30],
+    background_color => '#C0C0C0',
+    # replace the type with 'utility' as soon as the coercion works again in X11::XCB
+    window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'),
+);
+
+$first->map;
+
+sleep 0.25;
+
+$wscontent = get_ws($tmp);
+@floating = @{$wscontent->{floating_nodes}};
+ok(@floating == 1, 'one floating container opened');
+$floatingcon = $floating[0];
+is($floatingcon->{nodes}->[0]->{border}, '1pixel', 'border normal by default');
+
+exit_gracefully($process->pid);
+
+done_testing;