static int handle_expose() {
/* re-draw the background */
xcb_rectangle_t border = {0, 0, 300, (15*font_height) + 8};
- xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
+ xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel("#000000"));
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border);
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FONT, font_id);
if (current_step == STEP_WELCOME) {
/* restore font color */
- xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FFFFFF"));
+ xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel("#FFFFFF"));
txt(10, 2, "You have not configured i3 yet.");
txt(10, 3, "Do you want me to generate ~/.i3/config?");
txt(85, 7, "No, I will use the defaults");
/* green */
- xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#00FF00"));
+ xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel("#00FF00"));
txt(25, 5, "<Enter>");
/* red */
- xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FF0000"));
+ xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel("#FF0000"));
txt(31, 7, "<ESC>");
}
if (current_step == STEP_GENERATE) {
- xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FFFFFF"));
+ xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel("#FFFFFF"));
txt(10, 2, "Please choose either:");
txt(85, 4, "Win as default modifier");
/* green */
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_FONT;
- uint32_t values[] = { get_colorpixel(conn, "#00FF00"), font_id };
+ uint32_t values[] = { get_colorpixel("#00FF00"), font_id };
xcb_change_gc(conn, pixmap_gc, mask, values);
txt(25, 9, "<Enter>");
/* red */
- xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FF0000"));
+ xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel("#FF0000"));
txt(31, 10, "<ESC>");
}
xcb_change_gc(conn, gc, mask, &value);
}
-/*
- * Returns the colorpixel to use for the given hex color (think of HTML).
- *
- * The hex_color has to start with #, for example #FF00FF.
- *
- * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
- * This has to be done by the caller.
- *
- */
-uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
- char strgroups[3][3] = {{hex[1], hex[2], '\0'},
- {hex[3], hex[4], '\0'},
- {hex[5], hex[6], '\0'}};
- uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
- (strtol(strgroups[1], NULL, 16)),
- (strtol(strgroups[2], NULL, 16))};
-
- return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
-}
-
/*
* Returns the mask for Mode_switch (to be used for looking up keysymbols by
* keycode).
extern unsigned int xcb_numlock_mask;
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value);
-uint32_t get_colorpixel(xcb_connection_t *conn, char *hex);
uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode);
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height);
char *convert_ucs_to_utf8(char *input);
char *convert_utf8_to_ucs2(char *input, int *real_strlen);
-uint32_t get_colorpixel(xcb_connection_t *conn, char *hex);
uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode);
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height);
/* re-draw the background */
xcb_rectangle_t border = {0, 0, 500, font_height + 8}, inner = {2, 2, 496, font_height + 8 - 4};
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel(conn, "#FF0000") });
+ xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FF0000") });
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border);
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel(conn, "#000000") });
+ xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#000000") });
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &inner);
/* restore font color */
- xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel(conn, "#FFFFFF") });
+ xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
uint8_t *con = concat_strings(glyphs_ucs, input_position);
char *full_text = (char*)con;
if (prompt != NULL) {
#include "i3-input.h"
-/*
- * Returns the colorpixel to use for the given hex color (think of HTML).
- *
- * The hex_color has to start with #, for example #FF00FF.
- *
- * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
- * This has to be done by the caller.
- *
- */
-uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
- char strgroups[3][3] = {{hex[1], hex[2], '\0'},
- {hex[3], hex[4], '\0'},
- {hex[5], hex[6], '\0'}};
- uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
- (strtol(strgroups[1], NULL, 16)),
- (strtol(strgroups[2], NULL, 16))};
-
- return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
-}
-
/*
* Returns the mask for Mode_switch (to be used for looking up keysymbols by
* keycode).
include $(TOPDIR)/common.mk
+CPPFLAGS += -I$(TOPDIR)/include
+
# Depend on the object files of all source-files in src/*.c and on all header files
FILES=$(patsubst %.c,%.o,$(wildcard *.c))
HEADERS=$(wildcard *.h)
all: i3-nagbar
-i3-nagbar: ${FILES}
+i3-nagbar: $(TOPDIR)/libi3/libi3.a ${FILES}
echo "[i3-nagbar] LINK i3-nagbar"
- $(CC) $(LDFLAGS) -o $@ ${FILES} $(LIBS)
+ $(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
+
+$(TOPDIR)/libi3/%.a: $(TOPDIR)/libi3/*.c
+ $(MAKE) -C $(TOPDIR)/libi3
install: all
echo "[i3-nagbar] INSTALL"
extern xcb_window_t root;
-uint32_t get_colorpixel(xcb_connection_t *conn, char *hex);
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height);
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value);
#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
+#include "libi3.h"
#include "i3-nagbar.h"
typedef struct {
if (bar_type == TYPE_ERROR) {
/* Red theme for error messages */
- color_button_background = get_colorpixel(conn, "#680a0a");
- color_background = get_colorpixel(conn, "#900000");
- color_text = get_colorpixel(conn, "#ffffff");
- color_border = get_colorpixel(conn, "#d92424");
- color_border_bottom = get_colorpixel(conn, "#470909");
+ color_button_background = get_colorpixel("#680a0a");
+ color_background = get_colorpixel("#900000");
+ color_text = get_colorpixel("#ffffff");
+ color_border = get_colorpixel("#d92424");
+ color_border_bottom = get_colorpixel("#470909");
} else {
/* Yellowish theme for warnings */
- color_button_background = get_colorpixel(conn, "#ffc100");
- color_background = get_colorpixel(conn, "#ffa8000");
- color_text = get_colorpixel(conn, "#000000");
- color_border = get_colorpixel(conn, "#ab7100");
- color_border_bottom = get_colorpixel(conn, "#ab7100");
+ color_button_background = get_colorpixel("#ffc100");
+ color_background = get_colorpixel("#ffa8000");
+ color_text = get_colorpixel("#000000");
+ color_border = get_colorpixel("#ab7100");
+ color_border_bottom = get_colorpixel("#ab7100");
}
uint32_t font_id = get_font_id(conn, pattern, &font_height);
xcb_change_gc(conn, gc, mask, &value);
}
-/*
- * Returns the colorpixel to use for the given hex color (think of HTML).
- *
- * The hex_color has to start with #, for example #FF00FF.
- *
- * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
- * This has to be done by the caller.
- *
- */
-uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
- char strgroups[3][3] = {{hex[1], hex[2], '\0'},
- {hex[3], hex[4], '\0'},
- {hex[5], hex[6], '\0'}};
- uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
- (strtol(strgroups[1], NULL, 16)),
- (strtol(strgroups[2], NULL, 16))};
-
- return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
-}
-
/*
* Opens the window we use for input/output and maps it
*
}
}
-/*
- * Converts a colorstring to a colorpixel as expected from xcb_change_gc.
- * s is assumed to be in the format "rrggbb"
- *
- */
-uint32_t get_colorpixel(const char *s) {
- char strings[3][3] = { { s[0], s[1], '\0'} ,
- { s[2], s[3], '\0'} ,
- { s[4], s[5], '\0'} };
- uint8_t r = strtol(strings[0], NULL, 16);
- uint8_t g = strtol(strings[1], NULL, 16);
- uint8_t b = strtol(strings[2], NULL, 16);
- return (r << 16 | g << 8 | b);
-}
-
/*
* Redraws the statusline to the buffer
*
*/
void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width);
+/**
+ * Returns the colorpixel to use for the given hex color (think of HTML). Only
+ * works for true-color (vast majority of cases) at the moment, avoiding a
+ * roundtrip to X11.
+ *
+ * The hex_color has to start with #, for example #FF00FF.
+ *
+ * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
+ * This has to be done by the caller.
+ *
+ * NOTE that this function may in the future rely on a global xcb_connection_t
+ * variable called 'conn' to be present.
+ *
+ */
+uint32_t get_colorpixel(const char *hex) __attribute__((const));
+
#endif
*/
i3Font load_font(const char *pattern, bool fallback);
-/**
- * Returns the colorpixel to use for the given hex color (think of HTML).
- *
- * The hex_color has to start with #, for example #FF00FF.
- *
- * NOTE that get_colorpixel() does _NOT_ check the given color code for
- * validity. This has to be done by the caller.
- *
- */
-uint32_t get_colorpixel(char *hex);
-
/**
* Convenience wrapper around xcb_create_window which takes care of depth,
* generating an ID and checking for errors.
--- /dev/null
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ * i3 - an improved dynamic tiling window manager
+ *
+ * © 2009-2011 Michael Stapelberg and contributors
+ *
+ * See file LICENSE for license information.
+ *
+ */
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "libi3.h"
+
+/*
+ * Returns the colorpixel to use for the given hex color (think of HTML). Only
+ * works for true-color (vast majority of cases) at the moment, avoiding a
+ * roundtrip to X11.
+ *
+ * The hex_color has to start with #, for example #FF00FF.
+ *
+ * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
+ * This has to be done by the caller.
+ *
+ * NOTE that this function may in the future rely on a global xcb_connection_t
+ * variable called 'conn' to be present.
+ *
+ */
+uint32_t get_colorpixel(const char *hex) {
+ char strgroups[3][3] = {{hex[1], hex[2], '\0'},
+ {hex[3], hex[4], '\0'},
+ {hex[5], hex[6], '\0'}};
+ uint8_t r = strtol(strgroups[0], NULL, 16);
+ uint8_t g = strtol(strgroups[1], NULL, 16);
+ uint8_t b = strtol(strgroups[2], NULL, 16);
+
+ return (r << 16 | g << 8 | b);
+}
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
+#include "libi3.h"
+
/*
* Try to get the socket path from X11 and return NULL if it doesn’t work.
*
#include <err.h>
#include <stdlib.h>
+#include "libi3.h"
+
/*
* Connects to the i3 IPC socket and returns the file descriptor for the
* socket. die()s if anything goes wrong.
#include <i3/ipc.h>
+#include "libi3.h"
+
/*
* Formats a message (payload) of the given size and type and sends it to i3 via
* the given socket file descriptor.
#include <stdio.h>
#include <err.h>
+#include "libi3.h"
/*
* The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of
return new;
}
-/*
- * Returns the colorpixel to use for the given hex color (think of HTML).
- *
- * The hex_color has to start with #, for example #FF00FF.
- *
- * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
- * This has to be done by the caller.
- *
- */
-uint32_t get_colorpixel(char *hex) {
- char strgroups[3][3] = {{hex[1], hex[2], '\0'},
- {hex[3], hex[4], '\0'},
- {hex[5], hex[6], '\0'}};
- uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
- (strtol(strgroups[1], NULL, 16)),
- (strtol(strgroups[2], NULL, 16))};
-
- return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
-}
-
/*
* Convenience wrapper around xcb_create_window which takes care of depth, generating an ID and checking
* for errors.