diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | config.h | 18 | ||||
-rw-r--r-- | mcwm.c | 63 |
4 files changed, 67 insertions, 20 deletions
@@ -2,6 +2,10 @@ User visible changes +2010-06-24-3 + + * -f and -u options for focused and unfocused colours. + 2010-06-24 * When starting, we don't care about windows with override redirect @@ -19,8 +19,6 @@ In order of importance: Done, but needs looking over. -* Handle colours for real. Don't just assume raw pixel values will work. - * Special treatment when someone resizes a maximed window... Should it be possible at all? Set new border width. @@ -27,23 +27,19 @@ * to be in $PATH. * * Change to "xterm" if you're feeling conservative. + * + * Can be set from command line with "-t program". */ #define TERMINAL "urxvt" -/* Colour on border for focused windows. */ - /* - * FIXME: We blatantly ignore displays that doesn't handle direct - * colour values. Sorry. + * Default colour on border for focused windows. Can be set from + * command line with "-f color". */ +#define FOCUSCOL "chocolate1" -/* very light gray. */ -/* #define FOCUSCOL 0xe5e5e5 */ -/* amber */ -#define FOCUSCOL 0xff7f24 - -/* Ditto for unfocused. */ -#define UNFOCUSCOL 0x666666 +/* Ditto for unfocused. Use "-u color". */ +#define UNFOCUSCOL "grey40" /* Width of border window, in pixels. */ #define BORDERWIDTH 1 @@ -28,6 +28,7 @@ #include <unistd.h> #include <errno.h> #include <getopt.h> +#include <string.h> #include <sys/types.h> #include <sys/wait.h> @@ -60,6 +61,7 @@ #define MCWM_MOVE 2 #define MCWM_RESIZE 3 + /* Types. */ typedef enum { @@ -102,10 +104,13 @@ struct conf { bool borders; char *terminal; /* Path to terminal to start. */ + uint32_t focuscol; + uint32_t unfocuscol; } conf; /* Functions declerations. */ +uint32_t getcolor(const char *colstr); void newwin(xcb_window_t win); void setupwin(xcb_window_t win); xcb_keycode_t keysymtokeycode(xcb_keysym_t keysym, xcb_key_symbols_t *keysyms); @@ -130,6 +135,30 @@ void printhelp(void); /* Function bodies. */ +uint32_t getcolor(const char *colstr) +{ + xcb_alloc_named_color_reply_t *col_reply; + xcb_colormap_t colormap; + xcb_generic_error_t *error; + xcb_alloc_named_color_cookie_t colcookie; + + colormap = screen->default_colormap; + + colcookie = xcb_alloc_named_color(conn, colormap, strlen(colstr), colstr); + + col_reply = xcb_alloc_named_color_reply(conn, colcookie, &error); + if (NULL != error) + { + fprintf(stderr, "mcwm: Couldn't get pixel value for colour %s. " + "Exiting.\n", colstr); + + xcb_disconnect(conn); + exit(1); + } + + return col_reply->pixel; +} + /* * Set position, geometry and attributes of a new window and show it * on the screen. @@ -233,7 +262,7 @@ void setupwin(xcb_window_t win) if (conf.borders) { /* Set border color. */ - values[0] = UNFOCUSCOL; + values[0] = conf.unfocuscol; xcb_change_window_attributes(conn, win, XCB_CW_BORDER_PIXEL, values); /* Set border width. */ @@ -440,7 +469,7 @@ void setunfocus(xcb_drawable_t win) } /* Set new border colour. */ - values[0] = UNFOCUSCOL; + values[0] = conf.unfocuscol; xcb_change_window_attributes(conn, win, XCB_CW_BORDER_PIXEL, values); xcb_flush(conn); @@ -462,7 +491,7 @@ void setfocus(xcb_drawable_t win) if (conf.borders) { /* Set new border colour. */ - values[0] = FOCUSCOL; + values[0] = conf.focuscol; xcb_change_window_attributes(conn, win, XCB_CW_BORDER_PIXEL, values); /* Unset last focus. */ @@ -1468,9 +1497,13 @@ void events(void) void printhelp(void) { - printf("mcwm: Usage: mcwm [-b] [-t terminal-program]\n"); + printf("mcwm: Usage: mcwm [-b] [-t terminal-program] [-f color] " + "[- u color]\n"); printf(" -b means draw no borders\n"); printf(" -t urxvt will start urxvt when MODKEY + Return is pressed\n"); + printf(" -f color sets colour for focused window borders of focused " + "to a named color.\n"); + printf(" -u color sets colour for unfocused window borders."); } int main(int argc, char **argv) @@ -1481,13 +1514,19 @@ int main(int argc, char **argv) xcb_void_cookie_t cookie; xcb_generic_error_t *error; xcb_drawable_t root; + char *focuscol; + char *unfocuscol; + /* Set up defaults. */ + conf.borders = true; conf.terminal = TERMINAL; + focuscol = FOCUSCOL; + unfocuscol = UNFOCUSCOL; while (1) { - ch = getopt(argc, argv, "bt:"); + ch = getopt(argc, argv, "bt:f:u:"); if (-1 == ch) { @@ -1506,6 +1545,14 @@ int main(int argc, char **argv) conf.terminal = optarg; break; + case 'f': + focuscol = optarg; + break; + + case 'u': + unfocuscol = optarg; + break; + default: printhelp(); exit(0); @@ -1525,8 +1572,10 @@ int main(int argc, char **argv) PDEBUG("Screen size: %dx%d\nRoot window: %d\n", screen->width_in_pixels, screen->height_in_pixels, screen->root); - - /* FIXME: Get some colours. */ + + /* Get some colours. */ + conf.focuscol = getcolor(focuscol); + conf.unfocuscol = getcolor(unfocuscol); /* Loop over all clients and set up stuff. */ if (0 != setupscreen()) |