]> git.sur5r.net Git - i3/i3/commitdiff
bring_window_here function and command
authorBlekos EelVex Kostas <eelvex@gmail.com>
Sun, 11 Apr 2010 12:19:13 +0000 (15:19 +0300)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 17 Apr 2010 21:30:14 +0000 (23:30 +0200)
src/commands.c

index 6742a4697242813e2860f66539e022f716f34394..9d0d0f656d7b5a237e00381d57e73dbe792f3765 100644 (file)
@@ -703,6 +703,41 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa
         }
 }
 
+/*
+ * Brings the given window class / title to the current workspace.
+ *
+ */
+static void bring_window_here(xcb_connection_t *conn, const char *arguments) {
+       char *classtitle;
+       Client *client;
+
+       /* The first character is a quote, this was checked before */
+       classtitle = sstrdup(arguments+1);
+       /* The last character is a quote, we just set it to NULL */
+       classtitle[strlen(classtitle)-1] = '\0';
+
+       if ((client = get_matching_client(conn, classtitle, NULL)) == NULL) {
+               free(classtitle);
+               ELOG("No matching client found.\n");
+               return;
+       }
+
+       /* This is the workspace num that we are on */
+       int current_workspace_num = c_ws->output->current_workspace->num + 1;
+       /* This is the workspace num that the client is on */
+       int clients_workspace_num = client->workspace->num + 1;
+
+       free(classtitle);
+       workspace_show(conn, clients_workspace_num);
+       set_focus(conn, client, true);
+       if (client_is_floating(client))
+               move_floating_window_to_workspace(conn, client, current_workspace_num);
+       else move_current_window_to_workspace(conn, current_workspace_num);
+       workspace_show(conn, current_workspace_num);
+       set_focus(conn, client, true);
+
+}
+
 /*
  * Jumps to the given window class / title.
  * Title is matched using strstr, that is, matches if it appears anywhere
@@ -1104,6 +1139,13 @@ void parse_command(xcb_connection_t *conn, const char *command) {
                 return;
         }
 
+        if (STARTS_WITH(command, "bring ")) {
+                const char *arguments = command + strlen("bring ");
+                if (arguments[0] == '"')
+                        bring_window_here(conn, arguments);
+                return;
+        }
+
         /* Is it a jump to a specified workspace, row, col? */
         if (STARTS_WITH(command, "jump ")) {
                 const char *arguments = command + strlen("jump ");