]> git.sur5r.net Git - i3/i3/commitdiff
Use containers
authorMichael Stapelberg <michael+git@stapelberg.de>
Sat, 7 Feb 2009 20:08:30 +0000 (21:08 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Sat, 7 Feb 2009 20:08:30 +0000 (21:08 +0100)
Makefile
data.h
mainx.c

index 63877906d7903c052b6cddfbeed768f506d7e6ef..4d8e000618a2d40482ab7337cbb821af6f43e0ca 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,2 @@
 all:
-       gcc -g -I/usr/include/xcb -o mainx mainx.c -lxcb-wm
+       gcc -Wall -g -I/usr/include/xcb -o mainx mainx.c -lxcb-wm
diff --git a/data.h b/data.h
index 55486973652b5bd1579df1269812400cc80830bb..f514e58fc2b175c1032114cc363110d927458183 100644 (file)
--- a/data.h
+++ b/data.h
@@ -48,5 +48,9 @@ typedef struct Client {
  *
  */
 typedef struct Container {
+       /* Ensure MODE_DEFAULT maps to 0 because we use calloc for initialization later */
+       int row;
+       int col;
+       enum { MODE_DEFAULT = 0, MODE_STACK = 1 } mode;
        LIST_HEAD(client_head, Client) clients;
 } Container;
diff --git a/mainx.c b/mainx.c
index 0c4d8809b39412a9d683a1f48c1a532f832f66df..17d60ca09841626dd47d80b1b838e362c649b4bc 100644 (file)
--- a/mainx.c
+++ b/mainx.c
@@ -1,7 +1,10 @@
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include <xcb/xcb.h>
 
@@ -30,7 +33,7 @@ xcb_window_t root_win;
 LIST_HEAD(all_clients_head, Client) all_clients;
 
 /* _the_ table. Stores all clients. */
-Client *table[10][10];
+Container *table[10][10];
 
 int current_col = 0;
 int current_row = 0;
@@ -303,7 +306,7 @@ uint32_t get_colorpixel(xcb_connection_t *conn, xcb_window_t window, int r, int
 
        if (!reply) {
                printf("color fail\n");
-               return;
+               exit(1);
        }
 
        uint32_t pixel = reply->pixel;
@@ -342,25 +345,46 @@ void decorate_window(xcb_connection_t *conn, Client *client) {
         xcb_void_cookie_t textCookie = xcb_image_text_8_checked (conn, strlen (label), client->window, client->titlegc, 2, 15, label );
 }
 
+void render_container(xcb_connection_t *connection, Container *container) {
+       Client *client;
+       int values[4];
+       int mask =      XCB_CONFIG_WINDOW_X |
+                       XCB_CONFIG_WINDOW_Y |
+                       XCB_CONFIG_WINDOW_WIDTH |
+                       XCB_CONFIG_WINDOW_HEIGHT;
+
+       if (container->mode == MODE_DEFAULT) {
+               LIST_FOREACH(client, &(container->clients), clients) {
+                       /* TODO: at the moment, every column/row is 200px. This
+                        * needs to be changed to "percentage of the screen" by
+                        * default and adjustable by the user if necessary.
+                        */
+                       values[0] = container->col * 200;
+                       values[1] = container->row * 200;
+                       values[2] = 200;
+                       values[3] = 200;
+                       /* TODO: update only if necessary */
+                       xcb_configure_window(connection, client->window, mask, values);
+               }
+       } else {
+               /* TODO: Implement stacking */
+       }
+}
+
 void render_layout(xcb_connection_t *conn) {
        int cols, rows;
-       int values[4];
-       for (rows = 0; rows < 10; rows++) {
-               for (cols = 0; cols < 10; cols++) {
+
+       /* Go through the whole table and render what’s necessary */
+       for (rows = 0; rows < 10; rows++)
+               for (cols = 0; cols < 10; cols++)
                        if (table[cols][rows] != NULL) {
-                               Client *current = table[cols][rows];
-                               /* TODO; just update if necessary */
-                               values[0] = cols * 200;
-                               values[1] = rows * 200;
-                               values[2] = 200;
-                               values[3] = 200;
-                               xcb_configure_window(conn, current->window, XCB_CONFIG_WINDOW_X |
-                                                                               XCB_CONFIG_WINDOW_Y |
-                                                                               XCB_CONFIG_WINDOW_WIDTH |
-                                                                               XCB_CONFIG_WINDOW_HEIGHT , values);
+                               /* Update position of the container */
+                               table[cols][rows]->row = rows;
+                               table[cols][rows]->col = cols;
+
+                               /* Render it */
+                               render_container(conn, table[cols][rows]);
                        }
-               }
-       }
 }
 
 /*
@@ -380,13 +404,8 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
        /* Insert into the list of all clients */
        LIST_INSERT_HEAD(&all_clients, new, clients);
 
-       /* Insert into the table */
-       if (table[current_col][current_row] == NULL)
-               table[current_col][current_row] = new;
-       else {
-               current_row++;
-               table[current_col][current_row] = new;
-       }
+       /* Insert into the currently active container */
+       LIST_INSERT_HEAD(&(table[current_col][current_row]->clients), new, clients);
 
        new->window = xcb_generate_id(conn);
        new->child = child;
@@ -568,6 +587,7 @@ static int handle_motion(void *ignored, xcb_connection_t *conn, xcb_generic_even
        //xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, myc.window, XCB_CURRENT_TIME);
 
        }
+       /* TODO: what to return? */
 }
 
 
@@ -664,6 +684,13 @@ int main() {
                for (j = 0; j < 10; j++)
                        table[i][j] = NULL;
 
+       /*
+        * By default, the table is one row and one column big. It contains
+        * one container in default mode in it.
+        *
+        */
+       table[0][0] = calloc(sizeof(Container), 1);
+
        xcb_connection_t *c;
        xcb_event_handlers_t evenths;
        xcb_property_handlers_t prophs;
@@ -764,5 +791,6 @@ printf("could not grab pointer\n");
 
        xcb_event_wait_for_event_loop(&evenths);
 
-
+       /* not reached */
+       return 0;
 }