1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Some cleanups, tweak uncrustify.

This commit is contained in:
QC 2015-09-19 12:21:30 +02:00
parent 4c970fe4da
commit 442e235c24
19 changed files with 491 additions and 255 deletions

View file

@ -1,7 +1,7 @@
# #
# My favorite format # My favorite format
# #
code_width = 100
indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs
input_tab_size = 8 # original tab size input_tab_size = 8 # original tab size
output_tab_size = 4 # new tab size output_tab_size = 4 # new tab size

View file

@ -76,7 +76,8 @@ typedef enum
* *
* @returns 1 when it matches, 0 if not. * @returns 1 when it matches, 0 if not.
*/ */
typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensitive, unsigned int index, Switcher *data ); typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensitive,
unsigned int index, Switcher *data );
/** /**
* @param sw the Switcher to show. * @param sw the Switcher to show.
@ -96,7 +97,8 @@ typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensi
*/ */
MenuReturn menu ( Switcher *sw, char **input, char *prompt, MenuReturn menu ( Switcher *sw, char **input, char *prompt,
unsigned int *selected_line, unsigned int *selected_line,
unsigned int *next_pos, const char *message ) __attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) ); unsigned int *next_pos,
const char *message ) __attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
/** /**
* @param sig The caught signal * @param sig The caught signal
* *
@ -272,8 +274,10 @@ struct _Switcher
*/ */
void ( *init )( struct _Switcher *sw ); void ( *init )( struct _Switcher *sw );
char ** ( *get_data )( unsigned int *length, struct _Switcher *pd ); char ** ( *get_data )( unsigned int *length, struct _Switcher *pd );
int ( *match )( char **tokens, const char *input, int case_sensitive, int index, struct _Switcher *data ); int ( *match )( char **tokens, const char *input, int case_sensitive, int index,
SwitcherMode ( *result )( int menu_retv, char **input, unsigned int selected_line, struct _Switcher *pd ); struct _Switcher *data );
SwitcherMode ( *result )( int menu_retv, char **input, unsigned int selected_line,
struct _Switcher *pd );
void ( *destroy )( struct _Switcher *pd ); void ( *destroy )( struct _Switcher *pd );
// Token match. // Token match.
menu_match_cb token_match; menu_match_cb token_match;

View file

@ -98,4 +98,13 @@ unsigned int scrollbar_clicked ( scrollbar *sb, int y );
* Resize the scrollbar. * Resize the scrollbar.
*/ */
void scrollbar_resize ( scrollbar *sb, int w, int h ); void scrollbar_resize ( scrollbar *sb, int w, int h );
/**
* @param sb scrollbar object
* @param x x pos in pixels
* @param y y pos in pixels
*
* Move the scrollbar.
*/
void scrollbar_move ( scrollbar *sb, int x, int y );
#endif // ROFI_SCROLLBAR_H #endif // ROFI_SCROLLBAR_H

View file

@ -20,7 +20,8 @@ char* window_get_text_prop ( Display *display, Window w, Atom atom );
int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, int count ); int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, int count );
void window_set_atom_prop ( Display *display, Window w, Atom prop, Atom *atoms, int count ); void window_set_atom_prop ( Display *display, Window w, Atom prop, Atom *atoms, int count );
int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list, int count ); int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list,
int count );
/** /**

View file

@ -156,7 +156,8 @@ static void combi_mode_destroy ( Switcher *sw )
sw->private_data = NULL; sw->private_data = NULL;
} }
} }
static SwitcherMode combi_mode_result ( int mretv, char **input, unsigned int selected_line, Switcher *sw ) static SwitcherMode combi_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
{ {
CombiModePrivateData *pd = sw->private_data; CombiModePrivateData *pd = sw->private_data;
@ -192,11 +193,13 @@ static const char * combi_mgrv ( unsigned int selected_line, void *sw, int *stat
{ {
CombiModePrivateData *pd = ( (Switcher *) sw )->private_data; CombiModePrivateData *pd = ( (Switcher *) sw )->private_data;
for ( unsigned i = 0; i < pd->num_switchers; i++ ) { 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 ); g_free ( pd->cache );
pd->cache = g_strdup_printf ( "(%s) %s", pd->cache = g_strdup_printf ( "(%s) %s",
pd->switchers[i]->name, pd->switchers[i]->name,
pd->switchers[i]->mgrv ( selected_line - pd->starts[i], (void *) pd->switchers[i], state ) ); pd->switchers[i]->mgrv ( selected_line - pd->starts[i],
(void *) pd->switchers[i], state ) );
return pd->cache; return pd->cache;
} }
} }

View file

@ -169,7 +169,8 @@ static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNU
* This functions outputs the formatted string to stdout, appends a newline (\n) character and * This functions outputs the formatted string to stdout, appends a newline (\n) character and
* calls flush on the file descriptor. * calls flush on the file descriptor.
*/ */
static void dmenu_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter ) static void dmenu_output_formatted_line ( const char *format, const char *string, int selected_line,
const char *filter )
{ {
for ( int i = 0; format && format[i]; i++ ) { for ( int i = 0; format && format[i]; i++ ) {
if ( format[i] == 'i' ) { if ( format[i] == 'i' ) {
@ -330,8 +331,11 @@ int dmenu_switcher_dialog ( void )
* Select item mode. * Select item mode.
*/ */
restart = 1; restart = 1;
if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] != NULL ) { if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] !=
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); NULL ) {
dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line],
pd->selected_line,
input );
retv = TRUE; retv = TRUE;
if ( ( mretv & MENU_QUICK_SWITCH ) ) { if ( ( mretv & MENU_QUICK_SWITCH ) ) {
retv = 10 + ( mretv & MENU_LOWER_MASK ); retv = 10 + ( mretv & MENU_LOWER_MASK );
@ -349,7 +353,9 @@ int dmenu_switcher_dialog ( void )
restart = FALSE; restart = FALSE;
// Normal mode // Normal mode
if ( ( mretv & MENU_OK ) && cmd_list[pd->selected_line] != NULL ) { 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 ) ) { if ( ( mretv & MENU_SHIFT ) ) {
restart = TRUE; restart = TRUE;
// Move to next line. // Move to next line.
@ -370,7 +376,9 @@ int dmenu_switcher_dialog ( void )
} }
// Quick switch with entry selected. // Quick switch with entry selected.
else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line < UINT32_MAX ) { 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; restart = FALSE;
retv = 10 + ( mretv & MENU_LOWER_MASK ); retv = 10 + ( mretv & MENU_LOWER_MASK );

View file

@ -159,7 +159,8 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
( *length )++; ( *length )++;
} }
if ( fclose ( inp ) != 0 ) { if ( fclose ( inp ) != 0 ) {
fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n", strerror ( errno ) ); fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n",
strerror ( errno ) );
} }
} }
} }
@ -243,7 +244,9 @@ static char ** get_apps ( unsigned int *length )
} }
// TODO: check this is still fast enough. (takes 1ms on laptop.) // TODO: check this is still fast enough. (takes 1ms on laptop.)
if ( ( *length ) > num_favorites ) { 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 ); g_free ( path );
@ -258,7 +261,9 @@ static char ** get_apps ( unsigned int *length )
if ( ( *length ) > num_favorites ) { 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 );
} }
// Reduce array length; // Reduce array length;
( *length ) -= removed; ( *length ) -= removed;
@ -293,7 +298,8 @@ static char ** run_mode_get_data ( unsigned int *length, Switcher *sw )
return rmpd->cmd_list; return rmpd->cmd_list;
} }
static SwitcherMode run_mode_result ( int mretv, char **input, unsigned int selected_line, Switcher *sw ) static SwitcherMode run_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
{ {
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data; RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
SwitcherMode retv = MODE_EXIT; SwitcherMode retv = MODE_EXIT;

View file

@ -66,7 +66,8 @@ static char **get_script_output ( const char *command, unsigned int *length )
( *length )++; ( *length )++;
} }
if ( fclose ( inp ) != 0 ) { if ( fclose ( inp ) != 0 ) {
fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n", strerror ( errno ) ); fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n",
strerror ( errno ) );
} }
} }
} }
@ -120,7 +121,8 @@ static char ** script_mode_get_data ( unsigned int *length, Switcher *sw )
return rmpd->cmd_list; return rmpd->cmd_list;
} }
static SwitcherMode script_mode_result ( int mretv, char **input, unsigned int selected_line, Switcher *sw ) static SwitcherMode script_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
{ {
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
SwitcherMode retv = MODE_EXIT; SwitcherMode retv = MODE_EXIT;
@ -178,7 +180,8 @@ Switcher *script_switcher_parse_setup ( const char *str )
char *endp = NULL; char *endp = NULL;
char *parse = g_strdup ( str ); char *parse = g_strdup ( str );
unsigned int index = 0; 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 ) { if ( index == 0 ) {
g_strlcpy ( sw->name, token, 32 ); g_strlcpy ( sw->name, token, 32 );
} }

View file

@ -261,7 +261,9 @@ static char ** get_ssh ( unsigned int *length )
// TODO: check this is still fast enough. (takes 1ms on laptop.) // TODO: check this is still fast enough. (takes 1ms on laptop.)
if ( ( *length ) > num_favorites ) { 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 ); g_free ( path );
@ -293,7 +295,8 @@ static char ** ssh_mode_get_data ( unsigned int *length, Switcher *sw )
*length = rmpd->cmd_list_length; *length = rmpd->cmd_list_length;
return rmpd->cmd_list; return rmpd->cmd_list;
} }
static SwitcherMode ssh_mode_result ( int mretv, char **input, unsigned int selected_line, Switcher *sw ) static SwitcherMode ssh_mode_result ( int mretv, char **input, unsigned int selected_line,
Switcher *sw )
{ {
SwitcherMode retv = MODE_EXIT; SwitcherMode retv = MODE_EXIT;
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data; SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;

View file

@ -270,7 +270,9 @@ static client* window_client ( Display *display, Window win )
c->states = window_get_atom_prop ( display, win, netatoms[_NET_WM_STATE], c->state, CLIENTSTATE ); 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; char *name;
if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) { if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) {
@ -282,7 +284,8 @@ static client* window_client ( Display *display, Window win )
XFree ( name ); 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 ) { if ( name != NULL ) {
snprintf ( c->role, CLIENTROLE, "%s", name ); snprintf ( c->role, CLIENTROLE, "%s", name );
@ -398,7 +401,8 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
// Get the current desktop. // Get the current desktop.
unsigned long current_desktop = 0; 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; current_desktop = 0;
} }
@ -442,14 +446,16 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
} }
// Create pattern for printing the line. // 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; desktops = 1;
} }
if ( pd->config_i3_mode ) { if ( pd->config_i3_mode ) {
sprintf ( pattern, "%%-%ds %%s", MAX ( 5, classfield ) ); sprintf ( pattern, "%%-%ds %%s", MAX ( 5, classfield ) );
} }
else{ else{
sprintf ( pattern, "%%-%ds %%-%ds %%s", desktops < 10 ? 1 : 2, MAX ( 5, classfield ) ); sprintf ( pattern, "%%-%ds %%-%ds %%s", desktops < 10 ? 1 : 2,
MAX ( 5, classfield ) );
} }
pd->cmd_list = g_malloc0_n ( ( pd->ids->len + 1 ), sizeof ( char* ) ); pd->cmd_list = g_malloc0_n ( ( pd->ids->len + 1 ), sizeof ( char* ) );
@ -463,10 +469,13 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
unsigned long wmdesktop; unsigned long wmdesktop;
char desktop[5]; char desktop[5];
desktop[0] = 0; 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 ) { if ( !pd->config_i3_mode ) {
// find client's desktop. // 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. // Assume the client is on all desktops.
wmdesktop = 0xFFFFFFFF; wmdesktop = 0xFFFFFFFF;
} }
@ -502,7 +511,9 @@ static char ** window_mode_get_data ( unsigned int *length, Switcher *sw )
{ {
return _window_mode_get_data ( length, sw, FALSE ); return _window_mode_get_data ( length, sw, FALSE );
} }
static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input, unsigned int selected_line, Switcher *sw ) static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input,
unsigned int selected_line,
Switcher *sw )
{ {
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data; SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;
SwitcherMode retv = MODE_EXIT; SwitcherMode retv = MODE_EXIT;

View file

@ -449,34 +449,43 @@ void remove_pid_file ( int fd )
void config_sanity_check ( ) void config_sanity_check ( )
{ {
int found_error = FALSE; int found_error = FALSE;
GString *msg = g_string_new ( "<big><b>The configuration failed to validate:</b></big>\n" ); GString *msg = g_string_new (
"<big><b>The configuration failed to validate:</b></big>\n" );
if ( config.element_height < 1 ) { if ( config.element_height < 1 ) {
g_string_append_printf ( msg, "\t<b>config.element_height</b>=%d is invalid. An element needs to be atleast 1 line high.\n", g_string_append_printf (
config.element_height ); msg,
"\t<b>config.element_height</b>=%d is invalid. An element needs to be atleast 1 line high.\n",
config.element_height );
config.element_height = 1; config.element_height = 1;
found_error = TRUE; found_error = TRUE;
} }
if ( config.menu_columns == 0 ) { if ( config.menu_columns == 0 ) {
g_string_append_printf ( msg, "\t<b>config.menu_columns</b>=%d is invalid. You need at least one visible column.\n", g_string_append_printf (
config.menu_columns ); msg,
"\t<b>config.menu_columns</b>=%d is invalid. You need at least one visible column.\n",
config.menu_columns );
config.menu_columns = 1; config.menu_columns = 1;
found_error = TRUE; found_error = TRUE;
} }
if ( config.menu_width == 0 ) { if ( config.menu_width == 0 ) {
show_error_message ( "<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width.", TRUE ); show_error_message (
"<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width.", TRUE );
config.menu_columns = 50; config.menu_columns = 50;
found_error = TRUE; found_error = TRUE;
} }
if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) { if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) {
g_string_append_printf ( msg, "\t<b>config.location</b>=%d is invalid. Value should be between %d and %d.\n", g_string_append_printf (
config.location, WL_CENTER, WL_WEST ); msg, "\t<b>config.location</b>=%d is invalid. Value should be between %d and %d.\n",
config.location, WL_CENTER, WL_WEST );
config.location = WL_CENTER; config.location = WL_CENTER;
found_error = 1; found_error = 1;
} }
if ( 0 ) { if ( 0 ) {
if ( !( config.line_margin <= 50 ) ) { if ( !( config.line_margin <= 50 ) ) {
g_string_append_printf ( msg, "\t<b>config.line_margin</b>=%d is invalid. Value should be between %d and %d.\n", g_string_append_printf (
config.line_margin, 0, 50 ); msg,
"\t<b>config.line_margin</b>=%d is invalid. Value should be between %d and %d.\n",
config.line_margin, 0, 50 );
config.line_margin = 2; config.line_margin = 2;
found_error = 1; found_error = 1;
} }

View file

@ -34,36 +34,63 @@ extern unsigned int NumlockMask;
*/ */
DefaultBinding bindings[NUM_ABE] = DefaultBinding bindings[NUM_ABE] =
{ {
{ .id = PASTE_PRIMARY, .name = "kb-primary-paste", .keybinding = "Control+Shift+v,Shift+Insert", }, { .id = PASTE_PRIMARY, .name = "kb-primary-paste",
{ .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = "Control+v,Insert", }, .keybinding =
{ .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding = "Control+u", }, "Control+Shift+v,Shift+Insert", },
{ .id = MOVE_FRONT, .name = "kb-move-front", .keybinding = "Control+a", }, { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding =
{ .id = MOVE_END, .name = "kb-move-end", .keybinding = "Control+e", }, "Control+v,Insert", },
{ .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding =
"Control+u", },
{ .id = MOVE_FRONT, .name = "kb-move-front", .keybinding =
"Control+a", },
{ .id = MOVE_END, .name = "kb-move-end", .keybinding =
"Control+e", },
{ .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", }, { .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", },
{ .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", }, { .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", },
{ .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = "Left,Control+b" }, { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding =
{ .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = "Right,Control+f" }, "Left,Control+b" },
{ .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = "Control+Alt+h", }, { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding =
{ .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = "Control+Alt+d", }, "Right,Control+f" },
{ .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", }, { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding =
{ .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", }, "Control+Alt+h", },
{ .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", }, { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding =
{ .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return", }, "Control+Alt+d", },
{ .id = ACCEPT_ENTRY_CONTINUE, .name = "kb-accept-entry-continue", .keybinding = "Shift+Return", }, { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding =
{ .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = "Shift+Right,Control+Tab" }, "Delete,Control+d", },
{ .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = "Shift+Left,Control+Shift+Tab" }, { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding =
{ .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding = "grave,dead_grave" }, "BackSpace,Control+h", },
{ .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = "Shift+Delete" }, { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding =
{ .id = ROW_LEFT, .name = "kb-row-left", .keybinding = "Control+Page_Up" }, "Control+j,Control+m,Return,KP_Enter", },
{ .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = "Control+Page_Down" }, { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding =
{ .id = ROW_UP, .name = "kb-row-up", .keybinding = "Up,Control+p,Shift+Tab" }, "Control+Return", },
{ .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n" }, { .id = ACCEPT_ENTRY_CONTINUE, .name = "kb-accept-entry-continue", .keybinding =
"Shift+Return", },
{ .id = MODE_NEXT, .name = "kb-mode-next", .keybinding =
"Shift+Right,Control+Tab" },
{ .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding =
"Shift+Left,Control+Shift+Tab" },
{ .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding =
"grave,dead_grave" },
{ .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding =
"Shift+Delete" },
{ .id = ROW_LEFT, .name = "kb-row-left", .keybinding =
"Control+Page_Up" },
{ .id = ROW_RIGHT, .name = "kb-row-right", .keybinding =
"Control+Page_Down" },
{ .id = ROW_UP, .name = "kb-row-up", .keybinding =
"Up,Control+p,Shift+Tab" },
{ .id = ROW_DOWN, .name = "kb-row-down", .keybinding =
"Down,Control+n" },
{ .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab" }, { .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab" },
{ .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up" }, { .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up" },
{ .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down" }, { .id = PAGE_NEXT, .name = "kb-page-next", .keybinding =
{ .id = ROW_FIRST, .name = "kb-row-first", .keybinding = "Home,KP_Home" }, "Page_Down" },
{ .id = ROW_LAST, .name = "kb-row-last", .keybinding = "End,KP_End" }, { .id = ROW_FIRST, .name = "kb-row-first", .keybinding =
{ .id = ROW_SELECT, .name = "kb-row-select", .keybinding = "Control+space" }, "Home,KP_Home" },
{ .id = ROW_LAST, .name = "kb-row-last", .keybinding =
"End,KP_End" },
{ .id = ROW_SELECT, .name = "kb-row-select", .keybinding =
"Control+space" },
{ .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape" }, { .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape" },
{ .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1" }, { .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1" },
{ .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2" }, { .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2" },
@ -75,15 +102,24 @@ DefaultBinding bindings[NUM_ABE] =
{ .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8" }, { .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8" },
{ .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9" }, { .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9" },
{ .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0" }, { .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0" },
{ .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = "Alt+Shift+1" }, { .id = CUSTOM_11, .name = "kb-custom-11", .keybinding =
{ .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = "Alt+Shift+2" }, "Alt+Shift+1" },
{ .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = "Alt+Shift+3" }, { .id = CUSTOM_12, .name = "kb-custom-12", .keybinding =
{ .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = "Alt+Shift+4" }, "Alt+Shift+2" },
{ .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = "Alt+Shift+5" }, { .id = CUSTOM_13, .name = "kb-custom-13", .keybinding =
{ .id = CUSTOM_16, .name = "kb-custom-16", .keybinding = "Alt+Shift+6" }, "Alt+Shift+3" },
{ .id = CUSTOM_17, .name = "kb-custom-17", .keybinding = "Alt+Shift+7" }, { .id = CUSTOM_14, .name = "kb-custom-14", .keybinding =
{ .id = CUSTOM_18, .name = "kb-custom-18", .keybinding = "Alt+Shift+8" }, "Alt+Shift+4" },
{ .id = CUSTOM_19, .name = "kb-custom-19", .keybinding = "Alt+Shift+9" }, { .id = CUSTOM_15, .name = "kb-custom-15", .keybinding =
"Alt+Shift+5" },
{ .id = CUSTOM_16, .name = "kb-custom-16", .keybinding =
"Alt+Shift+6" },
{ .id = CUSTOM_17, .name = "kb-custom-17", .keybinding =
"Alt+Shift+7" },
{ .id = CUSTOM_18, .name = "kb-custom-18", .keybinding =
"Alt+Shift+8" },
{ .id = CUSTOM_19, .name = "kb-custom-19", .keybinding =
"Alt+Shift+9" },
}; };
@ -113,8 +149,10 @@ void parse_keys_abe ( void )
abe[iter].num_bindings = 0; abe[iter].num_bindings = 0;
// Iter over bindings. // Iter over bindings.
for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL; entry = strtok_r ( NULL, ",", &sp ) ) { for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL;
abe[iter].kb = g_realloc ( abe[iter].kb, ( abe[iter].num_bindings + 1 ) * sizeof ( KeyBinding ) ); 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] ); KeyBinding *kb = &( abe[iter].kb[abe[iter].num_bindings] );
x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ) ); x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ) );
abe[iter].num_bindings++; abe[iter].num_bindings++;

View file

@ -54,8 +54,7 @@
#include "x11-helper.h" #include "x11-helper.h"
#include "xrmoptions.h" #include "xrmoptions.h"
#include "dialogs/dialogs.h" #include "dialogs/dialogs.h"
//
// TEMP
SwitcherMode switcher_run ( char **input, Switcher *sw ); SwitcherMode switcher_run ( char **input, Switcher *sw );
typedef enum _MainLoopEvent typedef enum _MainLoopEvent
@ -63,34 +62,30 @@ typedef enum _MainLoopEvent
ML_XEVENT, ML_XEVENT,
ML_TIMEOUT ML_TIMEOUT
} MainLoopEvent; } MainLoopEvent;
typedef struct _Mode
{
Switcher *sw;
textbox *tb;
} Mode;
// Pidfile. // Pidfile.
extern Atom netatoms[NUM_NETATOMS];
char *pidfile = NULL; char *pidfile = NULL;
const char *cache_dir = NULL; const char *cache_dir = NULL;
SnDisplay *sndisplay = NULL; SnDisplay *sndisplay = NULL;
SnLauncheeContext *sncontext = NULL; SnLauncheeContext *sncontext = NULL;
Display *display = NULL; Display *display = NULL;
char *display_str = NULL; char *display_str = NULL;
extern Atom netatoms[NUM_NETATOMS];
Window main_window = None; Window main_window = None;
GC gc = NULL; GC gc = NULL;
Colormap map = None; Colormap map = None;
XVisualInfo vinfo;
unsigned int normal_window_mode = FALSE; unsigned int normal_window_mode = FALSE;
typedef struct _Mode
{
Switcher *sw;
textbox *tb;
} Mode;
// Array of switchers. // Array of switchers.
Mode *switchers = NULL; Mode *switchers = NULL;
// Number of switchers. unsigned int num_switchers = 0;
unsigned int num_switchers = 0;
// Current selected switcher. // Current selected switcher.
unsigned int curr_switcher = 0; unsigned int curr_switcher = 0;
XVisualInfo vinfo;
/** /**
* @param name Name of the switcher to lookup. * @param name Name of the switcher to lookup.
@ -122,15 +117,12 @@ static inline MainLoopEvent wait_for_xevent_or_timeout ( Display *display, int x
return ML_XEVENT; return ML_XEVENT;
} }
// If not, wait for timeout. // If not, wait for timeout.
struct timeval tv; struct timeval tv = { .tv_usec = 200000, .tv_sec = 0 };
fd_set in_fds; fd_set in_fds;
// Create a File Description Set containing x11_fd // Create a File Description Set containing x11_fd
FD_ZERO ( &in_fds ); FD_ZERO ( &in_fds );
FD_SET ( x11_fd, &in_fds ); FD_SET ( x11_fd, &in_fds );
// Set our timer. 200ms is a decent delay
tv.tv_usec = 200000;
tv.tv_sec = 0;
// Wait for X Event or a Timer // Wait for X Event or a Timer
if ( select ( x11_fd + 1, &in_fds, 0, 0, &tv ) == 0 ) { if ( select ( x11_fd + 1, &in_fds, 0, 0, &tv ) == 0 ) {
return ML_TIMEOUT; return ML_TIMEOUT;
@ -223,7 +215,9 @@ static Window create_window ( Display *display )
XSetForeground ( display, gc, color_separator ( display ) ); XSetForeground ( display, gc, color_separator ( display ) );
// make it an unmanaged window // make it an unmanaged window
if ( !normal_window_mode ) { if ( !normal_window_mode ) {
window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1 ); window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE],
&netatoms[_NET_WM_STATE_ABOVE],
1 );
XSetWindowAttributes sattr = { .override_redirect = True }; XSetWindowAttributes sattr = { .override_redirect = True };
XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr ); XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr );
} }
@ -313,11 +307,10 @@ static void menu_free_state ( MenuState *state )
} }
/** /**
* @param x [out] the calculated x position. * @param state the state of the View.
* @param y [out] the calculated y position.
* @param mon the work area. * @param mon the work area.
* @param h the required height of the window. *
* @param w the required width of the window. * Calculates the window poslition
*/ */
static void calculate_window_position ( MenuState *state, const workarea *mon ) static void calculate_window_position ( MenuState *state, const workarea *mon )
{ {
@ -363,7 +356,6 @@ static void calculate_window_position ( MenuState *state, const workarea *mon )
/** /**
* @param state Internal state of the menu. * @param state Internal state of the menu.
* @param num_lines the number of entries passed to the menu.
* *
* Calculate the number of rows, columns and elements to display based on the * Calculate the number of rows, columns and elements to display based on the
* configuration and available data. * configuration and available data.
@ -377,7 +369,8 @@ static void menu_calculate_rows_columns ( MenuState *state )
// (num elements is better name) then dividing by columns. // (num elements is better name) then dividing by columns.
state->max_rows = MIN ( state->menu_lines, state->max_rows = MIN ( state->menu_lines,
(unsigned int) ( (unsigned int) (
( state->num_lines + ( state->columns - state->num_lines % state->columns ) % ( state->num_lines +
( state->columns - state->num_lines % state->columns ) %
state->columns ) / ( state->columns ) state->columns ) / ( state->columns )
) ); ) );
// Always have at least one row. // Always have at least one row.
@ -388,8 +381,9 @@ static void menu_calculate_rows_columns ( MenuState *state )
state->max_rows = state->menu_lines; state->max_rows = state->menu_lines;
// If it would fit in one column, only use one column. // If it would fit in one column, only use one column.
if ( state->num_lines < state->max_elements ) { if ( state->num_lines < state->max_elements ) {
state->columns = ( state->num_lines + ( state->max_rows - state->num_lines % state->max_rows ) % state->columns =
state->max_rows ) / state->max_rows; ( state->num_lines + ( state->max_rows - state->num_lines % state->max_rows ) %
state->max_rows ) / state->max_rows;
state->max_elements = state->menu_lines * state->columns; state->max_elements = state->menu_lines * state->columns;
} }
// Sanitize. // Sanitize.
@ -416,7 +410,8 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea
} }
else{ else{
// Calculate as float to stop silly, big rounding down errors. // Calculate as float to stop silly, big rounding down errors.
state->w = config.menu_width < 101 ? ( mon->w / 100.0f ) * ( float ) config.menu_width : config.menu_width; state->w = config.menu_width <
101 ? ( mon->w / 100.0f ) * ( float ) config.menu_width : config.menu_width;
// Compensate for border width. // Compensate for border width.
state->w -= config.menu_bw * 2; state->w -= config.menu_bw * 2;
} }
@ -424,7 +419,8 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea
if ( state->columns > 0 ) { if ( state->columns > 0 ) {
state->element_width = state->w - ( 2 * ( config.padding ) ); state->element_width = state->w - ( 2 * ( config.padding ) );
// Divide by the # columns // Divide by the # columns
state->element_width = ( state->element_width - ( state->columns - 1 ) * config.line_margin ) / state->columns; state->element_width =
( state->element_width - ( state->columns - 1 ) * config.line_margin ) / state->columns;
} }
} }
@ -711,26 +707,27 @@ static void menu_mouse_navigation ( MenuState *state, XButtonEvent *xbe )
} }
} }
static void menu_refilter ( MenuState *state, char **lines, int sorting, int case_sensitive ) static void menu_refilter ( MenuState *state )
{ {
if ( strlen ( state->text->text ) > 0 ) { if ( strlen ( state->text->text ) > 0 ) {
unsigned int j = 0; unsigned int j = 0;
char **tokens = tokenize ( state->text->text, case_sensitive ); char **tokens = tokenize ( state->text->text, config.case_sensitive );
// input changed // input changed
for ( unsigned int i = 0; i < state->num_lines; i++ ) { for ( unsigned int i = 0; i < state->num_lines; i++ ) {
int match = state->sw->token_match ( tokens, lines[i], case_sensitive, i, state->sw ); int match = state->sw->token_match ( tokens, state->lines[i], config.case_sensitive, i,
state->sw );
// If each token was matched, add it to list. // If each token was matched, add it to list.
if ( match ) { if ( match ) {
state->line_map[j] = i; state->line_map[j] = i;
if ( sorting ) { if ( config.levenshtein_sort ) {
state->distance[i] = levenshtein ( state->text->text, lines[i] ); state->distance[i] = levenshtein ( state->text->text, state->lines[i] );
} }
j++; j++;
} }
} }
if ( sorting ) { if ( config.levenshtein_sort ) {
g_qsort_with_data ( state->line_map, j, sizeof ( int ), lev_sort, state->distance ); g_qsort_with_data ( state->line_map, j, sizeof ( int ), lev_sort, state->distance );
} }
@ -823,8 +820,10 @@ static void menu_draw ( MenuState *state )
{ {
TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT; TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT;
int fstate = 0; int fstate = 0;
const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw, &fstate ); const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw,
TextBoxFontType tbft = fstate | ( ( i + offset ) == state->selected ? HIGHLIGHT : type ); &fstate );
TextBoxFontType tbft = fstate |
( ( i + offset ) == state->selected ? HIGHLIGHT : type );
textbox_font ( state->boxes[i], tbft ); textbox_font ( state->boxes[i], tbft );
textbox_text ( state->boxes[i], text ); textbox_text ( state->boxes[i], text );
} }
@ -910,10 +909,8 @@ static void menu_paste ( MenuState *state, XSelectionEvent *xse )
static void menu_resize ( MenuState *state ) static void menu_resize ( MenuState *state )
{ {
if ( state->scrollbar ) { unsigned int sbw = config.line_margin + 8;
unsigned int sbw = config.line_margin + 8; scrollbar_move ( state->scrollbar, state->w - config.padding - sbw, state->top_offset );
XMoveWindow ( display, state->scrollbar->window, state->w - config.padding - sbw, state->top_offset );
}
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
int width = ( state->w - ( 2 * ( config.padding ) + int width = ( state->w - ( 2 * ( config.padding ) +
( num_switchers - 1 ) * config.line_margin ) ) / num_switchers; ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
@ -931,7 +928,8 @@ static void menu_resize ( MenuState *state )
*/ */
{ {
unsigned int last_length = state->max_elements; unsigned int last_length = state->max_elements;
int element_height = state->line_height * config.element_height + config.line_margin; int element_height = state->line_height * config.element_height +
config.line_margin;
// Calculated new number of boxes. // Calculated new number of boxes.
unsigned int h = ( state->h - state->top_offset ); unsigned int h = ( state->h - state->top_offset );
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
@ -958,8 +956,6 @@ static void menu_resize ( MenuState *state )
( state->max_rows ) * ( element_height ) - config.line_margin ); ( state->max_rows ) * ( element_height ) - config.line_margin );
} }
state->rchanged = TRUE; state->rchanged = TRUE;
state->update = TRUE; state->update = TRUE;
} }
@ -1096,11 +1092,14 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
} }
if ( !config.hide_scrollbar ) { if ( !config.hide_scrollbar ) {
unsigned int sbw = config.line_margin + 8; unsigned int sbw = config.line_margin + 8;
state.scrollbar = scrollbar_create ( main_window, &vinfo, map, state.scrollbar = scrollbar_create (
state.w - config.padding - sbw, main_window, &vinfo, map,
state.top_offset, state.w - config.padding - sbw,
sbw, state.top_offset,
( state.max_rows - 1 ) * ( element_height + config.line_margin ) + element_height ); sbw,
( state.max_rows -
1 ) *
( element_height + config.line_margin ) + element_height );
} }
@ -1113,7 +1112,8 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
// resize window vertically to suit // resize window vertically to suit
// Subtract the margin of the last row. // Subtract the margin of the last row.
state.h = state.top_offset + ( element_height + config.line_margin ) * ( state.max_rows ) - config.line_margin; state.h = state.top_offset +
( element_height + config.line_margin ) * ( state.max_rows ) - config.line_margin;
state.h += config.padding; state.h += config.padding;
state.h += 0; state.h += 0;
// Add entry // Add entry
@ -1130,12 +1130,17 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
calculate_window_position ( &state, &mon ); calculate_window_position ( &state, &mon );
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
int width = ( state.w - ( 2 * ( config.padding ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers; int width =
( state.w -
( 2 * ( config.padding ) +
( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
for ( unsigned int j = 0; j < num_switchers; j++ ) { for ( unsigned int j = 0; j < num_switchers; j++ ) {
switchers[j].tb = textbox_create ( main_window, &vinfo, map, TB_CENTER, switchers[j].tb = textbox_create ( main_window, &vinfo, map, TB_CENTER,
config.padding + j * ( width + config.line_margin ), config.padding + j * ( width + config.line_margin ),
state.h - state.line_height - config.padding, state.h - state.line_height - config.padding,
width, state.line_height, ( j == curr_switcher ) ? HIGHLIGHT : NORMAL, switchers[j].sw->name ); width, state.line_height,
( j == curr_switcher ) ? HIGHLIGHT : NORMAL,
switchers[j].sw->name );
textbox_show ( switchers[j].tb ); textbox_show ( switchers[j].tb );
} }
} }
@ -1149,9 +1154,11 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
state.selected = 0; state.selected = 0;
state.quit = FALSE; state.quit = FALSE;
menu_refilter ( &state, state.lines, config.levenshtein_sort, config.case_sensitive ); menu_refilter ( &state );
for ( unsigned int i = 0; ( *( state.selected_line ) ) < UINT32_MAX && !state.selected && i < state.filtered_lines; i++ ) { for ( unsigned int i = 0;
( *( state.selected_line ) ) < UINT32_MAX && !state.selected && i < state.filtered_lines;
i++ ) {
if ( state.line_map[i] == *( state.selected_line ) ) { if ( state.line_map[i] == *( state.selected_line ) ) {
state.selected = i; state.selected = i;
break; break;
@ -1181,7 +1188,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
// If not in lazy mode, refilter. // If not in lazy mode, refilter.
if ( state.num_lines <= config.lazy_filter_limit ) { if ( state.num_lines <= config.lazy_filter_limit ) {
if ( state.refilter ) { if ( state.refilter ) {
menu_refilter ( &state, state.lines, config.levenshtein_sort, config.case_sensitive ); menu_refilter ( &state );
menu_update ( &state ); menu_update ( &state );
} }
} }
@ -1189,7 +1196,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
// When timeout (and in lazy filter mode) // When timeout (and in lazy filter mode)
// We refilter then loop back and wait for Xevent. // We refilter then loop back and wait for Xevent.
if ( state.refilter ) { if ( state.refilter ) {
menu_refilter ( &state, state.lines, config.levenshtein_sort, config.case_sensitive ); menu_refilter ( &state );
menu_update ( &state ); menu_update ( &state );
} }
} }
@ -1257,11 +1264,13 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
// Handling of paste // Handling of paste
if ( abe_test_action ( PASTE_PRIMARY, ev.xkey.state, key ) ) { if ( abe_test_action ( PASTE_PRIMARY, ev.xkey.state, key ) ) {
XConvertSelection ( display, XA_PRIMARY, XConvertSelection ( display, XA_PRIMARY,
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime ); netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window,
CurrentTime );
} }
else if ( abe_test_action ( PASTE_SECONDARY, ev.xkey.state, key ) ) { else if ( abe_test_action ( PASTE_SECONDARY, ev.xkey.state, key ) ) {
XConvertSelection ( display, netatoms[CLIPBOARD], XConvertSelection ( display, netatoms[CLIPBOARD],
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime ); netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window,
CurrentTime );
} }
else if ( abe_test_action ( MODE_PREVIOUS, ev.xkey.state, key ) ) { else if ( abe_test_action ( MODE_PREVIOUS, ev.xkey.state, key ) ) {
state.retv = MENU_PREVIOUS; state.retv = MENU_PREVIOUS;
@ -1433,13 +1442,14 @@ void error_dialog ( const char *msg, int markup )
menu_calculate_window_and_element_width ( &state, &mon ); menu_calculate_window_and_element_width ( &state, &mon );
state.max_elements = 0; state.max_elements = 0;
state.text = textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT + ( ( markup ) ? TB_MARKUP : 0 ), state.text =
( config.padding ), textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT + ( ( markup ) ? TB_MARKUP : 0 ),
( config.padding ), ( config.padding ),
( state.w - ( 2 * ( config.padding ) ) ), ( config.padding ),
1, ( state.w - ( 2 * ( config.padding ) ) ),
NORMAL, 1,
( msg != NULL ) ? msg : "" ); NORMAL,
( msg != NULL ) ? msg : "" );
textbox_show ( state.text ); textbox_show ( state.text );
state.line_height = textbox_get_height ( state.text ); state.line_height = textbox_get_height ( state.text );
@ -1615,7 +1625,10 @@ static void handle_keypress ( XEvent *ev )
run_switcher ( index ); run_switcher ( index );
} }
else { else {
fprintf ( stderr, "Warning: Unhandled keypress in global keyhandler, keycode = %u mask = %u\n", ev->xkey.keycode, ev->xkey.state ); fprintf ( stderr,
"Warning: Unhandled keypress in global keyhandler, keycode = %u mask = %u\n",
ev->xkey.keycode,
ev->xkey.state );
} }
} }
@ -1700,7 +1713,8 @@ static void setup_switchers ( void )
token != NULL; token != NULL;
token = strtok_r ( NULL, ",", &savept ) ) { token = strtok_r ( NULL, ",", &savept ) ) {
// Resize and add entry. // Resize and add entry.
switchers = (Mode *) g_realloc ( switchers, sizeof ( Mode ) * ( num_switchers + 1 ) ); switchers =
(Mode *) g_realloc ( switchers, sizeof ( Mode ) * ( num_switchers + 1 ) );
switchers[num_switchers].tb = NULL; switchers[num_switchers].tb = NULL;
// Window switcher. // Window switcher.
@ -1794,7 +1808,8 @@ static int grab_global_keybindings ()
int key_bound = FALSE; int key_bound = FALSE;
for ( unsigned int i = 0; i < num_switchers; i++ ) { for ( unsigned int i = 0; i < num_switchers; i++ ) {
if ( switchers[i].sw->keystr != NULL ) { 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 ) { if ( switchers[i].sw->keysym != NoSymbol ) {
x11_grab_key ( display, switchers[i].sw->modmask, switchers[i].sw->keysym ); x11_grab_key ( display, switchers[i].sw->modmask, switchers[i].sw->keysym );
key_bound = TRUE; key_bound = TRUE;
@ -1834,7 +1849,9 @@ static void reload_configuration ()
XCloseDisplay ( temp_display ); XCloseDisplay ( temp_display );
} }
else { else {
fprintf ( stderr, "Failed to get a new connection to the X11 server. No point in continuing.\n" ); fprintf (
stderr,
"Failed to get a new connection to the X11 server. No point in continuing.\n" );
abort (); abort ();
} }
} }
@ -2128,7 +2145,8 @@ int main ( int argc, char *argv[] )
else{ else{
// Daemon mode, Listen to key presses.. // Daemon mode, Listen to key presses..
if ( !grab_global_keybindings () ) { if ( !grab_global_keybindings () ) {
fprintf ( stderr, "Rofi was launched in daemon mode, but no key-binding was specified.\n" ); fprintf ( stderr,
"Rofi was launched in daemon mode, but no key-binding was specified.\n" );
fprintf ( stderr, "Please check the manpage on how to specify a key-binding.\n" ); 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" ); fprintf ( stderr, "The following modi are enabled and keys can be specified:\n" );
for ( unsigned int i = 0; i < num_switchers; i++ ) { for ( unsigned int i = 0; i < num_switchers; i++ ) {

View file

@ -56,8 +56,11 @@ scrollbar *scrollbar_create ( Window parent, XVisualInfo *vinfo, Colormap map,
attr.colormap = map; attr.colormap = map;
attr.border_pixel = color_border ( display ); attr.border_pixel = color_border ( display );
attr.background_pixel = color_background ( display ); attr.background_pixel = color_background ( display );
sb->window = XCreateWindow ( display, sb->parent, sb->x, sb->y, sb->w, sb->h, 0, vinfo->depth, sb->window =
InputOutput, vinfo->visual, CWColormap | CWBorderPixel | CWBackPixel, &attr ); 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 ); XSelectInput ( display, sb->window, ExposureMask | ButtonPressMask | Button1MotionMask );
sb->gc = XCreateGC ( display, sb->window, 0, 0 ); sb->gc = XCreateGC ( display, sb->window, 0, 0 );
@ -128,21 +131,31 @@ void scrollbar_draw ( scrollbar *sb )
// Redraw base window // Redraw base window
XClearWindow ( display, sb->window ); XClearWindow ( display, sb->window );
// Paint the handle. // 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 ) void scrollbar_resize ( scrollbar *sb, int w, int h )
{ {
if ( sb != NULL ) { if ( sb != NULL ) {
if(h > 0 ) { if ( h > 0 ) {
sb->h = h; sb->h = h;
} }
if(w > 0 ) { if ( w > 0 ) {
sb->w = w; sb->w = w;
} }
XResizeWindow ( display, sb->window, sb->w, sb->h ); XResizeWindow ( display, sb->window, sb->w, sb->h );
} }
} }
void scrollbar_move ( scrollbar *sb, int x, int y )
{
if ( sb != NULL ) {
sb->x = x;
sb->y = y;
XMoveWindow ( display, sb->window, x, y );
}
}
unsigned int scrollbar_clicked ( scrollbar *sb, int y ) unsigned int scrollbar_clicked ( scrollbar *sb, int y )
{ {

View file

@ -110,8 +110,11 @@ textbox* textbox_create ( Window parent,
attr.colormap = map; attr.colormap = map;
attr.border_pixel = cp; attr.border_pixel = cp;
attr.background_pixel = cp; attr.background_pixel = cp;
tb->window = XCreateWindow ( display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, vinfo->depth, tb->window =
InputOutput, vinfo->visual, CWColormap | CWBorderPixel | CWBackPixel, &attr ); 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 ); PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font );
pango_layout_set_font_description ( tb->layout, pfd ); pango_layout_set_font_description ( tb->layout, pfd );
@ -135,7 +138,10 @@ textbox* textbox_create ( Window parent,
// edit mode controls // edit mode controls
if ( tb->flags & TB_EDITABLE ) { if ( tb->flags & TB_EDITABLE ) {
tb->xim = XOpenIM ( display, NULL, NULL, NULL ); 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 { else {
XSelectInput ( display, tb->window, ButtonPressMask ); XSelectInput ( display, tb->window, ButtonPressMask );
@ -688,7 +694,8 @@ static void parse_color ( Visual *visual, Colormap colormap,
} }
} }
} }
static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const char *str, RowColor *color ) static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const char *str,
RowColor *color )
{ {
if ( str == NULL ) { if ( str == NULL ) {
return; return;
@ -697,7 +704,9 @@ static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const
char *endp; char *endp;
char *token; char *token;
int index = 0; 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 ) switch ( index )
{ {
case 0: case 0:
@ -707,7 +716,8 @@ static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->fg ), "white" ); parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->fg ), "white" );
break; break;
case 2: 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; break;
case 3: case 3:
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlbg ), "black" ); parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlbg ), "black" );
@ -734,23 +744,38 @@ void textbox_setup ( XVisualInfo *visual, Colormap colormap )
config.color_active, &( colors[ACTIVE] ) ); config.color_active, &( colors[ACTIVE] ) );
} }
else { else {
parse_color ( visual_info->visual, target_colormap, config.menu_bg, &( colors[NORMAL].bg ), "black" ); parse_color ( visual_info->visual, target_colormap, config.menu_bg, &( colors[NORMAL].bg ),
parse_color ( visual_info->visual, target_colormap, config.menu_fg, &( colors[NORMAL].fg ), "white" ); "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt, &( colors[NORMAL].bgalt ), "black" ); parse_color ( visual_info->visual, target_colormap, config.menu_fg, &( colors[NORMAL].fg ),
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg, &( colors[NORMAL].hlfg ), "white" ); "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_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_bg_urgent,
parse_color ( visual_info->visual, target_colormap, config.menu_fg_urgent, &( colors[URGENT].fg ), "white" ); &( colors[URGENT].bg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt, &( colors[URGENT].bgalt ), "black" ); parse_color ( visual_info->visual, target_colormap, config.menu_fg_urgent,
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg_urgent, &( colors[URGENT].hlfg ), "white" ); &( colors[URGENT].fg ), "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_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_bg_active,
parse_color ( visual_info->visual, target_colormap, config.menu_fg_active, &( colors[ACTIVE].fg ), "white" ); &( colors[ACTIVE].bg ), "black" );
parse_color ( visual_info->visual, target_colormap, config.menu_bg_alt, &( colors[ACTIVE].bgalt ), "black" ); parse_color ( visual_info->visual, target_colormap, config.menu_fg_active,
parse_color ( visual_info->visual, target_colormap, config.menu_hlfg_active, &( colors[ACTIVE].hlfg ), "white" ); &( colors[ACTIVE].fg ), "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_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 ) ); 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 );
@ -835,7 +860,8 @@ int textbox_get_estimated_char_height ( void )
// Get width // Get width
PangoFontMetrics *metric = pango_context_get_metrics ( p_context, pfd, NULL ); 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_metrics_unref ( metric );
pango_font_description_free ( pfd ); pango_font_description_free ( pfd );

View file

@ -44,8 +44,13 @@
#include <X11/extensions/Xinerama.h> #include <X11/extensions/Xinerama.h>
#include <rofi.h> #include <rofi.h>
#define OVERLAP( a, b, c, d ) ( ( ( a ) == ( c ) && ( b ) == ( d ) ) || MIN ( ( a ) + ( b ), ( c ) + ( d ) ) - MAX ( ( a ), ( c ) ) > 0 ) #define OVERLAP( a, b, c, \
#define INTERSECT( x, y, w, h, x1, y1, w1, h1 ) ( OVERLAP ( ( x ), ( w ), ( x1 ), ( w1 ) ) && OVERLAP ( ( y ), ( h ), ( y1 ), ( h1 ) ) ) d ) ( ( ( a ) == ( c ) && \
( b ) == ( d ) ) || \
MIN ( ( a ) + ( b ), ( c ) + ( d ) ) - MAX ( ( a ), ( c ) ) > 0 )
#define INTERSECT( x, y, w, h, x1, y1, w1, \
h1 ) ( OVERLAP ( ( x ), ( w ), ( x1 ), \
( w1 ) ) && OVERLAP ( ( y ), ( h ), ( y1 ), ( h1 ) ) )
#include "x11-helper.h" #include "x11-helper.h"
Atom netatoms[NUM_NETATOMS]; Atom netatoms[NUM_NETATOMS];
@ -64,7 +69,8 @@ int window_get_prop ( Display *display, Window w, Atom prop,
memset ( buffer, 0, bytes ); memset ( buffer, 0, bytes );
if ( XGetWindowProperty ( display, w, prop, 0, bytes / 4, False, AnyPropertyType, type, if ( XGetWindowProperty ( display, w, prop, 0, bytes / 4, False, AnyPropertyType, type,
&format, &nitems, &nbytes, &ret ) == Success && ret && *type != None && format ) { &format, &nitems, &nbytes,
&ret ) == Success && ret && *type != None && format ) {
if ( format == 8 ) { if ( format == 8 ) {
memmove ( buffer, ret, MIN ( bytes, nitems ) ); memmove ( buffer, ret, MIN ( bytes, nitems ) );
} }
@ -103,7 +109,8 @@ char* window_get_text_prop ( Display *display, Window w, Atom atom )
g_strlcpy ( res, ( char * ) prop.value, l ); g_strlcpy ( res, ( char * ) prop.value, l );
} }
} }
else if ( Xutf8TextPropertyToTextList ( display, &prop, &list, &count ) >= Success && count > 0 && *list ) { else if ( Xutf8TextPropertyToTextList ( display, &prop, &list,
&count ) >= Success && count > 0 && *list ) {
size_t l = strlen ( *list ) + 1; size_t l = strlen ( *list ) + 1;
res = g_malloc ( l ); res = g_malloc ( l );
// make clang-check happy. // make clang-check happy.
@ -124,18 +131,22 @@ int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, in
{ {
Atom type; Atom type;
int items; int items;
return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( Atom ) ) && type == XA_ATOM ? items : 0; return window_get_prop ( display, w, atom, &type, &items, list,
count * sizeof ( Atom ) ) && type == XA_ATOM ? items : 0;
} }
void window_set_atom_prop ( Display *display, Window w, Atom prop, Atom *atoms, int count ) void window_set_atom_prop ( Display *display, Window w, Atom prop, Atom *atoms, int count )
{ {
XChangeProperty ( display, w, prop, XA_ATOM, 32, PropModeReplace, ( unsigned char * ) atoms, count ); XChangeProperty ( display, w, prop, XA_ATOM, 32, PropModeReplace, ( unsigned char * ) atoms,
count );
} }
int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list, int count ) int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list,
int count )
{ {
Atom type; int items; Atom type; int items;
return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( unsigned long ) ) && type == XA_CARDINAL ? items : 0; return window_get_prop ( display, w, atom, &type, &items, list, count *
sizeof ( unsigned long ) ) && type == XA_CARDINAL ? items : 0;
} }
@ -176,7 +187,8 @@ void monitor_dimensions ( Display *display, Screen *screen, int x, int y, workar
if ( info ) { if ( info ) {
for ( int i = 0; i < monitors; i++ ) { for ( int i = 0; i < monitors; i++ ) {
if ( INTERSECT ( x, y, 1, 1, info[i].x_org, info[i].y_org, info[i].width, info[i].height ) ) { if ( INTERSECT ( x, y, 1, 1, info[i].x_org, info[i].y_org, info[i].width,
info[i].height ) ) {
mon->x = info[i].x_org; mon->x = info[i].x_org;
mon->y = info[i].y_org; mon->y = info[i].y_org;
mon->w = info[i].width; mon->w = info[i].width;
@ -232,7 +244,8 @@ void monitor_active ( Display *display, workarea *mon )
} }
fprintf ( stderr, "Failed to find selected monitor.\n" ); fprintf ( stderr, "Failed to find selected monitor.\n" );
} }
if ( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id, sizeof ( Window ) ) if ( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id,
sizeof ( Window ) )
&& type == XA_WINDOW && count > 0 ) { && type == XA_WINDOW && count > 0 ) {
XWindowAttributes attr; XWindowAttributes attr;
if ( XGetWindowAttributes ( display, id, &attr ) ) { if ( XGetWindowAttributes ( display, id, &attr ) ) {
@ -293,7 +306,8 @@ int take_keyboard ( Display *display, Window w )
return 1; return 1;
} }
for ( int i = 0; i < 500; i++ ) { for ( int i = 0; i < 500; i++ ) {
if ( XGrabKeyboard ( display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime ) == GrabSuccess ) { if ( XGrabKeyboard ( display, w, True, GrabModeAsync, GrabModeAsync,
CurrentTime ) == GrabSuccess ) {
return 1; return 1;
} }
usleep ( 1000 ); usleep ( 1000 );
@ -320,8 +334,10 @@ void x11_grab_key ( Display *display, unsigned int modmask, KeySym key )
XGrabKey ( display, keycode, modmask | LockMask, root, True, GrabModeAsync, GrabModeAsync ); XGrabKey ( display, keycode, modmask | LockMask, root, True, GrabModeAsync, GrabModeAsync );
if ( NumlockMask ) { if ( NumlockMask ) {
XGrabKey ( display, keycode, modmask | NumlockMask, root, True, GrabModeAsync, GrabModeAsync ); XGrabKey ( display, keycode, modmask | NumlockMask, root, True, GrabModeAsync,
XGrabKey ( display, keycode, modmask | NumlockMask | LockMask, root, True, GrabModeAsync, GrabModeAsync ); GrabModeAsync );
XGrabKey ( display, keycode, modmask | NumlockMask | LockMask, root, True, GrabModeAsync,
GrabModeAsync );
} }
} }
@ -483,7 +499,8 @@ void create_visual_and_colormap ( Display *display )
// Try to create TrueColor map // Try to create TrueColor map
if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) { if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) {
// Visual found, lets try to create map. // Visual found, lets try to create map.
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone ); map = XCreateColormap ( display, DefaultRootWindow (
display ), vinfo.visual, AllocNone );
truecolor = TRUE; truecolor = TRUE;
} }
// Failed to create map. // Failed to create map.

View file

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

View file

@ -27,7 +27,8 @@ int main ( int argc, char ** argv )
cmd_set_arguments ( argc, argv ); cmd_set_arguments ( argc, argv );
char **list = NULL; char **list = NULL;
int llength = 0; int llength = 0;
char * test_str = "{host} {terminal} -e bash -c \"{ssh-client} {host}; echo '{terminal} {host}'\""; char * test_str =
"{host} {terminal} -e bash -c \"{ssh-client} {host}; echo '{terminal} {host}'\"";
helper_parse_setup ( test_str, &list, &llength, "{host}", "chuck", helper_parse_setup ( test_str, &list, &llength, "{host}", "chuck",
"{terminal}", "x-terminal-emulator", NULL ); "{terminal}", "x-terminal-emulator", NULL );

View file

@ -87,7 +87,10 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
// Set alternate row to normal row. // Set alternate row to normal row.
config.menu_bg_alt = config.menu_bg; config.menu_bg_alt = config.menu_bg;
textbox_setup ( &vinfo, map ); textbox_setup ( &vinfo, map );
textbox *box = textbox_create ( mw, &vinfo, map, TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1, NORMAL, "test" ); textbox *box =
textbox_create ( mw, &vinfo, map, TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1,
NORMAL,
"test" );
TASSERT ( box != NULL ); TASSERT ( box != NULL );
textbox_cursor_end ( box ); textbox_cursor_end ( box );