-all:
- gcc -Wall -gdwarf-2 -g3 -I/usr/include/xcb -c mainx.c
- gcc -Wall -gdwarf-2 -g3 -I/usr/include/xcb -c table.c
- gcc -Wall -gdwarf-2 -g3 -I/usr/include/xcb -c test_table.c
- gcc -Wall -gdwarf-2 -g3 -I/usr/include/xcb -o mainx mainx.o table.o -lxcb-wm
- gcc -Wall -gdwarf-2 -g3 -I/usr/include/xcb -o tt test_table.o table.o
+CFLAGS += -Wall
+# Extended debugging flags, macros shall be available in gcc
+CFLAGS += -gdwarf-2
+CFLAGS += -g3
+CFLAGS += -I/usr/include/xcb
+
+LDFLAGS += -lxcb-wm
+
+FILES=$(patsubst %.c,%.o,$(wildcard *.c))
+
+%.o: %.c %.h
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+all: ${FILES}
+ $(CC) -o mainx ${FILES} $(LDFLAGS)
+
+clean:
+ rm -f *.o
*
*/
struct Font {
+ /* The name of the font, that is what the pattern resolves to */
char *name;
+ /* A copy of the pattern to build a cache */
+ char *pattern;
+ /* The height of the font, built from font_ascent + font_descent */
int height;
+ /* The xcb-id for the font */
+ xcb_font_t id;
};
/*
--- /dev/null
+/*
+ * Handles font loading
+ *
+ */
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <xcb/xcb.h>
+
+#include "data.h"
+
+/* TODO: This is just here to be somewhere. Move it somewhere else. */
+void check_error(xcb_connection_t *connection, xcb_void_cookie_t cookie, char *errMessage) {
+ xcb_generic_error_t *error = xcb_request_check (connection, cookie);
+ if (error != NULL) {
+ fprintf(stderr, "ERROR: %s : %d\n", errMessage , error->error_code);
+ xcb_disconnect(connection);
+ exit(-1);
+ }
+}
+
+
+Font *load_font(xcb_connection_t *c, const char *pattern) {
+ Font *new = malloc(sizeof(Font));
+
+ xcb_list_fonts_with_info_cookie_t cookie = xcb_list_fonts_with_info(c, 1, strlen(pattern), pattern);
+ xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(c, cookie, NULL);
+ if (!reply) {
+ printf("Could not load font\n");
+ exit(1);
+ }
+
+ /* Oh my, this is so ugly :-(. Why can’t they just return a null-terminated
+ * string? That’s what abstraction layers are for. */
+ char buffer[xcb_list_fonts_with_info_name_length(reply)+1];
+ memset(buffer, 0, sizeof(buffer));
+ memcpy(buffer, xcb_list_fonts_with_info_name(reply), sizeof(buffer)-1);
+ new->name = strdup(buffer);
+ new->pattern = strdup(pattern);
+ new->height = reply->font_ascent + reply->font_descent;
+
+ /* Actually load the font */
+ new->id = xcb_generate_id(c);
+ xcb_void_cookie_t font_cookie = xcb_open_font_checked(c, new->id, strlen(pattern), pattern);
+ check_error(c, font_cookie, "Could not open font");
+
+ return new;
+}
--- /dev/null
+#include <xcb/xcb.h>
+
+#include "data.h"
+
+#ifndef _FONT_H
+#define _FONT_H
+
+Font *load_font(xcb_connection_t *c, const char *pattern);
+
+#endif
+++ /dev/null
-#include <termios.h>
-#include <unistd.h>
-#include <stdio.h>
-
-enum { move, snap, select };
-
-struct foo {
- int width;
- int height;
- int x;
- int y;
-};
-
-
-int main() {
- int c;
- int mode;
- struct termios tbuf, obuf;
- if (tcgetattr(STDIN_FILENO, &obuf) < 0 ||
- tcgetattr(STDIN_FILENO, &tbuf) < 0)
- perror("tcgetattr()");
- tbuf.c_lflag &= ~ICANON;
- tbuf.c_cc[VMIN] = 1;
- tbuf.c_cc[VTIME] = 0;
- tcsetattr(STDIN_FILENO, TCSANOW, &tbuf);
-
- int table[10][10];
- int colspan[10];
- int rowspan[10];
- int current_row = 0;
- int current_col = 0;
- int current = -1;
- int created_terms = 0;
-
- for (c = 0; c < 10; c++) {
- int i;
- for (i = 0; i < 10; i++)
- table[c][i] = -1;
- colspan[c] = 1;
- rowspan[c] = 1;
- }
-
- mode = select;
- while (printf("%s> ", (mode == move ? "move" : (mode == select ? "select" : "snap"))), c = getchar()) {
-
- printf("char %c, %d\n", c, c);
- if (c == 'm')
- mode = move;
- else if (c == 's')
- mode = snap;
- else if (c == 'u') {
- /* insert new 'terminal' below current one */
- int i;
- printf("current row = %d\n", current_row);
- printf("current col = %d\n", current_col);
- for (i = current_row; i < 10; i++) {
- if (table[current_col][i] == -1) {
- printf("found empty entry at %d\n", i);
- created_terms++;
- table[current_col][i] = created_terms;
- current_row = i;
- printf("created terminal %d\n", created_terms);
- printf("current_row = %d\n", current_row);
- break;
- }
- }
- }
- else if (c == 'n') {
- if (mode == move) {
- printf("move window left\n");
- table[current_col-1][current_row] = table[current_col][current_row];
- table[current_col][current_row] = -1;
-
- } else if (mode == snap) {
- printf("snap window left\n");
- } else if (mode == select) {
- printf("go to left window\n");
- if (current_col > 0)
- current_col--;
- printf("col now: %d\n", current_col);
- }
- mode = select;
-
- }
- else if (c == 'r') {
- if (mode == move) {
- printf("move window down\n");
- table[current_col][current_row+1] = table[current_col][current_row];
- table[current_col][current_row] = -1;
-
- } else if (mode == snap) {
- printf("snap window down\n");
- } else if (mode == select) {
- printf("go to window below\n");
- if (current_row < 9)
- current_row++;
- printf("row now: %d\n", current_row);
- }
- mode = select;
-
- }
- else if (c == 't') {
- if (mode == move) {
- printf("move window up\n");
- table[current_col][current_row-1] = table[current_col][current_row];
- table[current_col][current_row] = -1;
- } else if (mode == snap) {
- printf("snap window up\n");
- } else if (mode == select) {
- printf("go to upper window\n");
- if (current_row > 0)
- current_row--;
- printf("row now: %d\n", current_row);
- }
- mode = select;
-
- }
- else if (c == 'd') {
- if (mode == move) {
- printf("move window right\n");
- table[current_col+1][current_row] = table[current_col][current_row];
- table[current_col][current_row] = -1;
- current_col++;
- } else if (mode == snap) {
- printf("snap window right\n");
- colspan[table[current_col][current_row]]++;
- printf("colspan now is: %d\n", colspan[table[current_col][current_row]]++);
-
- } else if (mode == select) {
- printf("go to right window\n");
- if (current_col < 9)
- current_col++;
- printf("col now: %d\n", current_col);
- }
- mode = select;
-
- }
-
- int rows, cols;
- printf("your windows are as following:\n");
- system("/tmp/killgeom.sh");
- for (rows = 0; rows < 10; rows++)
- for (cols = 0; cols < 10; cols++) {
- if (table[cols][rows] != -1) {
- printf("client %d, x = %d, y = %d, width = %d, height = %d",
- table[cols][rows], cols * 60, rows * 60, 15 * 1, 15 * 1);
- if (cols == current_col && rows == current_row)
- printf(" < ===== YOU ARE HERE\n");
- else printf("\n");
- char *buffer;
- asprintf(&buffer, "/bin/sh -c \"urxvt -geometry %dx%d+%d+%d %s&\"",
- 15 * colspan[table[cols][rows]], 15, cols * 200, rows * 200, (cols == current_col && rows == current_row ? "-bg white" : "-bg gray"));
- printf("executing %s\n", buffer);
-
- system(buffer);
- free(buffer);
- }
- }
- printf("that's all\n");
- }
-}
#include "queue.h"
#include "table.h"
+#include "font.h"
-Font myfont;
+Font *myfont;
static const int TOP = 20;
static const int LEFT = 5;
table_t *byParent = 0;
xcb_window_t root_win;
+char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso8859-1";
int current_col = 0;
mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
- xcb_font_t font = xcb_generate_id (conn);
- char *font_name = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso8859-1";
- xcb_void_cookie_t fontCookie = xcb_open_font_checked (conn, font, strlen (font_name), font_name );
+ Font *font = load_font(conn, pattern);
values[0] = root_screen->black_pixel;
- if (globalc++ > 1)
+ if (client->container->currently_focused == client) {
+ printf("oh, currently active = %p\n", client);
values[1] = get_colorpixel(conn, client->window, 65535, 0, 0);
- else values[1] = get_colorpixel(conn, client->window, 0, 0, 65535);
- values[2] = font;
+ }else values[1] = get_colorpixel(conn, client->window, 0, 0, 65535);
+ values[2] = font->id;
xcb_change_gc(conn, client->titlegc, mask, values);
//char *label = "i3 rocks :>";
char *label;
asprintf(&label, "gots win %08x", client->window);
- xcb_void_cookie_t textCookie = xcb_image_text_8_checked (conn, strlen (label), client->window, client->titlegc, 2, 15, label );
+ xcb_void_cookie_t textCookie = xcb_image_text_8_checked (conn, strlen (label), client->window, client->titlegc, 2, 2 + font->height, label );
}
void render_container(xcb_connection_t *connection, Container *container) {
*/
void reparent_window(xcb_connection_t *conn, xcb_window_t child,
xcb_visualid_t visual, xcb_window_t root, uint8_t depth,
- int16_t x, int16_t y, uint16_t width, uint16_t height)
-{
+ int16_t x, int16_t y, uint16_t width, uint16_t height) {
Client *new = table_get(byChild, child);
if (new == NULL) {
/* Set focus if we could successfully move */
container->currently_focused = candidad;
xcb_set_input_focus(connection, XCB_INPUT_FOCUS_NONE, candidad->child, XCB_CURRENT_TIME);
+ render_layout(connection);
xcb_flush(connection);
return true;
if (CUR_CELL->currently_focused != NULL) {
xcb_set_input_focus(connection, XCB_INPUT_FOCUS_NONE,
CUR_CELL->currently_focused->child, XCB_CURRENT_TIME);
+ render_layout(connection);
xcb_flush(connection);
}
-static int handleExposeEvent(void *data, xcb_connection_t *c, xcb_expose_event_t *e)
-{
+static int handleExposeEvent(void *data, xcb_connection_t *c, xcb_expose_event_t *e) {
printf("exposeevent\n");
Client *client = table_get(byParent, e->window);
if(!client || e->count != 0)
decorate_window(c, client);
return 1;
}
-void manage_existing_windows(xcb_connection_t *c, xcb_property_handlers_t *prophs, xcb_window_t root)
-{
+void manage_existing_windows(xcb_connection_t *c, xcb_property_handlers_t *prophs, xcb_window_t root) {
xcb_query_tree_cookie_t wintree;
xcb_query_tree_reply_t *rep;
int i, len;
/* Font loading */
-char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso8859-1";
-
-xcb_list_fonts_with_info_cookie_t cookie = xcb_list_fonts_with_info(c, 1, strlen(pattern), pattern);
-xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(c, cookie, NULL);
-if (!reply) {
- printf("Could not load font\n");
- return 1;
-}
-
-myfont.name = strdup(xcb_list_fonts_with_info_name(reply));
-myfont.height = reply->font_ascent + reply->font_descent;
-
+ myfont = load_font(c, pattern);
xcb_event_handlers_init(c, &evenths);
for(i = 2; i < 128; ++i)
struct table_dimensions_t table_dims = {0, 0};
+/*
+ * Initialize table
+ *
+ */
void init_table() {
expand_table_cols();
expand_table_rows();
}
+/*
+ * Add one row to the table
+ *
+ */
void expand_table_rows() {
int c;
Container *new;
}
}
+/*
+ * Add one column to the table
+ *
+ */
void expand_table_cols() {
int c;
Container *new;
return (col >= 0 && col < table_dims.x) &&
(row >= 0 && row < table_dims.y);
}
-
+++ /dev/null
-#include <stdio.h>
-#include "table.h"
-
-void print_table() {
- int r, c;
- printf("printing table...\n");
- for (c = 0; c < table_dims.x; c++)
- for (r = 0; r < table_dims.y; r++)
- printf("table[%d][%d] = %p\n", c, r, table[c][r]);
- printf("done\n");
-}
-
-int main() {
- printf("table.c tests\n");
- printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
- init_table();
- printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
- print_table();
-
- printf("expand_table_cols()\n");
- expand_table_cols();
- printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
- print_table();
-
- printf("expand_table_rows()\n");
- expand_table_rows();
- printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
- print_table();
-
-}
--- /dev/null
+#include <stdio.h>
+#include "table.h"
+
+void print_table() {
+ int r, c;
+ printf("printing table...\n");
+ for (c = 0; c < table_dims.x; c++)
+ for (r = 0; r < table_dims.y; r++)
+ printf("table[%d][%d] = %p\n", c, r, table[c][r]);
+ printf("done\n");
+}
+
+int main() {
+ printf("table.c tests\n");
+ printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
+ init_table();
+ printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
+ print_table();
+
+ printf("expand_table_cols()\n");
+ expand_table_cols();
+ printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
+ print_table();
+
+ printf("expand_table_rows()\n");
+ expand_table_rows();
+ printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y);
+ print_table();
+
+}