mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Some cleanups, tweak uncrustify.
This commit is contained in:
parent
4c970fe4da
commit
442e235c24
19 changed files with 491 additions and 255 deletions
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# My favorite format
|
||||
#
|
||||
|
||||
code_width = 100
|
||||
indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs
|
||||
input_tab_size = 8 # original tab size
|
||||
output_tab_size = 4 # new tab size
|
||||
|
|
|
@ -76,7 +76,8 @@ typedef enum
|
|||
*
|
||||
* @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.
|
||||
|
@ -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,
|
||||
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
|
||||
*
|
||||
|
@ -272,8 +274,10 @@ struct _Switcher
|
|||
*/
|
||||
void ( *init )( struct _Switcher *sw );
|
||||
char ** ( *get_data )( unsigned int *length, struct _Switcher *pd );
|
||||
int ( *match )( char **tokens, const char *input, int case_sensitive, int index, struct _Switcher *data );
|
||||
SwitcherMode ( *result )( int menu_retv, char **input, unsigned int selected_line, struct _Switcher *pd );
|
||||
int ( *match )( char **tokens, const char *input, int case_sensitive, int index,
|
||||
struct _Switcher *data );
|
||||
SwitcherMode ( *result )( int menu_retv, char **input, unsigned int selected_line,
|
||||
struct _Switcher *pd );
|
||||
void ( *destroy )( struct _Switcher *pd );
|
||||
// Token match.
|
||||
menu_match_cb token_match;
|
||||
|
|
|
@ -98,4 +98,13 @@ unsigned int scrollbar_clicked ( scrollbar *sb, int y );
|
|||
* Resize the scrollbar.
|
||||
*/
|
||||
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
|
||||
|
|
|
@ -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 );
|
||||
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 );
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -156,7 +156,8 @@ static void combi_mode_destroy ( Switcher *sw )
|
|||
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;
|
||||
|
||||
|
@ -192,11 +193,13 @@ 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->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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* 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++ ) {
|
||||
if ( format[i] == 'i' ) {
|
||||
|
@ -330,8 +331,11 @@ 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,7 +353,9 @@ 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.
|
||||
|
@ -370,7 +376,9 @@ 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 );
|
||||
|
|
|
@ -159,7 +159,8 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
|
|||
( *length )++;
|
||||
}
|
||||
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.)
|
||||
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 );
|
||||
|
||||
|
@ -258,7 +261,9 @@ static char ** get_apps ( unsigned int *length )
|
|||
|
||||
|
||||
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;
|
||||
( *length ) -= removed;
|
||||
|
@ -293,7 +298,8 @@ static char ** run_mode_get_data ( unsigned int *length, Switcher *sw )
|
|||
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;
|
||||
SwitcherMode retv = MODE_EXIT;
|
||||
|
|
|
@ -66,7 +66,8 @@ static char **get_script_output ( const char *command, unsigned int *length )
|
|||
( *length )++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
SwitcherMode retv = MODE_EXIT;
|
||||
|
@ -178,7 +180,8 @@ 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 );
|
||||
}
|
||||
|
|
|
@ -261,7 +261,9 @@ 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 );
|
||||
|
||||
|
@ -293,7 +295,8 @@ static char ** ssh_mode_get_data ( unsigned int *length, Switcher *sw )
|
|||
*length = rmpd->cmd_list_length;
|
||||
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;
|
||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
||||
|
|
|
@ -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->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 ) {
|
||||
|
@ -282,7 +284,8 @@ 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 );
|
||||
|
@ -398,7 +401,8 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
|
|||
|
||||
// Get the current desktop.
|
||||
unsigned long current_desktop = 0;
|
||||
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_CURRENT_DESKTOP], ¤t_desktop, 1 ) ) {
|
||||
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_CURRENT_DESKTOP],
|
||||
¤t_desktop, 1 ) ) {
|
||||
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.
|
||||
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 ) {
|
||||
sprintf ( pattern, "%%-%ds %%s", MAX ( 5, classfield ) );
|
||||
}
|
||||
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* ) );
|
||||
|
||||
|
@ -463,10 +469,13 @@ 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;
|
||||
}
|
||||
|
@ -502,7 +511,9 @@ static char ** window_mode_get_data ( unsigned int *length, Switcher *sw )
|
|||
{
|
||||
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;
|
||||
SwitcherMode retv = MODE_EXIT;
|
||||
|
|
|
@ -449,34 +449,43 @@ void remove_pid_file ( int fd )
|
|||
void config_sanity_check ( )
|
||||
{
|
||||
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 ) {
|
||||
g_string_append_printf ( msg, "\t<b>config.element_height</b>=%d is invalid. An element needs to be atleast 1 line high.\n",
|
||||
config.element_height );
|
||||
g_string_append_printf (
|
||||
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;
|
||||
found_error = TRUE;
|
||||
}
|
||||
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",
|
||||
config.menu_columns );
|
||||
g_string_append_printf (
|
||||
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;
|
||||
found_error = TRUE;
|
||||
}
|
||||
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;
|
||||
found_error = TRUE;
|
||||
}
|
||||
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",
|
||||
config.location, WL_CENTER, WL_WEST );
|
||||
g_string_append_printf (
|
||||
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;
|
||||
found_error = 1;
|
||||
}
|
||||
if ( 0 ) {
|
||||
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",
|
||||
config.line_margin, 0, 50 );
|
||||
g_string_append_printf (
|
||||
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;
|
||||
found_error = 1;
|
||||
}
|
||||
|
|
112
source/keyb.c
112
source/keyb.c
|
@ -34,36 +34,63 @@ extern unsigned int NumlockMask;
|
|||
*/
|
||||
DefaultBinding bindings[NUM_ABE] =
|
||||
{
|
||||
{ .id = PASTE_PRIMARY, .name = "kb-primary-paste", .keybinding = "Control+Shift+v,Shift+Insert", },
|
||||
{ .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = "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 = PASTE_PRIMARY, .name = "kb-primary-paste",
|
||||
.keybinding =
|
||||
"Control+Shift+v,Shift+Insert", },
|
||||
{ .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding =
|
||||
"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_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_FORWARD, .name = "kb-move-char-forward", .keybinding = "Right,Control+f" },
|
||||
{ .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = "Control+Alt+h", },
|
||||
{ .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = "Control+Alt+d", },
|
||||
{ .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", },
|
||||
{ .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", },
|
||||
{ .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", },
|
||||
{ .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return", },
|
||||
{ .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 = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding =
|
||||
"Left,Control+b" },
|
||||
{ .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding =
|
||||
"Right,Control+f" },
|
||||
{ .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding =
|
||||
"Control+Alt+h", },
|
||||
{ .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding =
|
||||
"Control+Alt+d", },
|
||||
{ .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding =
|
||||
"Delete,Control+d", },
|
||||
{ .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding =
|
||||
"BackSpace,Control+h", },
|
||||
{ .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding =
|
||||
"Control+j,Control+m,Return,KP_Enter", },
|
||||
{ .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding =
|
||||
"Control+Return", },
|
||||
{ .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 = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up" },
|
||||
{ .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down" },
|
||||
{ .id = ROW_FIRST, .name = "kb-row-first", .keybinding = "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 = PAGE_NEXT, .name = "kb-page-next", .keybinding =
|
||||
"Page_Down" },
|
||||
{ .id = ROW_FIRST, .name = "kb-row-first", .keybinding =
|
||||
"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 = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1" },
|
||||
{ .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_9, .name = "kb-custom-9", .keybinding = "Alt+9" },
|
||||
{ .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0" },
|
||||
{ .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = "Alt+Shift+1" },
|
||||
{ .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = "Alt+Shift+2" },
|
||||
{ .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = "Alt+Shift+3" },
|
||||
{ .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = "Alt+Shift+4" },
|
||||
{ .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" },
|
||||
{ .id = CUSTOM_11, .name = "kb-custom-11", .keybinding =
|
||||
"Alt+Shift+1" },
|
||||
{ .id = CUSTOM_12, .name = "kb-custom-12", .keybinding =
|
||||
"Alt+Shift+2" },
|
||||
{ .id = CUSTOM_13, .name = "kb-custom-13", .keybinding =
|
||||
"Alt+Shift+3" },
|
||||
{ .id = CUSTOM_14, .name = "kb-custom-14", .keybinding =
|
||||
"Alt+Shift+4" },
|
||||
{ .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;
|
||||
|
||||
// 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++;
|
||||
|
|
162
source/rofi.c
162
source/rofi.c
|
@ -54,8 +54,7 @@
|
|||
#include "x11-helper.h"
|
||||
#include "xrmoptions.h"
|
||||
#include "dialogs/dialogs.h"
|
||||
//
|
||||
// TEMP
|
||||
|
||||
SwitcherMode switcher_run ( char **input, Switcher *sw );
|
||||
|
||||
typedef enum _MainLoopEvent
|
||||
|
@ -63,34 +62,30 @@ typedef enum _MainLoopEvent
|
|||
ML_XEVENT,
|
||||
ML_TIMEOUT
|
||||
} MainLoopEvent;
|
||||
typedef struct _Mode
|
||||
{
|
||||
Switcher *sw;
|
||||
textbox *tb;
|
||||
} Mode;
|
||||
|
||||
// Pidfile.
|
||||
extern Atom netatoms[NUM_NETATOMS];
|
||||
char *pidfile = NULL;
|
||||
const char *cache_dir = NULL;
|
||||
SnDisplay *sndisplay = NULL;
|
||||
SnLauncheeContext *sncontext = NULL;
|
||||
Display *display = NULL;
|
||||
char *display_str = NULL;
|
||||
|
||||
extern Atom netatoms[NUM_NETATOMS];
|
||||
Window main_window = None;
|
||||
GC gc = NULL;
|
||||
Colormap map = None;
|
||||
XVisualInfo vinfo;
|
||||
|
||||
unsigned int normal_window_mode = FALSE;
|
||||
|
||||
typedef struct _Mode
|
||||
{
|
||||
Switcher *sw;
|
||||
textbox *tb;
|
||||
} Mode;
|
||||
// Array of switchers.
|
||||
Mode *switchers = NULL;
|
||||
// Number of switchers.
|
||||
unsigned int num_switchers = 0;
|
||||
Mode *switchers = NULL;
|
||||
unsigned int num_switchers = 0;
|
||||
// Current selected switcher.
|
||||
unsigned int curr_switcher = 0;
|
||||
unsigned int curr_switcher = 0;
|
||||
XVisualInfo vinfo;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
// If not, wait for timeout.
|
||||
struct timeval tv;
|
||||
struct timeval tv = { .tv_usec = 200000, .tv_sec = 0 };
|
||||
fd_set in_fds;
|
||||
// Create a File Description Set containing x11_fd
|
||||
FD_ZERO ( &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
|
||||
if ( select ( x11_fd + 1, &in_fds, 0, 0, &tv ) == 0 ) {
|
||||
return ML_TIMEOUT;
|
||||
|
@ -223,7 +215,9 @@ static Window create_window ( Display *display )
|
|||
XSetForeground ( display, gc, color_separator ( display ) );
|
||||
// make it an unmanaged window
|
||||
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 };
|
||||
XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr );
|
||||
}
|
||||
|
@ -313,11 +307,10 @@ static void menu_free_state ( MenuState *state )
|
|||
}
|
||||
|
||||
/**
|
||||
* @param x [out] the calculated x position.
|
||||
* @param y [out] the calculated y position.
|
||||
* @param state the state of the View.
|
||||
* @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 )
|
||||
{
|
||||
|
@ -363,7 +356,6 @@ static void calculate_window_position ( MenuState *state, const workarea *mon )
|
|||
|
||||
/**
|
||||
* @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
|
||||
* 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.
|
||||
state->max_rows = MIN ( state->menu_lines,
|
||||
(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 )
|
||||
) );
|
||||
// Always have at least one row.
|
||||
|
@ -388,8 +381,9 @@ static void menu_calculate_rows_columns ( MenuState *state )
|
|||
state->max_rows = state->menu_lines;
|
||||
// If it would fit in one column, only use one column.
|
||||
if ( state->num_lines < state->max_elements ) {
|
||||
state->columns = ( state->num_lines + ( state->max_rows - state->num_lines % state->max_rows ) %
|
||||
state->max_rows ) / state->max_rows;
|
||||
state->columns =
|
||||
( 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;
|
||||
}
|
||||
// Sanitize.
|
||||
|
@ -416,7 +410,8 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea
|
|||
}
|
||||
else{
|
||||
// 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.
|
||||
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 ) {
|
||||
state->element_width = state->w - ( 2 * ( config.padding ) );
|
||||
// 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 ) {
|
||||
unsigned int j = 0;
|
||||
char **tokens = tokenize ( state->text->text, case_sensitive );
|
||||
char **tokens = tokenize ( state->text->text, config.case_sensitive );
|
||||
|
||||
// input changed
|
||||
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 ( match ) {
|
||||
state->line_map[j] = i;
|
||||
if ( sorting ) {
|
||||
state->distance[i] = levenshtein ( state->text->text, lines[i] );
|
||||
if ( config.levenshtein_sort ) {
|
||||
state->distance[i] = levenshtein ( state->text->text, state->lines[i] );
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if ( sorting ) {
|
||||
if ( config.levenshtein_sort ) {
|
||||
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;
|
||||
int fstate = 0;
|
||||
const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw, &fstate );
|
||||
TextBoxFontType tbft = fstate | ( ( i + offset ) == state->selected ? HIGHLIGHT : type );
|
||||
const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw,
|
||||
&fstate );
|
||||
TextBoxFontType tbft = fstate |
|
||||
( ( i + offset ) == state->selected ? HIGHLIGHT : type );
|
||||
textbox_font ( state->boxes[i], tbft );
|
||||
textbox_text ( state->boxes[i], text );
|
||||
}
|
||||
|
@ -910,10 +909,8 @@ static void menu_paste ( MenuState *state, XSelectionEvent *xse )
|
|||
|
||||
static void menu_resize ( MenuState *state )
|
||||
{
|
||||
if ( state->scrollbar ) {
|
||||
unsigned int sbw = config.line_margin + 8;
|
||||
XMoveWindow ( display, state->scrollbar->window, state->w - config.padding - sbw, state->top_offset );
|
||||
}
|
||||
unsigned int sbw = config.line_margin + 8;
|
||||
scrollbar_move ( state->scrollbar, state->w - config.padding - sbw, state->top_offset );
|
||||
if ( config.sidebar_mode == TRUE ) {
|
||||
int width = ( state->w - ( 2 * ( config.padding ) +
|
||||
( 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;
|
||||
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.
|
||||
unsigned int h = ( state->h - state->top_offset );
|
||||
if ( config.sidebar_mode == TRUE ) {
|
||||
|
@ -958,8 +956,6 @@ static void menu_resize ( MenuState *state )
|
|||
( state->max_rows ) * ( element_height ) - config.line_margin );
|
||||
}
|
||||
|
||||
|
||||
|
||||
state->rchanged = TRUE;
|
||||
state->update = TRUE;
|
||||
}
|
||||
|
@ -1096,11 +1092,14 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
|
|||
}
|
||||
if ( !config.hide_scrollbar ) {
|
||||
unsigned int sbw = config.line_margin + 8;
|
||||
state.scrollbar = scrollbar_create ( main_window, &vinfo, map,
|
||||
state.w - config.padding - sbw,
|
||||
state.top_offset,
|
||||
sbw,
|
||||
( state.max_rows - 1 ) * ( element_height + config.line_margin ) + element_height );
|
||||
state.scrollbar = scrollbar_create (
|
||||
main_window, &vinfo, map,
|
||||
state.w - config.padding - sbw,
|
||||
state.top_offset,
|
||||
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
|
||||
// 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 += 0;
|
||||
// Add entry
|
||||
|
@ -1130,12 +1130,17 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
|
|||
calculate_window_position ( &state, &mon );
|
||||
|
||||
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++ ) {
|
||||
switchers[j].tb = textbox_create ( main_window, &vinfo, map, TB_CENTER,
|
||||
config.padding + j * ( width + config.line_margin ),
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -1149,9 +1154,11 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
|
|||
state.selected = 0;
|
||||
|
||||
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 ) ) {
|
||||
state.selected = i;
|
||||
break;
|
||||
|
@ -1181,7 +1188,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
|
|||
// If not in lazy mode, refilter.
|
||||
if ( state.num_lines <= config.lazy_filter_limit ) {
|
||||
if ( state.refilter ) {
|
||||
menu_refilter ( &state, state.lines, config.levenshtein_sort, config.case_sensitive );
|
||||
menu_refilter ( &state );
|
||||
menu_update ( &state );
|
||||
}
|
||||
}
|
||||
|
@ -1189,7 +1196,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
|
|||
// When timeout (and in lazy filter mode)
|
||||
// We refilter then loop back and wait for Xevent.
|
||||
if ( state.refilter ) {
|
||||
menu_refilter ( &state, state.lines, config.levenshtein_sort, config.case_sensitive );
|
||||
menu_refilter ( &state );
|
||||
menu_update ( &state );
|
||||
}
|
||||
}
|
||||
|
@ -1257,11 +1264,13 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
|
|||
// Handling of paste
|
||||
if ( abe_test_action ( PASTE_PRIMARY, ev.xkey.state, key ) ) {
|
||||
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 ) ) {
|
||||
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 ) ) {
|
||||
state.retv = MENU_PREVIOUS;
|
||||
|
@ -1433,13 +1442,14 @@ void error_dialog ( const char *msg, int markup )
|
|||
menu_calculate_window_and_element_width ( &state, &mon );
|
||||
state.max_elements = 0;
|
||||
|
||||
state.text = textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT + ( ( markup ) ? TB_MARKUP : 0 ),
|
||||
( config.padding ),
|
||||
( config.padding ),
|
||||
( state.w - ( 2 * ( config.padding ) ) ),
|
||||
1,
|
||||
NORMAL,
|
||||
( msg != NULL ) ? msg : "" );
|
||||
state.text =
|
||||
textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT + ( ( markup ) ? TB_MARKUP : 0 ),
|
||||
( config.padding ),
|
||||
( config.padding ),
|
||||
( state.w - ( 2 * ( config.padding ) ) ),
|
||||
1,
|
||||
NORMAL,
|
||||
( msg != NULL ) ? msg : "" );
|
||||
textbox_show ( state.text );
|
||||
state.line_height = textbox_get_height ( state.text );
|
||||
|
||||
|
@ -1615,7 +1625,10 @@ static void handle_keypress ( XEvent *ev )
|
|||
run_switcher ( index );
|
||||
}
|
||||
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 = strtok_r ( NULL, ",", &savept ) ) {
|
||||
// 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;
|
||||
|
||||
// Window switcher.
|
||||
|
@ -1794,7 +1808,8 @@ 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;
|
||||
|
@ -1834,7 +1849,9 @@ static void reload_configuration ()
|
|||
XCloseDisplay ( temp_display );
|
||||
}
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
|
@ -2128,7 +2145,8 @@ int main ( int argc, char *argv[] )
|
|||
else{
|
||||
// Daemon mode, Listen to key presses..
|
||||
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, "The following modi are enabled and keys can be specified:\n" );
|
||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
||||
|
|
|
@ -56,8 +56,11 @@ 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 );
|
||||
|
@ -128,21 +131,31 @@ 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 )
|
||||
{
|
||||
if ( sb != NULL ) {
|
||||
if(h > 0 ) {
|
||||
if ( h > 0 ) {
|
||||
sb->h = h;
|
||||
}
|
||||
if(w > 0 ) {
|
||||
if ( w > 0 ) {
|
||||
sb->w = w;
|
||||
}
|
||||
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 )
|
||||
{
|
||||
|
|
|
@ -110,8 +110,11 @@ textbox* textbox_create ( Window parent,
|
|||
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 );
|
||||
|
@ -135,7 +138,10 @@ textbox* textbox_create ( Window parent,
|
|||
// 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 );
|
||||
|
@ -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 ) {
|
||||
return;
|
||||
|
@ -697,7 +704,9 @@ 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:
|
||||
|
@ -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" );
|
||||
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" );
|
||||
|
@ -734,23 +744,38 @@ void textbox_setup ( XVisualInfo *visual, Colormap 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 );
|
||||
|
@ -835,7 +860,8 @@ 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 );
|
||||
|
|
|
@ -44,8 +44,13 @@
|
|||
#include <X11/extensions/Xinerama.h>
|
||||
|
||||
#include <rofi.h>
|
||||
#define OVERLAP( a, b, c, 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 ) ) )
|
||||
#define OVERLAP( a, b, c, \
|
||||
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"
|
||||
|
||||
Atom netatoms[NUM_NETATOMS];
|
||||
|
@ -64,7 +69,8 @@ int window_get_prop ( Display *display, Window w, Atom prop,
|
|||
memset ( buffer, 0, bytes );
|
||||
|
||||
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 ) {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
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;
|
||||
res = g_malloc ( l );
|
||||
// make clang-check happy.
|
||||
|
@ -124,18 +131,22 @@ int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, in
|
|||
{
|
||||
Atom type;
|
||||
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 )
|
||||
{
|
||||
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;
|
||||
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 ) {
|
||||
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->y = info[i].y_org;
|
||||
mon->w = info[i].width;
|
||||
|
@ -232,7 +244,8 @@ void monitor_active ( Display *display, workarea *mon )
|
|||
}
|
||||
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 ) {
|
||||
XWindowAttributes attr;
|
||||
if ( XGetWindowAttributes ( display, id, &attr ) ) {
|
||||
|
@ -293,7 +306,8 @@ int take_keyboard ( Display *display, Window w )
|
|||
return 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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 );
|
||||
|
||||
if ( NumlockMask ) {
|
||||
XGrabKey ( display, keycode, modmask | NumlockMask, root, True, GrabModeAsync, GrabModeAsync );
|
||||
XGrabKey ( display, keycode, modmask | NumlockMask | LockMask, root, True, GrabModeAsync, GrabModeAsync );
|
||||
XGrabKey ( display, keycode, modmask | NumlockMask, root, True, 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
|
||||
if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) {
|
||||
// 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;
|
||||
}
|
||||
// Failed to create map.
|
||||
|
|
|
@ -53,84 +53,146 @@ 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_SNumber, "width", { .snum = &config.menu_width },
|
||||
NULL },
|
||||
|
||||
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL },
|
||||
{ xrm_Number, "columns", { .num = &config.menu_columns }, 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.
|
||||
|
@ -173,7 +235,8 @@ static void config_parser_set ( XrmOption *option, XrmValue *xrmValue )
|
|||
*( option->value.snum ) = (int) strtol ( xrmValue->addr, NULL, 10 );
|
||||
}
|
||||
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;
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -27,7 +27,8 @@ int main ( int argc, char ** argv )
|
|||
cmd_set_arguments ( argc, argv );
|
||||
char **list = NULL;
|
||||
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",
|
||||
"{terminal}", "x-terminal-emulator", NULL );
|
||||
|
||||
|
|
|
@ -87,7 +87,10 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
|||
// Set alternate row to normal row.
|
||||
config.menu_bg_alt = config.menu_bg;
|
||||
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 );
|
||||
|
||||
textbox_cursor_end ( box );
|
||||
|
|
Loading…
Reference in a new issue