1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

More line fixing.

This commit is contained in:
QC 2015-09-19 20:59:50 +02:00
parent b18d68eff2
commit 31fe5759b8
12 changed files with 156 additions and 340 deletions

View file

@ -58,8 +58,7 @@ static void combi_mode_parse_switchers ( Switcher *sw )
// Make a copy, as strtok will modify it.
char *switcher_str = g_strdup ( config.combi_modi );
// Split token on ','. This modifies switcher_str.
for ( char *token = strtok_r ( switcher_str, ",", &savept );
token != NULL;
for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL;
token = strtok_r ( NULL, ",", &savept ) ) {
// Resize and add entry.
pd->switchers = (Switcher * *) g_realloc ( pd->switchers,
@ -164,9 +163,7 @@ static SwitcherMode combi_mode_result ( int mretv, char **input, unsigned int se
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] &&
selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
return pd->switchers[i]->result ( mretv,
input,
selected_line - pd->starts[i],
return pd->switchers[i]->result ( mretv, input, selected_line - pd->starts[i],
pd->switchers[i] );
}
}
@ -179,11 +176,8 @@ static int combi_mode_match ( char **tokens, const char *input,
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
return pd->switchers[i]->token_match ( tokens,
input,
case_sensitive,
index - pd->starts[i],
pd->switchers[i] );
return pd->switchers[i]->token_match ( tokens, input, case_sensitive,
index - pd->starts[i], pd->switchers[i] );
}
}
abort ();
@ -193,11 +187,9 @@ static const char * combi_mgrv ( unsigned int selected_line, void *sw, int *stat
{
CombiModePrivateData *pd = ( (Switcher *) sw )->private_data;
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] && selected_line <
( pd->starts[i] + pd->lengths[i] ) ) {
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
g_free ( pd->cache );
pd->cache = g_strdup_printf ( "(%s) %s",
pd->switchers[i]->name,
pd->cache = g_strdup_printf ( "(%s) %s", pd->switchers[i]->name,
pd->switchers[i]->mgrv ( selected_line - pd->starts[i],
(void *) pd->switchers[i], state ) );
return pd->cache;

View file

@ -98,9 +98,7 @@ static char ** dmenu_mode_get_data ( unsigned int *length, Switcher *sw )
static void parse_pair ( char *input, struct range_pair *item )
{
int index = 0;
for ( char *token = strsep ( &input, "-" );
token != NULL;
token = strsep ( &input, "-" ) ) {
for ( char *token = strsep ( &input, "-" ); token != NULL; token = strsep ( &input, "-" ) ) {
if ( index == 0 ) {
item->start = item->stop = (unsigned int) strtoul ( token, NULL, 10 );
index++;
@ -119,9 +117,7 @@ static void parse_pair ( char *input, struct range_pair *item )
static void parse_ranges ( char *input, struct range_pair **list, unsigned int *length )
{
char *endp;
for ( char *token = strtok_r ( input, ",", &endp );
token != NULL;
token = strtok_r ( NULL, ",", &endp ) ) {
for ( char *token = strtok_r ( input, ",", &endp ); token != NULL; token = strtok_r ( NULL, ",", &endp ) ) {
// Make space.
*list = g_realloc ( ( *list ), ( ( *length ) + 1 ) * sizeof ( struct range_pair ) );
// Parse a single pair.
@ -318,8 +314,7 @@ int dmenu_switcher_dialog ( void )
do {
unsigned int next_pos = pd->selected_line;
int mretv = menu ( &dmenu_mode, &input, pd->prompt,
&( pd->selected_line ), &next_pos, pd->message );
int mretv = menu ( &dmenu_mode, &input, pd->prompt, &( pd->selected_line ), &next_pos, pd->message );
// Special behavior.
// TODO clean this up!
if ( only_selected ) {
@ -327,11 +322,8 @@ int dmenu_switcher_dialog ( void )
* Select item mode.
*/
restart = 1;
if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] !=
NULL ) {
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line],
pd->selected_line,
input );
if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] != NULL ) {
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input );
retv = TRUE;
if ( ( mretv & MENU_QUICK_SWITCH ) ) {
retv = 10 + ( mretv & MENU_LOWER_MASK );
@ -349,9 +341,7 @@ int dmenu_switcher_dialog ( void )
restart = FALSE;
// Normal mode
if ( ( mretv & MENU_OK ) && cmd_list[pd->selected_line] != NULL ) {
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line],
pd->selected_line,
input );
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input );
if ( ( mretv & MENU_SHIFT ) ) {
restart = TRUE;
// Move to next line.
@ -372,9 +362,7 @@ int dmenu_switcher_dialog ( void )
}
// Quick switch with entry selected.
else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line < UINT32_MAX ) {
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line],
pd->selected_line,
input );
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input );
restart = FALSE;
retv = 10 + ( mretv & MENU_LOWER_MASK );

View file

@ -56,12 +56,9 @@ static inline void execsh ( const char *cmd, int run_in_term )
helper_parse_setup ( config.run_command, &args, &argc, "{cmd}", cmd, NULL );
}
GError *error = NULL;
g_spawn_async ( NULL, args, NULL,
G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, &error );
g_spawn_async ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error );
if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd,
error->message );
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message );
error_dialog ( msg, FALSE );
g_free ( msg );
// print error.
@ -187,18 +184,14 @@ static char ** get_apps ( unsigned int *length )
path = g_strdup ( getenv ( "PATH" ) );
for ( const char *dirname = strtok ( path, ":" );
dirname != NULL;
dirname = strtok ( NULL, ":" ) ) {
for ( const char *dirname = strtok ( path, ":" ); dirname != NULL; dirname = strtok ( NULL, ":" ) ) {
DIR *dir = opendir ( dirname );
if ( dir != NULL ) {
struct dirent *dent;
while ( ( dent = readdir ( dir ) ) != NULL ) {
if ( dent->d_type != DT_REG &&
dent->d_type != DT_LNK &&
dent->d_type != DT_UNKNOWN ) {
if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) {
continue;
}
// Skip dot files.
@ -240,9 +233,7 @@ static char ** get_apps ( unsigned int *length )
}
// TODO: check this is still fast enough. (takes 1ms on laptop.)
if ( ( *length ) > num_favorites ) {
g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ),
sort_func,
NULL );
g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ), sort_func, NULL );
}
g_free ( path );

View file

@ -173,8 +173,7 @@ Switcher *script_switcher_parse_setup ( const char *str )
char *endp = NULL;
char *parse = g_strdup ( str );
unsigned int index = 0;
for ( char *token = strtok_r ( parse, ":", &endp ); token != NULL;
token = strtok_r ( NULL, ":", &endp ) ) {
for ( char *token = strtok_r ( parse, ":", &endp ); token != NULL; token = strtok_r ( NULL, ":", &endp ) ) {
if ( index == 0 ) {
g_strlcpy ( sw->name, token, 32 );
}
@ -197,8 +196,7 @@ Switcher *script_switcher_parse_setup ( const char *str )
return sw;
}
fprintf ( stderr, "The script command '%s' has %u options, but needs 2: <name>:<script>.\n",
str, index );
fprintf ( stderr, "The script command '%s' has %u options, but needs 2: <name>:<script>.\n", str, index );
script_switcher_free ( sw );
return NULL;
}

View file

@ -57,13 +57,10 @@ static inline int execshssh ( const char *host )
helper_parse_setup ( config.ssh_command, &args, &argsv, "{host}", host, NULL );
GError *error = NULL;
g_spawn_async ( NULL, args, NULL,
G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, &error );
g_spawn_async ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error );
if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to execute: 'ssh %s'\nError: '%s'", host,
error->message );
char *msg = g_strdup_printf ( "Failed to execute: 'ssh %s'\nError: '%s'", host, error->message );
error_dialog ( msg, FALSE );
g_free ( msg );
// print error.
@ -261,9 +258,7 @@ static char ** get_ssh ( unsigned int *length )
// TODO: check this is still fast enough. (takes 1ms on laptop.)
if ( ( *length ) > num_favorites ) {
g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ),
ssh_sort_func,
NULL );
g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ), ssh_sort_func, NULL );
}
g_free ( path );

View file

@ -269,9 +269,7 @@ static client* window_client ( Display *display, Window win )
c->states = window_get_atom_prop ( display, win, netatoms[_NET_WM_STATE], c->state, CLIENTSTATE );
c->window_types =
window_get_atom_prop ( display, win, netatoms[_NET_WM_WINDOW_TYPE], c->window_type,
CLIENTWINDOWTYPE );
c->window_types = window_get_atom_prop ( display, win, netatoms[_NET_WM_WINDOW_TYPE], c->window_type, CLIENTWINDOWTYPE );
char *name;
if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) {
@ -283,8 +281,7 @@ static client* window_client ( Display *display, Window win )
XFree ( name );
}
name =
window_get_text_prop ( display, c->window, XInternAtom ( display, "WM_WINDOW_ROLE", False ) );
name = window_get_text_prop ( display, c->window, XInternAtom ( display, "WM_WINDOW_ROLE", False ) );
if ( name != NULL ) {
snprintf ( c->role, CLIENTROLE, "%s", name );
@ -392,21 +389,18 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
pd->config_i3_mode = i3_support_initialize ( display );
// Get the active window so we can highlight this.
if ( !( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type,
&count, &curr_win_id, sizeof ( Window ) )
if ( !( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &curr_win_id, sizeof ( Window ) )
&& type == XA_WINDOW && count > 0 ) ) {
curr_win_id = 0;
}
// Get the current desktop.
unsigned long current_desktop = 0;
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_CURRENT_DESKTOP],
&current_desktop, 1 ) ) {
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_CURRENT_DESKTOP], &current_desktop, 1 ) ) {
current_desktop = 0;
}
if ( window_get_prop ( display, root, netatoms[_NET_CLIENT_LIST_STACKING],
&type, &nwins, wins, 100 * sizeof ( Window ) )
if ( window_get_prop ( display, root, netatoms[_NET_CLIENT_LIST_STACKING], &type, &nwins, wins, 100 * sizeof ( Window ) )
&& type == XA_WINDOW ) {
char pattern[50];
int i;
@ -443,8 +437,7 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
}
// Create pattern for printing the line.
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_NUMBER_OF_DESKTOPS],
&desktops, 1 ) ) {
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_NUMBER_OF_DESKTOPS], &desktops, 1 ) ) {
desktops = 1;
}
if ( pd->config_i3_mode ) {
@ -466,13 +459,10 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
unsigned long wmdesktop;
char desktop[5];
desktop[0] = 0;
char *line = g_malloc ( strlen ( c->title ) + strlen (
c->class ) + classfield + 50 );
char *line = g_malloc ( strlen ( c->title ) + strlen ( c->class ) + classfield + 50 );
if ( !pd->config_i3_mode ) {
// find client's desktop.
if ( !window_get_cardinal_prop ( display, c->window,
netatoms[_NET_WM_DESKTOP], &wmdesktop,
1 ) ) {
if ( !window_get_cardinal_prop ( display, c->window, netatoms[_NET_WM_DESKTOP], &wmdesktop, 1 ) ) {
// Assume the client is on all desktops.
wmdesktop = 0xFFFFFFFF;
}
@ -533,13 +523,11 @@ static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input,
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
// Change to the desktop of the selected window/client.
// TODO: get rid of strtol
window_send_message ( display, root, root, netatoms[_NET_CURRENT_DESKTOP],
strtol ( rmpd->cmd_list[selected_line], NULL, 10 ),
window_send_message ( display, root, root, netatoms[_NET_CURRENT_DESKTOP], strtol ( rmpd->cmd_list[selected_line], NULL, 10 ),
SubstructureNotifyMask | SubstructureRedirectMask, 0 );
XSync ( display, False );
window_send_message ( display, root, rmpd->ids->array[selected_line],
netatoms[_NET_ACTIVE_WINDOW], 2, // 2 = pager
window_send_message ( display, root, rmpd->ids->array[selected_line], netatoms[_NET_ACTIVE_WINDOW], 2, // 2 = pager
SubstructureNotifyMask | SubstructureRedirectMask, 0 );
}
}

View file

@ -111,10 +111,8 @@ void parse_keys_abe ( void )
abe[iter].num_bindings = 0;
// Iter over bindings.
for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL;
entry = strtok_r ( NULL, ",", &sp ) ) {
abe[iter].kb =
g_realloc ( abe[iter].kb, ( abe[iter].num_bindings + 1 ) * sizeof ( KeyBinding ) );
for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL; entry = strtok_r ( NULL, ",", &sp ) ) {
abe[iter].kb = g_realloc ( abe[iter].kb, ( abe[iter].num_bindings + 1 ) * sizeof ( KeyBinding ) );
KeyBinding *kb = &( abe[iter].kb[abe[iter].num_bindings] );
x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ) );
abe[iter].num_bindings++;

View file

@ -360,10 +360,9 @@ static void menu_calculate_rows_columns ( MenuState *state )
// Calculate the number or rows. We do this by getting the num_lines rounded up to X columns
// (num elements is better name) then dividing by columns.
state->max_rows = MIN ( state->menu_lines, (unsigned int) ( ( state->num_lines +
( state->columns - state->num_lines %
state->columns ) % state->columns ) /
( state->columns ) ) );
state->max_rows = MIN ( state->menu_lines, (unsigned int) ( ( state->num_lines + ( state->columns - state->num_lines %
state->columns ) %
state->columns ) / ( state->columns ) ) );
// Always have at least one row.
state->max_rows = MAX ( 1, state->max_rows );
@ -834,18 +833,15 @@ static void menu_update ( MenuState *state )
}
menu_draw ( state );
// Why do we need the special -1?
XDrawLine ( display, main_window, gc, 0,
state->line_height + ( config.padding ) * 1 + config.line_margin + 1, state->w,
XDrawLine ( display, main_window, gc, 0, state->line_height + ( config.padding ) * 1 + config.line_margin + 1, state->w,
state->line_height + ( config.padding ) * 1 + config.line_margin + 1 );
if ( state->message_tb ) {
XDrawLine ( display, main_window, gc,
0, state->top_offset - ( config.line_margin ) - 1,
XDrawLine ( display, main_window, gc, 0, state->top_offset - ( config.line_margin ) - 1,
state->w, state->top_offset - ( config.line_margin ) - 1 );
}
if ( config.sidebar_mode == TRUE ) {
XDrawLine ( display, main_window, gc,
0, state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin,
XDrawLine ( display, main_window, gc, 0, state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin,
state->w, state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin );
for ( unsigned int j = 0; j < num_switchers; j++ ) {
textbox_draw ( switchers[j].tb );
@ -890,8 +886,7 @@ static void menu_resize ( MenuState *state )
if ( config.sidebar_mode == TRUE ) {
int width = ( state->w - ( 2 * ( config.padding ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
for ( unsigned int j = 0; j < num_switchers; j++ ) {
textbox_moveresize ( switchers[j].tb,
config.padding + j * ( width + config.line_margin ),
textbox_moveresize ( switchers[j].tb, config.padding + j * ( width + config.line_margin ),
state->h - state->line_height - config.padding, width, state->line_height );
textbox_show ( switchers[j].tb );
textbox_draw ( switchers[j].tb );
@ -983,8 +978,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
// we need this at this point so we can get height.
state.line_height = textbox_get_estimated_char_height ();
state.case_indicator = textbox_create ( main_window, &vinfo, map, TB_AUTOWIDTH,
( config.padding ), ( config.padding ),
state.case_indicator = textbox_create ( main_window, &vinfo, map, TB_AUTOWIDTH, ( config.padding ), ( config.padding ),
0, state.line_height, NORMAL, "*" );
// Height of a row.
if ( config.menu_lines == 0 ) {
@ -1003,8 +997,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
state.prompt_tb = textbox_create ( main_window, &vinfo, map, TB_AUTOWIDTH, ( config.padding ), ( config.padding ),
0, state.line_height, NORMAL, prompt );
// Entry box
int entrybox_width = state.w - ( 2 * ( config.padding ) )
- textbox_get_width ( state.prompt_tb )
int entrybox_width = state.w - ( 2 * ( config.padding ) ) - textbox_get_width ( state.prompt_tb )
- textbox_get_width ( state.case_indicator );
state.text = textbox_create ( main_window, &vinfo, map, TB_EDITABLE,
@ -1726,8 +1719,7 @@ static int grab_global_keybindings ()
int key_bound = FALSE;
for ( unsigned int i = 0; i < num_switchers; i++ ) {
if ( switchers[i].sw->keystr != NULL ) {
x11_parse_key ( switchers[i].sw->keystr, &( switchers[i].sw->modmask ),
&( switchers[i].sw->keysym ) );
x11_parse_key ( switchers[i].sw->keystr, &( switchers[i].sw->modmask ), &( switchers[i].sw->keysym ) );
if ( switchers[i].sw->keysym != NoSymbol ) {
x11_grab_key ( display, switchers[i].sw->modmask, switchers[i].sw->keysym );
key_bound = TRUE;
@ -2063,8 +2055,7 @@ int main ( int argc, char *argv[] )
fprintf ( stderr, "Please check the manpage on how to specify a key-binding.\n" );
fprintf ( stderr, "The following modi are enabled and keys can be specified:\n" );
for ( unsigned int i = 0; i < num_switchers; i++ ) {
fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s <key>\n",
switchers[i].sw->name, switchers[i].sw->name );
fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s <key>\n", switchers[i].sw->name, switchers[i].sw->name );
}
return EXIT_FAILURE;
}

View file

@ -56,16 +56,12 @@ scrollbar *scrollbar_create ( Window parent, XVisualInfo *vinfo, Colormap map,
attr.colormap = map;
attr.border_pixel = color_border ( display );
attr.background_pixel = color_background ( display );
sb->window =
XCreateWindow ( display, sb->parent, sb->x, sb->y, sb->w, sb->h, 0, vinfo->depth,
InputOutput, vinfo->visual, CWColormap |
CWBorderPixel | CWBackPixel,
&attr );
sb->window = XCreateWindow ( display, sb->parent, sb->x, sb->y, sb->w, sb->h, 0, vinfo->depth, InputOutput, vinfo->visual,
CWColormap | CWBorderPixel | CWBackPixel, &attr );
XSelectInput ( display, sb->window, ExposureMask | ButtonPressMask | Button1MotionMask );
sb->gc = XCreateGC ( display, sb->window, 0, 0 );
XSetForeground ( display, sb->gc, color_separator ( display ) );
//XSetFillStyle ( display, sb->gc, FillSolid);
// Create GC.
return sb;
@ -131,9 +127,7 @@ void scrollbar_draw ( scrollbar *sb )
// Redraw base window
XClearWindow ( display, sb->window );
// Paint the handle.
XFillRectangle ( display, sb->window, sb->gc, config.line_margin, y, sb->w -
config.line_margin,
height );
XFillRectangle ( display, sb->window, sb->gc, config.line_margin, y, sb->w - config.line_margin, height );
}
}
void scrollbar_resize ( scrollbar *sb, int w, int h )

View file

@ -101,11 +101,8 @@ textbox* textbox_create ( Window parent, XVisualInfo *vinfo, Colormap map, Textb
attr.colormap = map;
attr.border_pixel = cp;
attr.background_pixel = cp;
tb->window =
XCreateWindow ( display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, vinfo->depth,
InputOutput, vinfo->visual, CWColormap |
CWBorderPixel | CWBackPixel,
&attr );
tb->window = XCreateWindow ( display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, vinfo->depth,
InputOutput, vinfo->visual, CWColormap | CWBorderPixel | CWBackPixel, &attr );
PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font );
pango_layout_set_font_description ( tb->layout, pfd );
@ -127,10 +124,8 @@ textbox* textbox_create ( Window parent, XVisualInfo *vinfo, Colormap map, Textb
// edit mode controls
if ( tb->flags & TB_EDITABLE ) {
tb->xim = XOpenIM ( display, NULL, NULL, NULL );
tb->xic =
XCreateIC ( tb->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow,
tb->window, XNFocusWindow, tb->window,
NULL );
tb->xic = XCreateIC ( tb->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow,
tb->window, XNFocusWindow, tb->window, NULL );
}
else {
XSelectInput ( display, tb->window, ButtonPressMask );
@ -343,9 +338,7 @@ void textbox_draw ( textbox *tb )
// draw the cursor
if ( tb->flags & TB_EDITABLE ) {
XftDrawRect ( draw, &tb->color_fg,
x / PANGO_SCALE + cursor_x, y / PANGO_SCALE, // Align with font
cursor_width, font_height );
XftDrawRect ( draw, &tb->color_fg, x / PANGO_SCALE + cursor_x, y / PANGO_SCALE, cursor_width, font_height );
}
// flip canvas to window
@ -389,13 +382,8 @@ static void textbox_cursor_inc_word ( textbox *tb )
while ( ( c = g_utf8_next_char ( c ) ) ) {
gunichar uc = g_utf8_get_char ( c );
GUnicodeBreakType bt = g_unichar_break_type ( uc );
if ( (
bt == G_UNICODE_BREAK_ALPHABETIC ||
bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC ||
bt == G_UNICODE_BREAK_QUOTATION
)
) {
if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
break;
}
}
@ -405,13 +393,8 @@ static void textbox_cursor_inc_word ( textbox *tb )
while ( ( c = g_utf8_next_char ( c ) ) ) {
gunichar uc = g_utf8_get_char ( c );
GUnicodeBreakType bt = g_unichar_break_type ( uc );
if ( !(
bt == G_UNICODE_BREAK_ALPHABETIC ||
bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC ||
bt == G_UNICODE_BREAK_QUOTATION
)
) {
if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
break;
}
}
@ -427,13 +410,8 @@ static void textbox_cursor_dec_word ( textbox *tb )
while ( ( c = g_utf8_prev_char ( c ) ) && c != tb->text ) {
gunichar uc = g_utf8_get_char ( c );
GUnicodeBreakType bt = g_unichar_break_type ( uc );
if ( (
bt == G_UNICODE_BREAK_ALPHABETIC ||
bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC ||
bt == G_UNICODE_BREAK_QUOTATION
)
) {
if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
break;
}
}
@ -441,13 +419,8 @@ static void textbox_cursor_dec_word ( textbox *tb )
while ( ( n = g_utf8_prev_char ( c ) ) ) {
gunichar uc = g_utf8_get_char ( n );
GUnicodeBreakType bt = g_unichar_break_type ( uc );
if ( !(
bt == G_UNICODE_BREAK_ALPHABETIC ||
bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC ||
bt == G_UNICODE_BREAK_QUOTATION
)
) {
if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
break;
}
c = n;
@ -684,9 +657,7 @@ static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const
char *endp;
char *token;
int index = 0;
for ( token =
strtok_r ( cstr, ",",
&endp ); token != NULL; token = strtok_r ( NULL, ",", &endp ) ) {
for ( token = strtok_r ( cstr, ",", &endp ); token != NULL; token = strtok_r ( NULL, ",", &endp ) ) {
switch ( index )
{
case 0:
@ -696,8 +667,7 @@ static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->fg ), "white" );
break;
case 2:
parse_color ( visual->visual, colormap, g_strstrip (
token ), &( color->bgalt ), "black" );
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->bgalt ), "black" );
break;
case 3:
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlbg ), "black" );
@ -716,46 +686,28 @@ void textbox_setup ( XVisualInfo *visual, Colormap colormap )
target_colormap = colormap;
if ( config.color_enabled ) {
textbox_parse_string ( visual, target_colormap,
config.color_normal, &( colors[NORMAL] ) );
textbox_parse_string ( visual, target_colormap,
config.color_urgent, &( colors[URGENT] ) );
textbox_parse_string ( visual, target_colormap,
config.color_active, &( colors[ACTIVE] ) );
textbox_parse_string ( visual, target_colormap, config.color_normal, &( colors[NORMAL] ) );
textbox_parse_string ( visual, target_colormap, config.color_urgent, &( colors[URGENT] ) );
textbox_parse_string ( visual, target_colormap, config.color_active, &( colors[ACTIVE] ) );
}
else {
parse_color ( visual_info->visual, target_colormap, config.menu_bg, &( colors[NORMAL].bg ),
"black" );
parse_color ( visual_info->visual, target_colormap, config.menu_fg, &( colors[NORMAL].fg ),
"white" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt,
&( colors[NORMAL].bgalt ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg,
&( colors[NORMAL].hlfg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlbg,
&( colors[NORMAL].hlbg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg, &( colors[NORMAL].bg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_fg, &( colors[NORMAL].fg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt, &( colors[NORMAL].bgalt ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg, &( colors[NORMAL].hlfg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlbg, &( colors[NORMAL].hlbg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_urgent,
&( colors[URGENT].bg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_fg_urgent,
&( colors[URGENT].fg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt,
&( colors[URGENT].bgalt ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg_urgent,
&( colors[URGENT].hlfg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlbg_urgent,
&( colors[URGENT].hlbg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_urgent, &( colors[URGENT].bg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_fg_urgent, &( colors[URGENT].fg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt, &( colors[URGENT].bgalt ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg_urgent, &( colors[URGENT].hlfg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlbg_urgent, &( colors[URGENT].hlbg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_active,
&( colors[ACTIVE].bg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_fg_active,
&( colors[ACTIVE].fg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt,
&( colors[ACTIVE].bgalt ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg_active,
&( colors[ACTIVE].hlfg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlbg_active,
&( colors[ACTIVE].hlbg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_active, &( colors[ACTIVE].bg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_fg_active, &( colors[ACTIVE].fg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt, &( colors[ACTIVE].bgalt ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg_active, &( colors[ACTIVE].hlfg ), "white" );
parse_color ( visual_info->visual, target_colormap, config.menu_hlbg_active, &( colors[ACTIVE].hlbg ), "black" );
}
PangoFontMap *font_map = pango_xft_get_font_map ( display, DefaultScreen ( display ) );
p_context = pango_font_map_create_context ( font_map );
@ -763,16 +715,11 @@ void textbox_setup ( XVisualInfo *visual, Colormap colormap )
static void textbox_clean_rowcolor ( RowColor * color )
{
XftColorFree ( display, visual_info->visual, target_colormap,
&( color->fg ) );
XftColorFree ( display, visual_info->visual, target_colormap,
&( color->bg ) );
XftColorFree ( display, visual_info->visual, target_colormap,
&( color->bgalt ) );
XftColorFree ( display, visual_info->visual, target_colormap,
&( color->hlfg ) );
XftColorFree ( display, visual_info->visual, target_colormap,
&( color->hlbg ) );
XftColorFree ( display, visual_info->visual, target_colormap, &( color->fg ) );
XftColorFree ( display, visual_info->visual, target_colormap, &( color->bg ) );
XftColorFree ( display, visual_info->visual, target_colormap, &( color->bgalt ) );
XftColorFree ( display, visual_info->visual, target_colormap, &( color->hlfg ) );
XftColorFree ( display, visual_info->visual, target_colormap, &( color->hlbg ) );
}
void textbox_cleanup ( void )
@ -840,8 +787,7 @@ int textbox_get_estimated_char_height ( void )
// Get width
PangoFontMetrics *metric = pango_context_get_metrics ( p_context, pfd, NULL );
int height = pango_font_metrics_get_ascent ( metric ) +
pango_font_metrics_get_descent ( metric );
int height = pango_font_metrics_get_ascent ( metric ) + pango_font_metrics_get_descent ( metric );
pango_font_metrics_unref ( metric );
pango_font_description_free ( pfd );

View file

@ -66,8 +66,8 @@ int window_get_prop ( Display *display, Window w, Atom prop, Atom *type, int *it
unsigned char *ret = NULL;
memset ( buffer, 0, bytes );
if ( XGetWindowProperty ( display, w, prop, 0, bytes / 4, False, AnyPropertyType, type, &format, &nitems, &nbytes,
&ret ) == Success && ret && *type != None && format ) {
if ( XGetWindowProperty ( display, w, prop, 0, bytes / 4, False, AnyPropertyType, type, &format, &nitems, &nbytes, &ret ) == Success &&
ret && *type != None && format ) {
if ( format == 8 ) {
memmove ( buffer, ret, MIN ( bytes, nitems ) );
}
@ -444,9 +444,8 @@ static int ( *xerror )( Display *, XErrorEvent * );
*/
static int display_oops ( Display *d, XErrorEvent *ee )
{
if ( ee->error_code == BadWindow
|| ( ee->request_code == X_GrabButton && ee->error_code == BadAccess )
|| ( ee->request_code == X_GrabKey && ee->error_code == BadAccess )) {
if ( ee->error_code == BadWindow || ( ee->request_code == X_GrabButton && ee->error_code == BadAccess )
|| ( ee->request_code == X_GrabKey && ee->error_code == BadAccess ) ) {
return 0;
}

View file

@ -53,146 +53,82 @@ typedef struct
* Currently supports string, boolean and number (signed and unsigned).
*/
static XrmOption xrmOptions[] = {
{ xrm_String, "switchers",
{ .str = &config.switchers },
NULL },
{ xrm_String, "modi", { .str = &config.switchers },
NULL },
{ xrm_Number, "opacity", { .num = &config.window_opacity },
NULL },
{ xrm_String, "switchers", { .str = &config.switchers }, NULL },
{ xrm_String, "modi", { .str = &config.switchers }, NULL },
{ xrm_Number, "opacity", { .num = &config.window_opacity }, NULL },
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL },
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL },
{ xrm_Number, "columns", { .num = &config.menu_columns }, NULL },
{ xrm_SNumber, "width", { .snum = &config.menu_width },
NULL },
{ xrm_Number, "lines", { .num = &config.menu_lines },
NULL },
{ xrm_Number, "columns", { .num = &config.menu_columns },
NULL },
{ xrm_String, "font", { .str = &config.menu_font },
NULL },
{ xrm_String, "font", { .str = &config.menu_font }, NULL },
/* Foreground color */
{ xrm_String, "foreground", { .str = &config.menu_fg },
NULL },
{ xrm_String, "fg", { .str = &config.menu_fg },
NULL },
{ xrm_String, "background", { .str = &config.menu_bg },
NULL },
{ xrm_String, "bg", { .str = &config.menu_bg },
NULL },
{ xrm_String, "foreground", { .str = &config.menu_fg }, NULL },
{ xrm_String, "fg", { .str = &config.menu_fg }, NULL },
{ xrm_String, "background", { .str = &config.menu_bg }, NULL },
{ xrm_String, "bg", { .str = &config.menu_bg }, NULL },
{ xrm_Boolean, "color-enabled", { .num = &config.color_enabled },
NULL },
{ xrm_String, "color-normal", { .str = &config.color_normal },
NULL },
{ xrm_String, "color-urgent", { .str = &config.color_urgent },
NULL },
{ xrm_String, "color-active", { .str = &config.color_active },
NULL },
{ xrm_String, "color-window", { .str = &config.color_window },
NULL },
{ xrm_Boolean, "color-enabled", { .num = &config.color_enabled }, NULL },
{ xrm_String, "color-normal", { .str = &config.color_normal }, NULL },
{ xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL },
{ xrm_String, "color-active", { .str = &config.color_active }, NULL },
{ xrm_String, "color-window", { .str = &config.color_window }, NULL },
{ xrm_String, "fg-active", { .str = &config.menu_fg_active },
NULL },
{ xrm_String, "fg-urgent", { .str = &config.menu_fg_urgent },
NULL },
{ xrm_String, "hlfg-active", { .str = &config.menu_hlfg_active },
NULL },
{ xrm_String, "hlfg-urgent", { .str = &config.menu_hlfg_urgent },
NULL },
{ xrm_String, "fg-active", { .str = &config.menu_fg_active }, NULL },
{ xrm_String, "fg-urgent", { .str = &config.menu_fg_urgent }, NULL },
{ xrm_String, "hlfg-active", { .str = &config.menu_hlfg_active }, NULL },
{ xrm_String, "hlfg-urgent", { .str = &config.menu_hlfg_urgent }, NULL },
{ xrm_String, "bg-active", { .str = &config.menu_bg_active },
NULL },
{ xrm_String, "bg-urgent", { .str = &config.menu_bg_urgent },
NULL },
{ xrm_String, "hlbg-active", { .str = &config.menu_hlbg_active },
NULL },
{ xrm_String, "hlbg-urgent", { .str = &config.menu_hlbg_urgent },
NULL },
{ xrm_String, "bg-active", { .str = &config.menu_bg_active }, NULL },
{ xrm_String, "bg-urgent", { .str = &config.menu_bg_urgent }, NULL },
{ xrm_String, "hlbg-active", { .str = &config.menu_hlbg_active }, NULL },
{ xrm_String, "hlbg-urgent", { .str = &config.menu_hlbg_urgent }, NULL },
{ xrm_String, "background-alternate", { .str = &config.menu_bg_alt },
NULL },
{ xrm_String, "bgalt", { .str = &config.menu_bg_alt },
NULL },
{ xrm_String, "background-alternate", { .str = &config.menu_bg_alt }, NULL },
{ xrm_String, "bgalt", { .str = &config.menu_bg_alt }, NULL },
{ xrm_String, "highlightfg", { .str = &config.menu_hlfg },
NULL },
{ xrm_String, "hlfg", { .str = &config.menu_hlfg },
NULL },
{ xrm_String, "highlightfg", { .str = &config.menu_hlfg }, NULL },
{ xrm_String, "hlfg", { .str = &config.menu_hlfg }, NULL },
{ xrm_String, "highlightbg", { .str = &config.menu_hlbg },
NULL },
{ xrm_String, "hlbg", { .str = &config.menu_hlbg },
NULL },
{ xrm_String, "highlightbg", { .str = &config.menu_hlbg }, NULL },
{ xrm_String, "hlbg", { .str = &config.menu_hlbg }, NULL },
{ xrm_String, "bordercolor", { .str = &config.menu_bc },
NULL },
{ xrm_String, "bc", { .str = &config.menu_bc },
NULL },
{ xrm_String, "bordercolor", { .str = &config.menu_bc }, NULL },
{ xrm_String, "bc", { .str = &config.menu_bc }, NULL },
{ xrm_Number, "borderwidth", { .num = &config.menu_bw },
NULL },
{ xrm_Number, "bw", { .num = &config.menu_bw },
NULL },
{ xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL },
{ xrm_Number, "bw", { .num = &config.menu_bw }, NULL },
{ xrm_Number, "location", { .num = &config.location },
NULL },
{ xrm_Number, "location", { .num = &config.location }, NULL },
{ xrm_Number, "padding", { .num = &config.padding },
NULL },
{ xrm_SNumber, "yoffset", { .snum = &config.y_offset },
NULL },
{ xrm_SNumber, "xoffset", { .snum = &config.x_offset },
NULL },
{ xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines },
NULL },
{ xrm_Number, "padding", { .num = &config.padding }, NULL },
{ xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL },
{ xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL },
{ xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL },
{ xrm_String, "terminal", { .str = &config.terminal_emulator },
NULL },
{ xrm_String, "ssh-client", { .str = &config.ssh_client },
NULL },
{ xrm_String, "ssh-command", { .str = &config.ssh_command },
NULL },
{ xrm_String, "run-command", { .str = &config.run_command },
NULL },
{ xrm_String, "run-list-command", { .str = &config.run_list_command },
NULL },
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command },
NULL },
{ xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL },
{ xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL },
{ xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL },
{ xrm_String, "run-command", { .str = &config.run_command }, NULL },
{ xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL },
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL },
{ xrm_Boolean, "disable-history", { .num = &config.disable_history },
NULL },
{ xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort },
NULL },
{ xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive },
NULL },
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode },
NULL },
{ xrm_Number, "lazy-filter-limit", { .num = &config.lazy_filter_limit },
NULL },
{ xrm_SNumber, "eh", { .snum = &config.element_height },
NULL },
{ xrm_Boolean, "auto-select", { .num = &config.auto_select },
NULL },
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts },
NULL },
{ xrm_String, "combi-modi", { .str = &config.combi_modi },
NULL },
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy },
NULL },
{ xrm_Number, "monitor", { .snum = &config.monitor },
NULL },
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL },
{ xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL },
{ xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL },
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL },
{ xrm_Number, "lazy-filter-limit", { .num = &config.lazy_filter_limit }, NULL },
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL },
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL },
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL },
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL },
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL },
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL },
/* Alias for dmenu compatibility. */
{ xrm_SNumber, "m", { .snum = &config.monitor },
NULL },
{ xrm_Number, "line-margin", { .num = &config.line_margin },
NULL },
{ xrm_String, "filter", { .str = &config.filter },
NULL },
{ xrm_String, "separator-style", { .str = &config.separator_style },
NULL },
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar },
NULL }
{ xrm_SNumber, "m", { .snum = &config.monitor }, NULL },
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL },
{ xrm_String, "filter", { .str = &config.filter }, NULL },
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL },
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL }
};
// Dynamic options.