mirror of https://github.com/davatorium/rofi.git
First try out. (tests not compiling at.. do make rofi)
This commit is contained in:
parent
d3cd99fddd
commit
291070e579
|
@ -360,6 +360,9 @@ KeySym sshdialog_keysym;
|
||||||
Window main_window = None;
|
Window main_window = None;
|
||||||
GC gc = NULL;
|
GC gc = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
Colormap map = None;
|
||||||
|
XVisualInfo vinfo;
|
||||||
/**
|
/**
|
||||||
* Allocate a pixel value for an X named color
|
* Allocate a pixel value for an X named color
|
||||||
*/
|
*/
|
||||||
|
@ -367,9 +370,14 @@ static unsigned int color_get ( Display *display, const char *const name )
|
||||||
{
|
{
|
||||||
int screen_id = DefaultScreen ( display );
|
int screen_id = DefaultScreen ( display );
|
||||||
XColor color;
|
XColor color;
|
||||||
Colormap map = DefaultColormap ( display, screen_id );
|
// 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;
|
return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param x The x position of the mouse [out]
|
* @param x The x position of the mouse [out]
|
||||||
|
@ -829,11 +837,22 @@ Window create_window ( Display *display )
|
||||||
{
|
{
|
||||||
Screen *screen = DefaultScreenOfDisplay ( display );
|
Screen *screen = DefaultScreenOfDisplay ( display );
|
||||||
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
|
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
Window box = XCreateSimpleWindow ( display, root, 0, 0, 200, 100,
|
||||||
config.menu_bw,
|
config.menu_bw,
|
||||||
color_get ( display, config.menu_bc ),
|
color_get ( display, config.menu_bc ),
|
||||||
color_get ( display, config.menu_bg ) );
|
color_get ( display, config.menu_bg ) );
|
||||||
|
*/
|
||||||
XSelectInput ( display, box, ExposureMask | ButtonPressMask );
|
XSelectInput ( display, box, ExposureMask | ButtonPressMask );
|
||||||
|
|
||||||
gc = XCreateGC ( display, box, 0, 0 );
|
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 ()
|
static int run_dmenu ()
|
||||||
{
|
{
|
||||||
|
XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo );
|
||||||
|
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
|
||||||
int ret_state;
|
int ret_state;
|
||||||
textbox_setup (
|
textbox_setup (
|
||||||
config.menu_bg, config.menu_bg_alt, config.menu_fg,
|
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 );
|
display = XOpenDisplay ( display_str );
|
||||||
XSync ( display, True );
|
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.
|
// Because of the above fork, we want to do this here.
|
||||||
// Make sure this is isolated to its own thread.
|
// Make sure this is isolated to its own thread.
|
||||||
textbox_setup (
|
textbox_setup (
|
||||||
|
@ -2403,6 +2428,9 @@ static void cleanup ()
|
||||||
{
|
{
|
||||||
// Cleanup
|
// Cleanup
|
||||||
if ( display != NULL ) {
|
if ( display != NULL ) {
|
||||||
|
if ( map != None ) {
|
||||||
|
XFreeColormap ( display, map );
|
||||||
|
}
|
||||||
if ( main_window != None ) {
|
if ( main_window != None ) {
|
||||||
XFreeGC ( display, gc );
|
XFreeGC ( display, gc );
|
||||||
XDestroyWindow ( display, main_window );
|
XDestroyWindow ( display, main_window );
|
||||||
|
@ -2643,6 +2671,8 @@ int main ( int argc, char *argv[] )
|
||||||
|
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
if ( find_arg_str ( argc, argv, "-e", &( msg ) ) ) {
|
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 (
|
textbox_setup (
|
||||||
config.menu_bg, config.menu_bg_alt, config.menu_fg,
|
config.menu_bg, config.menu_bg_alt, config.menu_fg,
|
||||||
config.menu_hlbg,
|
config.menu_hlbg,
|
||||||
|
|
|
@ -43,7 +43,8 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#define SIDE_MARGIN 2
|
#define SIDE_MARGIN 2
|
||||||
|
|
||||||
|
extern Colormap map;
|
||||||
|
extern XVisualInfo vinfo;
|
||||||
extern Display *display;
|
extern Display *display;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -236,8 +237,8 @@ void textbox_free ( textbox *tb )
|
||||||
void textbox_draw ( textbox *tb )
|
void textbox_draw ( textbox *tb )
|
||||||
{
|
{
|
||||||
GC context = XCreateGC ( display, tb->window, 0, 0 );
|
GC context = XCreateGC ( display, tb->window, 0, 0 );
|
||||||
Pixmap canvas = XCreatePixmap ( display, tb->window, tb->w, tb->h, DefaultDepth ( display, DefaultScreen ( display ) ) );
|
Pixmap canvas = XCreatePixmap ( display, tb->window, tb->w, tb->h, vinfo.depth );
|
||||||
XftDraw *draw = XftDrawCreate ( display, canvas, DefaultVisual ( display, DefaultScreen ( display ) ), DefaultColormap ( display, DefaultScreen ( display ) ) );
|
XftDraw *draw = XftDrawCreate ( display, canvas, vinfo.visual, map );
|
||||||
|
|
||||||
// clear canvas
|
// clear canvas
|
||||||
XftDrawRect ( draw, &tb->color_bg, 0, 0, tb->w, tb->h );
|
XftDrawRect ( draw, &tb->color_bg, 0, 0, tb->w, tb->h );
|
||||||
|
@ -287,6 +288,7 @@ void textbox_draw ( textbox *tb )
|
||||||
}
|
}
|
||||||
|
|
||||||
// flip canvas to window
|
// flip canvas to window
|
||||||
|
// XClearWindow ( display, tb->window);
|
||||||
XCopyArea ( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );
|
XCopyArea ( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );
|
||||||
|
|
||||||
XFreeGC ( display, context );
|
XFreeGC ( display, context );
|
||||||
|
@ -447,20 +449,34 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
|
||||||
/***
|
/***
|
||||||
* Font setup.
|
* 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 (
|
void textbox_setup (
|
||||||
const char *bg, const char *bg_alt, const char *fg,
|
const char *bg, const char *bg_alt, const char *fg,
|
||||||
const char *hlbg, const char *hlfg
|
const char *hlbg, const char *hlfg
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Visual *visual = DefaultVisual ( display, DefaultScreen ( display ) );
|
parse_color ( bg, &color_bg );
|
||||||
Colormap colormap = DefaultColormap ( display, DefaultScreen ( display ) );
|
parse_color ( fg, &color_fg );
|
||||||
|
parse_color ( bg_alt, &color_bg_alt );
|
||||||
XftColorAllocName ( display, visual, colormap, fg, &color_fg );
|
parse_color ( hlfg, &color_hlfg );
|
||||||
XftColorAllocName ( display, visual, colormap, bg, &color_bg );
|
parse_color ( hlbg, &color_hlbg );
|
||||||
XftColorAllocName ( display, visual, colormap, bg_alt, &color_bg_alt );
|
|
||||||
XftColorAllocName ( display, visual, colormap, hlfg, &color_hlfg );
|
|
||||||
XftColorAllocName ( display, visual, colormap, hlbg, &color_hlbg );
|
|
||||||
|
|
||||||
PangoFontMap *font_map = pango_xft_get_font_map ( display, DefaultScreen ( display ) );
|
PangoFontMap *font_map = pango_xft_get_font_map ( display, DefaultScreen ( display ) );
|
||||||
p_context = pango_font_map_create_context ( font_map );
|
p_context = pango_font_map_create_context ( font_map );
|
||||||
|
@ -470,8 +486,8 @@ void textbox_setup (
|
||||||
void textbox_cleanup ()
|
void textbox_cleanup ()
|
||||||
{
|
{
|
||||||
if ( p_context ) {
|
if ( p_context ) {
|
||||||
Visual *visual = DefaultVisual ( display, DefaultScreen ( display ) );
|
Visual *visual = vinfo.visual;
|
||||||
Colormap colormap = DefaultColormap ( display, DefaultScreen ( display ) );
|
Colormap colormap = map;
|
||||||
|
|
||||||
|
|
||||||
XftColorFree ( display, visual, colormap, &color_fg );
|
XftColorFree ( display, visual, colormap, &color_fg );
|
||||||
|
|
Loading…
Reference in New Issue