summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2015-01-20 23:32:57 +0100
committerDave Davenport <qball@gmpclient.org>2015-01-20 23:32:57 +0100
commit291070e579d9564a629b34c9e5ee0191aaa3a814 (patch)
tree5312dc7d1f366a7ba33d35f9d6af43db04c1627e
parentd3cd99fddd3c8dbbce143b61bed8f5cd57ad7ea5 (diff)
First try out. (tests not compiling at.. do make rofi)
-rw-r--r--source/rofi.c42
-rw-r--r--source/textbox.c44
2 files changed, 66 insertions, 20 deletions
diff --git a/source/rofi.c b/source/rofi.c
index 61359d69..c6793b41 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -360,15 +360,23 @@ KeySym sshdialog_keysym;
Window main_window = None;
GC gc = NULL;
+
+Colormap map = None;
+XVisualInfo vinfo;
/**
* Allocate a pixel value for an X named color
*/
static unsigned int color_get ( Display *display, const char *const name )
{
- int screen_id = DefaultScreen ( display );
- XColor color;
- Colormap map = DefaultColormap ( display, screen_id );
- return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None;
+ int screen_id = DefaultScreen ( display );
+ XColor color;
+ // Special format.
+ if ( strncmp ( name, "argb:", 5 ) == 0 ) {
+ return strtoul ( &name[5], NULL, 16 );
+ }
+ else {
+ return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None;
+ }
}
/**
@@ -829,11 +837,22 @@ Window create_window ( Display *display )
{
Screen *screen = DefaultScreenOfDisplay ( display );
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
- Window box = XCreateSimpleWindow ( display, root, 0, 0, 200, 100,
+
+
+ XSetWindowAttributes attr;
+ attr.colormap = map;
+ attr.border_pixel = color_get ( display, config.menu_bc );
+ attr.background_pixel = color_get ( display, config.menu_bg );
+
+ Window box = XCreateWindow ( display, DefaultRootWindow ( display ),
+ 0, 0, 200, 100, config.menu_bw, vinfo.depth, InputOutput,
+ vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr );
+ /*
+ Window box = XCreateSimpleWindow ( display, root, 0, 0, 200, 100,
config.menu_bw,
color_get ( display, config.menu_bc ),
color_get ( display, config.menu_bg ) );
-
+ */
XSelectInput ( display, box, ExposureMask | ButtonPressMask );
gc = XCreateGC ( display, box, 0, 0 );
@@ -2087,6 +2106,8 @@ SwitcherMode run_switcher_window ( char **input, G_GNUC_UNUSED void *data )
*/
static int run_dmenu ()
{
+ XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo );
+ map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
int ret_state;
textbox_setup (
config.menu_bg, config.menu_bg_alt, config.menu_fg,
@@ -2119,6 +2140,10 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
display = XOpenDisplay ( display_str );
XSync ( display, True );
}
+
+ XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo );
+ map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
+
// Because of the above fork, we want to do this here.
// Make sure this is isolated to its own thread.
textbox_setup (
@@ -2403,6 +2428,9 @@ static void cleanup ()
{
// Cleanup
if ( display != NULL ) {
+ if ( map != None ) {
+ XFreeColormap ( display, map );
+ }
if ( main_window != None ) {
XFreeGC ( display, gc );
XDestroyWindow ( display, main_window );
@@ -2643,6 +2671,8 @@ int main ( int argc, char *argv[] )
char *msg = NULL;
if ( find_arg_str ( argc, argv, "-e", &( msg ) ) ) {
+ XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo );
+ map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
textbox_setup (
config.menu_bg, config.menu_bg_alt, config.menu_fg,
config.menu_hlbg,
diff --git a/source/textbox.c b/source/textbox.c
index a323a2c7..828d50eb 100644
--- a/source/textbox.c
+++ b/source/textbox.c
@@ -43,8 +43,9 @@
#include <glib.h>
#define SIDE_MARGIN 2
-
-extern Display *display;
+extern Colormap map;
+extern XVisualInfo vinfo;
+extern Display *display;
/**
* Font + font color cache.
@@ -236,8 +237,8 @@ void textbox_free ( textbox *tb )
void textbox_draw ( textbox *tb )
{
GC context = XCreateGC ( display, tb->window, 0, 0 );
- Pixmap canvas = XCreatePixmap ( display, tb->window, tb->w, tb->h, DefaultDepth ( display, DefaultScreen ( display ) ) );
- XftDraw *draw = XftDrawCreate ( display, canvas, DefaultVisual ( display, DefaultScreen ( display ) ), DefaultColormap ( display, DefaultScreen ( display ) ) );
+ Pixmap canvas = XCreatePixmap ( display, tb->window, tb->w, tb->h, vinfo.depth );
+ XftDraw *draw = XftDrawCreate ( display, canvas, vinfo.visual, map );
// clear canvas
XftDrawRect ( draw, &tb->color_bg, 0, 0, tb->w, tb->h );
@@ -287,6 +288,7 @@ void textbox_draw ( textbox *tb )
}
// flip canvas to window
+ // XClearWindow ( display, tb->window);
XCopyArea ( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );
XFreeGC ( display, context );
@@ -447,20 +449,34 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
/***
* Font setup.
*/
+static void parse_color ( const char *bg, XftColor *color )
+{
+ Visual *visual = vinfo.visual;
+ Colormap colormap = map;
+ if ( strncmp ( bg, "argb:", 5 ) == 0 ) {
+ XRenderColor col;
+ unsigned int val = strtoul ( &bg[5], NULL, 16 );
+ col.alpha = ( ( val & 0xFF000000 ) >> 24 ) * 255;
+ col.red = ( ( val & 0x00FF0000 ) >> 16 ) * 255;
+ col.green = ( ( val & 0x0000FF00 ) >> 8 ) * 255;
+ col.blue = ( ( val & 0x000000FF ) ) * 255;
+ XftColorAllocValue ( display, visual, colormap, &col, color );
+ }
+ else {
+ XftColorAllocName ( display, visual, colormap, bg, color );
+ }
+}
void textbox_setup (
const char *bg, const char *bg_alt, const char *fg,
const char *hlbg, const char *hlfg
)
{
- Visual *visual = DefaultVisual ( display, DefaultScreen ( display ) );
- Colormap colormap = DefaultColormap ( display, DefaultScreen ( display ) );
-
- XftColorAllocName ( display, visual, colormap, fg, &color_fg );
- XftColorAllocName ( display, visual, colormap, bg, &color_bg );
- XftColorAllocName ( display, visual, colormap, bg_alt, &color_bg_alt );
- XftColorAllocName ( display, visual, colormap, hlfg, &color_hlfg );
- XftColorAllocName ( display, visual, colormap, hlbg, &color_hlbg );
+ parse_color ( bg, &color_bg );
+ parse_color ( fg, &color_fg );
+ parse_color ( bg_alt, &color_bg_alt );
+ parse_color ( hlfg, &color_hlfg );
+ parse_color ( hlbg, &color_hlbg );
PangoFontMap *font_map = pango_xft_get_font_map ( display, DefaultScreen ( display ) );
p_context = pango_font_map_create_context ( font_map );
@@ -470,8 +486,8 @@ void textbox_setup (
void textbox_cleanup ()
{
if ( p_context ) {
- Visual *visual = DefaultVisual ( display, DefaultScreen ( display ) );
- Colormap colormap = DefaultColormap ( display, DefaultScreen ( display ) );
+ Visual *visual = vinfo.visual;
+ Colormap colormap = map;
XftColorFree ( display, visual, colormap, &color_fg );